[inspector] add scope type for modules.

R=jgruber@chromium.org, kozyatinskiy@chromium.org
BUG=v8:5530

Review-Url: https://codereview.chromium.org/2568083002
Cr-Commit-Position: refs/heads/master@{#41765}
This commit is contained in:
yangguo 2016-12-16 06:28:56 -08:00 committed by Commit bot
parent 16fe426320
commit bcb73f6219
8 changed files with 27 additions and 29 deletions

View File

@ -43,6 +43,7 @@ DebuggerScript._scopeTypeNames.set(ScopeType.Catch, "catch");
DebuggerScript._scopeTypeNames.set(ScopeType.Block, "block");
DebuggerScript._scopeTypeNames.set(ScopeType.Script, "script");
DebuggerScript._scopeTypeNames.set(ScopeType.Eval, "eval");
DebuggerScript._scopeTypeNames.set(ScopeType.Module, "module");
/**
* @param {function()} fun
@ -543,6 +544,7 @@ DebuggerScript._buildScopeObject = function(scopeType, scopeObject)
case ScopeType.Block:
case ScopeType.Script:
case ScopeType.Eval:
case ScopeType.Module:
// For transient objects we create a "persistent" copy that contains
// the same properties.
// Reset scope object prototype to null so that the proto properties
@ -552,7 +554,8 @@ DebuggerScript._buildScopeObject = function(scopeType, scopeObject)
// Also drop empty Block, Eval and Script scopes, should we get any.
if (!properties.length && (scopeType === ScopeType.Script ||
scopeType === ScopeType.Block ||
scopeType === ScopeType.Eval)) {
scopeType === ScopeType.Eval ||
scopeType === ScopeType.Module)) {
break;
}
result = { __proto__: null };

View File

@ -200,7 +200,8 @@ var ScopeType = { Global: 0,
Catch: 4,
Block: 5,
Script: 6,
Eval: 7 };
Eval: 7,
Module: 8};
/** @typedef {{

View File

@ -212,6 +212,7 @@ InjectedScript.closureTypes["script"] = "Script";
InjectedScript.closureTypes["with"] = "With Block";
InjectedScript.closureTypes["global"] = "Global";
InjectedScript.closureTypes["eval"] = "Eval";
InjectedScript.closureTypes["module"] = "Module";
InjectedScript.prototype = {
/**

View File

@ -453,7 +453,7 @@
"id": "Scope",
"type": "object",
"properties": [
{ "name": "type", "type": "string", "enum": ["global", "local", "with", "closure", "catch", "block", "script", "eval"], "description": "Scope type." },
{ "name": "type", "type": "string", "enum": ["global", "local", "with", "closure", "catch", "block", "script", "eval", "module"], "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" },

View File

@ -3,7 +3,7 @@
// found in the LICENSE file.
// MODULE
// Flags: --expose-debug-as debug --allow-natives-syntax --noanalyze-environment-liveness
// Flags: --allow-natives-syntax --noanalyze-environment-liveness
// These tests are copied from mjsunit/debug-scopes.js and adapted for modules.
@ -70,7 +70,6 @@ function CheckFastAllScopes(scopes, exec_state)
assertTrue(scopes.length >= length);
for (var i = 0; i < scopes.length && i < length; i++) {
var scope = fast_all_scopes[length - i - 1];
assertTrue(scope.isScope());
assertEquals(scopes[scopes.length - i - 1], scope.scopeType());
}
}
@ -84,7 +83,6 @@ function CheckScopeChain(scopes, exec_state) {
"FrameMirror.allScopes length");
for (var i = 0; i < scopes.length; i++) {
var scope = exec_state.frame().scope(i);
assertTrue(scope.isScope());
assertEquals(scopes[i], scope.scopeType());
assertScopeMirrorEquals(all_scopes[i], scope);
}
@ -98,7 +96,6 @@ function CheckScopeChainNames(names, exec_state) {
assertEquals(names.length, all_scopes.length, "FrameMirror.allScopes length");
for (var i = 0; i < names.length; i++) {
var scope = exec_state.frame().scope(i);
assertTrue(scope.isScope());
assertEquals(names[i], scope.details().name())
}
}
@ -113,12 +110,8 @@ function CheckScopeContent(minimum_content, number, exec_state) {
var property_mirror = scope.scopeObject().property(p);
assertFalse(property_mirror.isUndefined(),
'property ' + p + ' not found in scope');
if (typeof(minimum_content[p]) === 'function') {
assertTrue(property_mirror.value().isFunction());
} else {
assertEquals(minimum_content[p], property_mirror.value().value(),
'property ' + p + ' has unexpected value');
}
assertEquals(minimum_content[p], property_mirror.value().value(),
'property ' + p + ' has unexpected value');
minimum_count++;
}
@ -152,7 +145,6 @@ function CheckScopeChainPositions(positions, exec_state) {
"FrameMirror.allScopes length");
for (var i = 0; i < positions.length; i++) {
var scope = exec_state.frame().scope(i);
assertTrue(scope.isScope());
var position = positions[i];
if (!position)
continue;
@ -408,7 +400,7 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Module,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:undefined}, 1, exec_state);
CheckScopeChainNames(["f", "closure_4", undefined, undefined, undefined],
exec_state)
};
@ -440,7 +432,7 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Module,
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:undefined}, 1, exec_state);
CheckScopeChainNames(["f", "closure_5", undefined, undefined, undefined],
exec_state)
};
@ -475,7 +467,7 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Script,
debug.ScopeType.Global], exec_state);
CheckScopeContent({a:1}, 1, exec_state);
CheckScopeContent({f:function(){}}, 2, exec_state);
CheckScopeContent({f:undefined}, 2, exec_state);
CheckScopeChainNames(
[undefined, "f", "closure_6", undefined, undefined, undefined],
exec_state);
@ -515,7 +507,7 @@ listener_delegate = function(exec_state) {
debug.ScopeType.Global], exec_state);
CheckScopeContent({}, 0, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 2, exec_state);
CheckScopeContent({a:1,b:2,x:3,y:4,f:undefined}, 2, exec_state);
CheckScopeChainNames(
[undefined, "f", "closure_7", undefined, undefined, undefined],
exec_state);

View File

@ -3,7 +3,6 @@
// found in the LICENSE file.
// MODULE
// Flags: --expose-debug-as debug
var Debug = debug.Debug;
@ -51,7 +50,8 @@ function assertScopeMirrorEquals(scope1, scope2) {
assertEquals(scope1.scopeType(), scope2.scopeType());
assertEquals(scope1.frameIndex(), scope2.frameIndex());
assertEquals(scope1.scopeIndex(), scope2.scopeIndex());
assertPropertiesEqual(scope1.scopeObject().value(), scope2.scopeObject().value());
assertPropertiesEqual(scope1.scopeObject().value(),
scope2.scopeObject().value());
}
function CheckFastAllScopes(scopes, exec_state)
@ -61,7 +61,6 @@ function CheckFastAllScopes(scopes, exec_state)
assertTrue(scopes.length >= length);
for (var i = 0; i < scopes.length && i < length; i++) {
var scope = fast_all_scopes[length - i - 1];
assertTrue(scope.isScope());
assertEquals(scopes[scopes.length - i - 1], scope.scopeType());
}
}
@ -74,7 +73,6 @@ function CheckScopeChain(scopes, exec_state) {
assertEquals(scopes.length, all_scopes.length, "FrameMirror.allScopes length");
for (var i = 0; i < scopes.length; i++) {
var scope = exec_state.frame().scope(i);
assertTrue(scope.isScope());
assertEquals(scopes[i], scope.scopeType());
assertScopeMirrorEquals(all_scopes[i], scope);
}
@ -86,7 +84,8 @@ function CheckScopeDoesNotHave(properties, number, exec_state) {
var scope = exec_state.frame().scope(number);
for (var p of properties) {
var property_mirror = scope.scopeObject().property(p);
assertTrue(property_mirror.isUndefined(), 'property ' + p + ' found in scope');
assertTrue(property_mirror.isUndefined(),
'property ' + p + ' found in scope');
}
}
@ -98,12 +97,10 @@ function CheckScopeContent(minimum_content, number, exec_state) {
var minimum_count = 0;
for (var p in minimum_content) {
var property_mirror = scope.scopeObject().property(p);
assertFalse(property_mirror.isUndefined(), 'property ' + p + ' not found in scope');
if (typeof(minimum_content[p]) === 'function') {
assertTrue(property_mirror.value().isFunction());
} else {
assertEquals(minimum_content[p], property_mirror.value().value(), 'property ' + p + ' has unexpected value');
}
assertFalse(property_mirror.isUndefined(),
'property ' + p + ' not found in scope');
assertEquals(minimum_content[p], property_mirror.value().value(),
'property ' + p + ' has unexpected value');
minimum_count++;
}

View File

@ -433,6 +433,7 @@ class DebugWrapper {
case "block": return this.ScopeType.Block;
case "script": return this.ScopeType.Script;
case "eval": return this.ScopeType.Eval;
case "module": return this.ScopeType.Module;
default: %AbortJS("Unexpected scope type");
}
}

View File

@ -10,6 +10,7 @@ from testrunner.objects import testcase
FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
MODULE_PATTERN = re.compile(r"^// MODULE$", flags=re.MULTILINE)
class DebuggerTestSuite(testsuite.TestSuite):
@ -54,6 +55,8 @@ class DebuggerTestSuite(testsuite.TestSuite):
files.append(os.path.join(self.root, "test-api.js"))
files.extend([ os.path.normpath(os.path.join(self.root, '..', '..', f))
for f in files_list ])
if MODULE_PATTERN.search(source):
files.append("--module")
files.append(os.path.join(self.root, testcase.path + self.suffix()))
flags += files