X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ef99ff287df9046eb88937225e0554eabb00e33c:/runtime/ArrayConstructor.cpp diff --git a/runtime/ArrayConstructor.cpp b/runtime/ArrayConstructor.cpp index ebcc437..4442930 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 "JSCInlines.h" namespace JSC { @@ -41,7 +44,7 @@ static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*); namespace JSC { -ASSERT_HAS_TRIVIAL_DESTRUCTOR(ArrayConstructor); +STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ArrayConstructor); const ClassInfo ArrayConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::arrayConstructorTable, CREATE_METHOD_TABLE(ArrayConstructor) }; @@ -51,46 +54,46 @@ 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) +ArrayConstructor::ArrayConstructor(VM& vm, Structure* structure) + : InternalFunction(vm, structure) { } -void ArrayConstructor::finishCreation(ExecState* exec, ArrayPrototype* arrayPrototype) +void ArrayConstructor::finishCreation(VM& vm, 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(vm, arrayPrototype->classInfo()->className); + putDirectWithoutTransition(vm, vm.propertyNames->prototype, arrayPrototype, DontEnum | DontDelete | ReadOnly); + putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete); } -bool ArrayConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot) +bool ArrayConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot) { - return getStaticFunctionSlot(exec, ExecState::arrayConstructorTable(exec), jsCast(cell), propertyName, slot); + return getStaticFunctionSlot(exec, ExecState::arrayConstructorTable(exec->vm()), jsCast(object), propertyName, slot); } -bool ArrayConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +// ------------------------------ Functions --------------------------- + +JSObject* constructArrayWithSizeQuirk(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, JSValue length) { - return getStaticFunctionDescriptor(exec, ExecState::arrayConstructorTable(exec), jsCast(object), propertyName, descriptor); + if (!length.isNumber()) + return constructArrayNegativeIndexed(exec, profile, globalObject, &length, 1); + + uint32_t n = length.toUInt32(exec); + if (n != length.toNumber(exec)) + return exec->vm().throwException(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer."))); + return constructEmptyArray(exec, profile, globalObject, n); } -// ------------------------------ Functions --------------------------- - 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) @@ -120,7 +123,7 @@ CallType ArrayConstructor::getCallData(JSCell*, CallData& callData) EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState* exec) { - return JSValue::encode(jsBoolean(exec->argument(0).inherits(&JSArray::s_info))); + return JSValue::encode(jsBoolean(exec->argument(0).inherits(JSArray::info()))); } } // namespace JSC