Title: [171328] trunk/Source/_javascript_Core
Revision
171328
Author
[email protected]
Date
2014-07-21 17:58:11 -0700 (Mon, 21 Jul 2014)

Log Message

Refactor ArrayPrototype to use getLength() and putLength() utility functions.
https://bugs.webkit.org/show_bug.cgi?id=135139.

Reviewed by Oliver Hunt.

- Specialize putProperty() to putLength() because it is only used for setting
  the length property.
- Added a getLength() utility function to get the value of the length property.
- Use these getLength() and putLength() functions instead of the existing code
  to get and put the length property.  Less code to read, easier to understand.

* runtime/ArrayPrototype.cpp:
(JSC::getLength):
(JSC::putLength):
(JSC::arrayProtoFuncToString):
(JSC::arrayProtoFuncToLocaleString):
(JSC::arrayProtoFuncJoin):
(JSC::arrayProtoFuncPop):
(JSC::arrayProtoFuncPush):
(JSC::arrayProtoFuncReverse):
(JSC::arrayProtoFuncShift):
(JSC::arrayProtoFuncSlice):
(JSC::arrayProtoFuncSort):
(JSC::arrayProtoFuncSplice):
(JSC::arrayProtoFuncUnShift):
(JSC::arrayProtoFuncReduce):
(JSC::arrayProtoFuncReduceRight):
(JSC::arrayProtoFuncIndexOf):
(JSC::arrayProtoFuncLastIndexOf):
(JSC::putProperty): Deleted.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (171327 => 171328)


--- trunk/Source/_javascript_Core/ChangeLog	2014-07-22 00:56:21 UTC (rev 171327)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-07-22 00:58:11 UTC (rev 171328)
@@ -1,3 +1,36 @@
+2014-07-21  Mark Lam  <[email protected]>
+
+        Refactor ArrayPrototype to use getLength() and putLength() utility functions.
+        https://bugs.webkit.org/show_bug.cgi?id=135139.
+
+        Reviewed by Oliver Hunt.
+
+        - Specialize putProperty() to putLength() because it is only used for setting
+          the length property.
+        - Added a getLength() utility function to get the value of the length property.
+        - Use these getLength() and putLength() functions instead of the existing code
+          to get and put the length property.  Less code to read, easier to understand.
+
+        * runtime/ArrayPrototype.cpp:
+        (JSC::getLength):
+        (JSC::putLength):
+        (JSC::arrayProtoFuncToString):
+        (JSC::arrayProtoFuncToLocaleString):
+        (JSC::arrayProtoFuncJoin):
+        (JSC::arrayProtoFuncPop):
+        (JSC::arrayProtoFuncPush):
+        (JSC::arrayProtoFuncReverse):
+        (JSC::arrayProtoFuncShift):
+        (JSC::arrayProtoFuncSlice):
+        (JSC::arrayProtoFuncSort):
+        (JSC::arrayProtoFuncSplice):
+        (JSC::arrayProtoFuncUnShift):
+        (JSC::arrayProtoFuncReduce):
+        (JSC::arrayProtoFuncReduceRight):
+        (JSC::arrayProtoFuncIndexOf):
+        (JSC::arrayProtoFuncLastIndexOf):
+        (JSC::putProperty): Deleted.
+
 2014-07-21  Diego Pino Garcia  <[email protected]>
 
         new Int32Array(new ArrayBuffer(100), 1, 1) shouldn't throw an error that says "RangeError: Byte offset and length out of range of buffer"

Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (171327 => 171328)


--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2014-07-22 00:56:21 UTC (rev 171327)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2014-07-22 00:58:11 UTC (rev 171328)
@@ -157,10 +157,15 @@
     return slot.getValue(exec, index);
 }
 
