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: --expose-debug-as debug |
| 6 |
| 7 // Test that debug-evaluate can find the correct this value for an |
| 8 // arrow function. |
| 9 |
| 10 Debug = debug.Debug |
| 11 |
| 12 var break_count = 0; |
| 13 var exception = null; |
| 14 |
| 15 function listener(event, exec_state, event_data, data) { |
| 16 if (event != Debug.DebugEvent.Break) return; |
| 17 try { |
| 18 for (var i = 0; i < exec_state.frameCount() - 1; i++) { |
| 19 var frame = exec_state.frame(0); |
| 20 var this_value = frame.evaluate("this").value(); |
| 21 if (frame.sourceLineText().indexOf("undefined this") > 0) { |
| 22 assertEquals(undefined, this_value); |
| 23 } else { |
| 24 assertEquals(receiver, this_value); |
| 25 } |
| 26 } |
| 27 break_count++; |
| 28 } catch (e) { |
| 29 exception = e; |
| 30 } |
| 31 } |
| 32 |
| 33 var receiver = {}; |
| 34 |
| 35 // Context-allocated receiver. |
| 36 function f() { |
| 37 assertEquals(receiver, this); |
| 38 debugger; |
| 39 return () => { |
| 40 assertEquals(receiver, this); |
| 41 debugger; |
| 42 with ({}) { |
| 43 return () => { |
| 44 debugger; |
| 45 try { |
| 46 throw new Error(); |
| 47 } catch (e) { |
| 48 return () => { |
| 49 debugger; |
| 50 return g.call(receiver); |
| 51 }; |
| 52 } |
| 53 }; |
| 54 } |
| 55 }; |
| 56 } |
| 57 |
| 58 // Stack-allocated receiver. |
| 59 function g() { |
| 60 debugger; |
| 61 return () => { |
| 62 debugger; // undefined this. |
| 63 with ({}) { |
| 64 return () => { |
| 65 debugger; // undefined this. |
| 66 try { |
| 67 throw new Error(); |
| 68 } catch (e) { |
| 69 return () => { |
| 70 debugger; // undefined this. |
| 71 return f.call(receiver); |
| 72 }; |
| 73 } |
| 74 }; |
| 75 } |
| 76 }; |
| 77 } |
| 78 |
| 79 Debug.setListener(listener); |
| 80 |
| 81 var h = f.call(receiver); |
| 82 for (var i = 0; i < 20; i++) h = h(); |
| 83 var h = g.call(receiver); |
| 84 for (var i = 0; i < 20; i++) h = h(); |
| 85 |
| 86 Debug.setListener(null); |
| 87 |
| 88 assertEquals(54, break_count); |
| 89 assertNull(exception); |
OLD | NEW |