blob: be1687b5e967d848b4009f7d925975cec9a319cc [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --harmony-sloppy --harmony-sloppy-let --harmony-sloppy-function
6// Flags: --legacy-const
7
8// Legacy-const-let conflict in a function throws, even if the legacy const
9// is in an eval
10
11// Throws at the top level of a function
12assertThrows(function() {
13 let x = 1;
14 eval('const x = 2');
15}, TypeError);
16
17// If the eval is in its own block scope, throws
18assertThrows(function() {
19 let y = 1;
20 { eval('const y = 2'); }
21}, TypeError);
22
23// If the let is in its own block scope, with the eval, throws
24assertThrows(function() {
25 {
26 let x = 1;
27 eval('const x = 2');
28 }
29}, TypeError);
30
31// Legal if the let is no longer visible
32assertDoesNotThrow(function() {
33 {
34 let x = 1;
35 }
36 eval('const x = 2');
37});
38
39// In global scope
40let caught = false;
41try {
42 let z = 1;
43 eval('const z = 2');
44} catch (e) {
45 caught = true;
46}
47assertTrue(caught);
48
49// Let declarations beyond a function boundary don't conflict
50caught = false;
51try {
52 let a = 1;
53 (function() {
54 eval('const a');
55 })();
56} catch (e) {
57 caught = true;
58}
59assertFalse(caught);
60
61// legacy const across with doesn't conflict
62caught = false;
63try {
64 (function() {
65 with ({x: 1}) {
66 eval("const x = 2;");
67 }
68 })();
69} catch (e) {
70 caught = true;
71}
72assertFalse(caught);
73
74// legacy const can still conflict with let across a with
75caught = false;
76try {
77 (function() {
78 let x;
79 with ({x: 1}) {
80 eval("const x = 2;");
81 }
82 })();
83} catch (e) {
84 caught = true;
85}
86assertTrue(caught);