Ignore:
Timestamp:
Aug 21, 2006, 10:43:55 AM (19 years ago)
Author:
ap
Message:

2006-08-21 Vladimir Olexa <[email protected]>

Reviewed by Darin.

http://bugzilla.opendarwin.org/show_bug.cgi?id=6252
JavaScript 1.6 Array.lastIndexOf

Test: fast/js/array-lastIndexOf.html

  • kjs/array_object.cpp: (ArrayProtoFunc::callAsFunction): Added a LastIndexOf case.
  • kjs/array_object.h: (KJS::ArrayProtoFunc::): Added LastIndexOf to enum.
  • tests/mozilla/expected.html: Two more tests now pass.
File:
1 edited

Legend:

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

    r15846 r15952  
    404404  some           ArrayProtoFunc::Some           DontEnum|Function 1
    405405  indexOf        ArrayProtoFunc::IndexOf        DontEnum|Function 1
     406  lastIndexOf    ArrayProtoFunc::LastIndexOf    DontEnum|Function 1
    406407  filter         ArrayProtoFunc::Filter         DontEnum|Function 1
    407408  map            ArrayProtoFunc::Map            DontEnum|Function 1
     
    893894    return jsNumber(-1);
    894895  }
    895 
     896  case LastIndexOf: {
     897       // JavaScript 1.6 Extension by Mozilla
     898      // Documentation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:lastIndexOf
     899
     900    int index = length - 1;
     901    double d = args[1]->toInteger(exec);
     902
     903    if (d < 0) {
     904        d += length;
     905        if (d < 0)
     906            return jsNumber(-1);
     907    }
     908    if (d < length)
     909        index = static_cast<int>(d);
     910         
     911    JSValue* searchElement = args[0];
     912    for (; index >= 0; --index) {
     913        JSValue* e = getProperty(exec, thisObj, index);
     914        if (!e)
     915            e = jsUndefined();
     916        if (strictEqual(exec, searchElement, e))
     917            return jsNumber(index);
     918    }
     919         
     920    return jsNumber(-1);
     921}
    896922  default:
    897923    assert(0);
Note: See TracChangeset for help on using the changeset viewer.