-static void putProperty(ExecState* exec, JSObject* obj, PropertyName propertyName, JSValue value)
+static ALWAYS_INLINE unsigned getLength(ExecState* exec, JSObject* obj)
 {
+    return obj->get(exec, exec->propertyNames().length).toUInt32(exec);
+}
+
+static void putLength(ExecState* exec, JSObject* obj, JSValue value)
+{
     PutPropertySlot slot(obj);
-    obj->methodTable()->put(obj, exec, propertyName, value, slot);
+    obj->methodTable()->put(obj, exec, exec->propertyNames().length, value, slot);
 }
 
 static unsigned argumentClampedIndexFromStartOrEnd(ExecState* exec, int argument, unsigned length, unsigned undefinedValue = 0)
@@ -296,7 +301,7 @@
     ASSERT(isJSArray(thisValue));
     JSArray* thisObj = asArray(thisValue);
     
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -335,7 +340,7 @@
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -373,7 +378,7 @@
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncJoin(ExecState* exec)
 {
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -475,13 +480,13 @@
         return JSValue::encode(asArray(thisValue)->pop(exec));
 
     JSObject* thisObj = thisValue.toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
     JSValue result;
     if (length == 0) {
-        putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length));
+        putLength(exec, thisObj, jsNumber(length));
         result = jsUndefined();
     } else {
         result = thisObj->get(exec, length - 1);
@@ -491,7 +496,7 @@
             throwTypeError(exec, ASCIILiteral("Unable to delete property."));
             return JSValue::encode(jsUndefined());
         }
-        putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length - 1));
+        putLength(exec, thisObj, jsNumber(length - 1));
     }
     return JSValue::encode(result);
 }
@@ -507,7 +512,7 @@
     }
     
     JSObject* thisObj = thisValue.toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -525,14 +530,14 @@
     }
     
     JSValue newLength(static_cast<int64_t>(length) + static_cast<int64_t>(exec->argumentCount()));
-    putProperty(exec, thisObj, exec->propertyNames().length, newLength);
+    putLength(exec, thisObj, newLength);
     return JSValue::encode(newLength);
 }
 
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncReverse(ExecState* exec)
 {
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -570,20 +575,20 @@
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncShift(ExecState* exec)
 {
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
     JSValue result;
     if (length == 0) {
-        putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length));
+        putLength(exec, thisObj, jsNumber(length));
         result = jsUndefined();
     } else {
         result = thisObj->get(exec, 0);
         shift<JSArray::ShiftCountForShift>(exec, thisObj, 0, 1, 0, length);
         if (exec->hadException())
             return JSValue::encode(jsUndefined());
-        putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length - 1));
+        putLength(exec, thisObj, jsNumber(length - 1));
     }
     return JSValue::encode(result);
 }
@@ -592,7 +597,7 @@
 {
     // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -700,7 +705,7 @@
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec)
 {
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (!length || exec->hadException())
         return JSValue::encode(thisObj);
 
@@ -775,7 +780,7 @@
     // 15.4.4.12
 
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
     
@@ -824,7 +829,7 @@
             return JSValue::encode(jsUndefined());
     }
 
-    putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length - deleteCount + additionalArgs));
+    putLength(exec, thisObj, jsNumber(length - deleteCount + additionalArgs));
     return JSValue::encode(result);
 }
 
@@ -833,7 +838,7 @@
     // 15.4.4.13
 
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -849,14 +854,14 @@
             return JSValue::encode(jsUndefined());
     }
     JSValue result = jsNumber(length + nrArgs);
-    putProperty(exec, thisObj, exec->propertyNames().length, result);
+    putLength(exec, thisObj, result);
     return JSValue::encode(result);
 }
 
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec)
 {
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -933,7 +938,7 @@
 EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec)
 {
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -1010,7 +1015,7 @@
 {
     // 15.4.4.14
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
 
@@ -1033,7 +1038,7 @@
 {
     // 15.4.4.15
     JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
-    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
+    unsigned length = getLength(exec, thisObj);
     if (!length)
         return JSValue::encode(jsNumber(-1));
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to