Commit 0dcc7a0e authored by jgruber's avatar jgruber Committed by Commit bot

[debug] Add Eval scope type to inspector protocol

BUG=v8:5530,chromium:667218

Review-Url: https://codereview.chromium.org/2519773003
Cr-Commit-Position: refs/heads/master@{#41205}
parent 3eff396a
......@@ -42,6 +42,7 @@ DebuggerScript._scopeTypeNames.set(ScopeType.Closure, "closure");
DebuggerScript._scopeTypeNames.set(ScopeType.Catch, "catch");
DebuggerScript._scopeTypeNames.set(ScopeType.Block, "block");
DebuggerScript._scopeTypeNames.set(ScopeType.Script, "script");
DebuggerScript._scopeTypeNames.set(ScopeType.Eval, "eval");
/**
* @param {function()} fun
......@@ -530,15 +531,19 @@ DebuggerScript._buildScopeObject = function(scopeType, scopeObject)
case ScopeType.Catch:
case ScopeType.Block:
case ScopeType.Script:
case ScopeType.Eval:
// For transient objects we create a "persistent" copy that contains
// the same properties.
// Reset scope object prototype to null so that the proto properties
// don't appear in the local scope section.
var properties = /** @type {!ObjectMirror} */(MakeMirror(scopeObject, true /* transient */)).properties();
// Almost always Script scope will be empty, so just filter out that noise.
// Also drop empty Block scopes, should we get any.
if (!properties.length && (scopeType === ScopeType.Script || scopeType === ScopeType.Block))
// Also drop empty Block, Eval and Script scopes, should we get any.
if (!properties.length && (scopeType === ScopeType.Script ||
scopeType === ScopeType.Block ||
scopeType === ScopeType.Eval)) {
break;
}
result = { __proto__: null };
for (var j = 0; j < properties.length; j++) {
var name = properties[j].name();
......
......@@ -198,7 +198,8 @@ var ScopeType = { Global: 0,
Closure: 3,
Catch: 4,
Block: 5,
Script: 6 };
Script: 6,
Eval: 7 };
/** @typedef {{
......
......@@ -211,6 +211,7 @@ InjectedScript.closureTypes["block"] = "Block";
InjectedScript.closureTypes["script"] = "Script";
InjectedScript.closureTypes["with"] = "With Block";
InjectedScript.closureTypes["global"] = "Global";
InjectedScript.closureTypes["eval"] = "Eval";
InjectedScript.prototype = {
/**
......
......@@ -456,7 +456,7 @@
"id": "Scope",
"type": "object",
"properties": [
{ "name": "type", "type": "string", "enum": ["global", "local", "with", "closure", "catch", "block", "script"], "description": "Scope type." },
{ "name": "type", "type": "string", "enum": ["global", "local", "with", "closure", "catch", "block", "script", "eval"], "description": "Scope type." },
{ "name": "object", "$ref": "Runtime.RemoteObject", "description": "Object representing the scope. For <code>global</code> and <code>with</code> scopes it represents the actual object; for the rest of the scopes, it is artificial transient object enumerating scope variables as its properties." },
{ "name": "name", "type": "string", "optional": true },
{ "name": "startLocation", "$ref": "Location", "optional": true, "description": "Location in the source code where scope starts" },
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --no-always-opt
// Flags: --no-always-opt
// Test that the (strict) eval scope is visible to the debugger.
......
......@@ -25,10 +25,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug --expose-gc --allow-natives-syntax
// Flags: --expose-gc
// Flags: --inline-construct
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
var listenerComplete = false;
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug
'use strict';
var Debug = debug.Debug;
......
......@@ -436,6 +436,7 @@ class DebugWrapper {
case "catch": return this.ScopeType.Catch;
case "block": return this.ScopeType.Block;
case "script": return this.ScopeType.Script;
case "eval": return this.ScopeType.Eval;
default: %AbortJS("Unexpected scope type");
}
}
......@@ -450,7 +451,7 @@ class DebugWrapper {
}
}
if (found == null) return { isUndefined : true }
if (found == null) return { isUndefined : () => true };
const val = { value : () => found.value.value };
return { value : () => val,
......
{
id : <messageId>
result : {
result : [
[0] : {
configurable : true
enumerable : true
isOwn : true
name : hest
value : {
description : 420
type : number
value : 420
}
writable : true
}
]
}
}
\ No newline at end of file
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
InspectorTest.addScript(
`function testNonEmptyEvalScope() {
eval("'use strict'; var hest = 420; debugger;");
}
function testEmptyEvalScope() {
eval("var fisk = 42; testNonEmptyEvalScope();");
}`);
Protocol.Debugger.enable();
Protocol.Debugger.oncePaused().then(dumpScopeOnPause);
Protocol.Runtime.evaluate({ "expression": "testEmptyEvalScope();" });
var waitScopeObjects = 0;
function dumpScopeOnPause(message)
{
var scopeChain = message.params.callFrames[0].scopeChain;
var evalScopeObjectIds = [];
for (var scope of scopeChain) {
if (scope.type === "eval") {
evalScopeObjectIds.push(scope.object.objectId);
}
}
waitScopeObjects = evalScopeObjectIds.length;
if (!waitScopeObjects) {
InspectorTest.completeTest();
} else {
for (var objectId of evalScopeObjectIds)
Protocol.Runtime.getProperties({ "objectId" : objectId })
.then(dumpProperties);
}
}
function dumpProperties(message)
{
InspectorTest.logMessage(message);
--waitScopeObjects;
if (!waitScopeObjects)
Protocol.Debugger.resume().then(InspectorTest.completeTest);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment