From d106bf27cf94572c943d38b3ea851a3f58c037f7 Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Wed, 4 Jul 2012 21:36:52 +0000 Subject: [PATCH] Web Inspector [JSC]: Implement ScriptCallStack::stackTrace https://bugs.webkit.org/show_bug.cgi?id=40118 Patch by Anthony Scian on 2012-07-04 Reviewed by Yong Li. Source/JavaScriptCore: Added member functions to expose function name, urlString, and line #. Refactored toString to make use of these member functions to reduce duplicated code for future maintenance. Manually tested refactoring of toString by tracing thrown exceptions. * interpreter/Interpreter.h: (JSC::StackFrame::toString): (JSC::StackFrame::friendlySourceURL): (JSC::StackFrame::friendlyFunctionName): (JSC::StackFrame::friendlyLineNumber): Source/WebCore: Implemented stub for createScriptCallStack to call into Interpreter and extract the current stack frames, iterate through the frames and create the return result required. No new tests, manually tested thrown exception and inspector tracebacks. * bindings/js/ScriptCallStackFactory.cpp: (WebCore::createScriptCallStack): LayoutTests: Updated test results now that createScriptCallStack is functional. * http/tests/inspector/console-resource-errors-expected.txt: * http/tests/inspector/console-xhr-logging-async-expected.txt: * http/tests/inspector/console-xhr-logging-expected.txt: * http/tests/inspector/network/script-as-text-loading-expected.txt: * inspector/timeline/timeline-animation-frame-expected.txt: * inspector/timeline/timeline-layout-expected.txt: * inspector/timeline/timeline-mark-timeline-expected.txt: * inspector/timeline/timeline-network-resource-expected.txt: * inspector/timeline/timeline-paint-expected.txt: * inspector/timeline/timeline-parse-html-expected.txt: * inspector/timeline/timeline-time-stamp-expected.txt: * inspector/timeline/timeline-timer-expected.txt: * platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121871 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 23 +++++++ .../inspector/console-resource-errors-expected.txt | 2 +- .../console-xhr-logging-async-expected.txt | 2 +- .../inspector/console-xhr-logging-expected.txt | 10 +-- .../network/script-as-text-loading-expected.txt | 2 +- .../timeline/timeline-animation-frame-expected.txt | 2 + .../timeline/timeline-layout-expected.txt | 1 + .../timeline/timeline-mark-timeline-expected.txt | 1 + .../timeline-network-resource-expected.txt | 1 + .../inspector/timeline/timeline-paint-expected.txt | 1 + .../timeline/timeline-parse-html-expected.txt | 2 + .../timeline/timeline-time-stamp-expected.txt | 1 + .../inspector/timeline/timeline-timer-expected.txt | 3 + .../console-xhr-logging-async-expected.txt | 8 +++ Source/JavaScriptCore/ChangeLog | 19 ++++++ Source/JavaScriptCore/interpreter/Interpreter.h | 78 ++++++++++++++-------- Source/WebCore/ChangeLog | 17 +++++ .../WebCore/bindings/js/ScriptCallStackFactory.cpp | 22 +++++- 18 files changed, 156 insertions(+), 39 deletions(-) create mode 100644 LayoutTests/platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 28491a1..0a6d772 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,26 @@ +2012-07-04 Anthony Scian + + Web Inspector [JSC]: Implement ScriptCallStack::stackTrace + https://bugs.webkit.org/show_bug.cgi?id=40118 + + Reviewed by Yong Li. + + Updated test results now that createScriptCallStack is functional. + + * http/tests/inspector/console-resource-errors-expected.txt: + * http/tests/inspector/console-xhr-logging-async-expected.txt: + * http/tests/inspector/console-xhr-logging-expected.txt: + * http/tests/inspector/network/script-as-text-loading-expected.txt: + * inspector/timeline/timeline-animation-frame-expected.txt: + * inspector/timeline/timeline-layout-expected.txt: + * inspector/timeline/timeline-mark-timeline-expected.txt: + * inspector/timeline/timeline-network-resource-expected.txt: + * inspector/timeline/timeline-paint-expected.txt: + * inspector/timeline/timeline-parse-html-expected.txt: + * inspector/timeline/timeline-time-stamp-expected.txt: + * inspector/timeline/timeline-timer-expected.txt: + * platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt: + 2012-07-04 Zan Dobersek Unreviewed GTK gardening, skip another two http tests that diff --git a/LayoutTests/http/tests/inspector/console-resource-errors-expected.txt b/LayoutTests/http/tests/inspector/console-resource-errors-expected.txt index aab1715..1d74861 100644 --- a/LayoutTests/http/tests/inspector/console-resource-errors-expected.txt +++ b/LayoutTests/http/tests/inspector/console-resource-errors-expected.txt @@ -4,5 +4,5 @@ Tests that errors to load a resource cause error messages to be logged to consol GET http://127.0.0.1:8000/inspector/missing.css 404 (Not Found) console-resource-errors-iframe.html:3 console-message console-error-level GET http://127.0.0.1:8000/inspector/non-existent-iframe.html 404 (Not Found) non-existent-iframe.html:1 console-message console-error-level GET http://127.0.0.1:8000/inspector/non-existent-script.js 404 (Not Found) console-resource-errors-iframe.html:4 console-message console-error-level -GET http://127.0.0.1:8000/inspector/non-existent-xhr 404 (Not Found) non-existent-xhr:1 console-message console-error-level +GET http://127.0.0.1:8000/inspector/non-existent-xhr 404 (Not Found) [native code]:1send [native code]:1loadXHR console-resource-errors.html:18performActions console-resource-errors.html:10eval codeeval [native code]:1_evaluateOn_evaluateAndWrapevaluate(anonymous function) [native code]:1 console-message console-error-level diff --git a/LayoutTests/http/tests/inspector/console-xhr-logging-async-expected.txt b/LayoutTests/http/tests/inspector/console-xhr-logging-async-expected.txt index 0df8a35..fb599ff 100644 --- a/LayoutTests/http/tests/inspector/console-xhr-logging-async-expected.txt +++ b/LayoutTests/http/tests/inspector/console-xhr-logging-async-expected.txt @@ -3,6 +3,6 @@ CONSOLE MESSAGE: line 14: Done. Tests that XMLHttpRequest Logging works when Enabled and doesn't show logs when Disabled for asynchronous XHRs. Bug 79229 -XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-exists.html". network-test.js:39 +XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-exists.html". [native code]:1 Done. console-xhr-logging-async.html:14 diff --git a/LayoutTests/http/tests/inspector/console-xhr-logging-expected.txt b/LayoutTests/http/tests/inspector/console-xhr-logging-expected.txt index 98e4881..5a1a566 100644 --- a/LayoutTests/http/tests/inspector/console-xhr-logging-expected.txt +++ b/LayoutTests/http/tests/inspector/console-xhr-logging-expected.txt @@ -11,17 +11,17 @@ CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/inspector/reso Tests that XMLHttpRequest Logging works when Enabled and doesn't show logs when Disabled. sending a GET request to resources/xhr-exists.html console-xhr-logging.html:10 -XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-exists.html". +XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-exists.html". [native code]:1 sending a GET request to resources/xhr-does-not-exist.html console-xhr-logging.html:10 -GET http://127.0.0.1:8000/inspector/resources/xhr-does-not-exist.html 404 (Not Found) resources/xhr-does-not-exist.html:1 -XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-does-not-exist.html". +GET http://127.0.0.1:8000/inspector/resources/xhr-does-not-exist.html 404 (Not Found) [native code]:1 +XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-does-not-exist.html". [native code]:1 sending a POST request to resources/post-target.cgi console-xhr-logging.html:10 -XHR finished loading: "http://127.0.0.1:8000/inspector/resources/post-target.cgi". +XHR finished loading: "http://127.0.0.1:8000/inspector/resources/post-target.cgi". [native code]:1 sending a GET request to http://localhost:8000/inspector/resources/xhr-exists.html console-xhr-logging.html:10 XMLHttpRequest cannot load http://localhost:8000/inspector/resources/xhr-exists.html. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. sending a GET request to resources/xhr-exists.html console-xhr-logging.html:10 sending a GET request to resources/xhr-does-not-exist.html console-xhr-logging.html:10 -GET http://127.0.0.1:8000/inspector/resources/xhr-does-not-exist.html 404 (Not Found) resources/xhr-does-not-exist.html:1 +GET http://127.0.0.1:8000/inspector/resources/xhr-does-not-exist.html 404 (Not Found) [native code]:1 sending a POST request to resources/post-target.cgi console-xhr-logging.html:10 sending a GET request to http://localhost:8000/inspector/resources/xhr-exists.html console-xhr-logging.html:10 XMLHttpRequest cannot load http://localhost:8000/inspector/resources/xhr-exists.html. Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin. diff --git a/LayoutTests/http/tests/inspector/network/script-as-text-loading-expected.txt b/LayoutTests/http/tests/inspector/network/script-as-text-loading-expected.txt index c117683..9121a08 100644 --- a/LayoutTests/http/tests/inspector/network/script-as-text-loading-expected.txt +++ b/LayoutTests/http/tests/inspector/network/script-as-text-loading-expected.txt @@ -1,5 +1,5 @@ Tests console message when script is loaded with incorrect text/html mime type. Bug 69972 -Resource interpreted as Script but transferred with MIME type text/plain: "http://127.0.0.1:8000/inspector/network/resources/script-as-text.php". +Resource interpreted as Script but transferred with MIME type text/plain: "http://127.0.0.1:8000/inspector/network/resources/script-as-text.php". [native code]:1 diff --git a/LayoutTests/inspector/timeline/timeline-animation-frame-expected.txt b/LayoutTests/inspector/timeline/timeline-animation-frame-expected.txt index e4716c4..15d78f6 100644 --- a/LayoutTests/inspector/timeline/timeline-animation-frame-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-animation-frame-expected.txt @@ -3,6 +3,7 @@ Tests the Timeline events for Animation Frame feature RequestAnimationFrame Properties: { startTime : + stackTrace : data : { id : } @@ -29,6 +30,7 @@ FireAnimationFrame Properties: CancelAnimationFrame Properties: { startTime : + stackTrace : data : { id : } diff --git a/LayoutTests/inspector/timeline/timeline-layout-expected.txt b/LayoutTests/inspector/timeline/timeline-layout-expected.txt index e1dba6f..bf51158 100644 --- a/LayoutTests/inspector/timeline/timeline-layout-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-layout-expected.txt @@ -4,6 +4,7 @@ Test data Layout Properties: { startTime : + stackTrace : data : { } children : diff --git a/LayoutTests/inspector/timeline/timeline-mark-timeline-expected.txt b/LayoutTests/inspector/timeline/timeline-mark-timeline-expected.txt index 7a22c9e..2f1cc10 100644 --- a/LayoutTests/inspector/timeline/timeline-mark-timeline-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-mark-timeline-expected.txt @@ -3,6 +3,7 @@ Tests the Timeline API mark feature TimeStamp Properties: { startTime : + stackTrace : data : { message : "MARK TIMELINE" } diff --git a/LayoutTests/inspector/timeline/timeline-network-resource-expected.txt b/LayoutTests/inspector/timeline/timeline-network-resource-expected.txt index d2cda50..2186cc1 100644 --- a/LayoutTests/inspector/timeline/timeline-network-resource-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-network-resource-expected.txt @@ -6,6 +6,7 @@ Script resource loaded ResourceSendRequest Properties: { startTime : + stackTrace : data : { requestId : url : diff --git a/LayoutTests/inspector/timeline/timeline-paint-expected.txt b/LayoutTests/inspector/timeline/timeline-paint-expected.txt index 56afda4..12beda8 100644 --- a/LayoutTests/inspector/timeline/timeline-paint-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-paint-expected.txt @@ -3,6 +3,7 @@ Tests the Timeline API instrumentation of a paint event Paint Properties: { startTime : + stackTrace : data : { x : 0 y : 0 diff --git a/LayoutTests/inspector/timeline/timeline-parse-html-expected.txt b/LayoutTests/inspector/timeline/timeline-parse-html-expected.txt index b36cd05..9226359 100644 --- a/LayoutTests/inspector/timeline/timeline-parse-html-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-parse-html-expected.txt @@ -4,6 +4,7 @@ Test data ParseHTML Properties: { startTime : + stackTrace : data : { length : 9 startLine : 0 @@ -20,6 +21,7 @@ ParseHTML Properties: ParseHTML Properties: { startTime : + stackTrace : data : { length : 1 startLine : 0 diff --git a/LayoutTests/inspector/timeline/timeline-time-stamp-expected.txt b/LayoutTests/inspector/timeline/timeline-time-stamp-expected.txt index 4979e837..9c5c1e7 100644 --- a/LayoutTests/inspector/timeline/timeline-time-stamp-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-time-stamp-expected.txt @@ -3,6 +3,7 @@ Tests the Timeline API timeStamp feature TimeStamp Properties: { startTime : + stackTrace : data : { message : "TIME STAMP" } diff --git a/LayoutTests/inspector/timeline/timeline-timer-expected.txt b/LayoutTests/inspector/timeline/timeline-timer-expected.txt index 0bd1926..e53388a 100644 --- a/LayoutTests/inspector/timeline/timeline-timer-expected.txt +++ b/LayoutTests/inspector/timeline/timeline-timer-expected.txt @@ -3,6 +3,7 @@ Tests the Timeline events for Timers TimerInstall Properties: { startTime : + stackTrace : data : { timerId : timeout : 10 @@ -17,6 +18,7 @@ TimerInstall Properties: TimerInstall Properties: { startTime : + stackTrace : data : { timerId : timeout : 20 @@ -73,6 +75,7 @@ TimerFire Properties: TimerRemove Properties: { startTime : + stackTrace : data : { timerId : } diff --git a/LayoutTests/platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt b/LayoutTests/platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt new file mode 100644 index 0000000..0df8a35 --- /dev/null +++ b/LayoutTests/platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt @@ -0,0 +1,8 @@ +CONSOLE MESSAGE: line 14: Done. +CONSOLE MESSAGE: line 14: Done. +Tests that XMLHttpRequest Logging works when Enabled and doesn't show logs when Disabled for asynchronous XHRs. + +Bug 79229 +XHR finished loading: "http://127.0.0.1:8000/inspector/resources/xhr-exists.html". network-test.js:39 +Done. console-xhr-logging-async.html:14 + diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index 51fb324..e6bd414 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,22 @@ +2012-07-04 Anthony Scian + + Web Inspector [JSC]: Implement ScriptCallStack::stackTrace + https://bugs.webkit.org/show_bug.cgi?id=40118 + + Reviewed by Yong Li. + + Added member functions to expose function name, urlString, and line #. + Refactored toString to make use of these member functions to reduce + duplicated code for future maintenance. + + Manually tested refactoring of toString by tracing thrown exceptions. + + * interpreter/Interpreter.h: + (JSC::StackFrame::toString): + (JSC::StackFrame::friendlySourceURL): + (JSC::StackFrame::friendlyFunctionName): + (JSC::StackFrame::friendlyLineNumber): + 2012-07-04 Andy Wingo [GTK] Enable parallel GC diff --git a/Source/JavaScriptCore/interpreter/Interpreter.h b/Source/JavaScriptCore/interpreter/Interpreter.h index adb23f2..ba2f4fa 100644 --- a/Source/JavaScriptCore/interpreter/Interpreter.h +++ b/Source/JavaScriptCore/interpreter/Interpreter.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2012 Research In Motion Limited. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,6 +40,7 @@ #include "RegisterFile.h" #include +#include namespace JSC { @@ -80,45 +82,63 @@ namespace JSC { UString sourceURL; UString toString(CallFrame* callFrame) const { - bool hasSourceURLInfo = !sourceURL.isNull() && !sourceURL.isEmpty(); - bool hasLineInfo = line > -1; + StringBuilder traceBuild; + String functionName = friendlyFunctionName(callFrame); + String sourceURL = friendlySourceURL(); + traceBuild.append(functionName); + if (!sourceURL.isEmpty()) { + if (!functionName.isEmpty()) + traceBuild.append('@'); + traceBuild.append(sourceURL); + if (line > -1) { + traceBuild.append(':'); + traceBuild.append(String::number(line)); + } + } + return traceBuild.toString().impl(); + } + String friendlySourceURL() const + { String traceLine; - JSObject* stackFrameCallee = callee.get(); switch (codeType) { case StackFrameEvalCode: - if (hasSourceURLInfo) { - traceLine = hasLineInfo ? String::format("eval code@%s:%d", sourceURL.ascii().data(), line) - : String::format("eval code@%s", sourceURL.ascii().data()); - } else - traceLine = String::format("eval code"); + case StackFrameFunctionCode: + case StackFrameGlobalCode: + if (!sourceURL.isEmpty()) + traceLine = sourceURL.impl(); break; - case StackFrameNativeCode: { - if (callee) { - UString functionName = getCalculatedDisplayName(callFrame, stackFrameCallee); - traceLine = String::format("%s@[native code]", functionName.ascii().data()); - } else - traceLine = "[native code]"; + case StackFrameNativeCode: + traceLine = "[native code]"; break; } - case StackFrameFunctionCode: { - UString functionName = getCalculatedDisplayName(callFrame, stackFrameCallee); - if (hasSourceURLInfo) { - traceLine = hasLineInfo ? String::format("%s@%s:%d", functionName.ascii().data(), sourceURL.ascii().data(), line) - : String::format("%s@%s", functionName.ascii().data(), sourceURL.ascii().data()); - } else - traceLine = String::format("%s\n", functionName.ascii().data()); + return traceLine.isNull() ? emptyString() : traceLine; + } + String friendlyFunctionName(CallFrame* callFrame) const + { + String traceLine; + JSObject* stackFrameCallee = callee.get(); + + switch (codeType) { + case StackFrameEvalCode: + traceLine = "eval code"; + break; + case StackFrameNativeCode: + if (callee) + traceLine = getCalculatedDisplayName(callFrame, stackFrameCallee).impl(); + break; + case StackFrameFunctionCode: + traceLine = getCalculatedDisplayName(callFrame, stackFrameCallee).impl(); break; - } case StackFrameGlobalCode: - if (hasSourceURLInfo) { - traceLine = hasLineInfo ? String::format("global code@%s:%d", sourceURL.ascii().data(), line) - : String::format("global code@%s", sourceURL.ascii().data()); - } else - traceLine = String::format("global code"); - + traceLine = "global code"; + break; } - return traceLine.impl(); + return traceLine.isNull() ? emptyString() : traceLine; + } + unsigned friendlyLineNumber() const + { + return line > -1 ? line : 0; } }; diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 7e104ab..a9a647e 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,20 @@ +2012-07-04 Anthony Scian + + Web Inspector [JSC]: Implement ScriptCallStack::stackTrace + https://bugs.webkit.org/show_bug.cgi?id=40118 + + Reviewed by Yong Li. + + Implemented stub for createScriptCallStack to call into + Interpreter and extract the current stack frames, iterate + through the frames and create the return result required. + + No new tests, manually tested thrown exception and inspector + tracebacks. + + * bindings/js/ScriptCallStackFactory.cpp: + (WebCore::createScriptCallStack): + 2012-07-04 Dana Jansens [chromium] Respect memory needed for RenderSurfaces when reserving contents textures diff --git a/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp b/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp index ccf673f..3bb69f4 100644 --- a/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp +++ b/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2010 Google Inc. All rights reserved. + * Copyright (C) 2012 Research In Motion Limited. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -33,6 +34,7 @@ #include "InspectorInstrumentation.h" #include "JSDOMBinding.h" +#include "JSMainThreadExecState.h" #include "ScriptArguments.h" #include "ScriptCallFrame.h" #include "ScriptCallStack.h" @@ -51,9 +53,25 @@ namespace WebCore { class ScriptExecutionContext; -PassRefPtr createScriptCallStack(size_t, bool) +PassRefPtr createScriptCallStack(size_t maxStackSize, bool emptyIsAllowed) { - return 0; + Vector frames; + if (JSC::ExecState* exec = JSMainThreadExecState::currentState()) { + Vector stackTrace; + Interpreter::getStackTrace(&exec->globalData(), stackTrace); + for (Vector::const_iterator iter = stackTrace.begin(); iter < stackTrace.end(); iter++) { + frames.append(ScriptCallFrame(iter->friendlyFunctionName(exec), iter->friendlySourceURL(), iter->friendlyLineNumber())); + if (frames.size() >= maxStackSize) + break; + } + } + if (frames.isEmpty() && !emptyIsAllowed) { + // No frames found. It may happen in the case where + // a bound function is called from native code for example. + // Fallback to setting lineNumber to 0, and source and function name to "undefined". + frames.append(ScriptCallFrame("undefined", "undefined", 0)); + } + return ScriptCallStack::create(frames); } PassRefPtr createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize) -- 2.7.4