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 --readonly-debug-evaluate |
| 6 |
| 7 Debug = debug.Debug |
| 8 |
| 9 var exception = null; |
| 10 let a = 1; |
| 11 var object = { property : 2, |
| 12 get getter() { return 3; } |
| 13 }; |
| 14 var string1 = { toString() { return "x"; } }; |
| 15 var string2 = { toString() { print("x"); return "x"; } }; |
| 16 var array = [4, 5]; |
| 17 |
| 18 function set_a() { a = 2; } |
| 19 |
| 20 function get_a() { return a; } |
| 21 |
| 22 function listener(event, exec_state, event_data, data) { |
| 23 if (event != Debug.DebugEvent.Break) return; |
| 24 try { |
| 25 // Simple test. |
| 26 assertEquals(3, exec_state.frame(0).evaluate("1 + 2").value()); |
| 27 // Context load. |
| 28 assertEquals(1, exec_state.frame(0).evaluate("a").value()); |
| 29 // Global and named property load. |
| 30 assertEquals(2, exec_state.frame(0).evaluate("object.property").value()); |
| 31 // Load via read-only getter. |
| 32 assertEquals(3, exec_state.frame(0).evaluate("object.getter").value()); |
| 33 // Implicit call to read-only toString. |
| 34 assertEquals("xy", exec_state.frame(0).evaluate("string1 + 'y'").value()); |
| 35 // Keyed property load. |
| 36 assertEquals(5, exec_state.frame(0).evaluate("array[1]").value()); |
| 37 // Call to read-only function. |
| 38 assertEquals(1, exec_state.frame(0).evaluate("get_a()").value()); |
| 39 // Call to read-only function within try-catch. |
| 40 assertEquals(1, exec_state.frame(0).evaluate("try { get_a() } catch (e) {}")
.value()); |
| 41 // Test that non-read-only code fails. |
| 42 assertThrows(() => exec_state.frame(0).evaluate("exception = 1"), EvalError)
; |
| 43 // Test that calling a non-read-only function fails. |
| 44 assertThrows(() => exec_state.frame(0).evaluate("set_a()"), EvalError); |
| 45 // Test that implicit call to a non-read-only function fails. |
| 46 assertThrows(() => exec_state.frame(0).evaluate("string2 + 'y'"), EvalError)
; |
| 47 // Test that try-catch does not catch the EvalError. |
| 48 assertThrows(() => exec_state.frame(0).evaluate("try { set_a() } catch (e) {
}"), EvalError); |
| 49 } catch (e) { |
| 50 exception = e; |
| 51 print(e, e.stack); |
| 52 }; |
| 53 }; |
| 54 |
| 55 // Add the debug event listener. |
| 56 Debug.setListener(listener); |
| 57 |
| 58 function f() { |
| 59 debugger; |
| 60 }; |
| 61 |
| 62 f(); |
| 63 |
| 64 assertNull(exception); |
| 65 assertEquals(1, a); |
OLD | NEW |