diff options
author | Ben Murdoch <benm@google.com> | 2011-05-16 16:25:10 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-23 18:54:14 +0100 |
commit | ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb (patch) | |
tree | db769fadd053248f85db67434a5b275224defef7 /Source/WebCore/bindings/v8 | |
parent | 52e2557aeb8477967e97fd24f20f8f407a10fa15 (diff) | |
download | external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.zip external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.tar.gz external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.tar.bz2 |
Merge WebKit at r76408: Initial merge by git.
Change-Id: I5b91decbd693ccbf5c1b8354b37cd68cc9a1ea53
Diffstat (limited to 'Source/WebCore/bindings/v8')
27 files changed, 234 insertions, 313 deletions
diff --git a/Source/WebCore/bindings/v8/DOMData.h b/Source/WebCore/bindings/v8/DOMData.h index 78edf92..b042606 100644 --- a/Source/WebCore/bindings/v8/DOMData.h +++ b/Source/WebCore/bindings/v8/DOMData.h @@ -43,7 +43,8 @@ namespace WebCore { // thread. The DOMData for the main thread and the DOMData for child threads // use different subclasses. // - class DOMData : public Noncopyable { + class DOMData { + WTF_MAKE_NONCOPYABLE(DOMData); public: DOMData(); virtual ~DOMData(); diff --git a/Source/WebCore/bindings/v8/DOMDataStore.cpp b/Source/WebCore/bindings/v8/DOMDataStore.cpp index 0d37dc0..5393bd9 100644 --- a/Source/WebCore/bindings/v8/DOMDataStore.cpp +++ b/Source/WebCore/bindings/v8/DOMDataStore.cpp @@ -148,11 +148,13 @@ void DOMDataStore::weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Objec DOMData::handleWeakObject(DOMDataStore::ActiveDOMObjectMap, v8::Persistent<v8::Object>::Cast(v8Object), domObject); } -void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* domObject) +void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> value, void* domObject) { ASSERT(WTF::isMainThread()); Node* node = static_cast<Node*>(domObject); + // Node wrappers must be JS objects. + v8::Persistent<v8::Object> v8Object = v8::Persistent<v8::Object>::Cast(value); WTF::MutexLocker locker(DOMDataStore::allStoresMutex()); DOMDataList& list = DOMDataStore::allStores(); @@ -171,7 +173,7 @@ void DOMDataStore::weakNodeCallback(v8::Persistent<v8::Value> v8Object, void* do node->deref(); // Nobody overrides Node::deref so it's safe } -bool DOMDataStore::IntrusiveDOMWrapperMap::removeIfPresent(Node* obj, v8::Persistent<v8::Data> value) +bool DOMDataStore::IntrusiveDOMWrapperMap::removeIfPresent(Node* obj, v8::Persistent<v8::Object> value) { ASSERT(obj); v8::Persistent<v8::Object>* entry = obj->wrapper(); diff --git a/Source/WebCore/bindings/v8/DOMDataStore.h b/Source/WebCore/bindings/v8/DOMDataStore.h index a1051dd..dbead9c 100644 --- a/Source/WebCore/bindings/v8/DOMDataStore.h +++ b/Source/WebCore/bindings/v8/DOMDataStore.h @@ -149,7 +149,8 @@ namespace WebCore { // This class doesn't manage the lifetime of the store. The data store // lifetime is managed by subclasses. // - class DOMDataStore : public Noncopyable { + class DOMDataStore { + WTF_MAKE_NONCOPYABLE(DOMDataStore); public: enum DOMWrapperMapType { DOMNodeMap, @@ -190,7 +191,7 @@ namespace WebCore { m_table.visit(store, visitor); } - virtual bool removeIfPresent(Node* key, v8::Persistent<v8::Data> value); + virtual bool removeIfPresent(Node*, v8::Persistent<v8::Object>); virtual void clear() { diff --git a/Source/WebCore/bindings/v8/DebuggerScript.js b/Source/WebCore/bindings/v8/DebuggerScript.js index 8c9d98e..eb9de2f 100644 --- a/Source/WebCore/bindings/v8/DebuggerScript.js +++ b/Source/WebCore/bindings/v8/DebuggerScript.js @@ -201,8 +201,10 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame) var script = func.script(); var sourceID = script && script.id(); - // Get line number. - var line = DebuggerScript._v8ToWebkitLineNumber(frameMirror.sourceLine()); + // Get location. + var location = frameMirror.sourceLocation(); + var line = DebuggerScript._v8ToWebkitLineNumber(location.line); + var column = DebuggerScript._v8ToWebkitLineNumber(location.column); // Get this object. var thisObject = frameMirror.details_.receiver(); @@ -250,6 +252,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame) return { "sourceID": sourceID, "line": line, + "column": column, "functionName": functionName, "type": "function", "thisObject": thisObject, diff --git a/Source/WebCore/bindings/v8/JavaScriptCallFrame.cpp b/Source/WebCore/bindings/v8/JavaScriptCallFrame.cpp index 20bf378..5bb436f 100644 --- a/Source/WebCore/bindings/v8/JavaScriptCallFrame.cpp +++ b/Source/WebCore/bindings/v8/JavaScriptCallFrame.cpp @@ -80,6 +80,16 @@ int JavaScriptCallFrame::line() const return 0; } +int JavaScriptCallFrame::column() const +{ + v8::HandleScope handleScope; + v8::Context::Scope contextScope(m_debuggerContext.get()); + v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("column")); + if (result->IsInt32()) + return result->Int32Value(); + return 0; +} + String JavaScriptCallFrame::functionName() const { v8::HandleScope handleScope; diff --git a/Source/WebCore/bindings/v8/JavaScriptCallFrame.h b/Source/WebCore/bindings/v8/JavaScriptCallFrame.h index 95a0510..2d14593 100644 --- a/Source/WebCore/bindings/v8/JavaScriptCallFrame.h +++ b/Source/WebCore/bindings/v8/JavaScriptCallFrame.h @@ -51,6 +51,7 @@ public: int sourceID() const; int line() const; + int column() const; String functionName() const; v8::Handle<v8::Value> scopeChain() const; diff --git a/Source/WebCore/bindings/v8/ScriptCachedFrameData.h b/Source/WebCore/bindings/v8/ScriptCachedFrameData.h index 1aa1f62..f08265b 100644 --- a/Source/WebCore/bindings/v8/ScriptCachedFrameData.h +++ b/Source/WebCore/bindings/v8/ScriptCachedFrameData.h @@ -67,7 +67,8 @@ namespace WebCore { class Frame; class DOMWindow; -class ScriptCachedFrameData : public Noncopyable { +class ScriptCachedFrameData { + WTF_MAKE_NONCOPYABLE(ScriptCachedFrameData); public: ScriptCachedFrameData(Frame*); ~ScriptCachedFrameData() { } diff --git a/Source/WebCore/bindings/v8/ScriptDebugServer.h b/Source/WebCore/bindings/v8/ScriptDebugServer.h index 40dd5fc..8fa723f 100644 --- a/Source/WebCore/bindings/v8/ScriptDebugServer.h +++ b/Source/WebCore/bindings/v8/ScriptDebugServer.h @@ -48,7 +48,8 @@ namespace WebCore { class Page; class ScriptDebugListener; -class ScriptDebugServer : public Noncopyable { +class ScriptDebugServer { + WTF_MAKE_NONCOPYABLE(ScriptDebugServer); public: static ScriptDebugServer& shared(); diff --git a/Source/WebCore/bindings/v8/ScriptProfiler.h b/Source/WebCore/bindings/v8/ScriptProfiler.h index b75a054..e0969e1 100644 --- a/Source/WebCore/bindings/v8/ScriptProfiler.h +++ b/Source/WebCore/bindings/v8/ScriptProfiler.h @@ -36,13 +36,13 @@ #include "ScriptProfile.h" #include "ScriptState.h" -#include <wtf/Noncopyable.h> namespace WebCore { class InspectorObject; -class ScriptProfiler : public Noncopyable { +class ScriptProfiler { + WTF_MAKE_NONCOPYABLE(ScriptProfiler); public: static void start(ScriptState* state, const String& title); static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title); diff --git a/Source/WebCore/bindings/v8/ScriptState.h b/Source/WebCore/bindings/v8/ScriptState.h index 11813b0..0fecee8 100644 --- a/Source/WebCore/bindings/v8/ScriptState.h +++ b/Source/WebCore/bindings/v8/ScriptState.h @@ -42,7 +42,8 @@ class Frame; class Node; class Page; -class ScriptState : public Noncopyable { +class ScriptState { + WTF_MAKE_NONCOPYABLE(ScriptState); public: bool hadException() { return !m_exception.IsEmpty(); } void setException(v8::Local<v8::Value> exception) @@ -79,7 +80,8 @@ public: ~EmptyScriptState() { } }; -class ScriptStateProtectedPtr : public Noncopyable { +class ScriptStateProtectedPtr { + WTF_MAKE_NONCOPYABLE(ScriptStateProtectedPtr); public: ScriptStateProtectedPtr() : m_scriptState(0) { } ScriptStateProtectedPtr(ScriptState* scriptState) : m_scriptState(scriptState) diff --git a/Source/WebCore/bindings/v8/SerializedScriptValue.cpp b/Source/WebCore/bindings/v8/SerializedScriptValue.cpp index 6ac4a65..666e619 100644 --- a/Source/WebCore/bindings/v8/SerializedScriptValue.cpp +++ b/Source/WebCore/bindings/v8/SerializedScriptValue.cpp @@ -128,7 +128,8 @@ private: // Writer is responsible for serializing primitive types and storing // information used to reconstruct composite types. -class Writer : Noncopyable { +class Writer { + WTF_MAKE_NONCOPYABLE(Writer); public: Writer() : m_position(0) @@ -377,7 +378,8 @@ public: } private: - class StateBase : public Noncopyable { + class StateBase { + WTF_MAKE_NONCOPYABLE(StateBase); public: virtual ~StateBase() { } @@ -1129,12 +1131,18 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() return adoptRef(new SerializedScriptValue()); } -SerializedScriptValue* SerializedScriptValue::nullValue() +SerializedScriptValue* SerializedScriptValue::nullValue() { DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, nullValue, (SerializedScriptValue::create())); return nullValue.get(); } +SerializedScriptValue* SerializedScriptValue::undefinedValue() +{ + DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, undefinedValue, (SerializedScriptValue::create(v8::Undefined()))); + return undefinedValue.get(); +} + PassRefPtr<SerializedScriptValue> SerializedScriptValue::release() { RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_data, WireData)); diff --git a/Source/WebCore/bindings/v8/SerializedScriptValue.h b/Source/WebCore/bindings/v8/SerializedScriptValue.h index b534a57..ead9511 100644 --- a/Source/WebCore/bindings/v8/SerializedScriptValue.h +++ b/Source/WebCore/bindings/v8/SerializedScriptValue.h @@ -52,8 +52,9 @@ public: static PassRefPtr<SerializedScriptValue> createFromWire(String data); static PassRefPtr<SerializedScriptValue> create(String data); static PassRefPtr<SerializedScriptValue> create(); - - static SerializedScriptValue* nullValue(); + + static SerializedScriptValue* nullValue(); + static SerializedScriptValue* undefinedValue(); PassRefPtr<SerializedScriptValue> release(); diff --git a/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp b/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp deleted file mode 100644 index e6871fd..0000000 --- a/Source/WebCore/bindings/v8/V8ConsoleMessage.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (C) 2009 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 "V8ConsoleMessage.h" - -#include "Console.h" -#include "DOMWindow.h" -#include "Frame.h" -#include "OwnPtr.h" -#include "Page.h" -#include "ScriptCallStack.h" -#include "ScriptCallStackFactory.h" -#include "V8Binding.h" -#include "V8Proxy.h" - -namespace WebCore { - -Vector<V8ConsoleMessage>* V8ConsoleMessage::m_delayedMessages = 0; - -V8ConsoleMessage::V8ConsoleMessage(const String& string, const String& sourceID, unsigned lineNumber) - : m_string(string) - , m_sourceID(sourceID) - , m_lineNumber(lineNumber) -{ -} - -void V8ConsoleMessage::dispatchNow(Page* page) -{ - dispatchNow(page, 0); -} - -void V8ConsoleMessage::dispatchLater() -{ - if (!m_delayedMessages) { - // Allocate a vector for the delayed messages. Will be - // deallocated when the delayed messages are processed - // in processDelayed(). - m_delayedMessages = new Vector<V8ConsoleMessage>(); - } - - m_delayedMessages->append(*this); -} - -void V8ConsoleMessage::processDelayed() -{ - if (!m_delayedMessages) - return; - - // Take ownership of the delayed vector to avoid re-entrancy issues. - OwnPtr<Vector<V8ConsoleMessage> > delayedMessages(m_delayedMessages); - m_delayedMessages = 0; - - // If we have a delayed vector it cannot be empty. - ASSERT(!delayedMessages->isEmpty()); - - // Add the delayed messages to the page of the active - // context. If that for some bizarre reason does not - // exist, we clear the list of delayed messages to avoid - // posting messages. We still deallocate the vector. - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - if (!frame) - return; - Page* page = frame->page(); - if (!page) - return; - - // Iterate through all the delayed messages and add them - // to the console. - const int size = delayedMessages->size(); - for (int i = 0; i < size; ++i) - delayedMessages->at(i).dispatchNow(page); -} - -void V8ConsoleMessage::handler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) -{ - // Use the frame where JavaScript is called from. - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - if (!frame) - return; - Page* page = frame->page(); - if (!page) - return; - - v8::Handle<v8::String> errorMessageString = message->Get(); - ASSERT(!errorMessageString.IsEmpty()); - String errorMessage = toWebCoreString(errorMessageString); - - v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); - RefPtr<ScriptCallStack> callStack; - // Currently stack trace is only collected when inspector is open. - if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) - callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture); - - v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); - bool useURL = resourceName.IsEmpty() || !resourceName->IsString(); - String resourceNameString = useURL ? frame->document()->url() : toWebCoreString(resourceName); - V8ConsoleMessage consoleMessage(errorMessage, resourceNameString, message->GetLineNumber()); - consoleMessage.dispatchNow(page, callStack); -} - -void V8ConsoleMessage::dispatchNow(Page* page, PassRefPtr<ScriptCallStack> callStack) -{ - ASSERT(page); - - // Process any delayed messages to make sure that messages - // appear in the right order in the console. - processDelayed(); - - Console* console = page->mainFrame()->domWindow()->console(); - MessageType messageType = callStack ? UncaughtExceptionMessageType : LogMessageType; - console->addMessage(JSMessageSource, messageType, ErrorMessageLevel, m_string, m_lineNumber, m_sourceID, callStack); -} - -} // namespace WebCore diff --git a/Source/WebCore/bindings/v8/V8ConsoleMessage.h b/Source/WebCore/bindings/v8/V8ConsoleMessage.h deleted file mode 100644 index 97de24f..0000000 --- a/Source/WebCore/bindings/v8/V8ConsoleMessage.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2009 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. - */ - -#ifndef V8ConsoleMessage_h -#define V8ConsoleMessage_h - -#include "PlatformString.h" -#include <v8.h> -#include <wtf/PassOwnPtr.h> -#include <wtf/Vector.h> - -namespace WebCore { - - class Page; - class ScriptCallStack; - - // V8ConsoleMessage encapsulates everything needed to - // log messages originating from JavaScript to the console. - class V8ConsoleMessage { - public: - V8ConsoleMessage(const String& string, const String& sourceID, unsigned lineNumber); - - // Add a message to the console. May end up calling JavaScript code - // indirectly through the inspector so only call this function when - // it is safe to do allocations. - void dispatchNow(Page*); - - // Add a message to the console but delay the reporting until it - // is safe to do so: Either when we leave JavaScript execution or - // when adding other console messages. The primary purpose of this - // method is to avoid calling into V8 to handle console messages - // when the VM is in a state that does not support GCs or allocations. - // Delayed messages are always reported in the page corresponding - // to the active context. - void dispatchLater(); - - // Process any delayed messages. May end up calling JavaScript code - // indirectly through the inspector so only call this function when - // it is safe to do allocations. - static void processDelayed(); - - // Convenience class for ensuring that delayed messages in the - // ConsoleMessageManager are processed quickly. - class Scope { - public: - Scope() { V8ConsoleMessage::processDelayed(); } - ~Scope() { V8ConsoleMessage::processDelayed(); } - }; - - // Callback from V8. - static void handler(v8::Handle<v8::Message>, v8::Handle<v8::Value> data); - - private: - const String m_string; - const String m_sourceID; - const unsigned m_lineNumber; - - void dispatchNow(Page*, PassRefPtr<ScriptCallStack>); - - // All delayed messages are stored in this vector. If the vector - // is 0, there are no delayed messages. - static Vector<V8ConsoleMessage>* m_delayedMessages; - }; - -} // namespace WebCore - -#endif // V8ConsoleMessage_h diff --git a/Source/WebCore/bindings/v8/V8DOMMap.h b/Source/WebCore/bindings/v8/V8DOMMap.h index c2b5a9d..51d933a 100644 --- a/Source/WebCore/bindings/v8/V8DOMMap.h +++ b/Source/WebCore/bindings/v8/V8DOMMap.h @@ -60,7 +60,7 @@ namespace WebCore { virtual void set(KeyType* obj, v8::Persistent<ValueType> wrapper) = 0; virtual bool contains(KeyType* obj) = 0; virtual void visit(DOMDataStore* store, Visitor* visitor) = 0; - virtual bool removeIfPresent(KeyType* key, v8::Persistent<v8::Data> value) = 0; + virtual bool removeIfPresent(KeyType*, v8::Persistent<ValueType>) = 0; virtual void clear() = 0; v8::WeakReferenceCallback weakReferenceCallback() { return m_weakReferenceCallback; } @@ -105,7 +105,7 @@ namespace WebCore { handle.Clear(); } - bool removeIfPresent(KeyType* key, v8::Persistent<v8::Data> value) + bool removeIfPresent(KeyType* key, v8::Persistent<ValueType> value) { typename HashMap<KeyType*, ValueType*>::iterator it = m_map.find(key); if (it == m_map.end() || it->second != *value) diff --git a/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp b/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp index 9918577..f53e1b7 100644 --- a/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -39,12 +39,13 @@ #include "FrameLoaderClient.h" #include "Page.h" #include "PageGroup.h" +#include "ScriptCallStack.h" +#include "ScriptCallStackFactory.h" #include "ScriptController.h" #include "StorageNamespace.h" #include "V8Binding.h" #include "V8BindingState.h" #include "V8Collection.h" -#include "V8ConsoleMessage.h" #include "V8DOMMap.h" #include "V8DOMWindow.h" #include "V8Document.h" @@ -88,12 +89,36 @@ static void reportFatalErrorInV8(const char* location, const char* message) // FIXME: clean up V8Proxy and disable JavaScript. int memoryUsageMB = -1; #if PLATFORM(CHROMIUM) - memoryUsageMB = ChromiumBridge::actualMemoryUsageMB(); + memoryUsageMB = PlatformBridge::actualMemoryUsageMB(); #endif printf("V8 error: %s (%s). Current memory usage: %d MB\n", message, location, memoryUsageMB); handleFatalErrorInV8(); } +static void v8UncaughtExceptionHandler(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) +{ + // Use the frame where JavaScript is called from. + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); + if (!frame) + return; + + v8::Handle<v8::String> errorMessageString = message->Get(); + ASSERT(!errorMessageString.IsEmpty()); + String errorMessage = toWebCoreString(errorMessageString); + + v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); + RefPtr<ScriptCallStack> callStack; + // Currently stack trace is only collected when inspector is open. + if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) + callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture); + + v8::Handle<v8::Value> resourceName = message->GetScriptResourceName(); + bool useURL = resourceName.IsEmpty() || !resourceName->IsString(); + Document* document = frame->document(); + String resourceNameString = useURL ? document->url() : toWebCoreString(resourceName); + document->reportException(errorMessage, message->GetLineNumber(), resourceNameString, callStack); +} + // Returns the owner frame pointer of a DOM wrapper object. It only works for // these DOM objects requiring cross-domain access check. static Frame* getTargetFrame(v8::Local<v8::Object> host, v8::Local<v8::Value> data) @@ -121,7 +146,7 @@ static void reportUnsafeJavaScriptAccess(v8::Local<v8::Object> host, v8::AccessT { Frame* target = getTargetFrame(host, data); if (target) - V8Proxy::reportUnsafeAccessTo(target, V8Proxy::ReportLater); + V8Proxy::reportUnsafeAccessTo(target); } PassRefPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame) @@ -270,7 +295,7 @@ bool V8DOMWindowShell::initContextIfNeeded() v8::V8::SetGlobalGCPrologueCallback(&V8GCController::gcPrologue); v8::V8::SetGlobalGCEpilogueCallback(&V8GCController::gcEpilogue); - v8::V8::AddMessageListener(&V8ConsoleMessage::handler); + v8::V8::AddMessageListener(&v8UncaughtExceptionHandler); v8::V8::SetFailedAccessCheckCallbackFunction(reportUnsafeJavaScriptAccess); diff --git a/Source/WebCore/bindings/v8/V8EventListener.h b/Source/WebCore/bindings/v8/V8EventListener.h index fb6c0bc..bcf7213 100644 --- a/Source/WebCore/bindings/v8/V8EventListener.h +++ b/Source/WebCore/bindings/v8/V8EventListener.h @@ -54,8 +54,7 @@ namespace WebCore { v8::Local<v8::Function> getListenerFunction(ScriptExecutionContext*); - private: - virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); + virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); }; } // namespace WebCore diff --git a/Source/WebCore/bindings/v8/V8NPUtils.cpp b/Source/WebCore/bindings/v8/V8NPUtils.cpp index 250ee5b..dccdb15 100644 --- a/Source/WebCore/bindings/v8/V8NPUtils.cpp +++ b/Source/WebCore/bindings/v8/V8NPUtils.cpp @@ -63,9 +63,14 @@ void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NP VOID_TO_NPVARIANT(*result); else if (object->IsString()) { v8::String::Utf8Value utf8(object); +<<<<<<< HEAD int length = utf8.length() + 1; char* utf8Chars = reinterpret_cast<char*>(malloc(length)); memcpy(utf8Chars, *utf8, length); +======= + char* utf8Chars = reinterpret_cast<char*>(malloc(utf8.length())); + memcpy(utf8Chars, *utf8, utf8.length()); +>>>>>>> WebKit.org at r76408 STRINGN_TO_NPVARIANT(utf8Chars, utf8.length(), *result); } else if (object->IsObject()) { DOMWindow* window = V8Proxy::retrieveWindow(V8Proxy::currentContext()); diff --git a/Source/WebCore/bindings/v8/V8Proxy.cpp b/Source/WebCore/bindings/v8/V8Proxy.cpp index 5eaba00..831a6ef 100644 --- a/Source/WebCore/bindings/v8/V8Proxy.cpp +++ b/Source/WebCore/bindings/v8/V8Proxy.cpp @@ -50,7 +50,6 @@ #include "V8Binding.h" #include "V8BindingState.h" #include "V8Collection.h" -#include "V8ConsoleMessage.h" #include "V8DOMCoreException.h" #include "V8DOMMap.h" #include "V8DOMWindow.h" @@ -139,21 +138,22 @@ typedef HashMap<int, v8::FunctionTemplate*> FunctionTemplateMap; bool AllowAllocation::m_current = false; +static void addMessageToConsole(Page* page, const String& message, const String& sourceID, unsigned lineNumber) +{ + ASSERT(page); + Console* console = page->mainFrame()->domWindow()->console(); + console->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, lineNumber, sourceID); +} + void logInfo(Frame* frame, const String& message, const String& url) { Page* page = frame->page(); if (!page) return; - V8ConsoleMessage consoleMessage(message, url, 0); - consoleMessage.dispatchNow(page); + addMessageToConsole(page, message, url, 0); } -enum DelayReporting { - ReportLater, - ReportNow -}; - -void V8Proxy::reportUnsafeAccessTo(Frame* target, DelayReporting delay) +void V8Proxy::reportUnsafeAccessTo(Frame* target) { ASSERT(target); Document* targetDocument = target->document(); @@ -174,20 +174,11 @@ void V8Proxy::reportUnsafeAccessTo(Frame* target, DelayReporting delay) // Build a console message with fake source ID and line number. const String kSourceID = ""; const int kLineNumber = 1; - V8ConsoleMessage message(str, kSourceID, kLineNumber); - if (delay == ReportNow) { - // NOTE: Safari prints the message in the target page, but it seems like - // it should be in the source page. Even for delayed messages, we put it in - // the source page; see V8ConsoleMessage::processDelayed(). - message.dispatchNow(source->page()); - } else { - ASSERT(delay == ReportLater); - // We cannot safely report the message eagerly, because this may cause - // allocations and GCs internally in V8 and we cannot handle that at this - // point. Therefore we delay the reporting. - message.dispatchLater(); - } + // NOTE: Safari prints the message in the target page, but it seems like + // it should be in the source page. Even for delayed messages, we put it in + // the source page. + addMessageToConsole(source->page(), str, kSourceID, kLineNumber); } static void handleFatalErrorInV8() @@ -440,8 +431,6 @@ v8::Local<v8::Value> V8Proxy::runScriptInternal(v8::Handle<v8::Script> script, b // Run the script and keep track of the current recursion depth. v8::Local<v8::Value> result; { - V8ConsoleMessage::Scope scope; - // See comment in V8Proxy::callFunction. m_frame->keepAlive(); @@ -477,8 +466,6 @@ v8::Local<v8::Value> V8Proxy::callFunction(v8::Handle<v8::Function> function, v8 V8GCController::checkMemoryUsage(); v8::Local<v8::Value> result; { - V8ConsoleMessage::Scope scope; - if (m_recursion >= kMaxRecursionDepth) { v8::Local<v8::String> code = v8::String::New("throw new RangeError('Maximum call stack size exceeded.')"); if (code.IsEmpty()) @@ -545,8 +532,6 @@ v8::Local<v8::Value> V8Proxy::newInstance(v8::Handle<v8::Function> constructor, // V8Proxy::callFunction. v8::Local<v8::Value> result; { - V8ConsoleMessage::Scope scope; - // See comment in V8Proxy::callFunction. m_frame->keepAlive(); @@ -808,11 +793,6 @@ v8::Handle<v8::Value> V8Proxy::checkNewLegal(const v8::Arguments& args) return args.This(); } -void V8Proxy::processConsoleMessages() -{ - V8ConsoleMessage::processDelayed(); -} - void V8Proxy::registerExtensionWithV8(v8::Extension* extension) { // If the extension exists in our list, it was already registered with V8. diff --git a/Source/WebCore/bindings/v8/V8Proxy.h b/Source/WebCore/bindings/v8/V8Proxy.h index 34e80e1..746d8f8 100644 --- a/Source/WebCore/bindings/v8/V8Proxy.h +++ b/Source/WebCore/bindings/v8/V8Proxy.h @@ -132,12 +132,6 @@ namespace WebCore { GeneralError }; - // When to report errors. - enum DelayReporting { - ReportLater, - ReportNow - }; - explicit V8Proxy(Frame*); ~V8Proxy(); @@ -271,9 +265,6 @@ namespace WebCore { template <typename T> static v8::Handle<v8::Value> constructDOMObjectWithScriptExecutionContext(const v8::Arguments&, WrapperTypeInfo*); - // Process any pending JavaScript console messages. - static void processConsoleMessages(); - v8::Local<v8::Context> context(); v8::Local<v8::Context> mainWorldContext(); @@ -294,7 +285,7 @@ namespace WebCore { static const V8Extensions& extensions() { return m_extensions; } // Report an unsafe attempt to access the given frame on the console. - static void reportUnsafeAccessTo(Frame* target, DelayReporting delay); + static void reportUnsafeAccessTo(Frame* target); private: void didLeaveScriptContext(); diff --git a/Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp b/Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp new file mode 100644 index 0000000..4203ad5 --- /dev/null +++ b/Source/WebCore/bindings/v8/V8WindowErrorHandler.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 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 "V8WindowErrorHandler.h" + +#include "ErrorEvent.h" +#include "V8Binding.h" + +namespace WebCore { + +V8WindowErrorHandler::V8WindowErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext) + : V8EventListener(listener, isInline, worldContext) +{ +} + +v8::Local<v8::Value> V8WindowErrorHandler::callListenerFunction(ScriptExecutionContext* context, v8::Handle<v8::Value> jsEvent, Event* event) +{ + if (!event->isErrorEvent()) + return V8EventListener::callListenerFunction(context, jsEvent, event); + + ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event); + v8::Local<v8::Object> listener = getListenerObject(context); + v8::Local<v8::Value> returnValue; + if (!listener.IsEmpty() && listener->IsFunction()) { + v8::Local<v8::Function> callFunction = v8::Local<v8::Function>::Cast(listener); + v8::Local<v8::Object> thisValue = v8::Context::GetCurrent()->Global(); + v8::Handle<v8::Value> parameters[3] = { v8String(errorEvent->message()), v8String(errorEvent->filename()), v8::Integer::New(errorEvent->lineno()) }; + returnValue = callFunction->Call(thisValue, 3, parameters); + if (!returnValue.IsEmpty() && returnValue->IsBoolean() && !returnValue->BooleanValue()) + event->preventDefault(); + } + return returnValue; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/v8/V8WindowErrorHandler.h b/Source/WebCore/bindings/v8/V8WindowErrorHandler.h new file mode 100644 index 0000000..493a9bf --- /dev/null +++ b/Source/WebCore/bindings/v8/V8WindowErrorHandler.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 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. + */ + +#ifndef V8WindowErrorHandler_h +#define V8WindowErrorHandler_h + +#include "V8EventListener.h" +#include <v8.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class V8WindowErrorHandler : public V8EventListener { +public: + static PassRefPtr<V8WindowErrorHandler> create(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext) + { + return adoptRef(new V8WindowErrorHandler(listener, isInline, worldContext)); + } + +private: + V8WindowErrorHandler(v8::Local<v8::Object> listener, bool isInline, const WorldContextHandle& worldContext); + + virtual v8::Local<v8::Value> callListenerFunction(ScriptExecutionContext*, v8::Handle<v8::Value> jsEvent, Event*); +}; + +} // namespace WebCore + +#endif // V8WindowErrorHandler_h diff --git a/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp b/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp index cefb2fa..aef892a 100644 --- a/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp +++ b/Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp @@ -37,10 +37,10 @@ #include "DedicatedWorkerContext.h" #include "Event.h" +#include "ScriptCallStack.h" #include "SharedWorker.h" #include "SharedWorkerContext.h" #include "V8Binding.h" -#include "V8ConsoleMessage.h" #include "V8DOMMap.h" #include "V8DedicatedWorkerContext.h" #include "V8Proxy.h" @@ -72,7 +72,7 @@ static void v8MessageHandler(v8::Handle<v8::Message> message, v8::Handle<v8::Val String errorMessage = toWebCoreString(message->Get()); int lineNumber = message->GetLineNumber(); String sourceURL = toWebCoreString(message->GetScriptResourceName()); - context->reportException(errorMessage, lineNumber, sourceURL); + context->reportException(errorMessage, lineNumber, sourceURL, 0); } isReportingException = false; diff --git a/Source/WebCore/bindings/v8/WorkerScriptController.cpp b/Source/WebCore/bindings/v8/WorkerScriptController.cpp index b56d383..42e02e6 100644 --- a/Source/WebCore/bindings/v8/WorkerScriptController.cpp +++ b/Source/WebCore/bindings/v8/WorkerScriptController.cpp @@ -34,11 +34,10 @@ #include "WorkerScriptController.h" -#include <v8.h> - +#include "DOMTimer.h" +#include "ScriptCallStack.h" #include "ScriptSourceCode.h" #include "ScriptValue.h" -#include "DOMTimer.h" #include "V8DOMMap.h" #include "V8Proxy.h" #include "V8WorkerContext.h" @@ -46,6 +45,7 @@ #include "WorkerContextExecutionProxy.h" #include "WorkerObjectProxy.h" #include "WorkerThread.h" +#include <v8.h> namespace WebCore { @@ -80,7 +80,7 @@ ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, if (exception) *exception = state.exception; else - m_workerContext->reportException(state.errorMessage, state.lineNumber, state.sourceURL); + m_workerContext->reportException(state.errorMessage, state.lineNumber, state.sourceURL, 0); } return result; diff --git a/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp b/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp index 9e89ce8..3d64edd 100644 --- a/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp +++ b/Source/WebCore/bindings/v8/custom/V8HTMLCollectionCustom.cpp @@ -59,7 +59,10 @@ static v8::Handle<v8::Value> getItem(HTMLCollection* collection, v8::Handle<v8:: { v8::Local<v8::Uint32> index = argument->ToArrayIndex(); if (index.IsEmpty()) { - v8::Handle<v8::Value> result = getNamedItems(collection, toWebCoreString(argument->ToString())); + v8::Local<v8::String> asString = argument->ToString(); + if (asString.IsEmpty()) + return v8::Handle<v8::Value>(); + v8::Handle<v8::Value> result = getNamedItems(collection, toWebCoreString(asString)); if (result.IsEmpty()) return v8::Undefined(); diff --git a/Source/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp b/Source/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp index 70df7c1..7fdfc55 100644 --- a/Source/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp +++ b/Source/WebCore/bindings/v8/custom/V8WebGLRenderingContextCustom.cpp @@ -48,6 +48,7 @@ #include "V8Int16Array.h" #include "V8Int32Array.h" #include "V8Int8Array.h" +#include "V8OESStandardDerivatives.h" #include "V8OESTextureFloat.h" #include "V8Proxy.h" #include "V8Uint16Array.h" @@ -160,6 +161,9 @@ static v8::Handle<v8::Value> toV8Object(WebGLExtension* extension, v8::Handle<v8 case WebGLExtension::WebKitLoseContextName: extensionObject = toV8(static_cast<WebKitLoseContext*>(extension)); break; + case WebGLExtension::OESStandardDerivativesName: + extensionObject = toV8(static_cast<OESStandardDerivatives*>(extension)); + break; case WebGLExtension::OESTextureFloatName: extensionObject = toV8(static_cast<OESTextureFloat*>(extension)); break; diff --git a/Source/WebCore/bindings/v8/specialization/V8BindingState.cpp b/Source/WebCore/bindings/v8/specialization/V8BindingState.cpp index 891272c..e00e35b 100644 --- a/Source/WebCore/bindings/v8/specialization/V8BindingState.cpp +++ b/Source/WebCore/bindings/v8/specialization/V8BindingState.cpp @@ -81,7 +81,7 @@ Frame* State<V8Binding>::firstFrame() void State<V8Binding>::immediatelyReportUnsafeAccessTo(Frame* target) { - V8Proxy::reportUnsafeAccessTo(target, V8Proxy::ReportNow); + V8Proxy::reportUnsafeAccessTo(target); } bool State<V8Binding>::processingUserGesture() |