Title: [121359] trunk/Source
Revision
121359
Author
commit-qu...@webkit.org
Date
2012-06-27 12:54:48 -0700 (Wed, 27 Jun 2012)

Log Message

Web Inspector [JSC]: Implement ScriptCallStack::stackTrace
https://bugs.webkit.org/show_bug.cgi?id=40118

Patch by Anthony Scian <asc...@rim.com> on 2012-06-27
Reviewed by Yong Li.

Source/_javascript_Core:

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:
(StackFrame):
(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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (121358 => 121359)


--- trunk/Source/_javascript_Core/ChangeLog	2012-06-27 19:50:52 UTC (rev 121358)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-06-27 19:54:48 UTC (rev 121359)
@@ -1,3 +1,23 @@
+2012-06-27  Anthony Scian  <asc...@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:
+        (StackFrame):
+        (JSC::StackFrame::toString):
+        (JSC::StackFrame::friendlySourceURL):
+        (JSC::StackFrame::friendlyFunctionName):
+        (JSC::StackFrame::friendlyLineNumber):
+
 2012-06-27  Oswald Buddenhagen  <oswald.buddenha...@nokia.com>
 
         [Qt] Remove redundant c++11 warning suppression code

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.h (121358 => 121359)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.h	2012-06-27 19:50:52 UTC (rev 121358)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.h	2012-06-27 19:54:48 UTC (rev 121359)
@@ -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,46 +82,62 @@
         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 (!functionName.isEmpty() && !sourceURL.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;
+        }
     };
 
     class TopCallFrameSetter {

Modified: trunk/Source/WebCore/ChangeLog (121358 => 121359)


--- trunk/Source/WebCore/ChangeLog	2012-06-27 19:50:52 UTC (rev 121358)
+++ trunk/Source/WebCore/ChangeLog	2012-06-27 19:54:48 UTC (rev 121359)
@@ -1,3 +1,20 @@
+2012-06-27  Anthony Scian  <asc...@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-06-27  Ryosuke Niwa  <rn...@webkit.org>
 
         Let Xcode have its own way.

Modified: trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp (121358 => 121359)


--- trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp	2012-06-27 19:50:52 UTC (rev 121358)
+++ trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp	2012-06-27 19:54:48 UTC (rev 121359)
@@ -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,26 @@
 
 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++) {
+            StackFrame level = *iter;
+            frames.append(ScriptCallFrame(level.friendlyFunctionName(exec), level.friendlySourceURL(), level.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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to