[V8] Add name of function for function's closure scope
Added ScopeDetails.name field for closure scopes. It contains function's debug name of current context of scope. BUG=493156 LOG=Y R=yurys@chromium.org,yangguo@chromium.org Review URL: https://codereview.chromium.org/1375813002 Cr-Commit-Position: refs/heads/master@{#31028}
This commit is contained in:
parent
623e802132
commit
ce54e16270
@ -132,6 +132,12 @@ MUST_USE_RESULT MaybeHandle<JSObject> ScopeIterator::MaterializeScopeDetails() {
|
||||
Handle<JSObject> scope_object;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(isolate_, scope_object, ScopeObject(), JSObject);
|
||||
details->set(kScopeDetailsObjectIndex, *scope_object);
|
||||
if (HasContext() && CurrentContext()->closure() != NULL) {
|
||||
Handle<String> closure_name = JSFunction::GetDebugName(
|
||||
Handle<JSFunction>(CurrentContext()->closure()));
|
||||
if (!closure_name.is_null() && (closure_name->length() != 0))
|
||||
details->set(kScopeDetailsNameIndex, *closure_name);
|
||||
}
|
||||
return isolate_->factory()->NewJSArrayWithElements(details);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,8 @@ class ScopeIterator {
|
||||
|
||||
static const int kScopeDetailsTypeIndex = 0;
|
||||
static const int kScopeDetailsObjectIndex = 1;
|
||||
static const int kScopeDetailsSize = 2;
|
||||
static const int kScopeDetailsNameIndex = 2;
|
||||
static const int kScopeDetailsSize = 3;
|
||||
|
||||
ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
|
||||
bool ignore_nested_scopes = false);
|
||||
|
@ -2233,8 +2233,10 @@ FrameMirror.prototype.toText = function(opt_locals) {
|
||||
};
|
||||
|
||||
|
||||
// This indexes correspond definitions in debug-scopes.h.
|
||||
var kScopeDetailsTypeIndex = 0;
|
||||
var kScopeDetailsObjectIndex = 1;
|
||||
var kScopeDetailsNameIndex = 2;
|
||||
|
||||
function ScopeDetails(frame, fun, index, opt_details) {
|
||||
if (frame) {
|
||||
@ -2271,6 +2273,14 @@ ScopeDetails.prototype.object = function() {
|
||||
};
|
||||
|
||||
|
||||
ScopeDetails.prototype.name = function() {
|
||||
if (!IS_UNDEFINED(this.break_id_)) {
|
||||
%CheckExecutionState(this.break_id_);
|
||||
}
|
||||
return this.details_[kScopeDetailsNameIndex];
|
||||
};
|
||||
|
||||
|
||||
ScopeDetails.prototype.setVariableValueImpl = function(name, new_value) {
|
||||
var raw_res;
|
||||
if (!IS_UNDEFINED(this.break_id_)) {
|
||||
|
@ -145,6 +145,18 @@ function CheckScopeChain(scopes, exec_state) {
|
||||
}
|
||||
|
||||
|
||||
// Check that the scope chain contains the expected names of scopes.
|
||||
function CheckScopeChainNames(names, exec_state) {
|
||||
var all_scopes = exec_state.frame().allScopes();
|
||||
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(scope.details().name(), names[i])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check that the content of the scope is as expected. For functions just check
|
||||
// that there is a function.
|
||||
function CheckScopeContent(content, number, exec_state) {
|
||||
@ -517,6 +529,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({a:1}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, "closure_1", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_1(1)();
|
||||
EndTest();
|
||||
@ -543,6 +556,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({a:1,x:3}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, "closure_2", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_2(1, 2)();
|
||||
EndTest();
|
||||
@ -570,6 +584,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:3,y:4}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, "closure_3", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_3(1, 2)();
|
||||
EndTest();
|
||||
@ -600,6 +615,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, "closure_4", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_4(1, 2)();
|
||||
EndTest();
|
||||
@ -629,6 +645,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:3,y:4,f:function(){}}, 1, exec_state);
|
||||
CheckScopeChainNames(["f", "closure_5", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_5(1, 2)();
|
||||
EndTest();
|
||||
@ -660,6 +677,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({a:1}, 1, exec_state);
|
||||
CheckScopeContent({f:function(){}}, 2, exec_state);
|
||||
CheckScopeChainNames([undefined, "f", "closure_6", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_6(1, 2)();
|
||||
EndTest();
|
||||
@ -696,6 +714,7 @@ listener_delegate = function(exec_state) {
|
||||
CheckScopeContent({}, 0, exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6}, 1, exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 2, exec_state);
|
||||
CheckScopeChainNames([undefined, "f", "closure_7", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_7(1, 2)();
|
||||
EndTest();
|
||||
@ -714,6 +733,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({x: 2}, 0, exec_state);
|
||||
CheckScopeChainNames([undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
closure_8();
|
||||
EndTest();
|
||||
@ -735,6 +755,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Closure,
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeChainNames([undefined, "closure_9", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_9();
|
||||
EndTest();
|
||||
@ -783,6 +804,7 @@ listener_delegate = function(exec_state) {
|
||||
CheckScopeContent({j:13}, 3, exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:9,y:10,i:11,j:12}, 4, exec_state);
|
||||
CheckScopeContent({a:1,b:2,x:3,y:4,i:5,j:6,f:function(){}}, 5, exec_state);
|
||||
CheckScopeChainNames([undefined, undefined, undefined, "f", "f", "the_full_monty", undefined, undefined], exec_state)
|
||||
};
|
||||
the_full_monty(1, 2)();
|
||||
EndTest();
|
||||
@ -830,6 +852,7 @@ listener_delegate = function(exec_state) {
|
||||
CheckScopeContent({x: 3}, 0, exec_state);
|
||||
CheckScopeContent({x: 2}, 1, exec_state);
|
||||
CheckScopeContent({x: 1}, 2, exec_state);
|
||||
CheckScopeChainNames(["inner", "inner", "closure_in_with_2", "closure_in_with_2", undefined, undefined], exec_state)
|
||||
};
|
||||
closure_in_with_2();
|
||||
EndTest();
|
||||
@ -860,6 +883,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Closure,
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeChainNames(["inner", "inner", "closure", "createClosure", undefined, undefined], exec_state)
|
||||
}
|
||||
closure_in_with_3();
|
||||
EndTest();
|
||||
@ -873,6 +897,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({x: 2}, 0, exec_state);
|
||||
CheckScopeContent({x: 1}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
|
||||
with({x:1}) {
|
||||
@ -887,6 +912,7 @@ EndTest();
|
||||
BeginTest("Global");
|
||||
listener_delegate = function(exec_state) {
|
||||
CheckScopeChain([debug.ScopeType.Script, debug.ScopeType.Global], exec_state);
|
||||
CheckScopeChainNames([undefined, undefined], exec_state)
|
||||
};
|
||||
debugger;
|
||||
EndTest();
|
||||
@ -908,6 +934,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 0, exec_state);
|
||||
CheckScopeChainNames(["catch_block_1", undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
catch_block_1();
|
||||
EndTest();
|
||||
@ -933,6 +960,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({n:10}, 0, exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 1, exec_state);
|
||||
CheckScopeChainNames(["catch_block_2", "catch_block_2", "catch_block_2", undefined, undefined], exec_state)
|
||||
};
|
||||
catch_block_2();
|
||||
EndTest();
|
||||
@ -958,6 +986,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 0, exec_state);
|
||||
CheckScopeContent({y:78}, 1, exec_state);
|
||||
CheckScopeChainNames(["catch_block_3", "catch_block_3", undefined, undefined], exec_state)
|
||||
};
|
||||
catch_block_3();
|
||||
EndTest();
|
||||
@ -986,6 +1015,7 @@ listener_delegate = function(exec_state) {
|
||||
CheckScopeContent({n:10}, 0, exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 1, exec_state);
|
||||
CheckScopeContent({y:98}, 2, exec_state);
|
||||
CheckScopeChainNames(["catch_block_4", "catch_block_4", "catch_block_4", undefined, undefined], exec_state)
|
||||
};
|
||||
catch_block_4();
|
||||
EndTest();
|
||||
@ -998,6 +1028,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 0, exec_state);
|
||||
CheckScopeChainNames([undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
|
||||
try {
|
||||
@ -1018,6 +1049,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({x: 2}, 0, exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
|
||||
try {
|
||||
@ -1048,6 +1080,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({e:'Exception'}, 0, exec_state);
|
||||
CheckScopeChainNames(["catch_block_7", undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
catch_block_7();
|
||||
EndTest();
|
||||
@ -1061,6 +1094,7 @@ listener_delegate = function(exec_state) {
|
||||
debug.ScopeType.Script,
|
||||
debug.ScopeType.Global], exec_state);
|
||||
CheckScopeContent({}, 1, exec_state);
|
||||
CheckScopeChainNames([undefined, undefined, undefined], exec_state)
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
Loading…
Reference in New Issue
Block a user