Changeset 11659 in webkit


Ignore:
Timestamp:
Dec 18, 2005 4:27:29 PM (18 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.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r11650 r11659  
     12005-12-18  Justin Haygood  <justin@xiondigital.net>
     2
     3        Reviewed, tweaked, and landed by Darin.
     4
     5        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5227
     6          Array indexOf() extension for JavaScript 1.5 Core
     7
     8        * kjs/array_object.h:
     9        * kjs/array_object.cpp: (ArrayProtoFunc::callAsFunction): Added implementation of indexOf.
     10
    1112005-12-18  Anders Carlsson  <andersca@mac.com>
    212
  • 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);
  • trunk/JavaScriptCore/kjs/array_object.h

    r11527 r11659  
    4646    enum { ToString, ToLocaleString, Concat, Join, Pop, Push,
    4747          Reverse, Shift, Slice, Sort, Splice, UnShift,
    48           Every, ForEach, Some };
     48          Every, ForEach, Some, IndexOf };
    4949  private:
    5050    int id;
  • trunk/LayoutTests/ChangeLog

    r11656 r11659  
     12005-12-18  Justin Haygood  <justin@xiondigital.net>
     2
     3        Reviewed, tweaked, and landed by Darin.
     4
     5        - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=5227
     6          Array indexOf() extension for JavaScript 1.5 Core
     7
     8        * fast/js/array-indexof-expected.txt: Added.
     9        * fast/js/array-indexof.html: Added.
     10
    1112005-12-18  Mitz Pettel  <opendarwin.org@mitzpettel.com>
    212
Note: See TracChangeset for help on using the changeset viewer.