diff --git a/browser/devtools/debugger/test/browser_dbg_displayName.html b/browser/devtools/debugger/test/browser_dbg_displayName.html index 454bff6fc304..3311a5ad1981 100644 --- a/browser/devtools/debugger/test/browser_dbg_displayName.html +++ b/browser/devtools/debugger/test/browser_dbg_displayName.html @@ -14,8 +14,11 @@ var a = function() { var anon = a(); anon.displayName = "anonFunc"; +var inferred = a(); + function evalCall() { eval("anon();"); + eval("inferred();"); } diff --git a/browser/devtools/debugger/test/browser_dbg_displayName.js b/browser/devtools/debugger/test/browser_dbg_displayName.js index f9972d90e1e9..7e3db24abc6e 100644 --- a/browser/devtools/debugger/test/browser_dbg_displayName.js +++ b/browser/devtools/debugger/test/browser_dbg_displayName.js @@ -3,6 +3,9 @@ * 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 gTab = null; var gDebuggee = null; @@ -36,13 +39,35 @@ function testAnonCall() { is(frames.querySelector("#stackframe-0 .dbg-stackframe-name").getAttribute("value"), "anonFunc", "Frame name should be anonFunc"); - resumeAndFinish(); + testInferredName(); }}, 0); }); 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() { gDebugger.DebuggerController.activeThread.resume(function() { removeTab(gTab); diff --git a/toolkit/devtools/debugger/server/dbg-script-actors.js b/toolkit/devtools/debugger/server/dbg-script-actors.js index 97d60cca6f24..9c85f9345bb1 100644 --- a/toolkit/devtools/debugger/server/dbg-script-actors.js +++ b/toolkit/devtools/debugger/server/dbg-script-actors.js @@ -1821,9 +1821,14 @@ function getFunctionName(aFunction) { if (aFunction.name) { name = aFunction.name; } else { + // Check if the developer has added a de-facto standard displayName + // property for us to use. let desc = aFunction.getOwnPropertyDescriptor("displayName"); if (desc && desc.value && typeof desc.value == "string") { name = desc.value; + } else if ("displayName" in aFunction) { + // Otherwise use SpiderMonkey's inferred name. + name = aFunction.displayName; } } return name;