Ignore:
Timestamp:
Feb 6, 2008, 9:40:16 AM (17 years ago)
Author:
Darin Adler
Message:

JavaScriptCore:

Reviewed by Sam.

Test results match Gecko with very few obscure exceptions that seem to be
bugs in Gecko.

Test: fast/js/array-functions-non-arrays.html

  • kjs/array_object.cpp: (KJS::arrayProtoFuncConcat): Removed DontEnum and DontDelete from the call to set length. (KJS::arrayProtoFuncPop): Ditto. Also added missing call to deleteProperty, which is not needed for real arrays, but is needed for non-arrays. (KJS::arrayProtoFuncPush): Ditto. (KJS::arrayProtoFuncShift): Ditto. (KJS::arrayProtoFuncSlice): Ditto. (KJS::arrayProtoFuncSort): Removed incorrect call to set length when the array has no elements. (KJS::arrayProtoFuncSplice): Removed DontEnum and DontDelete from the call to set length. (KJS::arrayProtoFuncUnShift): Ditto. Also added a check for 0 arguments to make behavior match the specification in that case.
  • kjs/nodes.cpp: (KJS::ArrayNode::evaluate): Removed DontEnum and DontDelete from the call to set length.

LayoutTests:

Reviewed by Sam.

  • fast/js/array-functions-non-arrays-expected.txt: Added.
  • fast/js/array-functions-non-arrays.html: Added.
  • fast/js/resources/array-functions-non-arrays.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r30040 r30041  
    249249        ++it;
    250250    }
    251     arr->put(exec, exec->propertyNames().length, jsNumber(n), DontEnum | DontDelete);
     251    arr->put(exec, exec->propertyNames().length, jsNumber(n));
    252252    return arr;
    253253}
     
    258258    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
    259259    if (length == 0) {
    260         thisObj->put(exec, exec->propertyNames().length, jsNumber(length), DontEnum | DontDelete);
     260        thisObj->put(exec, exec->propertyNames().length, jsNumber(length));
    261261        result = jsUndefined();
    262262    } else {
    263263        result = thisObj->get(exec, length - 1);
    264         thisObj->put(exec, exec->propertyNames().length, jsNumber(length - 1), DontEnum | DontDelete);
     264        thisObj->deleteProperty(exec, length - 1);
     265        thisObj->put(exec, exec->propertyNames().length, jsNumber(length - 1));
    265266    }
    266267    return result;
     
    273274        thisObj->put(exec, length + n, args[n]);
    274275    length += args.size();
    275     thisObj->put(exec, exec->propertyNames().length, jsNumber(length), DontEnum | DontDelete);
     276    thisObj->put(exec, exec->propertyNames().length, jsNumber(length));
    276277    return jsNumber(length);
    277278}
     
    306307    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
    307308    if (length == 0) {
    308         thisObj->put(exec, exec->propertyNames().length, jsNumber(length), DontEnum | DontDelete);
     309        thisObj->put(exec, exec->propertyNames().length, jsNumber(length));
    309310        result = jsUndefined();
    310311    } else {
     
    317318        }
    318319        thisObj->deleteProperty(exec, length - 1);
    319         thisObj->put(exec, exec->propertyNames().length, jsNumber(length - 1), DontEnum | DontDelete);
     320        thisObj->put(exec, exec->propertyNames().length, jsNumber(length - 1));
    320321    }
    321322    return result;
     
    361362            resObj->put(exec, n, v);
    362363    }
    363     resObj->put(exec, exec->propertyNames().length, jsNumber(n), DontEnum | DontDelete);
     364    resObj->put(exec, exec->propertyNames().length, jsNumber(n));
    364365    return result;
    365366}
     
    384385    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
    385386
    386     if (!length) {
    387         thisObj->put(exec, exec->propertyNames().length, jsNumber(0), DontEnum | DontDelete);
     387    if (!length)
    388388        return thisObj;
    389     }
    390389
    391390    // "Min" sort. Not the fastest, but definitely less code than heapsort
    392391    // or quicksort, and much less swapping than bubblesort/insertionsort.
    393     for (unsigned i = 0 ; i < length - 1 ; ++i) {
     392    for (unsigned i = 0; i < length - 1; ++i) {
    394393        JSValue* iObj = thisObj->get(exec, i);
    395394        unsigned themin = i;
    396395        JSValue* minObj = iObj;
    397         for (unsigned j = i + 1 ; j < length ; ++j) {
     396        for (unsigned j = i + 1; j < length; ++j) {
    398397            JSValue* jObj = thisObj->get(exec, j);
    399398            double compareResult;
     
    448447            resObj->put(exec, k, v);
    449448    }
    450     resObj->put(exec, exec->propertyNames().length, jsNumber(deleteCount), DontEnum | DontDelete);
     449    resObj->put(exec, exec->propertyNames().length, jsNumber(deleteCount));
    451450
    452451    unsigned additionalArgs = std::max<int>(args.size() - 2, 0);
     
    459458                    thisObj->deleteProperty(exec, k + additionalArgs);
    460459            }
    461             for (unsigned k = length ; k > length - deleteCount + additionalArgs; --k)
     460            for (unsigned k = length; k > length - deleteCount + additionalArgs; --k)
    462461                thisObj->deleteProperty(exec, k - 1);
    463462        } else {
     
    473472        thisObj->put(exec, k + begin, args[k + 2]);
    474473
    475     thisObj->put(exec, exec->propertyNames().length, jsNumber(length - deleteCount + additionalArgs), DontEnum | DontDelete);
     474    thisObj->put(exec, exec->propertyNames().length, jsNumber(length - deleteCount + additionalArgs));
    476475    return result;
    477476}
     
    482481    unsigned length = thisObj->get(exec, exec->propertyNames().length)->toUInt32(exec);
    483482    unsigned nrArgs = args.size();
    484     for (unsigned k = length; k > 0; --k) {
    485         if (JSValue* v = getProperty(exec, thisObj, k - 1))
    486             thisObj->put(exec, k + nrArgs-1, v);
    487         else
    488             thisObj->deleteProperty(exec, k + nrArgs-1);
     483    if (nrArgs) {
     484        for (unsigned k = length; k > 0; --k) {
     485            if (JSValue* v = getProperty(exec, thisObj, k - 1))
     486                thisObj->put(exec, k + nrArgs - 1, v);
     487            else
     488                thisObj->deleteProperty(exec, k + nrArgs - 1);
     489        }
    489490    }
    490491    for (unsigned k = 0; k < nrArgs; ++k)
    491492        thisObj->put(exec, k, args[k]);
    492493    JSValue* result = jsNumber(length + nrArgs);
    493     thisObj->put(exec, exec->propertyNames().length, result, DontEnum | DontDelete);
     494    thisObj->put(exec, exec->propertyNames().length, result);
    494495    return result;
    495496}
Note: See TracChangeset for help on using the changeset viewer.