js/src/jit-test/tests/basic/spread-call-eval.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/spread-call-eval.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +load(libdir + "asserts.js");
     1.5 +load(libdir + "iteration.js");
     1.6 +
     1.7 +assertEq(eval(...[]), undefined);
     1.8 +assertEq(eval(...["1 + 2"]), 3);
     1.9 +
    1.10 +let a = 10, b = 1;
    1.11 +assertEq(eval(...["a + b"]), 11);
    1.12 +
    1.13 +(function() {
    1.14 +  let a = 20;
    1.15 +  assertEq(eval(...["a + b"]), 21);
    1.16 +})();
    1.17 +
    1.18 +with ({ a: 30 }) {
    1.19 +  assertEq(eval(...["a + b"]), 31);
    1.20 +}
    1.21 +
    1.22 +let line0 = Error().lineNumber;
    1.23 +try {             // line0 + 1
    1.24 +  eval(...["("]); // line0 + 2
    1.25 +} catch (e) {
    1.26 +  assertEq(e.lineNumber, 1);
    1.27 +}
    1.28 +
    1.29 +// other iterable objects
    1.30 +assertEq(eval(...["a + b"][std_iterator]()), 11);
    1.31 +assertEq(eval(...Set(["a + b"])), 11);
    1.32 +let itr = {};
    1.33 +itr[std_iterator] = function() {
    1.34 +    return {
    1.35 +        i: 0,
    1.36 +        next: function() {
    1.37 +            this.i++;
    1.38 +            if (this.i == 1)
    1.39 +                return { value: "a + b", done: false };
    1.40 +            else
    1.41 +                return { value: undefined, done: true };
    1.42 +        }
    1.43 +    };
    1.44 +};
    1.45 +assertEq(eval(...itr), 11);
    1.46 +function* gen() {
    1.47 +    yield "a + b";
    1.48 +}
    1.49 +assertEq(eval(...gen()), 11);
    1.50 +
    1.51 +let c = ["C"], d = "D";
    1.52 +assertEq(eval(...c=["c[0] + d"]), "c[0] + dD");
    1.53 +
    1.54 +// According to the draft spec, null and undefined are to be treated as empty
    1.55 +// arrays. However, they are not iterable. If the spec is not changed to be in
    1.56 +// terms of iterables, these tests should be fixed.
    1.57 +//assertEq(eval("a + b", ...null), 11);
    1.58 +//assertEq(eval("a + b", ...undefined), 11);
    1.59 +assertThrowsInstanceOf(() => eval("a + b", ...null), TypeError);
    1.60 +assertThrowsInstanceOf(() => eval("a + b", ...undefined), TypeError);

mercurial