From 7e69b2f996b5f1b77a14474f9b8dd9731fd04f9f Mon Sep 17 00:00:00 2001 From: Dmitry Lomov Date: Fri, 14 Nov 2014 14:39:06 +0100 Subject: [PATCH] Implement 'setVariableValue' for debugger block scopes. R=aandrey@chromium.org, rossberg@chromium.org, yurys@chromium.org BUG=v8:3690 LOG=N Review URL: https://codereview.chromium.org/732543002 Cr-Commit-Position: refs/heads/master@{#25358} --- src/runtime/runtime-debug.cc | 15 ++++++-- test/mjsunit/harmony/debug-evaluate-blockscopes.js | 40 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/runtime/runtime-debug.cc b/src/runtime/runtime-debug.cc index 28657ee..d576dc7 100644 --- a/src/runtime/runtime-debug.cc +++ b/src/runtime/runtime-debug.cc @@ -986,6 +986,17 @@ static bool SetClosureVariableValue(Isolate* isolate, Handle context, } +static bool SetBlockContextVariableValue(Handle block_context, + Handle variable_name, + Handle new_value) { + DCHECK(block_context->IsBlockContext()); + Handle scope_info(ScopeInfo::cast(block_context->extension())); + + return SetContextLocalValue(block_context->GetIsolate(), scope_info, + block_context, variable_name, new_value); +} + + // Create a plain JSObject which materializes the scope for the specified // catch context. MUST_USE_RESULT static MaybeHandle MaterializeCatchScope( @@ -1304,8 +1315,8 @@ class ScopeIterator { return SetClosureVariableValue(isolate_, CurrentContext(), variable_name, new_value); case ScopeIterator::ScopeTypeBlock: - // TODO(2399): should we implement it? - break; + return SetBlockContextVariableValue(CurrentContext(), variable_name, + new_value); case ScopeIterator::ScopeTypeModule: // TODO(2399): should we implement it? break; diff --git a/test/mjsunit/harmony/debug-evaluate-blockscopes.js b/test/mjsunit/harmony/debug-evaluate-blockscopes.js index 16885d0..d133cc0 100644 --- a/test/mjsunit/harmony/debug-evaluate-blockscopes.js +++ b/test/mjsunit/harmony/debug-evaluate-blockscopes.js @@ -67,3 +67,43 @@ assertEquals(1, result); Debug.clearBreakPoint(bp); // Get rid of the debug event listener. Debug.setListener(null); + + +function f1() { + { + let i = 1; + debugger; + assertEquals(2, i); + } +} + +function f2() { + { + let i = 1; + debugger; + assertEquals(2, i); + return function() { return i++; } + } +} + +var exception; +Debug.setListener(function (event, exec_state, event_data, data) { + try { + if (event == Debug.DebugEvent.Break) { + var frame = exec_state.frame(); + assertEquals(1, frame.evaluate("i").value()); + var allScopes = frame.allScopes(); + assertEquals(1, allScopes[0].scopeObject().value().i); + allScopes[0].setVariableValue("i", 2); + } + } catch (e) { + exception = e; + } +}); + +exception = null; +f1(); +assertEquals(null, exception, exception); +exception = null; +f2(); +assertEquals(null, exception, exception); -- 2.7.4