js/src/jit-test/tests/for-of/array-iterator-generic.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Array.prototype.iterator is generic.
     2 // That is, it can be applied to arraylike objects and strings, not just arrays.
     4 load(libdir + "asserts.js");
     5 load(libdir + "iteration.js");
     7 function test(obj) {
     8     var it = Array.prototype[std_iterator].call(obj);
     9     var ki = Array.prototype.keys.call(obj);
    10     var ei = Array.prototype.entries.call(obj);
    11     for (var i = 0; i < (obj.length >>> 0); i++) {
    12         assertIteratorNext(it, obj[i]);
    13         assertIteratorNext(ki, i);
    14         assertIteratorNext(ei, [i, obj[i]]);
    15     }
    16     assertIteratorDone(it, undefined);
    17     assertIteratorDone(ki, undefined);
    18     assertIteratorDone(ei, undefined);
    19 }
    21 test({length: 0});
    22 test({length: 0, 0: 'x', 1: 'y'});
    23 test({length: 2, 0: 'x', 1: 'y'});
    24 test(Object.create(['x', 'y', 'z']));
    25 test(Object.create({length: 2, 0: 'x', 1: 'y'}));
    26 test("");
    27 test("ponies");
    29 // Perverse length values.
    30 test({length: 0x1f00000000});
    31 test({length: -0xfffffffe, 0: 'a', 1: 'b'});
    32 test({length: "011", 9: 9, 10: 10, 11: 11});
    33 test({length: -0});
    34 test({length: 2.7, 0: 0, 1: 1, 2: 2});
    35 test({length: {valueOf: function () { return 3; }}, 0: 0, 1: 1, 2: 2});

mercurial