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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/for-of/array-iterator-surfaces-2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,31 @@
     1.4 +// Superficial tests for iterators created by Array.prototype.iterator
     1.5 +
     1.6 +load(libdir + "iteration.js");
     1.7 +
     1.8 +var proto = Object.getPrototypeOf([][std_iterator]());
     1.9 +assertEq(Object.getPrototypeOf(proto), Iterator.prototype);
    1.10 +proto = Object.getPrototypeOf([].keys());
    1.11 +assertEq(Object.getPrototypeOf(proto), Iterator.prototype);
    1.12 +proto = Object.getPrototypeOf([].entries());
    1.13 +assertEq(Object.getPrototypeOf(proto), Iterator.prototype);
    1.14 +
    1.15 +function check(it) {
    1.16 +    assertEq(typeof it, 'object');
    1.17 +    assertEq(Object.getPrototypeOf(it), proto);
    1.18 +    assertEq(Object.getOwnPropertyNames(it).length, 0);
    1.19 +    assertEq(it[std_iterator](), it);
    1.20 +
    1.21 +    // for-in enumerates the iterator's properties.
    1.22 +    it.x = 0;
    1.23 +    var s = '';
    1.24 +    for (var p in it)
    1.25 +        s += p + '.';
    1.26 +    assertEq(s, 'x.');
    1.27 +}
    1.28 +
    1.29 +check([][std_iterator]());
    1.30 +check(Array.prototype[std_iterator].call({}));
    1.31 +check([].keys());
    1.32 +check(Array.prototype.keys.call({}));
    1.33 +check([].entries());
    1.34 +check(Array.prototype.entries.call({}));

mercurial