diff options
author | dglazkov@google.com <dglazkov@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-17 15:58:12 +0000 |
---|---|---|
committer | dglazkov@google.com <dglazkov@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-17 15:58:12 +0000 |
commit | 99773b20f52849656195cac3d563a4fb9c1035ab (patch) | |
tree | 457bed1c567070e6d03bd8664c7dcc20718e23ea | |
parent | 0c03b4947c75f74b5704438d09a49e0b20e23972 (diff) | |
download | chromium_src-99773b20f52849656195cac3d563a4fb9c1035ab.zip chromium_src-99773b20f52849656195cac3d563a4fb9c1035ab.tar.gz chromium_src-99773b20f52849656195cac3d563a4fb9c1035ab.tar.bz2 |
Implement ScriptCallContext (2/2)
This is not a complete change list, and should be reviewed together with http://codereview.chromium.org/7400
I will update the DEPS roll once part uno lands.
Review URL: http://codereview.chromium.org/7453
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3531 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | webkit/build/KJSBindings/KJSBindings.vcproj | 4 | ||||
-rw-r--r-- | webkit/build/V8Bindings/V8Bindings.vcproj | 4 | ||||
-rw-r--r-- | webkit/build/WebCore/WebCore.vcproj | 8 | ||||
-rw-r--r-- | webkit/build/port/port.vcproj | 4 | ||||
-rw-r--r-- | webkit/pending/InspectorController.h | 349 | ||||
-rw-r--r-- | webkit/port/bindings/v8/ScriptCallContextV8.cpp | 69 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.cpp | 22 | ||||
-rw-r--r-- | webkit/port/page/inspector/Console.js | 2 | ||||
-rw-r--r-- | webkit/port/page/inspector/InspectorController.cpp | 56 |
10 files changed, 156 insertions, 364 deletions
@@ -12,7 +12,7 @@ deps = { "http://googletest.googlecode.com/svn/trunk@63", "src/third_party/WebKit": - "/trunk/deps/third_party/WebKit@3501", + "/trunk/deps/third_party/WebKit@3530", "src/third_party/cygwin": "/trunk/deps/third_party/cygwin@3248", diff --git a/webkit/build/KJSBindings/KJSBindings.vcproj b/webkit/build/KJSBindings/KJSBindings.vcproj index 0de53be..85685bc 100644 --- a/webkit/build/KJSBindings/KJSBindings.vcproj +++ b/webkit/build/KJSBindings/KJSBindings.vcproj @@ -1954,6 +1954,10 @@ > </File> <File + RelativePath="..\..\..\third_party\WebKit\WebCore\bindings\js\ScriptCallContext.cpp" + > + </File> + <File RelativePath="..\..\..\third_party\WebKit\WebCore\bindings\js\ScriptController.cpp" > </File> diff --git a/webkit/build/V8Bindings/V8Bindings.vcproj b/webkit/build/V8Bindings/V8Bindings.vcproj index 096ea37..c8e2f45 100644 --- a/webkit/build/V8Bindings/V8Bindings.vcproj +++ b/webkit/build/V8Bindings/V8Bindings.vcproj @@ -2437,6 +2437,10 @@ > </File> <File + RelativePath="..\..\port\bindings\v8\ScriptCallContextV8.cpp" + > + </File> + <File RelativePath="..\..\port\bindings\v8\ScriptController.h" > </File> diff --git a/webkit/build/WebCore/WebCore.vcproj b/webkit/build/WebCore/WebCore.vcproj index 3dd3c0d..fb61b6b 100644 --- a/webkit/build/WebCore/WebCore.vcproj +++ b/webkit/build/WebCore/WebCore.vcproj @@ -246,6 +246,10 @@ > </File> <File + RelativePath="..\..\..\third_party\WebKit\WebCore\page\Console.cpp" + > + </File> + <File RelativePath="..\..\..\third_party\WebKit\WebCore\page\ContextMenuClient.h" > </File> @@ -394,6 +398,10 @@ > </File> <File + RelativePath="..\..\..\third_party\WebKit\WebCore\page\ScriptCallContext.h" + > + </File> + <File RelativePath="..\..\..\third_party\WebKit\WebCore\page\Settings.cpp" > </File> diff --git a/webkit/build/port/port.vcproj b/webkit/build/port/port.vcproj index e0af098..4e14bf8 100644 --- a/webkit/build/port/port.vcproj +++ b/webkit/build/port/port.vcproj @@ -187,10 +187,6 @@ RelativePath="..\..\port\page\AccessibilityObjectWrapperWin.h" > </File> - <File - RelativePath="..\..\port\page\Console.cpp" - > - </File> <Filter Name="chromium" > diff --git a/webkit/pending/InspectorController.h b/webkit/pending/InspectorController.h deleted file mode 100644 index 2ec61b7..0000000 --- a/webkit/pending/InspectorController.h +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef InspectorController_h -#define InspectorController_h - -#if USE(JSC) -#include "JavaScriptDebugListener.h" -#endif - -#include "Console.h" -#include "PlatformString.h" -#include "StringHash.h" -#include "DOMWindow.h" -#include <wtf/RefCounted.h> -#if USE(JSC) -#include <JavaScriptCore/JSContextRef.h> -#include <profiler/Profiler.h> -#elif USE(V8) -#include <v8.h> -#endif -#include <wtf/HashMap.h> -#include <wtf/HashSet.h> -#include <wtf/Vector.h> - -#if USE(JSC) -namespace KJS { - class Profile; - class UString; -} -#endif - -namespace WebCore { - -class Database; -class DocumentLoader; -class GraphicsContext; -class InspectorClient; -class JavaScriptCallFrame; -class Node; -class Page; -class ResourceResponse; -class ResourceError; -class SharedBuffer; - -struct ConsoleMessage; -struct InspectorDatabaseResource; -struct InspectorResource; -class ResourceRequest; - -// TODO(ojan): Webkit's version of this inherits from JavaScriptDebugListener. -// We need to do this once we start adding debugger hooks or when we do the next -// full webkit merge, whichever comes first. -class InspectorController : public RefCounted<InspectorController> { -public: - int m_bug1228513_inspectorState; - - typedef HashMap<unsigned long, RefPtr<InspectorResource> > ResourcesMap; - typedef HashMap<RefPtr<Frame>, ResourcesMap*> FrameResourcesMap; - typedef HashSet<RefPtr<InspectorDatabaseResource> > DatabaseResourcesSet; - - typedef enum { - CurrentPanel, - ConsolePanel, - DatabasesPanel, - ElementsPanel, - ProfilesPanel, - ResourcesPanel, - ScriptsPanel - } SpecialPanels; - - InspectorController(Page*, InspectorClient*); - ~InspectorController(); - - void inspectedPageDestroyed(); - void pageDestroyed() { m_page = 0; } - - bool enabled() const; - - Page* inspectedPage() const { return m_inspectedPage; } - - String localizedStringsURL(); - - void inspect(Node*); - void highlight(Node*); - void hideHighlight(); - - void show(); - void showPanel(SpecialPanels); - void close(); - -#if USE(JSC) - bool isRecordingUserInitiatedProfile() const { return m_recordingUserInitiatedProfile; } - void startUserInitiatedProfiling(); - void stopUserInitiatedProfiling(); -#endif - - bool windowVisible(); - void setWindowVisible(bool visible = true, bool attached = false); - -#if USE(JSC) - void addMessageToConsole(MessageSource, MessageLevel, KJS::ExecState*, const KJS::ArgList& arguments, unsigned lineNumber, const String& sourceID); -#elif USE(V8) - // TODO(ojan): Do we need to implement this version? -#endif - void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID); - - void clearConsoleMessages(); - void toggleRecordButton(bool); - -#if USE(JSC) - void addProfile(PassRefPtr<KJS::Profile>, unsigned lineNumber, const KJS::UString& sourceURL); - void addProfileMessageToConsole(PassRefPtr<KJS::Profile> prpProfile, unsigned lineNumber, const KJS::UString& sourceURL); - void addScriptProfile(KJS::Profile* profile); - const Vector<RefPtr<KJS::Profile> >& profiles() const { return m_profiles; } -#endif - - void attachWindow(); - void detachWindow(); - - void setAttachedWindow(bool); - void setAttachedWindowHeight(unsigned height); - -#if USE(JSC) - JSContextRef scriptContext() const { return m_scriptContext; }; - void setScriptContext(JSContextRef context) { m_scriptContext = context; }; -#elif USE(V8) - void setScriptObject(v8::Handle<v8::Object> newScriptObject); -#endif - - void inspectedWindowScriptObjectCleared(Frame*); - void windowScriptObjectAvailable(); - - void scriptObjectReady(); - - void populateScriptObjects(); - void resetScriptObjects(); - - void didCommitLoad(DocumentLoader*); - void frameDetachedFromParent(Frame*); - - void didLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length); - - void identifierForInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&); - void willSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse); - void didReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&); - void didReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived); - void didFinishLoading(DocumentLoader*, unsigned long identifier); - void didFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&); -#if USE(JSC) - void resourceRetrievedByXMLHttpRequest(unsigned long identifier, KJS::UString& sourceString); -#elif USE(V8) - void resourceRetrievedByXMLHttpRequest(unsigned long identifier, String& sourceString); -#endif - -#if ENABLE(DATABASE) - void didOpenDatabase(Database*, const String& domain, const String& name, const String& version); -#endif - - const ResourcesMap& resources() const { return m_resources; } - - void moveWindowBy(float x, float y) const; - void closeWindow(); - - void startDebuggingAndReloadInspectedPage(); - void stopDebugging(); - -#if USE(JSC) - bool debuggerAttached() const { return m_debuggerAttached; } - - JavaScriptCallFrame* currentCallFrame() const; - - void addBreakpoint(int sourceID, unsigned lineNumber); - void removeBreakpoint(int sourceID, unsigned lineNumber); - - bool pauseOnExceptions(); - void setPauseOnExceptions(bool pause); - - void pauseInDebugger(); - void resumeDebugger(); - - void stepOverStatementInDebugger(); - void stepIntoStatementInDebugger(); - void stepOutOfFunctionInDebugger(); -#endif - - void drawNodeHighlight(GraphicsContext&) const; - -#if USE(JSC) - void count(const KJS::UString& title, unsigned lineNumber, const String& sourceID); - - void startTiming(const KJS::UString& title); - bool stopTiming(const KJS::UString& title, double& elapsed); - - void startGroup(MessageSource source, KJS::ExecState* exec, const KJS::ArgList& arguments, unsigned lineNumber, const String& sourceURL); - void endGroup(MessageSource source, unsigned lineNumber, const String& sourceURL); -#endif - -#if USE(V8) - // InspectorController.idl - void addSourceToFrame(unsigned long identifier, Node* frame); - Node* getResourceDocumentNode(unsigned long identifier); - void highlightDOMNode(Node* node); - void hideDOMNodeHighlight(); - void loaded(); - void attach(); - void detach(); - // TODO(jackson): search should return an array of JSRanges - void search(Node* node, const String& query); - DOMWindow* inspectedWindow(); - String platform() const; -#endif - -private: - void focusNode(); - - void addConsoleMessage(ConsoleMessage*); - void addScriptConsoleMessage(const ConsoleMessage*); - - void addResource(InspectorResource*); - void removeResource(InspectorResource*); - -#if USE(JSC) - JSObjectRef addScriptResource(InspectorResource*); -#elif USE(V8) - void addScriptResource(InspectorResource*); -#endif - void removeScriptResource(InspectorResource*); - -#if USE(JSC) - JSObjectRef addAndUpdateScriptResource(InspectorResource*); -#elif USE(V8) - void addAndUpdateScriptResource(InspectorResource*); -#endif - void updateScriptResourceRequest(InspectorResource*); - void updateScriptResourceResponse(InspectorResource*); - void updateScriptResourceType(InspectorResource*); - void updateScriptResource(InspectorResource*, int length); - void updateScriptResource(InspectorResource*, bool finished, bool failed = false); - void updateScriptResource(InspectorResource*, double startTime, double responseReceivedTime, double endTime); - - void pruneResources(ResourcesMap*, DocumentLoader* loaderToKeep = 0); - void removeAllResources(ResourcesMap* map) { pruneResources(map); } - - // Return true if the inspector should track request/response activity. - // Chrome's policy is to only log requests if the inspector is already open. - // This reduces the passive bloat from InspectorController: http://b/1113875 - bool trackResources() const { return m_trackResources; } - - // Start/stop resource tracking. - void enableTrackResources(bool trackResources); - - bool m_trackResources; - - // Helper function to determine when the script object is initialized -#if USE(JSC) - inline bool hasScriptObject() const { return m_scriptObject; } -#elif USE(V8) - inline bool hasScriptObject() { return !m_scriptObject.IsEmpty(); } -#endif - -#if ENABLE(DATABASE) -#if USE(JSC) - JSObjectRef addDatabaseScriptResource(InspectorDatabaseResource*); - void removeDatabaseScriptResource(InspectorDatabaseResource*); -#elif USE(V8) - // TODO(ojan): implement when we turn on databases. -#endif -#endif - -#if USE(JSC) - JSValueRef callSimpleFunction(JSContextRef, JSObjectRef thisObject, const char* functionName) const; - JSValueRef callFunction(JSContextRef, JSObjectRef thisObject, const char* functionName, size_t argumentCount, const JSValueRef arguments[], JSValueRef& exception) const; - - bool handleException(JSContextRef, JSValueRef exception, unsigned lineNumber) const; -#endif - - void showWindow(); - -#if USE(JSC) - virtual void didParseSource(KJS::ExecState*, const KJS::SourceProvider& source, int startingLineNumber, const KJS::UString& sourceURL, int sourceID); - virtual void failedToParseSource(KJS::ExecState*, const KJS::SourceProvider& source, int startingLineNumber, const KJS::UString& sourceURL, int errorLine, const KJS::UString& errorMessage); - virtual void didPause(); -#elif USE(V8) - // TODO(ojan): implement when we start integrating in the debugger. -#endif - - Page* m_inspectedPage; - InspectorClient* m_client; - Page* m_page; - RefPtr<Node> m_nodeToFocus; - RefPtr<InspectorResource> m_mainResource; - ResourcesMap m_resources; - HashSet<String> m_knownResources; - FrameResourcesMap m_frameResources; - Vector<ConsoleMessage*> m_consoleMessages; -#if USE(JSC) - Vector<RefPtr<KJS::Profile> > m_profiles; -#endif - HashMap<String, double> m_times; - HashMap<String, unsigned> m_counts; -#if ENABLE(DATABASE) - DatabaseResourcesSet m_databaseResources; -#endif -#if USE(JSC) - JSObjectRef m_scriptObject; - JSObjectRef m_controllerScriptObject; - JSContextRef m_scriptContext; -#elif USE(V8) - v8::Persistent<v8::Object> m_scriptObject; -#endif - bool m_windowVisible; - bool m_debuggerAttached; - bool m_attachDebuggerWhenShown; - bool m_recordingUserInitiatedProfile; - SpecialPanels m_showAfterVisible; - unsigned long m_nextIdentifier; - RefPtr<Node> m_highlightedNode; - unsigned m_groupLevel; -}; - -} // namespace WebCore - -#endif // !defined(InspectorController_h) diff --git a/webkit/port/bindings/v8/ScriptCallContextV8.cpp b/webkit/port/bindings/v8/ScriptCallContextV8.cpp new file mode 100644 index 0000000..d959fc5 --- /dev/null +++ b/webkit/port/bindings/v8/ScriptCallContextV8.cpp @@ -0,0 +1,69 @@ +// Copyright (c) 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "config.h" +#include "ScriptCallContext.h" + +#include "PlatformString.h" +#include "KURL.h" +#include "v8.h" +#include "v8_binding.h" + +namespace WebCore { + +ScriptCallContext::ScriptCallContext(const v8::Arguments& args) + : m_args(args) +{ +} + +String ScriptCallContext::argumentStringAt(unsigned index, + bool checkForNullOrUndefined) +{ + if (index >= argumentCount()) + return String(); + + return ToWebCoreString(m_args[index]); +} + +unsigned ScriptCallContext::argumentCount() const +{ + return m_args.Length(); +} + +unsigned ScriptCallContext::lineNumber() const +{ + return 0; +} + +KURL ScriptCallContext::sourceURL() const +{ + return KURL(); +} + +} // namespace WebCore diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp index b6ff5f3..1d36ccc 100644 --- a/webkit/port/bindings/v8/v8_custom.cpp +++ b/webkit/port/bindings/v8/v8_custom.cpp @@ -97,6 +97,7 @@ #include "RenderPartObject.h" #include "RenderWidget.h" #include "ScheduledAction.h" +#include "ScriptCallContext.h" #include "SecurityOrigin.h" #include "Settings.h" #include "StyleSheetList.h" @@ -2273,14 +2274,17 @@ CALLBACK_FUNC_DECL(ConsoleError) { INC_STATS(L"DOM.Console.error()"); v8::Handle<v8::Value> holder = args.Holder(); Console* imp = V8Proxy::ToNativeObject<Console>(V8ClassIndex::CONSOLE, holder); - String message = ToWebCoreString(args[0]); - imp->error(message); + ScriptCallContext context(args); + imp->error(&context); return v8::Undefined(); } CALLBACK_FUNC_DECL(ConsoleGroup) { INC_STATS(L"DOM.Console.group()"); - V8Proxy::SetDOMException(NOT_SUPPORTED_ERR); + v8::Handle<v8::Value> holder = args.Holder(); + Console* imp = V8Proxy::ToNativeObject<Console>(V8ClassIndex::CONSOLE, holder); + ScriptCallContext context(args); + imp->group(&context); return v8::Undefined(); } @@ -2288,8 +2292,8 @@ CALLBACK_FUNC_DECL(ConsoleInfo) { INC_STATS(L"DOM.Console.info()"); v8::Handle<v8::Value> holder = args.Holder(); Console* imp = V8Proxy::ToNativeObject<Console>(V8ClassIndex::CONSOLE, holder); - String message = ToWebCoreString(args[0]); - imp->info(message); + ScriptCallContext context(args); + imp->info(&context); return v8::Undefined(); } @@ -2297,8 +2301,8 @@ CALLBACK_FUNC_DECL(ConsoleLog) { INC_STATS(L"DOM.Console.log()"); v8::Handle<v8::Value> holder = args.Holder(); Console* imp = V8Proxy::ToNativeObject<Console>(V8ClassIndex::CONSOLE, holder); - String message = ToWebCoreString(args[0]); - imp->log(message); + ScriptCallContext context(args); + imp->log(&context); return v8::Undefined(); } @@ -2324,8 +2328,8 @@ CALLBACK_FUNC_DECL(ConsoleWarn) { INC_STATS(L"DOM.Console.warn()"); v8::Handle<v8::Value> holder = args.Holder(); Console* imp = V8Proxy::ToNativeObject<Console>(V8ClassIndex::CONSOLE, holder); - String message = ToWebCoreString(args[0]); - imp->warn(message); + ScriptCallContext context(args); + imp->warn(&context); return v8::Undefined(); } diff --git a/webkit/port/page/inspector/Console.js b/webkit/port/page/inspector/Console.js index 1292531..18e3537 100644 --- a/webkit/port/page/inspector/Console.js +++ b/webkit/port/page/inspector/Console.js @@ -494,7 +494,7 @@ WebInspector.ConsoleMessage.prototype = { function formatForConsole(obj) { - return WebInspector.console._format(obj, plainText); + return WebInspector.console._format(obj, plaintext); } if (Object.type(parameters[0], InspectorController.inspectedWindow()) === "string") { diff --git a/webkit/port/page/inspector/InspectorController.cpp b/webkit/port/page/inspector/InspectorController.cpp index 7aa0a44..ede3b0b 100644 --- a/webkit/port/page/inspector/InspectorController.cpp +++ b/webkit/port/page/inspector/InspectorController.cpp @@ -66,6 +66,7 @@ #include "Range.h" #include "ResourceRequest.h" #include "ResourceResponse.h" +#include "ScriptCallContext.h" #include "ScriptController.h" #include "Settings.h" #include "SharedBuffer.h" @@ -129,9 +130,39 @@ struct ConsoleMessage { , groupLevel(g) { } + + ConsoleMessage(MessageSource s, MessageLevel l, ScriptCallContext* context, unsigned g) + : source(s) + , level(l) +#if USE(JSC) + , wrappedArguments(args.size()) +#endif + , line(context->lineNumber()) + , url(context->sourceURL()) + , groupLevel(g) + { +#if USE(JSC) + JSLock lock(false); + 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)); + } +#endif + } + MessageSource source; MessageLevel level; String message; +#if USE(JSC) + Vector<ProtectedPtr<JSValue> > wrappedArguments; +#endif unsigned line; String url; unsigned groupLevel; @@ -752,6 +783,14 @@ void InspectorController::enableTrackResources(bool trackResources) m_resources.clear(); } +void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, ScriptCallContext* context) +{ + if (!enabled()) + return; + + addConsoleMessage(new ConsoleMessage(source, level, context, m_groupLevel)); +} + void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID) { if (!enabled()) @@ -789,6 +828,23 @@ void InspectorController::clearConsoleMessages() m_consoleMessages.clear(); } +void InspectorController::startGroup(MessageSource source, ScriptCallContext* context) +{ + ++m_groupLevel; + + addConsoleMessage(new ConsoleMessage(source, StartGroupMessageLevel, context, m_groupLevel)); +} + +void InspectorController::endGroup(MessageSource source, unsigned lineNumber, const String& sourceURL) +{ + if (m_groupLevel == 0) + return; + + --m_groupLevel; + + addConsoleMessage(new ConsoleMessage(source, EndGroupMessageLevel, String(), lineNumber, sourceURL, m_groupLevel)); +} + void InspectorController::attachWindow() { if (!enabled()) |