| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 listener_delegate(exec_state); | 56 listener_delegate(exec_state); |
| 57 } | 57 } |
| 58 } catch (e) { | 58 } catch (e) { |
| 59 exception = e; | 59 exception = e; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Add the debug event listener. | 63 // Add the debug event listener. |
| 64 Debug.setListener(listener); | 64 Debug.setListener(listener); |
| 65 | 65 |
| 66 var actual_new_value; | 66 var actual_new_result; |
| 67 try { | 67 try { |
| 68 actual_new_result = fun(); | 68 actual_new_result = fun(); |
| 69 } finally { | 69 } finally { |
| 70 Debug.setListener(null); | 70 Debug.setListener(null); |
| 71 } | 71 } |
| 72 | 72 |
| 73 if (exception != null) { | 73 if (exception != null) { |
| 74 assertUnreachable("Exception in listener\n" + exception.stack); | 74 assertUnreachable("Exception in listener\n" + exception.stack); |
| 75 } | 75 } |
| 76 assertTrue(listener_called); | 76 assertTrue(listener_called); |
| 77 | 77 |
| 78 assertEquals(expected_new_result, actual_new_result); | 78 assertEquals(expected_new_result, actual_new_result); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Accepts a closure 'fun' that returns a variable from it's outer scope. | 81 // Accepts a closure 'fun' that returns a variable from its outer scope. |
| 82 // The test changes the value of variable via the handle to function and checks | 82 // The test changes the value of variable via the handle to function and checks |
| 83 // that the return value changed accordingly. | 83 // that the return value changed accordingly. |
| 84 function RunClosureTest(scope_number, expected_old_result, variable_name, | 84 function RunClosureTest(scope_number, expected_old_result, variable_name, |
| 85 new_value, expected_new_result, fun) { | 85 new_value, expected_new_result, fun) { |
| 86 var actual_old_result = fun(); | 86 var actual_old_result = fun(); |
| 87 assertEquals(expected_old_result, actual_old_result); | 87 assertEquals(expected_old_result, actual_old_result); |
| 88 | 88 |
| 89 var fun_mirror = Debug.MakeMirror(fun); | 89 var fun_mirror = Debug.MakeMirror(fun); |
| 90 | 90 |
| 91 var scope = fun_mirror.scope(scope_number); | 91 var scope = fun_mirror.scope(scope_number); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 assertSame("123", DebugCommandProcessor.resolveValue_( | 301 assertSame("123", DebugCommandProcessor.resolveValue_( |
| 302 {type: "string", stringDescription: "123"})); | 302 {type: "string", stringDescription: "123"})); |
| 303 assertSame(123, DebugCommandProcessor.resolveValue_( | 303 assertSame(123, DebugCommandProcessor.resolveValue_( |
| 304 {type: "number", stringDescription: "123"})); | 304 {type: "number", stringDescription: "123"})); |
| 305 | 305 |
| 306 assertSame(Number, DebugCommandProcessor.resolveValue_( | 306 assertSame(Number, DebugCommandProcessor.resolveValue_( |
| 307 {handle: Debug.MakeMirror(Number).handle()})); | 307 {handle: Debug.MakeMirror(Number).handle()})); |
| 308 assertSame(RunClosureTest, DebugCommandProcessor.resolveValue_( | 308 assertSame(RunClosureTest, DebugCommandProcessor.resolveValue_( |
| 309 {handle: Debug.MakeMirror(RunClosureTest).handle()})); | 309 {handle: Debug.MakeMirror(RunClosureTest).handle()})); |
| 310 |
| 311 |
| 312 // Test script-scope variable. |
| 313 let abc = 12; |
| 314 { |
| 315 let exception; |
| 316 function listener(event, exec_state) { |
| 317 try { |
| 318 if (event == Debug.DebugEvent.Break) { |
| 319 let scope_count = exec_state.frame().scopeCount(); |
| 320 let script_scope = exec_state.frame().scope(scope_count - 2); |
| 321 assertTrue(script_scope.isScope()); |
| 322 assertEquals(debug.ScopeType.Script, script_scope.scopeType()); |
| 323 script_scope.setVariableValue('abc', 42); |
| 324 } |
| 325 } catch(e) { exception = e } |
| 326 } |
| 327 |
| 328 Debug.setListener(listener); |
| 329 assertEquals(12, abc); |
| 330 debugger; |
| 331 assertEquals(42, abc); |
| 332 |
| 333 if (exception != null) { |
| 334 assertUnreachable("Exception in listener\n" + exception.stack); |
| 335 } |
| 336 } |
| 337 |
| 338 Debug.setListener(null); |
| OLD | NEW |