summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/NumberConstructor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/NumberConstructor.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/NumberConstructor.cpp110
1 files changed, 64 insertions, 46 deletions
diff --git a/Source/JavaScriptCore/runtime/NumberConstructor.cpp b/Source/JavaScriptCore/runtime/NumberConstructor.cpp
index 8e858a24f..a06378b83 100644
--- a/Source/JavaScriptCore/runtime/NumberConstructor.cpp
+++ b/Source/JavaScriptCore/runtime/NumberConstructor.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org)
- * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2011, 2015-2016 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -25,15 +25,14 @@
#include "Lookup.h"
#include "NumberObject.h"
#include "NumberPrototype.h"
-#include "Operations.h"
+#include "JSCInlines.h"
+#include "JSGlobalObjectFunctions.h"
+#include "StructureInlines.h"
namespace JSC {
-static EncodedJSValue numberConstructorNaNValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
-static EncodedJSValue numberConstructorNegInfinity(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
-static EncodedJSValue numberConstructorPosInfinity(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
-static EncodedJSValue numberConstructorMaxValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
-static EncodedJSValue numberConstructorMinValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName);
+static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsInteger(ExecState*);
+static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsSafeInteger(ExecState*);
} // namespace JSC
@@ -43,15 +42,15 @@ namespace JSC {
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NumberConstructor);
-const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::numberConstructorTable, CREATE_METHOD_TABLE(NumberConstructor) };
+const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, &numberConstructorTable, CREATE_METHOD_TABLE(NumberConstructor) };
/* Source for NumberConstructor.lut.h
@begin numberConstructorTable
- NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly
- NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly
- POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly
- MAX_VALUE numberConstructorMaxValue DontEnum|DontDelete|ReadOnly
- MIN_VALUE numberConstructorMinValue DontEnum|DontDelete|ReadOnly
+ isFinite JSBuiltin DontEnum|Function 1
+ isInteger numberConstructorFuncIsInteger DontEnum|Function 1
+ isNaN JSBuiltin DontEnum|Function 1
+ isSafeInteger numberConstructorFuncIsSafeInteger DontEnum|Function 1
+ parseFloat globalFuncParseFloat DontEnum|Function 1
@end
*/
@@ -63,58 +62,45 @@ NumberConstructor::NumberConstructor(VM& vm, Structure* structure)
void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype)
{
Base::finishCreation(vm, NumberPrototype::info()->className);
- ASSERT(inherits(info()));
+ ASSERT(inherits(vm, info()));
// Number.Prototype
putDirectWithoutTransition(vm, vm.propertyNames->prototype, numberPrototype, DontEnum | DontDelete | ReadOnly);
// no. of arguments for constructor
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
-}
-
-bool NumberConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
-{
- return getStaticValueSlot<NumberConstructor, InternalFunction>(exec, ExecState::numberConstructorTable(exec->vm()), jsCast<NumberConstructor*>(object), propertyName, slot);
-}
-
-static EncodedJSValue numberConstructorNaNValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName)
-{
- return JSValue::encode(jsNaN());
-}
-static EncodedJSValue numberConstructorNegInfinity(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName)
-{
- return JSValue::encode(jsNumber(-std::numeric_limits<double>::infinity()));
-}
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "EPSILON"), jsDoubleNumber(std::numeric_limits<double>::epsilon()), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "MAX_VALUE"), jsDoubleNumber(1.7976931348623157E+308), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "MIN_VALUE"), jsDoubleNumber(5E-324), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "MAX_SAFE_INTEGER"), jsDoubleNumber(maxSafeInteger()), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "MIN_SAFE_INTEGER"), jsDoubleNumber(minSafeInteger()), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "NEGATIVE_INFINITY"), jsDoubleNumber(-std::numeric_limits<double>::infinity()), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "POSITIVE_INFINITY"), jsDoubleNumber(std::numeric_limits<double>::infinity()), DontDelete | DontEnum | ReadOnly);
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "NaN"), jsNaN(), DontDelete | DontEnum | ReadOnly);
-static EncodedJSValue numberConstructorPosInfinity(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName)
-{
- return JSValue::encode(jsNumber(std::numeric_limits<double>::infinity()));
-}
-
-static EncodedJSValue numberConstructorMaxValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName)
-{
- return JSValue::encode(jsNumber(1.7976931348623157E+308));
-}
-
-static EncodedJSValue numberConstructorMinValue(ExecState*, EncodedJSValue, EncodedJSValue, PropertyName)
-{
- return JSValue::encode(jsNumber(5E-324));
+ putDirectWithoutTransition(vm, Identifier::fromString(&vm, "parseInt"), numberPrototype->globalObject()->parseIntFunction(), DontEnum);
}
// ECMA 15.7.1
static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec)
{
- NumberObject* object = NumberObject::create(exec->vm(), asInternalFunction(exec->callee())->globalObject()->numberObjectStructure());
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
double n = exec->argumentCount() ? exec->uncheckedArgument(0).toNumber(exec) : 0;
- object->setInternalValue(exec->vm(), jsNumber(n));
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ Structure* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), exec->lexicalGlobalObject()->numberObjectStructure());
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+
+ NumberObject* object = NumberObject::create(vm, structure);
+ object->setInternalValue(vm, jsNumber(n));
return JSValue::encode(object);
}
ConstructType NumberConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
constructData.native.function = constructWithNumberConstructor;
- return ConstructTypeHost;
+ return ConstructType::Host;
}
// ECMA 15.7.2
@@ -126,7 +112,39 @@ static EncodedJSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec)
CallType NumberConstructor::getCallData(JSCell*, CallData& callData)
{
callData.native.function = callNumberConstructor;
- return CallTypeHost;
+ return CallType::Host;
+}
+
+// ECMA-262 20.1.2.3
+static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsInteger(ExecState* exec)
+{
+ JSValue argument = exec->argument(0);
+ bool isInteger;
+ if (argument.isInt32())
+ isInteger = true;
+ else if (!argument.isDouble())
+ isInteger = false;
+ else {
+ double number = argument.asDouble();
+ isInteger = std::isfinite(number) && trunc(number) == number;
+ }
+ return JSValue::encode(jsBoolean(isInteger));
+}
+
+// ECMA-262 20.1.2.5
+static EncodedJSValue JSC_HOST_CALL numberConstructorFuncIsSafeInteger(ExecState* exec)
+{
+ JSValue argument = exec->argument(0);
+ bool isInteger;
+ if (argument.isInt32())
+ isInteger = true;
+ else if (!argument.isDouble())
+ isInteger = false;
+ else {
+ double number = argument.asDouble();
+ isInteger = trunc(number) == number && std::abs(number) <= 9007199254740991.0;
+ }
+ return JSValue::encode(jsBoolean(isInteger));
}
} // namespace JSC