diff options
author | kozyatinskiy <kozyatinskiy@chromium.org> | 2015-11-20 11:41:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-20 19:42:46 +0000 |
commit | 38152e7ee5c9daace6e192d9478ad01740defaee (patch) | |
tree | fc23e000bdb3ff6642736be9adaa542473f77789 | |
parent | 71dafdfe7183b9b016460ceb0d1ce184b7aee341 (diff) | |
download | chromium_src-38152e7ee5c9daace6e192d9478ad01740defaee.zip chromium_src-38152e7ee5c9daace6e192d9478ad01740defaee.tar.gz chromium_src-38152e7ee5c9daace6e192d9478ad01740defaee.tar.bz2 |
[DevTools] Use JSFunction::GetDebugName V8 API for getting function name
JSFunction::GetDebugName returns first of Function.displayName, Function.name, SharedFunctionInfo::name, inferred_name which is set and string.
This function names is used in callstack sidebar on pause and in console message's callstack.
R=pfeldman@chromium.org
BUG=17356
Review URL: https://codereview.chromium.org/1455703002
Cr-Commit-Position: refs/heads/master@{#360884}
7 files changed, 131 insertions, 24 deletions
diff --git a/third_party/WebKit/LayoutTests/inspector/console/function-name-in-console-message-stack-expected.txt b/third_party/WebKit/LayoutTests/inspector/console/function-name-in-console-message-stack-expected.txt new file mode 100644 index 0000000..eee1aff --- /dev/null +++ b/third_party/WebKit/LayoutTests/inspector/console/function-name-in-console-message-stack-expected.txt @@ -0,0 +1,8 @@ +CONSOLE ERROR: line 8: Uncaught Error +Tests exception message contains stack with correct function name. + + function-name-in-console-message-stack.html:8 Uncaught Error +foo.displayName @ function-name-in-console-message-stack.html:8 +bar.displayName @ function-name-in-console-message-stack.html:16 +baz.function.name @ function-name-in-console-message-stack.html:23 + diff --git a/third_party/WebKit/LayoutTests/inspector/console/function-name-in-console-message-stack.html b/third_party/WebKit/LayoutTests/inspector/console/function-name-in-console-message-stack.html new file mode 100644 index 0000000..d222c30 --- /dev/null +++ b/third_party/WebKit/LayoutTests/inspector/console/function-name-in-console-message-stack.html @@ -0,0 +1,49 @@ +<html> +<head> +<script src="../../http/tests/inspector/inspector-test.js"></script> +<script src="../../http/tests/inspector/console-test.js"></script> +<script> +var foo = function () +{ + throw new Error(); +} + +foo.displayName = 'foo.displayName'; +Object.defineProperty(foo, 'name', { value: 'foo.function.name' } ); + +var bar = function() +{ + foo(); +} + +bar.displayName = 'bar.displayName'; + +var baz = function() +{ + bar(); +} + +Object.defineProperty(baz, 'name', { value: 'baz.function.name' } ); + +function test() +{ + InspectorTest.waitUntilNthMessageReceived(1, step1); + InspectorTest.evaluateInPage("setTimeout(baz, 0);"); + + function step1() + { + InspectorTest.expandConsoleMessages(step2); + } + + function step2() + { + InspectorTest.dumpConsoleMessagesIgnoreErrorStackFrames(); + InspectorTest.completeTest(); + } +}; +</script> +</head> +<body onload="runTest()"> +<p>Tests exception message contains stack with correct function name.</p> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/function-name-in-callstack-expected.txt b/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/function-name-in-callstack-expected.txt new file mode 100644 index 0000000..07494cc --- /dev/null +++ b/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/function-name-in-callstack-expected.txt @@ -0,0 +1,11 @@ +Tests that callFrames on pause contains function name taking into account displayName and Function.name. + +Set timer for test function. +Script execution paused. +callFrames.length = 4 +functionName: foo.displayName +functionName: bar.displayName +functionName: baz.function.name +functionName: testFunction +Script execution resumed. + diff --git a/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/function-name-in-callstack.html b/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/function-name-in-callstack.html new file mode 100644 index 0000000..0959900 --- /dev/null +++ b/third_party/WebKit/LayoutTests/inspector/sources/debugger-pause/function-name-in-callstack.html @@ -0,0 +1,59 @@ +<html> +<head> +<script src="../../../http/tests/inspector/inspector-test.js"></script> +<script src="../../../http/tests/inspector/debugger-test.js"></script> +<script> +var foo = function () +{ + debugger; +} + +foo.displayName = 'foo.displayName'; +Object.defineProperty(foo, 'name', { value: 'foo.function.name' } ); + +var bar = function() +{ + foo(); +} + +bar.displayName = 'bar.displayName'; + +var baz = function() +{ + bar(); +} + +Object.defineProperty(baz, 'name', { value: 'baz.function.name' } ); + +function testFunction() +{ + baz(); +} + +function test() +{ + InspectorTest.startDebuggerTest(step1); + + function step1() + { + InspectorTest.runTestFunctionAndWaitUntilPaused(step2); + } + + function step2(callFrames) + { + InspectorTest.addResult("callFrames.length = " + callFrames.length); + for (var i = 0; i < callFrames.length; ++i) + InspectorTest.addResult("functionName: " + callFrames[i].functionName); + InspectorTest.completeDebuggerTest(); + } +} +</script> +</head> + +<body onload="runTest()"> +<p> +Tests that callFrames on pause contains function name taking into account displayName and Function.name. +</p> + +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/inspector/sources/debugger/properties-special-expected.txt b/third_party/WebKit/LayoutTests/inspector/sources/debugger/properties-special-expected.txt index 427e428..bc4d62d 100644 --- a/third_party/WebKit/LayoutTests/inspector/sources/debugger/properties-special-expected.txt +++ b/third_party/WebKit/LayoutTests/inspector/sources/debugger/properties-special-expected.txt @@ -14,7 +14,7 @@ properties-special.html:11 anonymous(a, b) prototype: Object __proto__: () <function scope> -properties-special.html:12 anonymous() +properties-special.html:12 bound () arguments: (...) caller: (...) length: 1 diff --git a/third_party/WebKit/Source/core/inspector/DebuggerScript.js b/third_party/WebKit/Source/core/inspector/DebuggerScript.js index 9eb6285..fd1b976 100644 --- a/third_party/WebKit/Source/core/inspector/DebuggerScript.js +++ b/third_party/WebKit/Source/core/inspector/DebuggerScript.js @@ -87,7 +87,7 @@ DebuggerScript.getGeneratorObjectDetails = function(object) return null; var result = { "function": funcMirror.value(), - "functionName": DebuggerScript._displayFunctionName(funcMirror) || "", + "functionName": funcMirror.debugName(), "status": mirror.status() }; var script = funcMirror.script(); @@ -362,17 +362,6 @@ DebuggerScript.isEvalCompilation = function(eventData) return (script.compilationType() === Debug.ScriptCompilationType.Eval); } -DebuggerScript._displayFunctionName = function(funcMirror) -{ - if (!funcMirror.resolved()) - return undefined - var displayName; - var valueMirror = funcMirror.property("displayName").value(); - if (valueMirror && valueMirror.isString()) - displayName = valueMirror.value(); - return displayName || funcMirror.name() || funcMirror.inferredName(); -} - // NOTE: This function is performance critical, as it can be run on every // statement that generates an async event (like addEventListener) to support // asynchronous call stacks. Thus, when possible, initialize the data lazily. @@ -485,7 +474,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame, sc function functionName() { - return DebuggerScript._displayFunctionName(ensureFuncMirror()); + return ensureFuncMirror().debugName(); } function functionLine() diff --git a/third_party/WebKit/Source/core/inspector/v8/V8InjectedScriptHost.cpp b/third_party/WebKit/Source/core/inspector/v8/V8InjectedScriptHost.cpp index f1298a2..c6d33dc 100644 --- a/third_party/WebKit/Source/core/inspector/v8/V8InjectedScriptHost.cpp +++ b/third_party/WebKit/Source/core/inspector/v8/V8InjectedScriptHost.cpp @@ -66,18 +66,9 @@ void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> function) { - v8::Local<v8::Value> value = function->GetDisplayName(); + v8::Local<v8::Value> value = function->GetDebugName(); if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) return v8::Local<v8::String>::Cast(value); - - value = function->GetName(); - if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) - return v8::Local<v8::String>::Cast(value); - - value = function->GetInferredName(); - if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) - return v8::Local<v8::String>::Cast(value); - return v8::Local<v8::String>(); } |