]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/ArrayConstructor.cpp
JavaScriptCore-1218.35.tar.gz
[apple/javascriptcore.git] / runtime / ArrayConstructor.cpp
index ebcc43781c6017ac457d037d7fb3e12209e9570a..7520557161481d9e4f1fe8964eed8f12eb0a635a 100644 (file)
 #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<InternalFunction>(exec, ExecState::arrayConstructorTable(exec), jsCast<ArrayConstructor*>(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<InternalFunction>(exec, ExecState::arrayConstructorTable(exec), jsCast<ArrayConstructor*>(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)