summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Comprehensions/generator-semantics.js
blob: 52426115fe6e468d965debb6ed9a02f203e18a9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Interaction of eval with generator expressions.
function a1() {
  var a = 10;
  var g = (for (y of [0]) eval('var a=42;'));
  g.next();
  return a;
}
assertEq(a1(), 10);

function a2() {
  var a = 10;
  (for (y of [0]) eval('a=42')).next();
  return a;
}
assertEq(a2(), 42)

// Arguments and this.
function b1() {
  return [for (arg of (for (i of [0, 1, 2]) arguments[i])) arg];
}
assertDeepEq(b1('a', 'b', 'c'), ['a', 'b', 'c']);

function b2() {
  return [for (x of (for (i of [0]) this)) x];
}
var b2o = { b2: b2 }
assertDeepEq(b2o.b2(), [b2o])

// Assignment to eval or arguments.
function c1() {
  return [for (arg of (for (i of [0, 1, 2]) arguments = i)) arg];
}
assertDeepEq(c1(), [0, 1, 2]);

function c2() {
  "use strict";
  return eval('[for (arg of (for (i of [0, 1, 2]) arguments = i)) arg]');
}
assertThrows(c2, SyntaxError);

function c3() {
  return [for (arg of (for (i of [0, 1, 2]) eval = i)) arg];
}
assertDeepEq(c3(), [0, 1, 2]);

function c4() {
  "use strict";
  return eval('[for (arg of (for (i of [0, 1, 2]) eval = i)) arg]');
}
assertThrows(c4, SyntaxError);

reportCompare(null, null, "test");