js/src/jit-test/tests/for-of/string-iterator-surfaces.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/string-iterator-surfaces.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +// String.prototype[@@iterator] and StringIterator.prototype surface tests
     1.5 +
     1.6 +load(libdir + "array-compare.js");
     1.7 +load(libdir + "asserts.js");
     1.8 +load(libdir + "iteration.js");
     1.9 +
    1.10 +function assertDataDescriptor(actual, expected) {
    1.11 +    assertEq(actual.value, expected.value);
    1.12 +    assertEq(actual.writable, expected.writable);
    1.13 +    assertEq(actual.enumerable, expected.enumerable);
    1.14 +    assertEq(actual.configurable, expected.configurable);
    1.15 +}
    1.16 +
    1.17 +function isConstructor(o) {
    1.18 +    try {
    1.19 +        new (new Proxy(o, {construct: () => ({})}));
    1.20 +        return true;
    1.21 +    } catch(e) {
    1.22 +        return false;
    1.23 +    }
    1.24 +}
    1.25 +
    1.26 +function assertBuiltinFunction(o, name, arity) {
    1.27 +    var fn = o[name];
    1.28 +    assertDataDescriptor(Object.getOwnPropertyDescriptor(o, name), {
    1.29 +        value: fn,
    1.30 +        writable: true,
    1.31 +        enumerable: false,
    1.32 +        configurable: true,
    1.33 +    });
    1.34 +
    1.35 +    assertEq(typeof fn, "function");
    1.36 +    assertEq(Object.getPrototypeOf(fn), Function.prototype);
    1.37 +    // FIXME: Proxy should only have [[Construct]] if target has [[Construct]] (bug 929467)
    1.38 +    // assertEq(isConstructor(fn), false);
    1.39 +
    1.40 +    arraysEqual(Object.getOwnPropertyNames(fn).sort(), ["length", "name", "arguments", "caller"].sort());
    1.41 +
    1.42 +    // Also test "name", "arguments" and "caller" in addition to "length"?
    1.43 +    assertDataDescriptor(Object.getOwnPropertyDescriptor(fn, "length"), {
    1.44 +        value: arity,
    1.45 +        writable: false,
    1.46 +        enumerable: false,
    1.47 +        configurable: false,
    1.48 +    });
    1.49 +}
    1.50 +
    1.51 +
    1.52 +// String.prototype[@@iterator] is a built-in function
    1.53 +assertBuiltinFunction(String.prototype, std_iterator, 0);
    1.54 +
    1.55 +// Test StringIterator.prototype surface
    1.56 +var iter = ""[std_iterator]();
    1.57 +var iterProto = Object.getPrototypeOf(iter);
    1.58 +
    1.59 +// StringIterator.prototype inherits from Object.prototype
    1.60 +assertEq(Object.getPrototypeOf(iterProto), Object.prototype);
    1.61 +
    1.62 +// Own properties for StringIterator.prototype: "next" and @@iterator
    1.63 +arraysEqual(Object.getOwnPropertyNames(iterProto).sort(), ["next", std_iterator].sort());
    1.64 +
    1.65 +// StringIterator.prototype[@@iterator] is a built-in function
    1.66 +assertBuiltinFunction(iterProto, std_iterator, 0);
    1.67 +
    1.68 +// StringIterator.prototype.next is a built-in function
    1.69 +assertBuiltinFunction(iterProto, "next", 0);
    1.70 +
    1.71 +// StringIterator.prototype[@@iterator] is generic and returns |this|
    1.72 +for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iter, iterProto]) {
    1.73 +    assertEq(iterProto[std_iterator].call(v), v);
    1.74 +}
    1.75 +
    1.76 +// StringIterator.prototype.next is not generic
    1.77 +for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iterProto]) {
    1.78 +    assertThrowsInstanceOf(() => iterProto.next.call(v), TypeError);
    1.79 +}

mercurial