Web Inspector [JSC]: Implement ScriptCallStack::stackTrace
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Jul 2012 21:36:52 +0000 (21:36 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Jul 2012 21:36:52 +0000 (21:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=40118

Patch by Anthony Scian <ascian@rim.com> 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: https://svn.webkit.org/repository/webkit/trunk@121871 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/console-resource-errors-expected.txt
LayoutTests/http/tests/inspector/console-xhr-logging-async-expected.txt
LayoutTests/http/tests/inspector/console-xhr-logging-expected.txt
LayoutTests/http/tests/inspector/network/script-as-text-loading-expected.txt
LayoutTests/inspector/timeline/timeline-animation-frame-expected.txt
LayoutTests/inspector/timeline/timeline-layout-expected.txt
LayoutTests/inspector/timeline/timeline-mark-timeline-expected.txt
LayoutTests/inspector/timeline/timeline-network-resource-expected.txt
LayoutTests/inspector/timeline/timeline-paint-expected.txt
LayoutTests/inspector/timeline/timeline-parse-html-expected.txt
LayoutTests/inspector/timeline/timeline-time-stamp-expected.txt
LayoutTests/inspector/timeline/timeline-timer-expected.txt
LayoutTests/platform/chromium/http/tests/inspector/console-xhr-logging-async-expected.txt [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/interpreter/Interpreter.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptCallStackFactory.cpp

index 28491a1..0a6d772 100644 (file)
@@ -1,3 +1,26 @@
+2012-07-04  Anthony Scian  <ascian@rim.com>
+
+        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  <zandobersek@gmail.com>
 
         Unreviewed GTK gardening, skip another two http tests that
index aab1715..1d74861 100644 (file)
@@ -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
 
index 0df8a35..fb599ff 100644 (file)
@@ -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
 
index 98e4881..5a1a566 100644 (file)
@@ -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.
index c117683..9121a08 100644 (file)
@@ -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
 
index e4716c4..15d78f6 100644 (file)
@@ -3,6 +3,7 @@ Tests the Timeline events for Animation Frame feature
 RequestAnimationFrame Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         id : <number>
     }
@@ -29,6 +30,7 @@ FireAnimationFrame Properties:
 CancelAnimationFrame Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         id : <number>
     }
index e1dba6f..bf51158 100644 (file)
@@ -4,6 +4,7 @@ Test data
 Layout Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
     }
     children : <object>
index 7a22c9e..2f1cc10 100644 (file)
@@ -3,6 +3,7 @@ Tests the Timeline API mark feature
 TimeStamp Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         message : "MARK TIMELINE"
     }
index d2cda50..2186cc1 100644 (file)
@@ -6,6 +6,7 @@ Script resource loaded
 ResourceSendRequest Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         requestId : <string>
         url : <string>
index 56afda4..12beda8 100644 (file)
@@ -3,6 +3,7 @@ Tests the Timeline API instrumentation of a paint event
 Paint Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         x : 0
         y : 0
index b36cd05..9226359 100644 (file)
@@ -4,6 +4,7 @@ Test data
 ParseHTML Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         length : 9
         startLine : 0
@@ -20,6 +21,7 @@ ParseHTML Properties:
 ParseHTML Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         length : 1
         startLine : 0
index 4979e83..9c5c1e7 100644 (file)
@@ -3,6 +3,7 @@ Tests the Timeline API timeStamp feature
 TimeStamp Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         message : "TIME STAMP"
     }
index 0bd1926..e53388a 100644 (file)
@@ -3,6 +3,7 @@ Tests the Timeline events for Timers
 TimerInstall Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         timerId : <number>
         timeout : 10
@@ -17,6 +18,7 @@ TimerInstall Properties:
 TimerInstall Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         timerId : <number>
         timeout : 20
@@ -73,6 +75,7 @@ TimerFire Properties:
 TimerRemove Properties:
 {
     startTime : <number>
+    stackTrace : <object>
     data : {
         timerId : <number>
     }
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 (file)
index 0000000..0df8a35
--- /dev/null
@@ -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
+
index 51fb324..e6bd414 100644 (file)
@@ -1,3 +1,22 @@
+2012-07-04  Anthony Scian  <ascian@rim.com>
+
+        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  <wingo@igalia.com>
 
         [GTK] Enable parallel GC
index adb23f2..ba2f4fa 100644 (file)
@@ -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 <wtf/HashMap.h>
+#include <wtf/text/StringBuilder.h>
 
 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;
         }
     };
 
index 7e104ab..a9a647e 100644 (file)
@@ -1,3 +1,20 @@
+2012-07-04  Anthony Scian  <ascian@rim.com>
+
+        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  <danakj@chromium.org>
 
         [chromium] Respect memory needed for RenderSurfaces when reserving contents textures
index ccf673f..3bb69f4 100644 (file)
@@ -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<ScriptCallStack> createScriptCallStack(size_t, bool)
+PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize, bool emptyIsAllowed)
 {
-    return 0;
+    Vector<ScriptCallFrame> frames;
+    if (JSC::ExecState* exec = JSMainThreadExecState::currentState()) {
+        Vector<StackFrame> stackTrace;
+        Interpreter::getStackTrace(&exec->globalData(), stackTrace);
+        for (Vector<StackFrame>::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<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize)