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