Use the statically-inferred name for anonymous functions (bug 786711) r=msucan,vporof

This commit is contained in:
Panos Astithas 2012-09-10 11:48:52 +03:00
Родитель e3fbd8f676
Коммит 7b37b54fa1
3 изменённых файлов: 34 добавлений и 1 удалений

Просмотреть файл

@ -14,8 +14,11 @@ var a = function() {
var anon = a(); var anon = a();
anon.displayName = "anonFunc"; anon.displayName = "anonFunc";
var inferred = a();
function evalCall() { function evalCall() {
eval("anon();"); eval("anon();");
eval("inferred();");
} }
</script> </script>

Просмотреть файл

@ -3,6 +3,9 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
// Tests that anonymous functions appear in the stack frame list with either
// their displayName property or a SpiderMonkey-inferred name.
var gPane = null; var gPane = null;
var gTab = null; var gTab = null;
var gDebuggee = null; var gDebuggee = null;
@ -36,13 +39,35 @@ function testAnonCall() {
is(frames.querySelector("#stackframe-0 .dbg-stackframe-name").getAttribute("value"), is(frames.querySelector("#stackframe-0 .dbg-stackframe-name").getAttribute("value"),
"anonFunc", "Frame name should be anonFunc"); "anonFunc", "Frame name should be anonFunc");
resumeAndFinish(); testInferredName();
}}, 0); }}, 0);
}); });
gDebuggee.evalCall(); gDebuggee.evalCall();
} }
function testInferredName() {
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
Services.tm.currentThread.dispatch({ run: function() {
let frames = gDebugger.DebuggerView.StackFrames._frames;
is(gDebugger.DebuggerController.activeThread.state, "paused",
"Should only be getting stack frames while paused.");
is(frames.querySelectorAll(".dbg-stackframe").length, 3,
"Should have three frames.");
is(frames.querySelector("#stackframe-0 .dbg-stackframe-name").getAttribute("value"),
"a/<", "Frame name should be a/<");
resumeAndFinish();
}}, 0);
});
gDebugger.DebuggerController.activeThread.resume();
}
function resumeAndFinish() { function resumeAndFinish() {
gDebugger.DebuggerController.activeThread.resume(function() { gDebugger.DebuggerController.activeThread.resume(function() {
removeTab(gTab); removeTab(gTab);

Просмотреть файл

@ -1821,9 +1821,14 @@ function getFunctionName(aFunction) {
if (aFunction.name) { if (aFunction.name) {
name = aFunction.name; name = aFunction.name;
} else { } else {
// Check if the developer has added a de-facto standard displayName
// property for us to use.
let desc = aFunction.getOwnPropertyDescriptor("displayName"); let desc = aFunction.getOwnPropertyDescriptor("displayName");
if (desc && desc.value && typeof desc.value == "string") { if (desc && desc.value && typeof desc.value == "string") {
name = desc.value; name = desc.value;
} else if ("displayName" in aFunction) {
// Otherwise use SpiderMonkey's inferred name.
name = aFunction.displayName;
} }
} }
return name; return name;