X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..4be4e30906bcb8ee30b4d189205cb70bad6707ce:/runtime/ArrayConstructor.cpp diff --git a/runtime/ArrayConstructor.cpp b/runtime/ArrayConstructor.cpp index ebcc437..7520557 100644 --- a/runtime/ArrayConstructor.cpp +++ b/runtime/ArrayConstructor.cpp @@ -25,11 +25,14 @@ #include "ArrayConstructor.h" #include "ArrayPrototype.h" +#include "ButterflyInlines.h" +#include "CopiedSpaceInlines.h" #include "Error.h" #include "ExceptionHelpers.h" #include "JSArray.h" #include "JSFunction.h" #include "Lookup.h" +#include "Operations.h" namespace JSC { @@ -51,8 +54,6 @@ const ClassInfo ArrayConstructor::s_info = { "Function", &InternalFunction::s_in @end */ -ASSERT_CLASS_FITS_IN_CELL(ArrayConstructor); - ArrayConstructor::ArrayConstructor(JSGlobalObject* globalObject, Structure* structure) : InternalFunction(globalObject, structure) { @@ -60,37 +61,44 @@ ArrayConstructor::ArrayConstructor(JSGlobalObject* globalObject, Structure* stru void ArrayConstructor::finishCreation(ExecState* exec, ArrayPrototype* arrayPrototype) { - Base::finishCreation(exec->globalData(), Identifier(exec, arrayPrototype->classInfo()->className)); - putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly); - putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete); + Base::finishCreation(exec->vm(), arrayPrototype->classInfo()->className); + putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly); + putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(1), ReadOnly | DontEnum | DontDelete); } -bool ArrayConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot) +bool ArrayConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot &slot) { return getStaticFunctionSlot(exec, ExecState::arrayConstructorTable(exec), jsCast(cell), propertyName, slot); } -bool ArrayConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +bool ArrayConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor) { return getStaticFunctionDescriptor(exec, ExecState::arrayConstructorTable(exec), jsCast(object), propertyName, descriptor); } // ------------------------------ Functions --------------------------- +JSObject* constructArrayWithSizeQuirk(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, JSValue length) +{ + if (!length.isNumber()) + return constructArray(exec, profile, globalObject, &length, 1); + + uint32_t n = length.toUInt32(exec); + if (n != length.toNumber(exec)) + return throwError(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer."))); + return constructEmptyArray(exec, profile, globalObject, n); +} + static inline JSObject* constructArrayWithSizeQuirk(ExecState* exec, const ArgList& args) { JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject(); // a single numeric argument denotes the array size (!) - if (args.size() == 1 && args.at(0).isNumber()) { - uint32_t n = args.at(0).toUInt32(exec); - if (n != args.at(0).toNumber(exec)) - return throwError(exec, createRangeError(exec, "Array size is not a small enough positive integer.")); - return constructEmptyArray(exec, globalObject, n); - } + if (args.size() == 1) + return constructArrayWithSizeQuirk(exec, 0, globalObject, args.at(0)); // otherwise the array is constructed with the arguments in it - return constructArray(exec, globalObject, args); + return constructArray(exec, 0, globalObject, args); } static EncodedJSValue JSC_HOST_CALL constructWithArrayConstructor(ExecState* exec)