Changeset 42567 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Apr 15, 2009, 7:12:23 PM (16 years ago)
Author:
[email protected]
Message:

Bug 25227: Array.filter triggers an assertion when the target array shrinks while being filtered
<https://bugs.webkit.org/show_bug.cgi?id=25227>

Reviewed by Gavin Barraclough.

We correct this simply by making the fast array path fall back on the slow path if
we ever discover the fast access is unsafe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/ArrayPrototype.cpp

    r42563 r42567  
    589589    unsigned filterIndex = 0;
    590590    unsigned length = thisObj->get(exec, exec->propertyNames().length).toUInt32(exec);
    591     if (callType == CallTypeHost || !isJSArray(&exec->globalData(), thisObj) || !asArray(thisObj)->canGetIndex(length - 1)) {
    592         for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
    593             PropertySlot slot(thisObj);
    594            
    595             if (!thisObj->getPropertySlot(exec, k, slot))
    596                 continue;
    597 
    598             JSValuePtr v = slot.getValue(exec, k);
    599 
    600             ArgList eachArguments;
    601 
    602             eachArguments.append(v);
    603             eachArguments.append(jsNumber(exec, k));
    604             eachArguments.append(thisObj);
    605 
    606             JSValuePtr result = call(exec, function, callType, callData, applyThis, eachArguments);
    607 
    608             if (result.toBoolean(exec))
    609                 resultArray->put(exec, filterIndex++, v);
    610         }
    611     } else {
     591    unsigned k = 0;
     592    if (callType == CallTypeJS && isJSArray(&exec->globalData(), thisObj)) {
    612593        JSFunction* f = asFunction(function);
    613594        JSArray* array = asArray(thisObj);
    614595        CachedCall cachedCall(exec, f, 3, exec->exceptionSlot());
    615         for (unsigned k = 0; k < length && !exec->hadException(); ++k) {           
     596        for (; k < length && !exec->hadException(); ++k) {
     597            if (!array->canGetIndex(k))
     598                break;
    616599            JSValuePtr v = array->getIndex(k);
    617600            cachedCall.setThis(applyThis);
     
    619602            cachedCall.setArgument(1, jsNumber(exec, k));
    620603            cachedCall.setArgument(2, thisObj);
    621 
     604           
    622605            JSValuePtr result = cachedCall.call();
    623606            if (result.toBoolean(exec))
    624607                resultArray->put(exec, filterIndex++, v);
    625608        }
     609        if (k == length)
     610            return resultArray;
     611    }
     612    for (; k < length && !exec->hadException(); ++k) {
     613        PropertySlot slot(thisObj);
     614
     615        if (!thisObj->getPropertySlot(exec, k, slot))
     616            continue;
     617
     618        JSValuePtr v = slot.getValue(exec, k);
     619
     620        ArgList eachArguments;
     621
     622        eachArguments.append(v);
     623        eachArguments.append(jsNumber(exec, k));
     624        eachArguments.append(thisObj);
     625
     626        JSValuePtr result = call(exec, function, callType, callData, applyThis, eachArguments);
     627
     628        if (result.toBoolean(exec))
     629            resultArray->put(exec, filterIndex++, v);
    626630    }
    627631    return resultArray;
Note: See TracChangeset for help on using the changeset viewer.