Ignore:
Timestamp:
Dec 18, 2005, 4:27:29 PM (19 years ago)
Author:
darin
Message:

JavaScriptCore:

Reviewed, tweaked, and landed by Darin.

  • kjs/array_object.h:
  • kjs/array_object.cpp: (ArrayProtoFunc::callAsFunction): Added implementation of indexOf.

LayoutTests:

Reviewed, tweaked, and landed by Darin.

  • fast/js/array-indexof-expected.txt: Added.
  • fast/js/array-indexof.html: Added.
File:
1 edited

Legend:

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

    r11566 r11659  
    393393  forEach        ArrayProtoFunc::ForEach        DontEnum|Function 5
    394394  some           ArrayProtoFunc::Some           DontEnum|Function 5
     395  indexOf        ArrayProtoFunc::IndexOf       DontEnum|Function 1
    395396@end
    396397*/
     
    811812    break;
    812813  }
    813    
     814
     815  case IndexOf: {
     816    // JavaScript 1.5 Extension by Mozilla
     817    // Documentation: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf
     818
     819    unsigned index = 0;
     820    double d = args[1]->toInteger(exec);
     821    if (d < 0)
     822        d += length;
     823    if (d > 0) {
     824        if (d > length)
     825            index = length;
     826        else
     827            index = static_cast<unsigned>(d);
     828    }
     829
     830    JSValue* searchElement = args[0];
     831    for (; index < length; ++index) {
     832        JSValue* e = getProperty(exec, thisObj, index);
     833        if (!e)
     834            e = jsUndefined();
     835        if (strictEqual(exec, searchElement, e))
     836            return jsNumber(index);
     837    }
     838
     839    return jsNumber(-1);
     840  }
     841
    814842  default:
    815843    assert(0);
Note: See TracChangeset for help on using the changeset viewer.