Changeset 20569 in webkit


Ignore:
Timestamp:
Mar 28, 2007 11:20:38 PM (17 years ago)
Author:
dsmith
Message:

JavaScriptCore:

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=12963
Fix some inconsistencies in the Mozilla JS Array extras implementations
with respect to the Mozilla implementation:

  • holes in arrays should be skipped, not treated as undefined, by all such methods
  • an element with value undefined is not a hole
  • Array.prototype.forEach should return undefined
  • kjs/array_object.cpp: (ArrayInstance::getOwnPropertySlot): (ArrayProtoFunc::callAsFunction):

LayoutTests:

Reviewed by Darin.

http://bugs.webkit.org/show_bug.cgi?id=12963
Fix some inconsistencies in the Mozilla JS Array extras implementations
with respect to the Mozilla implementation:

  • holes in arrays should be skipped, not treated as undefined, by all such methods
  • an element with value undefined is not a hole
  • Array.prototype.forEach should return undefined
  • fast/js/array-every-expected.txt:
  • fast/js/array-filter-expected.txt: Added.
  • fast/js/array-filter.html: Added.
  • fast/js/array-foreach-expected.txt:
  • fast/js/array-foreach.html:
  • fast/js/array-indexof-expected.txt:
  • fast/js/array-indexof.html:
  • fast/js/array-lastIndexOf-expected.txt:
  • fast/js/array-map-expected.txt: Added.
  • fast/js/array-map.html: Added.
  • fast/js/array-some-expected.txt:
  • fast/js/array-some.html:
  • fast/js/resources/array-every.js:
  • fast/js/resources/array-lastIndexOf.js:
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r20544 r20569  
     12007-03-28  Jeff Walden  <jwalden+code@mit.edu>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=12963
     6        Fix some inconsistencies in the Mozilla JS Array extras implementations
     7        with respect to the Mozilla implementation:
     8
     9          - holes in arrays should be skipped, not treated as undefined,
     10            by all such methods
     11          - an element with value undefined is not a hole
     12          - Array.prototype.forEach should return undefined
     13
     14        * kjs/array_object.cpp:
     15        (ArrayInstance::getOwnPropertySlot):
     16        (ArrayProtoFunc::callAsFunction):
     17
    1182007-03-27  Anders Carlsson  <acarlsson@apple.com>
    219
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r20310 r20569  
    102102    if (index < storageLength) {
    103103      JSValue *v = storage[index];
    104       if (!v || v->isUndefined())
     104      if (!v)
    105105        return false;     
    106106      slot.setValueSlot(this, &storage[index]);
     
    121121  if (index < storageLength) {
    122122    JSValue *v = storage[index];
    123     if (!v || v->isUndefined())
     123    if (!v)
    124124      return false;
    125125    slot.setValueSlot(this, &storage[index]);
     
    790790    if (id == Filter)
    791791      resultArray = static_cast<JSObject *>(exec->lexicalInterpreter()->builtinArray()->construct(exec, List::empty()));
    792     else
    793  {
     792    else {
    794793      List args;
    795794      args.append(jsNumber(length));
     
    840839      result = jsBoolean(id == Every);
    841840    else
    842       result = thisObj;
     841      result = jsUndefined();
    843842   
    844843    for (unsigned k = 0; k < length && !exec->hadException(); ++k) {
     
    887886        JSValue* e = getProperty(exec, thisObj, index);
    888887        if (!e)
    889             e = jsUndefined();
     888            continue;
    890889        if (strictEqual(exec, searchElement, e))
    891890            return jsNumber(index);
     
    913912        JSValue* e = getProperty(exec, thisObj, index);
    914913        if (!e)
    915             e = jsUndefined();
     914            continue;
    916915        if (strictEqual(exec, searchElement, e))
    917916            return jsNumber(index);
  • trunk/LayoutTests/ChangeLog

    r20565 r20569  
     12007-03-28  Jeff Walden  <jwalden+code@mit.edu>
     2
     3        Reviewed by Darin.
     4
     5         http://bugs.webkit.org/show_bug.cgi?id=12963
     6         Fix some inconsistencies in the Mozilla JS Array extras implementations
     7         with respect to the Mozilla implementation:
     8
     9           - holes in arrays should be skipped, not treated as undefined,
     10             by all such methods
     11           - an element with value undefined is not a hole
     12           - Array.prototype.forEach should return undefined
     13
     14        * fast/js/array-every-expected.txt:
     15        * fast/js/array-filter-expected.txt: Added.
     16        * fast/js/array-filter.html: Added.
     17        * fast/js/array-foreach-expected.txt:
     18        * fast/js/array-foreach.html:
     19        * fast/js/array-indexof-expected.txt:
     20        * fast/js/array-indexof.html:
     21        * fast/js/array-lastIndexOf-expected.txt:
     22        * fast/js/array-map-expected.txt: Added.
     23        * fast/js/array-map.html: Added.
     24        * fast/js/array-some-expected.txt:
     25        * fast/js/array-some.html:
     26        * fast/js/resources/array-every.js:
     27        * fast/js/resources/array-lastIndexOf.js:
     28
    1292007-03-28  Maciej Stachowiak  <mjs@apple.com>
    230
  • trunk/LayoutTests/fast/js/array-every-expected.txt

    r12001 r20569  
    4343PASS [12, 54, 18, 130, 44].every(isBigEnoughShortCircuit) is true
    4444PASS accumulator.toString() is [12, 54, 18, 130, 44].toString()
     45
     467.0 Behavior for Holes in Arrays
     47PASS arr.every(isNotUndefined) is true
     48PASS arr.every(isNotUndefined) is true
    4549PASS successfullyParsed is true
    4650
  • trunk/LayoutTests/fast/js/array-foreach-expected.txt

    r19397 r20569  
    5252TypeError: Type error
    5353
     546.0 Behavior for Holes in Arrays
     55This test checks that holes in arrays (indexes which have been deleted or are not present) are not included in enumeration:
     56
     57Manually deleted index not enumerated
     58Array created using constructor has no properties, so no indexes enumerated
     59
     607.0 Return Value
     61This test checks that the return value of Array.prototype.forEach is undefined:
     62
     63Return value is undefined!
     64
  • trunk/LayoutTests/fast/js/array-foreach.html

    r19397 r20569  
    140140</script>
    141141
     142<br/>
     1436.0 Behavior for Holes in Arrays<br/>
     144This test checks that holes in arrays (indexes which have been deleted or are not present) are not included in enumeration:<br/><br/>
     145<script>
     146function throwIfUndefined(element, index, array) {
     147    if (typeof element === "undefined")
     148        throw "undefined element enumerated!";
     149}
     150
     151var arr;
     152try {
     153    arr = [5, 5, 5, 5];
     154    delete arr[1];
     155    arr.forEach(throwIfUndefined);
     156    print("Manually deleted index not enumerated");
     157} catch (e) {
     158    print(e);
     159}
     160
     161try {
     162    arr = new Array(20);
     163    arr.forEach(throwIfUndefined);
     164    print("Array created using constructor has no properties, so no indexes enumerated");
     165} catch (e) {
     166    print(e);
     167}
     168
     169</script>
     170
     171<br/>
     1727.0 Return Value<br/>
     173This test checks that the return value of Array.prototype.forEach is undefined:<br/><br/>
     174<script>
     175var wasUndefined = typeof ([1, 2, 3].forEach(function(){})) === "undefined";
     176
     177print("Return value is " + (wasUndefined ? "" : "NOT ") + "undefined!");
     178</script>
     179
    142180</body>
    143181</html>
  • trunk/LayoutTests/fast/js/array-indexof-expected.txt

    r12001 r20569  
    5050* The indexOf undefined is 7
    5151* The indexOf undefined is -1
     52* The indexOf undefined is 3
     53* The indexOf undefined is -1
     54* The indexOf undefined is -1
    5255
    535614.0 Object using the Array prototype
  • trunk/LayoutTests/fast/js/array-indexof.html

    r11995 r20569  
    1515testArray3[5] = 9;
    1616testArray3.length = 6;
     17var testArray4 = [5, 5, 5, undefined];
     18delete testArray4[1];
     19var testArray5 = [5, 5, 5, undefined];
     20delete testArray5[3];
     21var testArray6 = new Array(20);
    1722if (window.layoutTestController)
    1823    layoutTestController.dumpAsText();
     
    2429
    2530<p>1.0 Direct Testing, no starting at Parameter<br>
    26         * The indexOf String "Hello" is <script>document.write(testArray.indexOf("Hello"))</script><br>
    27         * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hi"))</script><br>
    28         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf( true ))</script><br>
    29         * The indexOf Number '5' is <script>document.write(testArray.indexOf( 5 ))</script><br>
    30         * The indexOf Number '9' is <script>document.write(testArray.indexOf( 9 ))</script>
     31    * The indexOf String "Hello" is <script>document.write(testArray.indexOf("Hello"))</script><br>
     32    * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hi"))</script><br>
     33    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf( true ))</script><br>
     34    * The indexOf Number '5' is <script>document.write(testArray.indexOf( 5 ))</script><br>
     35    * The indexOf Number '9' is <script>document.write(testArray.indexOf( 9 ))</script>
    3136</p>
    3237
    3338<p>2.0 A firstIndex parameter of 1 (positive offset test)<br>
    34         * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hi",1))</script><br>
    35         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true,1))</script><br>
    36         * The indexOf Number 5 is <script>document.write(testArray.indexOf(5,1))</script><br>
    37         * The indexOf Number 9 is <script>document.write(testArray.indexOf(9,1))</script>
     39    * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hi",1))</script><br>
     40    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true,1))</script><br>
     41    * The indexOf Number 5 is <script>document.write(testArray.indexOf(5,1))</script><br>
     42    * The indexOf Number 9 is <script>document.write(testArray.indexOf(9,1))</script>
    3843</p>
    3944
    4045<p>3.0 A firstIndex parameter of -4 (negative offset test)<br>
    41         * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hi",-4))</script><br>
    42         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true,-4))</script><br>
    43         * The indexOf Number 5 is <script>document.write(testArray.indexOf(5,-4))</script><br>
    44         * The indexOf Number 9 is <script>document.write(testArray.indexOf(9,-4))</script>
     46    * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hi",-4))</script><br>
     47    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true,-4))</script><br>
     48    * The indexOf Number 5 is <script>document.write(testArray.indexOf(5,-4))</script><br>
     49    * The indexOf Number 9 is <script>document.write(testArray.indexOf(9,-4))</script>
    4550</p>
    4651
    4752<p>4.0 A big positive firstIndex of 1000, to test the firstIndex > length<br>
    48         * The indexOf Number '9' is <script>document.write(testArray.indexOf(9,1000))</script>
     53    * The indexOf Number '9' is <script>document.write(testArray.indexOf(9,1000))</script>
    4954</p>
    5055
    5156<p>5.0 A big positive firstIndex of 4294967301, to test when firstIndex > width of int (32-bits)<br>
    52         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, 4294967301))</script>
     57    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, 4294967301))</script>
    5358</p>
    5459
    5560<p>6.0 No arguments<br>
    56         * No arguments passed: <script>document.write(testArray.indexOf())</script><br>
    57         * No arguments passed: <script>document.write(testArray2.indexOf())</script>
     61    * No arguments passed: <script>document.write(testArray.indexOf())</script><br>
     62    * No arguments passed: <script>document.write(testArray2.indexOf())</script>
    5863</p>
    5964
    6065<p>7.0 Looking for null<br>
    61         * The indexOf null is <script>document.write(testArray.indexOf(null))</script><br>
    62         * The indexOf null is <script>document.write(testArray2.indexOf(null))</script>
     66    * The indexOf null is <script>document.write(testArray.indexOf(null))</script><br>
     67    * The indexOf null is <script>document.write(testArray2.indexOf(null))</script>
    6368</p>
    6469
    6570<p>8.0 Extra arguments<br>
    66         * The indexOf String "Hello" is <script>document.write(testArray.indexOf("Hello", 0, true))</script>
     71    * The indexOf String "Hello" is <script>document.write(testArray.indexOf("Hello", 0, true))</script>
    6772</p>
    6873
    6974<p>9.0 NaN firstIndex<br>
    70         * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hello", "Hey"))</script>
     75    * The indexOf String "Hi" is <script>document.write(testArray.indexOf("Hello", "Hey"))</script>
    7176</p>
    7277
    7378<p>10.0 Small firstIndex<br>
    74         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, 0.45))</script>
     79    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, 0.45))</script>
    7580</p>
    7681
    7782<p>11.0 Negative firstIndex bigger than the length of the array<br>
    78         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, -1000))</script>
     83    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, -1000))</script>
    7984</p>
    8085
    8186<p>12.0 Negative firstIndex bigger than 32-bits<br>
    82         * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, -5294967301))</script>
     87    * The indexOf Boolean 'true' is <script>document.write(testArray.indexOf(true, -5294967301))</script>
    8388</p>
    8489
    8590<p>13.0 Looking for undefined<br>
    86         * The indexOf undefined is <script>document.write(testArray.indexOf(undefined))</script><br>
    87         * The indexOf undefined is <script>document.write(testArray2.indexOf(undefined))</script>
     91    * The indexOf undefined is <script>document.write(testArray.indexOf(undefined))</script><br>
     92    * The indexOf undefined is <script>document.write(testArray2.indexOf(undefined))</script><br>
     93    * The indexOf undefined is <script>document.write(testArray4.indexOf(undefined))</script><br>
     94    * The indexOf undefined is <script>document.write(testArray5.indexOf(undefined))</script><br>
     95    * The indexOf undefined is <script>document.write(testArray6.indexOf(undefined))</script>
    8896</p>
    8997
    9098<p>14.0 Object using the Array prototype<br>
    91         * The indexOf String "Hello" is <script>document.write(testArray3.indexOf("Hello"))</script><br>
    92         * The indexOf String "Hi" is <script>document.write(testArray3.indexOf("Hi"))</script><br>
    93         * The indexOf Boolean 'true' is <script>document.write(testArray3.indexOf(true))</script><br>
    94         * The indexOf Number '5' is <script>document.write(testArray3.indexOf(5))</script><br>
    95         * The indexOf Number '9' is <script>document.write(testArray3.indexOf(9))</script>
     99    * The indexOf String "Hello" is <script>document.write(testArray3.indexOf("Hello"))</script><br>
     100    * The indexOf String "Hi" is <script>document.write(testArray3.indexOf("Hi"))</script><br>
     101    * The indexOf Boolean 'true' is <script>document.write(testArray3.indexOf(true))</script><br>
     102    * The indexOf Number '5' is <script>document.write(testArray3.indexOf(5))</script><br>
     103    * The indexOf Number '9' is <script>document.write(testArray3.indexOf(9))</script>
    96104</p>
    97105
  • trunk/LayoutTests/fast/js/array-lastIndexOf-expected.txt

    r15952 r20569  
    1212PASS lastIndex is 0
    1313PASS lastIndex is 3
     14PASS lastIndex is -1
     15PASS lastIndex is -1
     16PASS lastIndex is -1
     17PASS lastIndex is 19
     18PASS lastIndex is -1
     19PASS lastIndex is -1
    1420PASS successfullyParsed is true
    1521
  • trunk/LayoutTests/fast/js/array-some-expected.txt

    r19397 r20569  
    5959Done with second array.
    6060
     617.0 Behavior with Holes in Arrays
     62This test checks that the callback function is not invoked for holes in the array. Five arrays are tested:
     63
     64Testing element 2...
     65Testing element 8...
     66Testing element 1...
     67Testing element 4...
     68Done with first array.
     69Testing element undefined...
     70Done with second array.
     71Done with third array.
     72Done with fourth array.
     73Testing element undefined...
     74Done with fifth array.
     75
  • trunk/LayoutTests/fast/js/array-some.html

    r19397 r20569  
    157157[12, 5, 8, 1, 44].some(isBigEnough);
    158158print("Done with second array.");
     159
     160</script>
     161<br/>
     1627.0 Behavior with Holes in Arrays<br/>
     163This test checks that the callback function is not invoked for holes in the array. Five arrays are tested:<br/><br/>
     164<script>
     165function isBigEnough(element, index, array) {
     166    print("Testing element " + element + "...");
     167    return (element >= 10);
     168}
     169
     170var arr = [2, 5, 8, 1, 4];
     171delete arr[1];
     172arr.some(isBigEnough);
     173print("Done with first array.");
     174
     175arr = [undefined];
     176arr.some(isBigEnough);
     177print("Done with second array.");
     178
     179delete arr[0];
     180arr.some(isBigEnough);
     181print("Done with third array.");
     182
     183arr = new Array(20);
     184arr.some(isBigEnough);
     185print("Done with fourth array.");
     186
     187arr[17] = undefined;
     188arr.some(isBigEnough);
     189print("Done with fifth array.");
     190
    159191</script>
    160192</body>
  • trunk/LayoutTests/fast/js/resources/array-every.js

    r11995 r20569  
    8181shouldBeTrue("[12, 54, 18, 130, 44].every(isBigEnoughShortCircuit)");
    8282shouldBe("accumulator.toString()", "[12, 54, 18, 130, 44].toString()");
     83debug("");
     84
     85debug('7.0 Behavior for Holes in Arrays');
     86var arr = [5, 5, 5, 5];
     87delete arr[1];
     88function isNotUndefined(element, index, array) {
     89    return typeof element !== "undefined";
     90}
     91shouldBeTrue("arr.every(isNotUndefined)");
     92arr = new Array(20);
     93shouldBeTrue("arr.every(isNotUndefined)");
    8394
    8495successfullyParsed = true;
  • trunk/LayoutTests/fast/js/resources/array-lastIndexOf.js

    r15952 r20569  
    2424shouldBe('lastIndex', '3');
    2525
     26delete testArray[1];
     27
     28lastIndex = testArray.lastIndexOf(undefined);
     29shouldBe('lastIndex', '-1');
     30
     31delete testArray[3];
     32
     33lastIndex = testArray.lastIndexOf(undefined);
     34shouldBe('lastIndex', '-1');
     35
     36testArray = new Array(20);
     37
     38lastIndex = testArray.lastIndexOf(undefined);
     39shouldBe('lastIndex', '-1');
     40
     41testArray[19] = undefined;
     42
     43lastIndex = testArray.lastIndexOf(undefined);
     44shouldBe('lastIndex', '19');
     45
     46lastIndex = testArray.lastIndexOf(undefined, 18);
     47shouldBe('lastIndex', '-1');
     48
     49delete testArray[19];
     50
     51lastIndex = testArray.lastIndexOf(undefined);
     52shouldBe('lastIndex', '-1');
     53
    2654var successfullyParsed = true;
Note: See TracChangeset for help on using the changeset viewer.