X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..cb9aa2694aba0ae4f946ed34b8e0f6c99c1cfe44:/runtime/NumberConstructor.cpp diff --git a/runtime/NumberConstructor.cpp b/runtime/NumberConstructor.cpp index cc6c51d..04c5098 100644 --- a/runtime/NumberConstructor.cpp +++ b/runtime/NumberConstructor.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 1999-2000,2003 Harri Porten (porten@kde.org) - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008, 2011 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 @@ -22,18 +22,18 @@ #include "config.h" #include "NumberConstructor.h" +#include "Lookup.h" #include "NumberObject.h" #include "NumberPrototype.h" +#include "JSCInlines.h" namespace JSC { -ASSERT_CLASS_FITS_IN_CELL(NumberConstructor); - -static JSValue numberConstructorNaNValue(ExecState*, const Identifier&, const PropertySlot&); -static JSValue numberConstructorNegInfinity(ExecState*, const Identifier&, const PropertySlot&); -static JSValue numberConstructorPosInfinity(ExecState*, const Identifier&, const PropertySlot&); -static JSValue numberConstructorMaxValue(ExecState*, const Identifier&, const PropertySlot&); -static JSValue numberConstructorMinValue(ExecState*, const Identifier&, const PropertySlot&); +static EncodedJSValue numberConstructorNaNValue(ExecState*, JSObject*, EncodedJSValue, PropertyName); +static EncodedJSValue numberConstructorNegInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName); +static EncodedJSValue numberConstructorPosInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName); +static EncodedJSValue numberConstructorMaxValue(ExecState*, JSObject*, EncodedJSValue, PropertyName); +static EncodedJSValue numberConstructorMinValue(ExecState*, JSObject*, EncodedJSValue, PropertyName); } // namespace JSC @@ -41,10 +41,12 @@ static JSValue numberConstructorMinValue(ExecState*, const Identifier&, const Pr namespace JSC { -const ClassInfo NumberConstructor::info = { "Function", &InternalFunction::info, 0, ExecState::numberTable }; +STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NumberConstructor); + +const ClassInfo NumberConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::numberConstructorTable, CREATE_METHOD_TABLE(NumberConstructor) }; /* Source for NumberConstructor.lut.h -@begin numberTable +@begin numberConstructorTable NaN numberConstructorNaNValue DontEnum|DontDelete|ReadOnly NEGATIVE_INFINITY numberConstructorNegInfinity DontEnum|DontDelete|ReadOnly POSITIVE_INFINITY numberConstructorPosInfinity DontEnum|DontDelete|ReadOnly @@ -53,73 +55,75 @@ const ClassInfo NumberConstructor::info = { "Function", &InternalFunction::info, @end */ -NumberConstructor::NumberConstructor(ExecState* exec, NonNullPassRefPtr structure, NumberPrototype* numberPrototype) - : InternalFunction(&exec->globalData(), structure, Identifier(exec, numberPrototype->info.className)) +NumberConstructor::NumberConstructor(VM& vm, Structure* structure) + : InternalFunction(vm, structure) { - // Number.Prototype - putDirectWithoutTransition(exec->propertyNames().prototype, numberPrototype, DontEnum | DontDelete | ReadOnly); - - // no. of arguments for constructor - putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete); } -bool NumberConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +void NumberConstructor::finishCreation(VM& vm, NumberPrototype* numberPrototype) { - return getStaticValueSlot(exec, ExecState::numberTable(exec), this, propertyName, slot); + Base::finishCreation(vm, NumberPrototype::info()->className); + ASSERT(inherits(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::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +bool NumberConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot) { - return getStaticValueDescriptor(exec, ExecState::numberTable(exec), this, propertyName, descriptor); + return getStaticValueSlot(exec, ExecState::numberConstructorTable(exec->vm()), jsCast(object), propertyName, slot); } -static JSValue numberConstructorNaNValue(ExecState* exec, const Identifier&, const PropertySlot&) +static EncodedJSValue numberConstructorNaNValue(ExecState*, JSObject*, EncodedJSValue, PropertyName) { - return jsNaN(exec); + return JSValue::encode(jsNaN()); } -static JSValue numberConstructorNegInfinity(ExecState* exec, const Identifier&, const PropertySlot&) +static EncodedJSValue numberConstructorNegInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName) { - return jsNumber(exec, -Inf); + return JSValue::encode(jsNumber(-std::numeric_limits::infinity())); } -static JSValue numberConstructorPosInfinity(ExecState* exec, const Identifier&, const PropertySlot&) +static EncodedJSValue numberConstructorPosInfinity(ExecState*, JSObject*, EncodedJSValue, PropertyName) { - return jsNumber(exec, Inf); + return JSValue::encode(jsNumber(std::numeric_limits::infinity())); } -static JSValue numberConstructorMaxValue(ExecState* exec, const Identifier&, const PropertySlot&) +static EncodedJSValue numberConstructorMaxValue(ExecState*, JSObject*, EncodedJSValue, PropertyName) { - return jsNumber(exec, 1.7976931348623157E+308); + return JSValue::encode(jsNumber(1.7976931348623157E+308)); } -static JSValue numberConstructorMinValue(ExecState* exec, const Identifier&, const PropertySlot&) +static EncodedJSValue numberConstructorMinValue(ExecState*, JSObject*, EncodedJSValue, PropertyName) { - return jsNumber(exec, 5E-324); + return JSValue::encode(jsNumber(5E-324)); } // ECMA 15.7.1 -static JSObject* constructWithNumberConstructor(ExecState* exec, JSObject*, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructWithNumberConstructor(ExecState* exec) { - NumberObject* object = new (exec) NumberObject(exec->lexicalGlobalObject()->numberObjectStructure()); - double n = args.isEmpty() ? 0 : args.at(0).toNumber(exec); - object->setInternalValue(jsNumber(exec, n)); - return object; + NumberObject* object = NumberObject::create(exec->vm(), asInternalFunction(exec->callee())->globalObject()->numberObjectStructure()); + double n = exec->argumentCount() ? exec->uncheckedArgument(0).toNumber(exec) : 0; + object->setInternalValue(exec->vm(), jsNumber(n)); + return JSValue::encode(object); } -ConstructType NumberConstructor::getConstructData(ConstructData& constructData) +ConstructType NumberConstructor::getConstructData(JSCell*, ConstructData& constructData) { constructData.native.function = constructWithNumberConstructor; return ConstructTypeHost; } // ECMA 15.7.2 -static JSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec) { - return jsNumber(exec, args.isEmpty() ? 0 : args.at(0).toNumber(exec)); + return JSValue::encode(jsNumber(!exec->argumentCount() ? 0 : exec->uncheckedArgument(0).toNumber(exec))); } -CallType NumberConstructor::getCallData(CallData& callData) +CallType NumberConstructor::getCallData(JSCell*, CallData& callData) { callData.native.function = callNumberConstructor; return CallTypeHost;