OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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: --ignition |
| 6 |
| 7 // Test that declaring local variables in IIFEs works with |
| 8 // side-effect free debug-evaluate. |
| 9 |
| 10 Debug = debug.Debug |
| 11 |
| 12 var exception = null; |
| 13 |
| 14 function listener(event, exec_state, event_data, data) { |
| 15 if (event != Debug.DebugEvent.Break) return; |
| 16 try { |
| 17 function success(expectation, source) { |
| 18 assertEquals(expectation, |
| 19 exec_state.frame(0).evaluate(source, true).value()); |
| 20 } |
| 21 function fail(source) { |
| 22 assertThrows(() => exec_state.frame(0).evaluate(source, true), |
| 23 EvalError); |
| 24 } |
| 25 // Declaring 'a' sets a property to the global object. |
| 26 fail("var a = 3"); |
| 27 exec_state.frame(0).evaluate("var a = 2", false); |
| 28 assertEquals(2, a); |
| 29 // Wrapping into an IIFE would be fine, since 'a' is local. |
| 30 success(100, |
| 31 `(function(x) { |
| 32 var a = 0; |
| 33 for (var i = 0; i < x; i++) { |
| 34 a += x; |
| 35 } |
| 36 return a; |
| 37 })(10);`); |
| 38 success(100, |
| 39 `(x => { |
| 40 let a = 0; |
| 41 for (var i = 0; i < x; i++) { |
| 42 a += x; |
| 43 } |
| 44 return a; |
| 45 })(10);`); |
| 46 // Not using 'var' to declare would make the access go to global object. |
| 47 fail( `(function(x) { |
| 48 a = 0; |
| 49 for (var i = 0; i < x; i++) { |
| 50 a += x; |
| 51 } |
| 52 return a; |
| 53 })(10);`); |
| 54 } catch (e) { |
| 55 exception = e; |
| 56 print(e, e.stack); |
| 57 }; |
| 58 }; |
| 59 |
| 60 // Add the debug event listener. |
| 61 Debug.setListener(listener); |
| 62 |
| 63 function f() { |
| 64 debugger; |
| 65 }; |
| 66 |
| 67 f(); |
| 68 |
| 69 assertNull(exception); |
OLD | NEW |