Changeset 171328 in webkit


Ignore:
Timestamp:
Jul 21, 2014, 5:58:11 PM (11 years ago)
Author:
mark.lam@apple.com
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.

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r171323 r171328  
     12014-07-21  Mark Lam  <mark.lam@apple.com>
     2
     3        Refactor ArrayPrototype to use getLength() and putLength() utility functions.
     4        https://bugs.webkit.org/show_bug.cgi?id=135139.
     5
     6        Reviewed by Oliver Hunt.
     7
     8        - Specialize putProperty() to putLength() because it is only used for setting
     9          the length property.
     10        - Added a getLength() utility function to get the value of the length property.
     11        - Use these getLength() and putLength() functions instead of the existing code
     12          to get and put the length property.  Less code to read, easier to understand.
     13
     14        * runtime/ArrayPrototype.cpp:
     15        (JSC::getLength):
     16        (JSC::putLength):
     17        (JSC::arrayProtoFuncToString):
     18        (JSC::arrayProtoFuncToLocaleString):
     19        (JSC::arrayProtoFuncJoin):
     20        (JSC::arrayProtoFuncPop):
     21        (JSC::arrayProtoFuncPush):
     22        (JSC::arrayProtoFuncReverse):
     23        (JSC::arrayProtoFuncShift):
     24        (JSC::arrayProtoFuncSlice):
     25        (JSC::arrayProtoFuncSort):
     26        (JSC::arrayProtoFuncSplice):
     27        (JSC::arrayProtoFuncUnShift):
     28        (JSC::arrayProtoFuncReduce):
     29        (JSC::arrayProtoFuncReduceRight):
     30        (JSC::arrayProtoFuncIndexOf):
     31        (JSC::arrayProtoFuncLastIndexOf):
     32        (JSC::putProperty): Deleted.
     33
    1342014-07-21  Diego Pino Garcia  <dpino@igalia.com>
    235
  • trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r167797 r171328  
    158158}
    159159
    160 static void putProperty(ExecState* exec, JSObject* obj, PropertyName propertyName, JSValue value)
     160static ALWAYS_INLINE unsigned getLength(ExecState* exec, JSObject* obj)
     161{
     162    return obj->get(exec, exec->propertyNames().length).toUInt32(exec);
     163}
     164
     165static void putLength(ExecState* exec, JSObject* obj, JSValue value)
    161166{
    162167    PutPropertySlot slot(obj);
    163     obj->methodTable()->put(obj, exec, propertyName, value, slot);
     168    obj->methodTable()->put(obj, exec, exec->propertyNames().length, value, slot);
    164169}
    165170
     
    297302    JSArray* thisObj = asArray(thisValue);
    298303   
    299     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     304    unsigned length = getLength(exec, thisObj);
    300305    if (exec->hadException())
    301306        return JSValue::encode(jsUndefined());
     
    336341        return JSValue::encode(jsUndefined());
    337342
    338     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     343    unsigned length = getLength(exec, thisObj);
    339344    if (exec->hadException())
    340345        return JSValue::encode(jsUndefined());
     
    374379{
    375380    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    376     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     381    unsigned length = getLength(exec, thisObj);
    377382    if (exec->hadException())
    378383        return JSValue::encode(jsUndefined());
     
    476481
    477482    JSObject* thisObj = thisValue.toObject(exec);
    478     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     483    unsigned length = getLength(exec, thisObj);
    479484    if (exec->hadException())
    480485        return JSValue::encode(jsUndefined());
     
    482487    JSValue result;
    483488    if (length == 0) {
    484         putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length));
     489        putLength(exec, thisObj, jsNumber(length));
    485490        result = jsUndefined();
    486491    } else {
     
    492497            return JSValue::encode(jsUndefined());
    493498        }
    494         putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length - 1));
     499        putLength(exec, thisObj, jsNumber(length - 1));
    495500    }
    496501    return JSValue::encode(result);
     
    508513   
    509514    JSObject* thisObj = thisValue.toObject(exec);
    510     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     515    unsigned length = getLength(exec, thisObj);
    511516    if (exec->hadException())
    512517        return JSValue::encode(jsUndefined());
     
    526531   
    527532    JSValue newLength(static_cast<int64_t>(length) + static_cast<int64_t>(exec->argumentCount()));
    528     putProperty(exec, thisObj, exec->propertyNames().length, newLength);
     533    putLength(exec, thisObj, newLength);
    529534    return JSValue::encode(newLength);
    530535}
     
    533538{
    534539    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    535     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     540    unsigned length = getLength(exec, thisObj);
    536541    if (exec->hadException())
    537542        return JSValue::encode(jsUndefined());
     
    571576{
    572577    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    573     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     578    unsigned length = getLength(exec, thisObj);
    574579    if (exec->hadException())
    575580        return JSValue::encode(jsUndefined());
     
    577582    JSValue result;
    578583    if (length == 0) {
    579         putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length));
     584        putLength(exec, thisObj, jsNumber(length));
    580585        result = jsUndefined();
    581586    } else {
     
    584589        if (exec->hadException())
    585590            return JSValue::encode(jsUndefined());
    586         putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length - 1));
     591        putLength(exec, thisObj, jsNumber(length - 1));
    587592    }
    588593    return JSValue::encode(result);
     
    593598    // http://developer.netscape.com/docs/manuals/js/client/jsref/array.htm#1193713 or 15.4.4.10
    594599    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    595     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     600    unsigned length = getLength(exec, thisObj);
    596601    if (exec->hadException())
    597602        return JSValue::encode(jsUndefined());
     
    701706{
    702707    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    703     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     708    unsigned length = getLength(exec, thisObj);
    704709    if (!length || exec->hadException())
    705710        return JSValue::encode(thisObj);
     
    776781
    777782    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    778     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     783    unsigned length = getLength(exec, thisObj);
    779784    if (exec->hadException())
    780785        return JSValue::encode(jsUndefined());
     
    825830    }
    826831
    827     putProperty(exec, thisObj, exec->propertyNames().length, jsNumber(length - deleteCount + additionalArgs));
     832    putLength(exec, thisObj, jsNumber(length - deleteCount + additionalArgs));
    828833    return JSValue::encode(result);
    829834}
     
    834839
    835840    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    836     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     841    unsigned length = getLength(exec, thisObj);
    837842    if (exec->hadException())
    838843        return JSValue::encode(jsUndefined());
     
    850855    }
    851856    JSValue result = jsNumber(length + nrArgs);
    852     putProperty(exec, thisObj, exec->propertyNames().length, result);
     857    putLength(exec, thisObj, result);
    853858    return JSValue::encode(result);
    854859}
     
    857862{
    858863    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    859     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     864    unsigned length = getLength(exec, thisObj);
    860865    if (exec->hadException())
    861866        return JSValue::encode(jsUndefined());
     
    934939{
    935940    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    936     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     941    unsigned length = getLength(exec, thisObj);
    937942    if (exec->hadException())
    938943        return JSValue::encode(jsUndefined());
     
    10111016    // 15.4.4.14
    10121017    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    1013     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     1018    unsigned length = getLength(exec, thisObj);
    10141019    if (exec->hadException())
    10151020        return JSValue::encode(jsUndefined());
     
    10341039    // 15.4.4.15
    10351040    JSObject* thisObj = exec->thisValue().toThis(exec, StrictMode).toObject(exec);
    1036     unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
     1041    unsigned length = getLength(exec, thisObj);
    10371042    if (!length)
    10381043        return JSValue::encode(jsNumber(-1));
Note: See TracChangeset for help on using the changeset viewer.