weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org) |
ggaren@apple.com | 19fe509 | 2011-05-18 02:39:00 +0000 | [diff] [blame] | 3 | * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved. |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 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" |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 24 | |
eric@webkit.org | 66cf578 | 2010-04-21 14:09:49 +0000 | [diff] [blame] | 25 | #include "Lookup.h" |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 26 | #include "NumberObject.h" |
| 27 | #include "NumberPrototype.h" |
fpizlo@apple.com | a4b4cbe | 2013-01-12 04:47:03 +0000 | [diff] [blame] | 28 | #include "Operations.h" |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 29 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 30 | namespace JSC { |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 31 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 32 | static JSValue numberConstructorNaNValue(ExecState*, JSValue, PropertyName); |
| 33 | static JSValue numberConstructorNegInfinity(ExecState*, JSValue, PropertyName); |
| 34 | static JSValue numberConstructorPosInfinity(ExecState*, JSValue, PropertyName); |
| 35 | static JSValue numberConstructorMaxValue(ExecState*, JSValue, PropertyName); |
| 36 | static JSValue numberConstructorMinValue(ExecState*, JSValue, PropertyName); |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 37 | |
| 38 | } // namespace JSC |
| 39 | |
| 40 | #include "NumberConstructor.lut.h" |
| 41 | |
| 42 | namespace JSC { |
| 43 | |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 44 | ASSERT_HAS_TRIVIAL_DESTRUCTOR(NumberConstructor); |
| 45 | |
mhahnenberg@apple.com | 3e08466 | 2011-09-26 07:05:28 +0000 | [diff] [blame] | 46 | const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::numberConstructorTable, CREATE_METHOD_TABLE(NumberConstructor) }; |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 47 | |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 48 | /* Source for NumberConstructor.lut.h |
ggaren@apple.com | 19fe509 | 2011-05-18 02:39:00 +0000 | [diff] [blame] | 49 | @begin numberConstructorTable |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 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 |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 55 | @end |
| 56 | */ |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 57 | |
mhahnenberg@apple.com | 5e10972 | 2011-09-14 18:55:25 +0000 | [diff] [blame] | 58 | NumberConstructor::NumberConstructor(JSGlobalObject* globalObject, Structure* structure) |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 59 | : InternalFunction(globalObject, structure) |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 60 | { |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void NumberConstructor::finishCreation(ExecState* exec, NumberPrototype* numberPrototype) |
| 64 | { |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 65 | Base::finishCreation(exec->globalData(), numberPrototype->s_info.className); |
barraclough@apple.com | 737a158 | 2011-02-21 19:31:42 +0000 | [diff] [blame] | 66 | ASSERT(inherits(&s_info)); |
| 67 | |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 68 | // Number.Prototype |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 69 | putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, numberPrototype, DontEnum | DontDelete | ReadOnly); |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 70 | |
| 71 | // no. of arguments for constructor |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 72 | putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete); |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 73 | } |
| 74 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 75 | bool NumberConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot) |
mhahnenberg@apple.com | 1986964 | 2011-10-08 21:31:32 +0000 | [diff] [blame] | 76 | { |
mhahnenberg@apple.com | 135f051 | 2011-11-11 20:40:10 +0000 | [diff] [blame] | 77 | return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, ExecState::numberConstructorTable(exec), jsCast<NumberConstructor*>(cell), propertyName, slot); |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 78 | } |
| 79 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 80 | bool NumberConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) |
oliver@apple.com | 4b4f785 | 2009-08-26 16:52:15 +0000 | [diff] [blame] | 81 | { |
mhahnenberg@apple.com | 135f051 | 2011-11-11 20:40:10 +0000 | [diff] [blame] | 82 | return getStaticValueDescriptor<NumberConstructor, InternalFunction>(exec, ExecState::numberConstructorTable(exec), jsCast<NumberConstructor*>(object), propertyName, descriptor); |
oliver@apple.com | 4b4f785 | 2009-08-26 16:52:15 +0000 | [diff] [blame] | 83 | } |
| 84 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 85 | void NumberConstructor::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot) |
barraclough@apple.com | 38bb997 | 2011-12-27 04:56:37 +0000 | [diff] [blame] | 86 | { |
| 87 | lookupPut<NumberConstructor, InternalFunction>(exec, propertyName, value, ExecState::numberConstructorTable(exec), jsCast<NumberConstructor*>(cell), slot); |
| 88 | } |
| 89 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 90 | static JSValue numberConstructorNaNValue(ExecState*, JSValue, PropertyName) |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 91 | { |
oliver@apple.com | 5b67d9e | 2010-10-25 22:40:53 +0000 | [diff] [blame] | 92 | return jsNaN(); |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 93 | } |
| 94 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 95 | static JSValue numberConstructorNegInfinity(ExecState*, JSValue, PropertyName) |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 96 | { |
barraclough@apple.com | f1fa579 | 2011-06-11 02:03:00 +0000 | [diff] [blame] | 97 | return jsNumber(-std::numeric_limits<double>::infinity()); |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 98 | } |
| 99 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 100 | static JSValue numberConstructorPosInfinity(ExecState*, JSValue, PropertyName) |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 101 | { |
barraclough@apple.com | f1fa579 | 2011-06-11 02:03:00 +0000 | [diff] [blame] | 102 | return jsNumber(std::numeric_limits<double>::infinity()); |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 103 | } |
| 104 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 105 | static JSValue numberConstructorMaxValue(ExecState*, JSValue, PropertyName) |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 106 | { |
oliver@apple.com | 5b67d9e | 2010-10-25 22:40:53 +0000 | [diff] [blame] | 107 | return jsNumber(1.7976931348623157E+308); |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 108 | } |
| 109 | |
barraclough@apple.com | 38d3c75 | 2012-05-12 00:39:43 +0000 | [diff] [blame] | 110 | static JSValue numberConstructorMinValue(ExecState*, JSValue, PropertyName) |
weinig@apple.com | caf5e3b | 2008-09-27 02:36:15 +0000 | [diff] [blame] | 111 | { |
oliver@apple.com | 5b67d9e | 2010-10-25 22:40:53 +0000 | [diff] [blame] | 112 | return jsNumber(5E-324); |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // ECMA 15.7.1 |
barraclough@apple.com | 11d351a | 2010-06-04 21:38:38 +0000 | [diff] [blame] | 116 | static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec) |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 117 | { |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 118 | NumberObject* object = NumberObject::create(exec->globalData(), asInternalFunction(exec->callee())->globalObject()->numberObjectStructure()); |
barraclough@apple.com | 11d351a | 2010-06-04 21:38:38 +0000 | [diff] [blame] | 119 | double n = exec->argumentCount() ? exec->argument(0).toNumber(exec) : 0; |
oliver@apple.com | 168e506 | 2011-01-31 20:07:21 +0000 | [diff] [blame] | 120 | object->setInternalValue(exec->globalData(), jsNumber(n)); |
barraclough@apple.com | 11d351a | 2010-06-04 21:38:38 +0000 | [diff] [blame] | 121 | return JSValue::encode(object); |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 122 | } |
| 123 | |
mhahnenberg@apple.com | 79c8e6e | 2011-10-08 23:26:41 +0000 | [diff] [blame] | 124 | ConstructType NumberConstructor::getConstructData(JSCell*, ConstructData& constructData) |
| 125 | { |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 126 | constructData.native.function = constructWithNumberConstructor; |
ggaren@apple.com | 9a0472b | 2008-07-28 20:04:48 +0000 | [diff] [blame] | 127 | return ConstructTypeHost; |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // ECMA 15.7.2 |
barraclough@apple.com | 99ff343 | 2010-06-03 20:00:18 +0000 | [diff] [blame] | 131 | static EncodedJSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec) |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 132 | { |
oliver@apple.com | 5b67d9e | 2010-10-25 22:40:53 +0000 | [diff] [blame] | 133 | return JSValue::encode(jsNumber(!exec->argumentCount() ? 0 : exec->argument(0).toNumber(exec))); |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 134 | } |
| 135 | |
mhahnenberg@apple.com | 2413eb8 | 2011-09-27 22:46:51 +0000 | [diff] [blame] | 136 | CallType NumberConstructor::getCallData(JSCell*, CallData& callData) |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 137 | { |
| 138 | callData.native.function = callNumberConstructor; |
ggaren@apple.com | 1914ee9 | 2008-07-18 22:18:21 +0000 | [diff] [blame] | 139 | return CallTypeHost; |
weinig@apple.com | 2ce2a7f | 2008-06-28 21:22:01 +0000 | [diff] [blame] | 140 | } |
| 141 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 142 | } // namespace JSC |