summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorsgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 09:53:07 +0000
committersgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 09:53:07 +0000
commit64b72829159ea486b30525473d243377f108aaa7 (patch)
treeb916ac9885ed61b2dc4dbf7620916724de9fd233 /webkit
parent60ff8f919f6687ba7438e1e728a854801b63af76 (diff)
downloadchromium_src-64b72829159ea486b30525473d243377f108aaa7.zip
chromium_src-64b72829159ea486b30525473d243377f108aaa7.tar.gz
chromium_src-64b72829159ea486b30525473d243377f108aaa7.tar.bz2
Added line number and source URL information to inspector console messages.
This uses a debugger API in V8 which can look at the JavaScript execution stack and find the line number and source URL for the top stack frame. The JavaScript functions required for this are added to a new utility context created in V8Proxy. This context is created as a singleton (on demand) as it has no dependency in the page currently running. I will not submit this change until V8 version 0.4.5 is used in Chrome as this change depends on a new V8 debugger API added to that version. The change also requires a second step to udate the WebKit DEPS. BUG=2960 Review URL: http://codereview.chromium.org/12804 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/port/bindings/v8/ScriptCallContextV8.cpp8
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp72
-rw-r--r--webkit/port/bindings/v8/v8_proxy.h19
-rw-r--r--webkit/tools/layout_tests/test_lists/tests_fixable.txt4
4 files changed, 97 insertions, 6 deletions
diff --git a/webkit/port/bindings/v8/ScriptCallContextV8.cpp b/webkit/port/bindings/v8/ScriptCallContextV8.cpp
index d959fc5..cef54a4 100644
--- a/webkit/port/bindings/v8/ScriptCallContextV8.cpp
+++ b/webkit/port/bindings/v8/ScriptCallContextV8.cpp
@@ -34,12 +34,16 @@
#include "KURL.h"
#include "v8.h"
#include "v8_binding.h"
+#include "v8_proxy.h"
namespace WebCore {
ScriptCallContext::ScriptCallContext(const v8::Arguments& args)
: m_args(args)
{
+ // Line numbers in V8 are starting from zero.
+ m_lineNumber = V8Proxy::GetSourceLineNumber() + 1;
+ m_sourceURL = KURL(V8Proxy::GetSourceName());
}
String ScriptCallContext::argumentStringAt(unsigned index,
@@ -58,12 +62,12 @@ unsigned ScriptCallContext::argumentCount() const
unsigned ScriptCallContext::lineNumber() const
{
- return 0;
+ return m_lineNumber;
}
KURL ScriptCallContext::sourceURL() const
{
- return KURL();
+ return m_sourceURL;
}
} // namespace WebCore
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index 0703bad..5981ef8b 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -30,6 +30,7 @@
#include "config.h"
#include <v8.h>
+#include <v8-debug.h>
#include "v8_proxy.h"
#include "dom_wrapper_map.h"
@@ -217,6 +218,10 @@ namespace WebCore {
// collector will remove these groups after each GC.
+// Static utility context.
+v8::Persistent<v8::Context> V8Proxy::m_utilityContext;
+
+
// A helper class for undetectable document.all
class UndetectableHTMLCollection : public HTMLCollection {
};
@@ -3147,4 +3152,71 @@ void V8Proxy::ProcessConsoleMessages()
ConsoleMessageManager::ProcessDelayedMessages();
}
+
+// Create the utility context for holding JavaScript functions used internally
+// which are not visible to JavaScript executing on the page.
+void V8Proxy::CreateUtilityContext() {
+ ASSERT(m_utilityContext.IsEmpty());
+
+ v8::HandleScope scope;
+ v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
+ m_utilityContext = v8::Context::New(NULL, global_template);
+ v8::Context::Scope context_scope(m_utilityContext);
+
+ // Compile JavaScript function for retrieving the source line of the top
+ // JavaScript stack frame.
+ static const char* frame_source_line_source =
+ "function frame_source_line(exec_state) {"
+ " return exec_state.frame(0).sourceLine();"
+ "}";
+ v8::Script::Compile(v8::String::New(frame_source_line_source))->Run();
+
+ // Compile JavaScript function for retrieving the source name of the top
+ // JavaScript stack frame.
+ static const char* frame_source_name_source =
+ "function frame_source_name(exec_state) {"
+ " var frame = exec_state.frame(0);"
+ " if (frame.func().resolved() && "
+ " frame.func().script() && "
+ " frame.func().script().name()) {"
+ " return frame.func().script().name();"
+ " }"
+ "}";
+ v8::Script::Compile(v8::String::New(frame_source_name_source))->Run();
+}
+
+
+int V8Proxy::GetSourceLineNumber() {
+ v8::HandleScope scope;
+ v8::Handle<v8::Context> utility_context = V8Proxy::GetUtilityContext();
+ if (utility_context.IsEmpty()) {
+ return 0;
+ }
+ v8::Context::Scope context_scope(utility_context);
+ v8::Handle<v8::Function> frame_source_line;
+ frame_source_line = v8::Local<v8::Function>::Cast(
+ utility_context->Global()->Get(v8::String::New("frame_source_line")));
+ if (frame_source_line.IsEmpty()) {
+ return 0;
+ }
+ return v8::Debug::Call(frame_source_line)->Int32Value();
+}
+
+
+String V8Proxy::GetSourceName() {
+ v8::HandleScope scope;
+ v8::Handle<v8::Context> utility_context = GetUtilityContext();
+ if (utility_context.IsEmpty()) {
+ return String();
+ }
+ v8::Context::Scope context_scope(utility_context);
+ v8::Handle<v8::Function> frame_source_name;
+ frame_source_name = v8::Local<v8::Function>::Cast(
+ utility_context->Global()->Get(v8::String::New("frame_source_name")));
+ if (frame_source_name.IsEmpty()) {
+ return String();
+ }
+ return ToWebCoreString(v8::Debug::Call(frame_source_name));
+}
+
} // namespace WebCore
diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h
index f2a2275..4450dcc 100644
--- a/webkit/port/bindings/v8/v8_proxy.h
+++ b/webkit/port/bindings/v8/v8_proxy.h
@@ -421,6 +421,11 @@ class V8Proxy {
static bool IsWrapperOfType(v8::Handle<v8::Value> obj,
V8ClassIndex::V8WrapperType classType);
+ // Function for retrieving the line number and source name for the top
+ // JavaScript stack frame.
+ static int GetSourceLineNumber();
+ static String GetSourceName();
+
private:
void initContextIfNeeded();
void DisconnectEventListeners();
@@ -495,12 +500,26 @@ class V8Proxy {
return v8::Local<v8::Context>::New(m_context);
}
+ // Create and populate the utility context.
+ static void CreateUtilityContext();
+
+ // Returns a local handle of the utility context.
+ static v8::Local<v8::Context> GetUtilityContext() {
+ if (m_utilityContext.IsEmpty()) {
+ CreateUtilityContext();
+ }
+ return v8::Local<v8::Context>::New(m_utilityContext);
+ }
+
Frame* m_frame;
v8::Persistent<v8::Context> m_context;
v8::Persistent<v8::Object> m_global;
v8::Persistent<v8::Value> m_document;
+ // Utility context holding JavaScript functions used internally.
+ static v8::Persistent<v8::Context> m_utilityContext;
+
int m_handlerLineno;
// A list of event listeners created for this frame,
diff --git a/webkit/tools/layout_tests/test_lists/tests_fixable.txt b/webkit/tools/layout_tests/test_lists/tests_fixable.txt
index 5d8d686..9aa53908 100644
--- a/webkit/tools/layout_tests/test_lists/tests_fixable.txt
+++ b/webkit/tools/layout_tests/test_lists/tests_fixable.txt
@@ -541,10 +541,6 @@ LayoutTests/fast/js/removing-Cf-characters.html = FAIL
LayoutTests/fast/js/static-scope-object.html = FAIL
LayoutTests/fast/js/delete-getters-setters.html = FAIL
-// Console output won't have line numbers until V8 gives us a way to get that
-// information. <http://crbug.com/2960>
-LayoutTests/fast/dom/Window/console-functions.html = FAIL
-
// Shadows don't render correctly for these tests.
// http://code.google.com/p/chromium/issues/detail?id=2969
LINUX WIN : LayoutTests/fast/canvas/shadow-offset-1.html = FAIL