js/src/jit-test/tests/basic/spread-call-eval.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.

michael@0 1 load(libdir + "asserts.js");
michael@0 2 load(libdir + "iteration.js");
michael@0 3
michael@0 4 assertEq(eval(...[]), undefined);
michael@0 5 assertEq(eval(...["1 + 2"]), 3);
michael@0 6
michael@0 7 let a = 10, b = 1;
michael@0 8 assertEq(eval(...["a + b"]), 11);
michael@0 9
michael@0 10 (function() {
michael@0 11 let a = 20;
michael@0 12 assertEq(eval(...["a + b"]), 21);
michael@0 13 })();
michael@0 14
michael@0 15 with ({ a: 30 }) {
michael@0 16 assertEq(eval(...["a + b"]), 31);
michael@0 17 }
michael@0 18
michael@0 19 let line0 = Error().lineNumber;
michael@0 20 try { // line0 + 1
michael@0 21 eval(...["("]); // line0 + 2
michael@0 22 } catch (e) {
michael@0 23 assertEq(e.lineNumber, 1);
michael@0 24 }
michael@0 25
michael@0 26 // other iterable objects
michael@0 27 assertEq(eval(...["a + b"][std_iterator]()), 11);
michael@0 28 assertEq(eval(...Set(["a + b"])), 11);
michael@0 29 let itr = {};
michael@0 30 itr[std_iterator] = function() {
michael@0 31 return {
michael@0 32 i: 0,
michael@0 33 next: function() {
michael@0 34 this.i++;
michael@0 35 if (this.i == 1)
michael@0 36 return { value: "a + b", done: false };
michael@0 37 else
michael@0 38 return { value: undefined, done: true };
michael@0 39 }
michael@0 40 };
michael@0 41 };
michael@0 42 assertEq(eval(...itr), 11);
michael@0 43 function* gen() {
michael@0 44 yield "a + b";
michael@0 45 }
michael@0 46 assertEq(eval(...gen()), 11);
michael@0 47
michael@0 48 let c = ["C"], d = "D";
michael@0 49 assertEq(eval(...c=["c[0] + d"]), "c[0] + dD");
michael@0 50
michael@0 51 // According to the draft spec, null and undefined are to be treated as empty
michael@0 52 // arrays. However, they are not iterable. If the spec is not changed to be in
michael@0 53 // terms of iterables, these tests should be fixed.
michael@0 54 //assertEq(eval("a + b", ...null), 11);
michael@0 55 //assertEq(eval("a + b", ...undefined), 11);
michael@0 56 assertThrowsInstanceOf(() => eval("a + b", ...null), TypeError);
michael@0 57 assertThrowsInstanceOf(() => eval("a + b", ...undefined), TypeError);

mercurial