blob: 4d9b2983d23bf558465e0d0b2209c19b43023d5b [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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005// See: http://code.google.com/p/v8/issues/detail?id=3926
6
7// Switch statements should disable hole check elimination
8
9// Ensure that both reads and writes encounter the hole check
10// FullCodeGen had an issue on reads; TurboFan had an issue on writes
11function f(x) {
12 var z;
13 switch (x) {
14 case 1:
15 let y = 1;
16 case 2:
17 y = 2;
18 case 3:
19 z = y;
20 }
21 return z;
22}
23assertEquals(2, f(1));
24assertThrows(function() {f(2)}, ReferenceError);
25assertThrows(function() {f(3)}, ReferenceError);
26
27// Ensure that hole checks are done even in subordinate scopes
28assertThrows(function() {
29 switch (1) {
30 case 0:
31 let x = 2;
32 case 1:
33 { // this block, plus the let below, adds another linear lexical scope
34 let y = 3;
35 x;
36 }
37 }
38}, ReferenceError);
39
40// Ensure that inner functions and eval don't skip hole checks
41
42function g(x) {
43 switch (x) {
44 case 1:
45 let z;
46 case 2:
47 return function() { z = 1; }
48 case 3:
49 return function() { return z; }
50 case 4:
51 return eval("z = 1");
52 case 5:
53 return eval("z");
54 }
55}
56
57assertEquals(undefined, g(1)());
58assertThrows(g(2), ReferenceError);
59assertThrows(g(3), ReferenceError);
60assertThrows(function () {g(4)}, ReferenceError);
61assertThrows(function () {g(5)}, ReferenceError);
62
63// Ensure the same in strict mode, with different eval and function semantics
64
65function h(x) {
66 'use strict'
67 switch (x) {
68 case 1:
69 let z;
70 case 2:
71 return function() { z = 1; }
72 case 3:
73 return function() { return z; }
74 case 4:
75 return eval("z = 1");
76 case 5:
77 return eval("z");
78 }
79}
80
81assertEquals(undefined, h(1)());
82assertThrows(h(2), ReferenceError);
83assertThrows(h(3), ReferenceError);
84assertThrows(function () {h(4)}, ReferenceError);
85assertThrows(function () {h(5)}, ReferenceError);