Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: test/debugger/debug/debug-evaluate-no-side-effect.js

Issue 2720013003: [debug] add more tests for side-effect free debug-evaluate. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/debug/debug-evaluate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --ignition 5 // Flags: --ignition
6 6
7 Debug = debug.Debug 7 Debug = debug.Debug
8 8
9 var exception = null; 9 var exception = null;
10 let a = 1; 10 let a = 1;
11 var object = { property : 2, 11 var object = { property : 2,
12 get getter() { return 3; } 12 get getter() { return 3; }
13 }; 13 };
14 var string1 = { toString() { return "x"; } }; 14 var string1 = { toString() { return "x"; } };
15 var string2 = { toString() { print("x"); return "x"; } }; 15 var string2 = { toString() { print("x"); return "x"; } };
16 var array = [4, 5]; 16 var array = [4, 5];
17 var error = new Error(); 17 var error = new Error();
18 18
19 function set_a() { a = 2; } 19 function set_a() { a = 2; }
20 function get_a() { return a; }
21 var bound = get_a.bind(0);
20 22
21 function get_a() { return a; } 23 var global_eval = eval;
22 24
23 function listener(event, exec_state, event_data, data) { 25 function listener(event, exec_state, event_data, data) {
24 if (event != Debug.DebugEvent.Break) return; 26 if (event != Debug.DebugEvent.Break) return;
25 try { 27 try {
26 function success(expectation, source) { 28 function success(expectation, source) {
27 assertEquals(expectation, 29 assertEquals(expectation,
28 exec_state.frame(0).evaluate(source, true).value()); 30 exec_state.frame(0).evaluate(source, true).value());
29 } 31 }
30 function fail(source) { 32 function fail(source) {
31 assertThrows(() => exec_state.frame(0).evaluate(source, true), 33 assertThrows(() => exec_state.frame(0).evaluate(source, true),
32 EvalError); 34 EvalError);
33 } 35 }
34 // Simple test. 36 // Simple test.
35 success(3, "1 + 2"); 37 success(3, "1 + 2");
36 // Dymanic load. 38 // Dymanic load.
37 success(array, "array"); 39 success(array, "array");
38 // Context load. 40 // Context load.
39 success(1, "a"); 41 success(1, "a");
40 // Global and named property load. 42 // Global and named property load.
41 success(2, "object.property"); 43 success(2, "object.property");
42 // Load via read-only getter. 44 // Load via read-only getter.
43 success(3, "object.getter"); 45 success(3, "object.getter");
44 // Implicit call to read-only toString. 46 // Implicit call to read-only toString.
45 success("xy", "string1 + 'y'"); 47 success("xy", "string1 + 'y'");
46 // Keyed property load. 48 // Keyed property load.
47 success(5, "array[1]"); 49 success(5, "array[1]");
48 // Call to read-only function. 50 // Call to read-only function.
49 success(1, "get_a()"); 51 success(1, "get_a()");
52 success(1, "bound()");
53 success({}, "new get_a()");
50 // Call to read-only function within try-catch. 54 // Call to read-only function within try-catch.
51 success(1, "try { get_a() } catch (e) {}"); 55 success(1, "try { get_a() } catch (e) {}");
52 // Call to C++ built-in. 56 // Call to C++ built-in.
53 success(Math.sin(2), "Math.sin(2)"); 57 success(Math.sin(2), "Math.sin(2)");
54 // Call to whitelisted get accessors. 58 // Call to whitelisted get accessors.
55 success(3, "'abc'.length"); 59 success(3, "'abc'.length");
56 success(2, "array.length"); 60 success(2, "array.length");
61 success(1, "'x'.length");
62 success(0, "set_a.length");
63 success("set_a", "set_a.name");
64 success(0, "bound.length");
65 success("bound get_a", "bound.name");
57 // Test that non-read-only code fails. 66 // Test that non-read-only code fails.
58 fail("exception = 1"); 67 fail("exception = 1");
59 // Test that calling a non-read-only function fails. 68 // Test that calling a non-read-only function fails.
60 fail("set_a()"); 69 fail("set_a()");
70 fail("new set_a()");
61 // Test that implicit call to a non-read-only function fails. 71 // Test that implicit call to a non-read-only function fails.
62 fail("string2 + 'y'"); 72 fail("string2 + 'y'");
63 // Test that try-catch does not catch the EvalError. 73 // Test that try-catch does not catch the EvalError.
64 fail("try { set_a() } catch (e) {}"); 74 fail("try { set_a() } catch (e) {}");
65 // Test that call to set accessor fails. 75 // Test that call to set accessor fails.
66 fail("array.length = 4"); 76 fail("array.length = 4");
67 // Test that call to non-whitelisted get accessor fails. 77 // Test that call to non-whitelisted get accessor fails.
68 fail("error.stack"); 78 fail("error.stack");
79 // Eval is not allowed.
80 fail("eval('Math.sin(1)')");
81 fail("eval('exception = 1')");
82 fail("global_eval('1')");
69 } catch (e) { 83 } catch (e) {
70 exception = e; 84 exception = e;
71 print(e, e.stack); 85 print(e, e.stack);
72 }; 86 };
73 }; 87 };
74 88
75 // Add the debug event listener. 89 // Add the debug event listener.
76 Debug.setListener(listener); 90 Debug.setListener(listener);
77 91
78 function f() { 92 function f() {
79 debugger; 93 debugger;
80 }; 94 };
81 95
82 f(); 96 f();
83 97
84 assertNull(exception); 98 assertNull(exception);
85 assertEquals(1, a); 99 assertEquals(1, a);
OLDNEW
« no previous file with comments | « src/debug/debug-evaluate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698