diff options
| author | sgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 08:48:32 +0000 |
|---|---|---|
| committer | sgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 08:48:32 +0000 |
| commit | bff42e50789d69e1b8a95ce29559dd3b5f1045b1 (patch) | |
| tree | 0975be57559810fcc63eca41b2763ab77eff3030 | |
| parent | 3f0be0417100a9d0b9e31347cabebc0e1fe07842 (diff) | |
| download | chromium_src-bff42e50789d69e1b8a95ce29559dd3b5f1045b1.zip chromium_src-bff42e50789d69e1b8a95ce29559dd3b5f1045b1.tar.gz chromium_src-bff42e50789d69e1b8a95ce29559dd3b5f1045b1.tar.bz2 | |
Change the handling of console.log etc. to pass the parameters correctly and not just concattenate them into a long string. This makes the formatting using % syntax work in the inspector. It also makes the counting of repeated messages work the same way as in TOT WebKit.
This change needs a DEPS update after commit to make it compile.
Review URL: http://codereview.chromium.org/13621
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6577 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | webkit/port/bindings/v8/ScriptCallContextV8.cpp | 9 | ||||
| -rw-r--r-- | webkit/port/bindings/v8/ScriptValue.h | 11 | ||||
| -rw-r--r-- | webkit/port/page/inspector/InspectorController.cpp | 43 |
3 files changed, 46 insertions, 17 deletions
diff --git a/webkit/port/bindings/v8/ScriptCallContextV8.cpp b/webkit/port/bindings/v8/ScriptCallContextV8.cpp index cef54a4..35400e8 100644 --- a/webkit/port/bindings/v8/ScriptCallContextV8.cpp +++ b/webkit/port/bindings/v8/ScriptCallContextV8.cpp @@ -29,6 +29,7 @@ #include "config.h" #include "ScriptCallContext.h" +#include "ScriptValue.h" #include "PlatformString.h" #include "KURL.h" @@ -46,6 +47,14 @@ ScriptCallContext::ScriptCallContext(const v8::Arguments& args) m_sourceURL = KURL(V8Proxy::GetSourceName()); } +ScriptValue ScriptCallContext::argumentAt(unsigned index) +{ + if (index >= argumentCount()) + return ScriptValue(v8::Handle<v8::Value>()); + + return ScriptValue(m_args[index]); +} + String ScriptCallContext::argumentStringAt(unsigned index, bool checkForNullOrUndefined) { diff --git a/webkit/port/bindings/v8/ScriptValue.h b/webkit/port/bindings/v8/ScriptValue.h index 4695d0e..5106cb4 100644 --- a/webkit/port/bindings/v8/ScriptValue.h +++ b/webkit/port/bindings/v8/ScriptValue.h @@ -82,6 +82,16 @@ public: return *this; } + bool operator==(const ScriptValue value) const + { + return m_value == value.m_value; + } + + bool operator!=(const ScriptValue value) const + { + return !operator==(value); + } + void clear() { if (!m_value.IsEmpty()) { #ifndef NDEBUG @@ -97,6 +107,7 @@ public: clear(); } + v8::Handle<v8::Value> v8Value() const { return m_value; } bool getString(String& result) const; private: diff --git a/webkit/port/page/inspector/InspectorController.cpp b/webkit/port/page/inspector/InspectorController.cpp index 68ce6e1..773dbdd 100644 --- a/webkit/port/page/inspector/InspectorController.cpp +++ b/webkit/port/page/inspector/InspectorController.cpp @@ -140,6 +140,8 @@ struct ConsoleMessage { , level(l) #if USE(JSC) , wrappedArguments(args.size()) +#elif USE(V8) + , arguments(context->argumentCount()) #endif , line(context->lineNumber()) , url(context->sourceURL()) @@ -151,13 +153,8 @@ struct ConsoleMessage { for (unsigned i = 0; i < context->argumentCount(); ++i) wrappedArguments[i] = JSInspectedObjectWrapper::wrap(context->argumentAt(i)); #elif USE(V8) - // FIXME: This is not correct. The objects are being converted to - // string and appended to one big message. But it's better than only - // supporting one string argument that we had previously. for (unsigned i = 0; i < context->argumentCount(); ++i) { - if (i) - message.append(", "); - message.append(context->argumentStringAt(i)); + arguments[i] = context->argumentAt(i); } #endif } @@ -170,7 +167,7 @@ struct ConsoleMessage { #if USE(JSC) && msg.wrappedArguments == this->wrappedArguments #elif USE(V8) - && msg.message == this->message + && msg.arguments == this->arguments #endif && msg.line == this->line && msg.url == this->url @@ -182,6 +179,8 @@ struct ConsoleMessage { String message; #if USE(JSC) Vector<ProtectedPtr<JSValue> > wrappedArguments; +#elif USE(V8) + Vector<ScriptValue> arguments; #endif unsigned line; String url; @@ -1346,18 +1345,28 @@ void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message) if (addMessageToConsole.IsEmpty() || !addMessageToConsole->IsFunction()) return; - v8::Handle<v8::Value> args[] = { - v8::Number::New(message->source), - v8::Number::New(message->level), - v8::Number::New(message->line), - v8StringOrNull(message->url), - v8::Number::New(message->groupLevel), - v8::Number::New(message->repeatCount), - v8StringOrNull(message->message), - }; + // Create an instance of WebInspector.ConsoleMessage passing the variable + // number of arguments available. + static unsigned kArgcFixed = 6; + unsigned argc = kArgcFixed + message->arguments.size(); + v8::Handle<v8::Value> *args = new v8::Handle<v8::Value>[argc]; + if (args == 0) + return; + unsigned i = 0; + args[i++] = v8::Number::New(message->source); + args[i++] = v8::Number::New(message->level); + args[i++] = v8::Number::New(message->line); + args[i++] = v8StringOrNull(message->url); + args[i++] = v8::Number::New(message->groupLevel); + args[i++] = v8::Number::New(message->repeatCount); + ASSERT(kArgcFixed == i); + for (unsigned i = 0; i < message->arguments.size(); ++i) { + args[kArgcFixed + i] = message->arguments[i].v8Value(); + } v8::Handle<v8::Object> consoleMessage = - SafeAllocation::NewInstance(consoleMessageConstructor, 7, args); + SafeAllocation::NewInstance(consoleMessageConstructor, argc, args); + delete[] args; if (consoleMessage.IsEmpty()) return; |
