diff options
author | Ben Murdoch <benm@google.com> | 2010-08-11 14:44:44 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-08-12 19:15:41 +0100 |
commit | dd8bb3de4f353a81954234999f1fea748aee2ea9 (patch) | |
tree | 729b52bf09294f0d6c67cd5ea80aee1b727b7bd8 /WebCore/bindings | |
parent | f3d41ba51d86bf719c7a65ab5297aea3c17e2d98 (diff) | |
download | external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.zip external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.gz external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.bz2 |
Merge WebKit at r65072 : Initial merge by git.
Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585
Diffstat (limited to 'WebCore/bindings')
110 files changed, 1502 insertions, 1918 deletions
diff --git a/WebCore/bindings/cpp/WebDOMCString.h b/WebCore/bindings/cpp/WebDOMCString.h index e02a587..c921895 100644 --- a/WebCore/bindings/cpp/WebDOMCString.h +++ b/WebCore/bindings/cpp/WebDOMCString.h @@ -22,12 +22,9 @@ #define WebDOMCString_h #include <WebDOMObject.h> +#include <wtf/Forward.h> #include <stddef.h> // For size_t -namespace WTF { -class CString; -}; - // UTF-16 character type #if defined(WIN32) typedef wchar_t WebUChar; diff --git a/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp b/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp index aa511ad..3bab0c1 100644 --- a/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp +++ b/WebCore/bindings/cpp/WebDOMHTMLDocumentCustom.cpp @@ -27,7 +27,7 @@ static inline void documentWrite(const WebDOMString& text, WebCore::HTMLDocument* document, bool addNewline) { - WebCore::SegmentedString segmentedString = WebCore::String(text); + WebCore::SegmentedString segmentedString = WTF::String(text); if (addNewline) segmentedString.append(WebCore::SegmentedString(&WebCore::newlineCharacter, 1)); document->write(segmentedString); diff --git a/WebCore/bindings/cpp/WebDOMString.cpp b/WebCore/bindings/cpp/WebDOMString.cpp index d87dedd..59d98f7 100644 --- a/WebCore/bindings/cpp/WebDOMString.cpp +++ b/WebCore/bindings/cpp/WebDOMString.cpp @@ -26,7 +26,7 @@ #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> -class WebDOMStringPrivate : public WebCore::StringImpl { +class WebDOMStringPrivate : public WTF::StringImpl { }; void WebDOMString::reset() @@ -45,7 +45,7 @@ void WebDOMString::assign(const WebDOMString& other) void WebDOMString::assign(const WebUChar* data, size_t length) { assign(static_cast<WebDOMStringPrivate*>( - WebCore::StringImpl::create(data, length).get())); + WTF::StringImpl::create(data, length).get())); } size_t WebDOMString::length() const @@ -60,52 +60,52 @@ const WebUChar* WebDOMString::data() const WebDOMCString WebDOMString::utf8() const { - return WebCore::String(m_private).utf8(); + return WTF::String(m_private).utf8(); } WebDOMString WebDOMString::fromUTF8(const char* data, size_t length) { - return WebCore::String::fromUTF8(data, length); + return WTF::String::fromUTF8(data, length); } WebDOMString WebDOMString::fromUTF8(const char* data) { - return WebCore::String::fromUTF8(data); + return WTF::String::fromUTF8(data); } -WebDOMString::WebDOMString(const WebCore::String& s) +WebDOMString::WebDOMString(const WTF::String& s) : m_private(static_cast<WebDOMStringPrivate*>(s.impl())) { if (m_private) m_private->ref(); } -WebDOMString& WebDOMString::operator=(const WebCore::String& s) +WebDOMString& WebDOMString::operator=(const WTF::String& s) { assign(static_cast<WebDOMStringPrivate*>(s.impl())); return *this; } -WebDOMString::operator WebCore::String() const +WebDOMString::operator WTF::String() const { return m_private; } -WebDOMString::WebDOMString(const WebCore::AtomicString& s) +WebDOMString::WebDOMString(const WTF::AtomicString& s) : m_private(0) { assign(s.string()); } -WebDOMString& WebDOMString::operator=(const WebCore::AtomicString& s) +WebDOMString& WebDOMString::operator=(const WTF::AtomicString& s) { assign(s.string()); return *this; } -WebDOMString::operator WebCore::AtomicString() const +WebDOMString::operator WTF::AtomicString() const { - return WebCore::AtomicString(static_cast<WebCore::StringImpl *>(m_private)); + return WTF::AtomicString(static_cast<WTF::StringImpl *>(m_private)); } bool WebDOMString::equals(const char* string) const diff --git a/WebCore/bindings/cpp/WebDOMString.h b/WebCore/bindings/cpp/WebDOMString.h index ca09ee8..0eea1ae 100644 --- a/WebCore/bindings/cpp/WebDOMString.h +++ b/WebCore/bindings/cpp/WebDOMString.h @@ -22,11 +22,7 @@ #define WebDOMString_h #include <WebDOMCString.h> - -namespace WebCore { -class String; -class AtomicString; -} +#include <wtf/Forward.h> class WebDOMStringPrivate; @@ -81,13 +77,13 @@ public: return *this; } - WebDOMString(const WebCore::String&); - WebDOMString& operator=(const WebCore::String&); - operator WebCore::String() const; + WebDOMString(const WTF::String&); + WebDOMString& operator=(const WTF::String&); + operator WTF::String() const; - WebDOMString(const WebCore::AtomicString&); - WebDOMString& operator=(const WebCore::AtomicString&); - operator WebCore::AtomicString() const; + WebDOMString(const WTF::AtomicString&); + WebDOMString& operator=(const WTF::AtomicString&); + operator WTF::AtomicString() const; bool equals(const char* string) const; diff --git a/WebCore/bindings/cpp/WebNativeEventListener.cpp b/WebCore/bindings/cpp/WebNativeEventListener.cpp index ddd7112..b781eb7 100644 --- a/WebCore/bindings/cpp/WebNativeEventListener.cpp +++ b/WebCore/bindings/cpp/WebNativeEventListener.cpp @@ -40,7 +40,7 @@ void WebNativeEventListener::handleEvent(WebCore::ScriptExecutionContext*, WebCo m_listener->handleEvent(toWebKit(event)); } -bool WebNativeEventListener::reportError(WebCore::ScriptExecutionContext*, const WebCore::String&, const WebCore::String&, int) +bool WebNativeEventListener::reportError(WebCore::ScriptExecutionContext*, const WTF::String&, const WTF::String&, int) { // FIXME: Implement error handling return false; diff --git a/WebCore/bindings/cpp/WebNativeEventListener.h b/WebCore/bindings/cpp/WebNativeEventListener.h index fff1b1c..13b4f5b 100644 --- a/WebCore/bindings/cpp/WebNativeEventListener.h +++ b/WebCore/bindings/cpp/WebNativeEventListener.h @@ -44,7 +44,7 @@ public: private: virtual void handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*); - virtual bool reportError(WebCore::ScriptExecutionContext*, const WebCore::String& message, const WebCore::String& url, int lineNumber); + virtual bool reportError(WebCore::ScriptExecutionContext*, const WTF::String& message, const WTF::String& url, int lineNumber); protected: WebNativeEventListener(WebUserEventListener*); diff --git a/WebCore/bindings/generic/ActiveDOMCallback.cpp b/WebCore/bindings/generic/ActiveDOMCallback.cpp new file mode 100644 index 0000000..2e69d10 --- /dev/null +++ b/WebCore/bindings/generic/ActiveDOMCallback.cpp @@ -0,0 +1,144 @@ +/* + * 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 "ActiveDOMCallback.h" + +#include "ActiveDOMObject.h" +#include "ScriptExecutionContext.h" +#include <wtf/PassOwnPtr.h> +#include <wtf/ThreadingPrimitives.h> + +namespace WebCore { + +static void destroyOnContextThread(PassOwnPtr<ActiveDOMObjectCallbackImpl>); + +class DestroyOnContextThreadTask : public ScriptExecutionContext::Task { +public: + static PassOwnPtr<DestroyOnContextThreadTask> create(PassOwnPtr<ActiveDOMObjectCallbackImpl> impl) + { + return adoptPtr(new DestroyOnContextThreadTask(impl)); + } + + virtual void performTask(ScriptExecutionContext*) + { + destroyOnContextThread(m_impl.release()); + } + +private: + DestroyOnContextThreadTask(PassOwnPtr<ActiveDOMObjectCallbackImpl> impl) + : m_impl(impl) + { + } + + OwnPtr<ActiveDOMObjectCallbackImpl> m_impl; +}; + +// Instances of this class are accessed only on the context thread, so we don't need to use locks. +class ActiveDOMObjectCallbackImpl : public ActiveDOMObject { +public: + ActiveDOMObjectCallbackImpl(ScriptExecutionContext* context) + : ActiveDOMObject(context, this) + , m_suspended(false) + , m_stopped(false) + { + } + + virtual void contextDestroyed() + { + MutexLocker locker(m_mutex); + ActiveDOMObject::contextDestroyed(); + } + virtual bool canSuspend() const { return false; } + virtual void suspend() + { + MutexLocker locker(m_mutex); + m_suspended = true; + } + virtual void resume() + { + MutexLocker locker(m_mutex); + m_suspended = false; + } + virtual void stop() + { + MutexLocker locker(m_mutex); + m_stopped = true; + } + bool canInvokeCallback() + { + MutexLocker locker(m_mutex); + return (!m_suspended && !m_stopped); + } + ScriptExecutionContext* scriptExecutionContext() + { + MutexLocker locker(m_mutex); + return ActiveDOMObject::scriptExecutionContext(); + } + Mutex& mutex() { return m_mutex; } + +private: + Mutex m_mutex; + bool m_suspended; + bool m_stopped; +}; + +static void destroyOnContextThread(PassOwnPtr<ActiveDOMObjectCallbackImpl> impl) +{ + OwnPtr<ActiveDOMObjectCallbackImpl> implOwnPtr = impl; + + ScriptExecutionContext* context = implOwnPtr->scriptExecutionContext(); + MutexLocker locker(implOwnPtr->mutex()); + if (context && !context->isContextThread()) + context->postTask(DestroyOnContextThreadTask::create(implOwnPtr.release())); +} + +ActiveDOMCallback::ActiveDOMCallback(ScriptExecutionContext* context) + : m_impl(new ActiveDOMObjectCallbackImpl(context)) +{ + ASSERT(context->isContextThread()); +} + +ActiveDOMCallback::~ActiveDOMCallback() +{ + destroyOnContextThread(m_impl.release()); +} + +bool ActiveDOMCallback::canInvokeCallback() const +{ + return m_impl->canInvokeCallback(); +} + +ScriptExecutionContext* ActiveDOMCallback::scriptExecutionContext() const +{ + return m_impl->scriptExecutionContext(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptArray.h b/WebCore/bindings/generic/ActiveDOMCallback.h index 9aa8764..2fe99ab 100644 --- a/WebCore/bindings/v8/ScriptArray.h +++ b/WebCore/bindings/generic/ActiveDOMCallback.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Google Inc. All rights reserved. + * 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 @@ -28,34 +28,31 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ScriptArray_h -#define ScriptArray_h +#ifndef ActiveDOMCallback_h +#define ActiveDOMCallback_h -#include "ScriptObject.h" - -#include <v8.h> +#include <wtf/OwnPtr.h> namespace WebCore { -class ScriptState; -class SerializedScriptValue; -class ScriptArray : public ScriptObject { +class ActiveDOMObjectCallbackImpl; +class ScriptExecutionContext; + +// A class that allows callbacks to behave like ActiveDOMObjects, and also +// be destroyed on the context thread or any other thread. +class ActiveDOMCallback { public: - ScriptArray(ScriptState* scriptState, v8::Handle<v8::Array>); - ScriptArray() {}; - virtual ~ScriptArray() {} - - bool set(unsigned index, const ScriptObject&); - bool set(unsigned index, SerializedScriptValue*); - bool set(unsigned index, const String&); - bool set(unsigned index, double); - bool set(unsigned index, long long); - bool set(unsigned index, int); - bool set(unsigned index, bool); - unsigned length(); - - static ScriptArray createNew(ScriptState*); + ActiveDOMCallback(ScriptExecutionContext* context); + ~ActiveDOMCallback(); + + bool canInvokeCallback() const; + ScriptExecutionContext* scriptExecutionContext() const; + +private: + // The ActiveDOMObject part of the callback. + OwnPtr<ActiveDOMObjectCallbackImpl> m_impl; }; -} -#endif // ScriptArray_h +} // namespace WebCore + +#endif // ActiveDOMCallback_h diff --git a/WebCore/bindings/generic/BindingDOMWindow.h b/WebCore/bindings/generic/BindingDOMWindow.h index f883d11..dda5644 100644 --- a/WebCore/bindings/generic/BindingDOMWindow.h +++ b/WebCore/bindings/generic/BindingDOMWindow.h @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -31,11 +31,17 @@ #ifndef BindingDOMWindow_h #define BindingDOMWindow_h +#include "DOMWindow.h" #include "Frame.h" #include "FrameLoadRequest.h" +#include "FrameLoader.h" +#include "FrameView.h" #include "GenericBinding.h" #include "Page.h" +#include "PlatformScreen.h" +#include "ScriptController.h" #include "SecurityOrigin.h" +#include "WindowFeatures.h" namespace WebCore { @@ -52,6 +58,20 @@ public: const String& frameName, const WindowFeatures& windowFeatures, BindingValue dialogArgs); + + static WebCore::DOMWindow* open(State<Binding>*, + WebCore::DOMWindow* parent, + const String& url, + const String& frameName, + const WindowFeatures& rawFeatures); + + // FIXME: There should be a place for generic binding utilities. + static KURL completeURL(State<Binding>*, const String& relativeURL); + +private: + // Horizontal and vertical offset, from the parent content area, + // around newly opened popups that don't specify a location. + static const int popupTilePixels = 10; }; // Implementations of templated methods must be in this file. @@ -103,8 +123,8 @@ Frame* BindingDOMWindow<Binding>::createWindow(State<Binding>* state, if (!protocolIsJavaScript(url) || BindingSecurity<Binding>::canAccessFrame(state, newFrame, true)) { KURL completedUrl = - url.isEmpty() ? KURL(ParsedURLString, "") : completeURL(url); - bool userGesture = processingUserGesture(); + url.isEmpty() ? KURL(ParsedURLString, "") : completeURL(state, url); + bool userGesture = state->processingUserGesture(); if (created) newFrame->loader()->changeLocation(completedUrl, referrer, false, false, userGesture); @@ -115,6 +135,153 @@ Frame* BindingDOMWindow<Binding>::createWindow(State<Binding>* state, return newFrame; } +template<class Binding> +WebCore::DOMWindow* BindingDOMWindow<Binding>::open(State<Binding>* state, + WebCore::DOMWindow* parent, + const String& urlString, + const String& frameName, + const WindowFeatures& rawFeatures) +{ + Frame* frame = parent->frame(); + + if (!BindingSecurity<Binding>::canAccessFrame(state, frame, true)) + return 0; + + Frame* firstFrame = state->getFirstFrame(); + if (!firstFrame) + return 0; + + Frame* activeFrame = state->getActiveFrame(); + // We may not have a calling context if we are invoked by a plugin + // via NPAPI. + if (!activeFrame) + activeFrame = firstFrame; + + Page* page = frame->page(); + if (!page) + return 0; + + // Because FrameTree::find() returns true for empty strings, we must check + // for empty framenames. Otherwise, illegitimate window.open() calls with + // no name will pass right through the popup blocker. + if (!BindingSecurity<Binding>::allowPopUp(state) + && (frameName.isEmpty() || !frame->tree()->find(frameName))) { + return 0; + } + + // Get the target frame for the special cases of _top and _parent. + // In those cases, we can schedule a location change right now and + // return early. + bool topOrParent = false; + if (frameName == "_top") { + frame = frame->tree()->top(); + topOrParent = true; + } else if (frameName == "_parent") { + if (Frame* parent = frame->tree()->parent()) + frame = parent; + topOrParent = true; + } + if (topOrParent) { + if (!BindingSecurity<Binding>::shouldAllowNavigation(state, frame)) + return 0; + + String completedUrl; + if (!urlString.isEmpty()) + completedUrl = completeURL(state, urlString); + + if (!completedUrl.isEmpty() + && (!protocolIsJavaScript(completedUrl) + || BindingSecurity<Binding>::canAccessFrame(state, frame, true))) { + bool userGesture = state->processingUserGesture(); + + // For whatever reason, Firefox uses the first frame to determine + // the outgoingReferrer. We replicate that behavior here. + String referrer = firstFrame->loader()->outgoingReferrer(); + + frame->redirectScheduler()->scheduleLocationChange(completedUrl, referrer, false, false, userGesture); + } + return frame->domWindow(); + } + + // In the case of a named frame or a new window, we'll use the + // createWindow() helper. + + // Work with a copy of the parsed values so we can restore the + // values we may not want to overwrite after we do the multiple + // monitor fixes. + WindowFeatures windowFeatures(rawFeatures); + FloatRect screenRect = screenAvailableRect(page->mainFrame()->view()); + + // Set default size and location near parent window if none were specified. + // These may be further modified by adjustWindowRect, below. + if (!windowFeatures.xSet) { + windowFeatures.x = parent->screenX() - screenRect.x() + popupTilePixels; + windowFeatures.xSet = true; + } + if (!windowFeatures.ySet) { + windowFeatures.y = parent->screenY() - screenRect.y() + popupTilePixels; + windowFeatures.ySet = true; + } + if (!windowFeatures.widthSet) { + windowFeatures.width = parent->innerWidth(); + windowFeatures.widthSet = true; + } + if (!windowFeatures.heightSet) { + windowFeatures.height = parent->innerHeight(); + windowFeatures.heightSet = true; + } + + FloatRect windowRect(windowFeatures.x, windowFeatures.y, windowFeatures.width, windowFeatures.height); + + // The new window's location is relative to its current screen, so shift + // it in case it's on a secondary monitor. See http://b/viewIssue?id=967905. + windowRect.move(screenRect.x(), screenRect.y()); + WebCore::DOMWindow::adjustWindowRect(screenRect, windowRect, windowRect); + + windowFeatures.x = windowRect.x(); + windowFeatures.y = windowRect.y(); + windowFeatures.height = windowRect.height(); + windowFeatures.width = windowRect.width(); + + // If either of the origin coordinates or dimensions weren't set + // in the original string, make sure they aren't set now. + if (!rawFeatures.xSet) { + windowFeatures.x = 0; + windowFeatures.xSet = false; + } + if (!rawFeatures.ySet) { + windowFeatures.y = 0; + windowFeatures.ySet = false; + } + if (!rawFeatures.widthSet) { + windowFeatures.width = 0; + windowFeatures.widthSet = false; + } + if (!rawFeatures.heightSet) { + windowFeatures.height = 0; + windowFeatures.heightSet = false; + } + + frame = createWindow(state, activeFrame, firstFrame, frame, urlString, frameName, windowFeatures, Binding::emptyScriptValue()); + + if (!frame) + return 0; + + return frame->domWindow(); +} + +template <class Binding> +KURL BindingDOMWindow<Binding>::completeURL(State<Binding>* state, + const String& relativeURL) +{ + // For historical reasons, we need to complete the URL using the + // dynamic frame. + Frame* frame = state->getFirstFrame(); + if (!frame) + return KURL(); + return frame->loader()->completeURL(relativeURL); +} + } // namespace WebCore #endif // BindingDOMWindow_h diff --git a/WebCore/bindings/generic/BindingSecurity.h b/WebCore/bindings/generic/BindingSecurity.h index d7c9dfe..1124f7e 100644 --- a/WebCore/bindings/generic/BindingSecurity.h +++ b/WebCore/bindings/generic/BindingSecurity.h @@ -34,14 +34,15 @@ #include "BindingSecurityBase.h" #include "CSSHelper.h" #include "Element.h" +#include "Frame.h" #include "GenericBinding.h" #include "HTMLFrameElementBase.h" #include "HTMLNames.h" +#include "Settings.h" namespace WebCore { class DOMWindow; -class Frame; class Node; // Security functions shared by various language bindings. @@ -55,9 +56,12 @@ public: // current security context. static bool checkNodeSecurity(State<Binding>*, Node* target); + static bool allowPopUp(State<Binding>*); static bool allowSettingFrameSrcToJavascriptUrl(State<Binding>*, HTMLFrameElementBase*, String value); static bool allowSettingSrcToJavascriptURL(State<Binding>*, Element*, String name, String value); + static bool shouldAllowNavigation(State<Binding>*, Frame*); + private: explicit BindingSecurity() {} ~BindingSecurity(); @@ -110,6 +114,18 @@ bool BindingSecurity<Binding>::checkNodeSecurity(State<Binding>* state, Node* no } template <class Binding> +bool BindingSecurity<Binding>::allowPopUp(State<Binding>* state) +{ + if (state->processingUserGesture()) + return true; + + Frame* frame = state->getFirstFrame(); + ASSERT(frame); + Settings* settings = frame->settings(); + return settings && settings->javaScriptCanOpenWindowsAutomatically(); +} + +template <class Binding> bool BindingSecurity<Binding>::allowSettingFrameSrcToJavascriptUrl(State<Binding>* state, HTMLFrameElementBase* frame, String value) { if (protocolIsJavaScript(deprecatedParseURL(value))) { @@ -128,6 +144,13 @@ bool BindingSecurity<Binding>::allowSettingSrcToJavascriptURL(State<Binding>* st return true; } +template <class Binding> +bool BindingSecurity<Binding>::shouldAllowNavigation(State<Binding>* state, Frame* frame) +{ + Frame* activeFrame = state->getActiveFrame(); + return activeFrame && activeFrame->loader()->shouldAllowNavigation(frame); +} + } #endif // BindingSecurity_h diff --git a/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp b/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp index eb027c3..94e984f 100644 --- a/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp +++ b/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp @@ -47,6 +47,7 @@ bool RuntimeEnabledFeatures::isIndexedDBEnabled = false; bool RuntimeEnabledFeatures::isWebGLEnabled = false; bool RuntimeEnabledFeatures::isPushStateEnabled = false; bool RuntimeEnabledFeatures::isTouchEnabled = true; +bool RuntimeEnabledFeatures::isDeviceMotionEnabled = true; bool RuntimeEnabledFeatures::isDeviceOrientationEnabled = true; bool RuntimeEnabledFeatures::isSpeechInputEnabled = true; diff --git a/WebCore/bindings/generic/RuntimeEnabledFeatures.h b/WebCore/bindings/generic/RuntimeEnabledFeatures.h index c9eb21f..fd7308e 100644 --- a/WebCore/bindings/generic/RuntimeEnabledFeatures.h +++ b/WebCore/bindings/generic/RuntimeEnabledFeatures.h @@ -114,6 +114,11 @@ public: static bool ontouchcancelEnabled() { return isTouchEnabled; } #endif + static void setDeviceMotionEnabled(bool isEnabled) { isDeviceMotionEnabled = isEnabled; } + static bool deviceMotionEnabled() { return isDeviceMotionEnabled; } + static bool deviceMotionEventEnabled() { return isDeviceMotionEnabled; } + static bool ondevicemotionEnabled() { return isDeviceMotionEnabled; } + static void setDeviceOrientationEnabled(bool isEnabled) { isDeviceOrientationEnabled = isEnabled; } static bool deviceOrientationEnabled() { return isDeviceOrientationEnabled; } static bool deviceOrientationEventEnabled() { return isDeviceOrientationEnabled; } @@ -136,6 +141,7 @@ private: static bool isWebGLEnabled; static bool isPushStateEnabled; static bool isTouchEnabled; + static bool isDeviceMotionEnabled; static bool isDeviceOrientationEnabled; static bool isSpeechInputEnabled; }; diff --git a/WebCore/bindings/gobject/ConvertToUTF8String.cpp b/WebCore/bindings/gobject/ConvertToUTF8String.cpp index 57010fa..67375e4 100644 --- a/WebCore/bindings/gobject/ConvertToUTF8String.cpp +++ b/WebCore/bindings/gobject/ConvertToUTF8String.cpp @@ -27,7 +27,7 @@ #include <glib.h> -gchar* convertToUTF8String(WebCore::String const& s) +gchar* convertToUTF8String(WTF::String const& s) { return g_strdup(s.utf8().data()); } diff --git a/WebCore/bindings/gobject/ConvertToUTF8String.h b/WebCore/bindings/gobject/ConvertToUTF8String.h index 02b6416..bc234cf 100644 --- a/WebCore/bindings/gobject/ConvertToUTF8String.h +++ b/WebCore/bindings/gobject/ConvertToUTF8String.h @@ -21,14 +21,15 @@ #ifndef ConvertToUTF8String_h #define ConvertToUTF8String_h +#include <wtf/Forward.h> + namespace WebCore { -class String; class KURL; } typedef char gchar; -gchar* convertToUTF8String(WebCore::String const& s); +gchar* convertToUTF8String(WTF::String const& s); gchar* convertToUTF8String(WebCore::KURL const& s); #endif /* ConvertToUTF8String_h */ diff --git a/WebCore/bindings/gobject/WebKitDOMBinding.cpp b/WebCore/bindings/gobject/WebKitDOMBinding.cpp index aa4610b..1154d6c 100644 --- a/WebCore/bindings/gobject/WebKitDOMBinding.cpp +++ b/WebCore/bindings/gobject/WebKitDOMBinding.cpp @@ -24,14 +24,19 @@ #include "config.h" #include "WebKitDOMBinding.h" +#include "Element.h" #include "Event.h" #include "EventException.h" #include "HTMLNames.h" +#include "MouseEvent.h" +#include "UIEvent.h" #include "WebKitDOMDOMWindowPrivate.h" #include "WebKitDOMElementPrivate.h" #include "WebKitDOMNode.h" #include "WebKitDOMNodePrivate.h" #include "WebKitHTMLElementWrapperFactory.h" +#include "webkit/WebKitDOMMouseEventPrivate.h" +#include "webkit/WebKitDOMUIEventPrivate.h" namespace WebKit { @@ -78,7 +83,7 @@ static gpointer createWrapper(Node* node) if (node->isHTMLElement()) wrappedNode = createHTMLElementWrapper(static_cast<HTMLElement*>(node)); else - wrappedNode = wrapNode(node); + wrappedNode = wrapElement(static_cast<Element*>(node)); break; default: wrappedNode = wrapNode(node); @@ -119,6 +124,27 @@ gpointer kit(Element* element) return DOMObjectCache::put(element, wrappedElement); } +gpointer kit(Event* event) +{ + if (!event) + return 0; + + gpointer kitEvent = DOMObjectCache::get(event); + if (kitEvent) + return kitEvent; + + gpointer wrappedEvent; + + if (event->isMouseEvent()) + wrappedEvent = wrapMouseEvent(static_cast<MouseEvent*>(event)); + else if (event->isUIEvent()) + wrappedEvent = wrapUIEvent(static_cast<UIEvent*>(event)); + else + wrappedEvent = 0; + + return DOMObjectCache::put(event, wrappedEvent); +} + static gpointer wrapEventTarget(EventTarget* target) { ASSERT(target); diff --git a/WebCore/bindings/gobject/WebKitDOMBinding.h b/WebCore/bindings/gobject/WebKitDOMBinding.h index 236c450..2248f78 100644 --- a/WebCore/bindings/gobject/WebKitDOMBinding.h +++ b/WebCore/bindings/gobject/WebKitDOMBinding.h @@ -29,12 +29,14 @@ namespace WebCore { class Node; class Element; +class Event; class EventTarget; } // namespace WebCore namespace WebKit { gpointer kit(WebCore::Node* node); gpointer kit(WebCore::Element* element); +gpointer kit(WebCore::Event* event); gpointer kit(WebCore::EventTarget* target); class DOMObjectCache { diff --git a/WebCore/bindings/gobject/WebKitDOMEventTarget.cpp b/WebCore/bindings/gobject/WebKitDOMEventTarget.cpp index 2d2a31a..f2b1a94 100644 --- a/WebCore/bindings/gobject/WebKitDOMEventTarget.cpp +++ b/WebCore/bindings/gobject/WebKitDOMEventTarget.cpp @@ -31,6 +31,7 @@ #include "config.h" #include "WebKitDOMEventTarget.h" +#include "EventTarget.h" #include "WebKitDOMEvent.h" typedef WebKitDOMEventTargetIface WebKitDOMEventTargetInterface; @@ -75,3 +76,18 @@ void webkit_dom_event_target_dispatch_event(WebKitDOMEventTarget* target, WebKit if (iface->dispatch_event) iface->dispatch_event(target, event, error); } + +namespace WebKit { + +WebCore::EventTarget* core(WebKitDOMEventTarget* request) +{ + g_return_val_if_fail(request, 0); + + WebCore::EventTarget* coreObject = static_cast<WebCore::EventTarget*>(WEBKIT_DOM_OBJECT(request)->coreObject); + g_return_val_if_fail(coreObject, 0); + + return coreObject; +} + +} // namespace WebKit + diff --git a/WebCore/bindings/gobject/WebKitDOMEventTargetPrivate.h b/WebCore/bindings/gobject/WebKitDOMEventTargetPrivate.h new file mode 100644 index 0000000..4741409 --- /dev/null +++ b/WebCore/bindings/gobject/WebKitDOMEventTargetPrivate.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2010 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitDOMEventTargetPrivate_h +#define WebKitDOMEventTargetPrivate_h + +#include "EventTarget.h" +#include <glib-object.h> +#include <webkit/WebKitDOMEventTarget.h> + +namespace WebKit { +WebCore::EventTarget* +core(WebKitDOMEventTarget *request); +} // namespace WebKit + +#endif /* WebKitDOMEventTargetPrivate_h */ diff --git a/WebCore/bindings/gobject/WebKitHTMLElementWrapperFactory.cpp b/WebCore/bindings/gobject/WebKitHTMLElementWrapperFactory.cpp index 44928eb..4c57946 100644 --- a/WebCore/bindings/gobject/WebKitHTMLElementWrapperFactory.cpp +++ b/WebCore/bindings/gobject/WebKitHTMLElementWrapperFactory.cpp @@ -449,7 +449,7 @@ static gpointer createUListWrapper(PassRefPtr<HTMLElement> element) gpointer createHTMLElementWrapper(PassRefPtr<WebCore::HTMLElement> element) { - static HashMap<WebCore::AtomicStringImpl*, CreateHTMLElementWrapperFunction> map; + static HashMap<WTF::AtomicStringImpl*, CreateHTMLElementWrapperFunction> map; if (map.isEmpty()) { map.set(aTag.localName().impl(), createAnchorWrapper); map.set(appletTag.localName().impl(), createAppletWrapper); diff --git a/WebCore/bindings/js/DOMWrapperWorld.h b/WebCore/bindings/js/DOMWrapperWorld.h index 832c5e0..35b68fc 100644 --- a/WebCore/bindings/js/DOMWrapperWorld.h +++ b/WebCore/bindings/js/DOMWrapperWorld.h @@ -26,11 +26,11 @@ #include "JSDOMGlobalObject.h" #include "JSDOMWrapper.h" #include <runtime/WeakGCMap.h> +#include <wtf/Forward.h> namespace WebCore { class ScriptController; -class StringImpl; typedef JSC::WeakGCMap<void*, DOMObject*> DOMObjectWrapperMap; typedef JSC::WeakGCMap<StringImpl*, JSC::JSString*> JSStringCache; diff --git a/WebCore/bindings/js/IDBBindingUtilities.h b/WebCore/bindings/js/IDBBindingUtilities.h index f410344..7e72152 100644 --- a/WebCore/bindings/js/IDBBindingUtilities.h +++ b/WebCore/bindings/js/IDBBindingUtilities.h @@ -28,7 +28,7 @@ #if ENABLE(INDEXED_DATABASE) -#include "ScriptValue.h" +#include "ScriptValue.h" #include <wtf/Forward.h> namespace WebCore { diff --git a/WebCore/bindings/js/JSBindingsAllInOne.cpp b/WebCore/bindings/js/JSBindingsAllInOne.cpp index b517496..922e449 100644 --- a/WebCore/bindings/js/JSBindingsAllInOne.cpp +++ b/WebCore/bindings/js/JSBindingsAllInOne.cpp @@ -57,8 +57,6 @@ #include "JSDOMWrapper.cpp" #include "JSDataGridColumnListCustom.cpp" #include "JSDataGridDataSource.cpp" -#include "JSDatabaseCustom.cpp" -#include "JSDatabaseSyncCustom.cpp" #include "JSDebugWrapperSet.cpp" #include "JSDedicatedWorkerContextCustom.cpp" #include "JSDesktopNotificationsCustom.cpp" @@ -139,7 +137,6 @@ #include "JavaScriptCallFrame.cpp" #include "MemoryInfo.cpp" #include "ScheduledAction.cpp" -#include "ScriptArray.cpp" #include "ScriptCachedFrameData.cpp" #include "ScriptCallFrame.cpp" #include "ScriptCallStack.cpp" diff --git a/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp b/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp index 3026a33..69c8865 100644 --- a/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp +++ b/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp @@ -31,7 +31,6 @@ #if ENABLE(DATABASE) -#include "Frame.h" #include "JSSQLError.h" #include "JSSQLTransaction.h" #include "ScriptExecutionContext.h" @@ -41,22 +40,19 @@ namespace WebCore { using namespace JSC; -bool JSSQLStatementErrorCallback::handleEvent(ScriptExecutionContext* context, SQLTransaction* transaction, SQLError* error) +bool JSSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) { - ASSERT(m_data); - ASSERT(context); + if (!m_data || !m_data->globalObject() || !canInvokeCallback()) + return true; RefPtr<JSSQLStatementErrorCallback> protect(this); JSC::JSLock lock(SilenceAssertionsOnly); - JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, m_isolatedWorld.get()); - if (!globalObject) - return true; // if we cannot invoke the callback, roll back the transaction - ExecState* exec = globalObject->globalExec(); + ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; - args.append(toJS(exec, deprecatedGlobalObjectForPrototype(exec), transaction)); - args.append(toJS(exec, deprecatedGlobalObjectForPrototype(exec), error)); + args.append(toJS(exec, transaction)); + args.append(toJS(exec, error)); bool raisedException = false; JSValue result = m_data->invokeCallback(args, &raisedException); diff --git a/WebCore/bindings/js/JSDOMBinding.h b/WebCore/bindings/js/JSDOMBinding.h index 3f2502d..7086a89 100644 --- a/WebCore/bindings/js/JSDOMBinding.h +++ b/WebCore/bindings/js/JSDOMBinding.h @@ -30,6 +30,7 @@ #include <runtime/Completion.h> #include <runtime/Lookup.h> #include <runtime/WeakGCMap.h> +#include <wtf/Forward.h> #include <wtf/Noncopyable.h> namespace JSC { @@ -44,7 +45,6 @@ namespace WebCore { class JSNode; class KURL; class Node; - class String; class ScriptController; class ScriptCachedFrameData; diff --git a/WebCore/bindings/js/JSDOMWindowBase.h b/WebCore/bindings/js/JSDOMWindowBase.h index 2726996..f4f1ef9 100644 --- a/WebCore/bindings/js/JSDOMWindowBase.h +++ b/WebCore/bindings/js/JSDOMWindowBase.h @@ -23,12 +23,12 @@ #include "PlatformString.h" #include "JSDOMBinding.h" #include <runtime/Protect.h> +#include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/OwnPtr.h> namespace WebCore { - class AtomicString; class DOMWindow; class Event; class Frame; diff --git a/WebCore/bindings/js/JSDOMWindowCustom.cpp b/WebCore/bindings/js/JSDOMWindowCustom.cpp index 30d79b3..252ea93 100644 --- a/WebCore/bindings/js/JSDOMWindowCustom.cpp +++ b/WebCore/bindings/js/JSDOMWindowCustom.cpp @@ -22,7 +22,6 @@ #include "AtomicString.h" #include "Chrome.h" -#include "Database.h" #include "DOMWindow.h" #include "Document.h" #include "ExceptionCode.h" @@ -36,10 +35,6 @@ #include "HTMLDocument.h" #include "History.h" #include "JSAudioConstructor.h" -#if ENABLE(DATABASE) -#include "JSDatabase.h" -#include "JSDatabaseCallback.h" -#endif #include "JSDOMWindowShell.h" #include "JSEvent.h" #include "JSEventListener.h" @@ -1006,49 +1001,6 @@ JSValue JSDOMWindow::removeEventListener(ExecState* exec) return jsUndefined(); } -#if ENABLE(DATABASE) -JSValue JSDOMWindow::openDatabase(ExecState* exec) -{ - if (!allowsAccessFrom(exec) || (exec->argumentCount() < 4)) { - setDOMException(exec, SYNTAX_ERR); - return jsUndefined(); - } - - String name = ustringToString(exec->argument(0).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String version = ustringToString(exec->argument(1).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String displayName = ustringToString(exec->argument(2).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - // exec->argument(3) = estimated size - unsigned long estimatedSize = exec->argument(3).toUInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - RefPtr<DatabaseCallback> creationCallback; - if (exec->argumentCount() >= 5) { - if (!exec->argument(4).isObject()) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - creationCallback = JSDatabaseCallback::create(asObject(exec->argument(4)), globalObject()); - } - - ExceptionCode ec = 0; - JSValue result = toJS(exec, globalObject(), WTF::getPtr(impl()->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec))); - - setDOMException(exec, ec); - return result; -} -#endif - DOMWindow* toDOMWindow(JSValue value) { if (!value.isObject()) diff --git a/WebCore/bindings/js/JSDatabaseCustom.cpp b/WebCore/bindings/js/JSDatabaseCustom.cpp deleted file mode 100644 index 6733320..0000000 --- a/WebCore/bindings/js/JSDatabaseCustom.cpp +++ /dev/null @@ -1,146 +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. - */ - -#include "config.h" -#include "JSDatabase.h" - -#if ENABLE(DATABASE) - -#include "DOMWindow.h" -#include "Database.h" -#include "Document.h" -#include "ExceptionCode.h" -#include "JSSQLTransactionCallback.h" -#include "JSSQLTransactionErrorCallback.h" -#include "JSCustomVoidCallback.h" -#include "JSDOMWindowCustom.h" -#include "PlatformString.h" -#include "SQLValue.h" -#include <runtime/JSArray.h> - -namespace WebCore { - -using namespace JSC; - -JSValue JSDatabase::changeVersion(ExecState* exec) -{ - String oldVersion = ustringToString(exec->argument(0).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String newVersion = ustringToString(exec->argument(1).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - RefPtr<SQLTransactionCallback> callback; - if (exec->argumentCount() > 2 && !exec->argument(2).isNull()) { - JSObject* object = exec->argument(2).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - callback = JSSQLTransactionCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); - } - - RefPtr<SQLTransactionErrorCallback> errorCallback; - if (exec->argumentCount() > 3 && !exec->argument(3).isNull()) { - JSObject* object = exec->argument(3).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - errorCallback = JSSQLTransactionErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); - } - - RefPtr<VoidCallback> successCallback; - if (exec->argumentCount() > 4 && !exec->argument(4).isNull()) { - JSObject* object = exec->argument(4).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - successCallback = JSCustomVoidCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); - } - - m_impl->changeVersion(oldVersion, newVersion, callback.release(), errorCallback.release(), successCallback.release()); - - return jsUndefined(); -} - -static JSValue createTransaction(ExecState* exec, Database* database, JSDOMGlobalObject* globalObject, bool readOnly) -{ - JSObject* object = exec->argument(0).getObject(); - - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - RefPtr<SQLTransactionCallback> callback(JSSQLTransactionCallback::create(object, globalObject)); - RefPtr<SQLTransactionErrorCallback> errorCallback; - if (exec->argumentCount() > 1 && !exec->argument(1).isNull()) { - object = exec->argument(1).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - errorCallback = JSSQLTransactionErrorCallback::create(object, globalObject); - } - - RefPtr<VoidCallback> successCallback; - if (exec->argumentCount() > 2 && !exec->argument(2).isNull()) { - object = exec->argument(2).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - successCallback = JSCustomVoidCallback::create(object, globalObject); - } - - database->transaction(callback.release(), errorCallback.release(), successCallback.release(), readOnly); - return jsUndefined(); -} - -JSValue JSDatabase::transaction(ExecState* exec) -{ - return createTransaction(exec, m_impl.get(), static_cast<JSDOMGlobalObject*>(globalObject()), false); -} - -JSValue JSDatabase::readTransaction(ExecState* exec) -{ - return createTransaction(exec, m_impl.get(), static_cast<JSDOMGlobalObject*>(globalObject()), true); -} - -} - -#endif // ENABLE(DATABASE) diff --git a/WebCore/bindings/js/JSDatabaseSyncCustom.cpp b/WebCore/bindings/js/JSDatabaseSyncCustom.cpp deleted file mode 100644 index f929658..0000000 --- a/WebCore/bindings/js/JSDatabaseSyncCustom.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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: - * - * 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. - */ - -#include "config.h" -#include "JSDatabaseSync.h" - -#if ENABLE(DATABASE) - -#include "DatabaseSync.h" -#include "ExceptionCode.h" -#include "JSSQLTransactionSyncCallback.h" -#include "PlatformString.h" -#include "SQLValue.h" -#include <runtime/JSArray.h> - -namespace WebCore { - -using namespace JSC; - -JSValue JSDatabaseSync::changeVersion(ExecState* exec) -{ - String oldVersion = ustringToString(exec->argument(0).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String newVersion = ustringToString(exec->argument(1).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - RefPtr<SQLTransactionSyncCallback> callback; - if (exec->argumentCount() > 2 && !exec->argument(2).isNull()) { - JSObject* object = exec->argument(2).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - callback = JSSQLTransactionSyncCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); - } - - ExceptionCode ec = 0; - m_impl->changeVersion(oldVersion, newVersion, callback.release(), ec); - setDOMException(exec, ec); - - return jsUndefined(); -} - -static JSValue createTransaction(ExecState* exec, DatabaseSync* database, JSDOMGlobalObject* globalObject, bool readOnly) -{ - JSObject* object = exec->argument(0).getObject(); - if (!object) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - RefPtr<SQLTransactionSyncCallback> callback(JSSQLTransactionSyncCallback::create(object, globalObject)); - - ExceptionCode ec = 0; - database->transaction(callback.release(), readOnly, ec); - setDOMException(exec, ec); - - return jsUndefined(); -} - -JSValue JSDatabaseSync::transaction(ExecState* exec) -{ - return createTransaction(exec, m_impl.get(), static_cast<JSDOMGlobalObject*>(globalObject()), false); -} - -JSValue JSDatabaseSync::readTransaction(ExecState* exec) -{ - return createTransaction(exec, m_impl.get(), static_cast<JSDOMGlobalObject*>(globalObject()), true); -} - -} - -#endif // ENABLE(DATABASE) diff --git a/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp b/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp index 6c4dfb4..38334b9 100644 --- a/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp +++ b/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp @@ -47,8 +47,15 @@ namespace WebCore { JSValue JSNotificationCenter::requestPermission(ExecState* exec) { - // Permission request is only valid from page context. ScriptExecutionContext* context = impl()->context(); + + // Make sure that script execution context is valid. + if (!context) { + setDOMException(exec, INVALID_STATE_ERR); + return jsUndefined(); + } + + // Permission request is only valid from page context. if (context->isWorkerContext()) return throwSyntaxError(exec); diff --git a/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp b/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp new file mode 100644 index 0000000..225a626 --- /dev/null +++ b/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2010 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: + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 "JSDeviceMotionEvent.h" + +#if ENABLE(DEVICE_ORIENTATION) + +#include "DeviceMotionData.h" +#include "DeviceMotionEvent.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSDeviceMotionEvent::xAcceleration(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideXAcceleration()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->xAcceleration()); +} + +JSValue JSDeviceMotionEvent::yAcceleration(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideYAcceleration()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->yAcceleration()); +} + +JSValue JSDeviceMotionEvent::zAcceleration(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideZAcceleration()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->zAcceleration()); +} + +JSValue JSDeviceMotionEvent::xRotationRate(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideXRotationRate()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->xRotationRate()); +} + +JSValue JSDeviceMotionEvent::yRotationRate(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideYRotationRate()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->yRotationRate()); +} + +JSValue JSDeviceMotionEvent::zRotationRate(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideZRotationRate()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->zRotationRate()); +} + +JSValue JSDeviceMotionEvent::interval(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideInterval()) + return jsNull(); + return jsNumber(exec, imp->deviceMotionData()->interval()); +} + +JSValue JSDeviceMotionEvent::initDeviceMotionEvent(ExecState* exec) +{ + const String& type = ustringToString(exec->argument(0).toString(exec)); + bool bubbles = exec->argument(1).toBoolean(exec); + bool cancelable = exec->argument(2).toBoolean(exec); + // If any of the parameters are null or undefined, mark them as not provided. + // Otherwise, use the standard JavaScript conversion. + bool xAccelerationProvided = !exec->argument(3).isUndefinedOrNull(); + double xAcceleration = exec->argument(3).toNumber(exec); + bool yAccelerationProvided = !exec->argument(4).isUndefinedOrNull(); + double yAcceleration = exec->argument(4).toNumber(exec); + bool zAccelerationProvided = !exec->argument(5).isUndefinedOrNull(); + double zAcceleration = exec->argument(5).toNumber(exec); + bool xRotationRateProvided = !exec->argument(6).isUndefinedOrNull(); + double xRotationRate = exec->argument(6).toNumber(exec); + bool yRotationRateProvided = !exec->argument(7).isUndefinedOrNull(); + double yRotationRate = exec->argument(7).toNumber(exec); + bool zRotationRateProvided = !exec->argument(8).isUndefinedOrNull(); + double zRotationRate = exec->argument(8).toNumber(exec); + bool intervalProvided = !exec->argument(9).isUndefinedOrNull(); + double interval = exec->argument(9).toNumber(exec); + RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(xAccelerationProvided, xAcceleration, + yAccelerationProvided, yAcceleration, + zAccelerationProvided, zAcceleration, + xRotationRateProvided, xRotationRate, + yRotationRateProvided, yRotationRate, + zRotationRateProvided, zRotationRate, + intervalProvided, interval); + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get()); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/WebCore/bindings/js/JSEventCustom.cpp b/WebCore/bindings/js/JSEventCustom.cpp index b6190ff..7479020 100644 --- a/WebCore/bindings/js/JSEventCustom.cpp +++ b/WebCore/bindings/js/JSEventCustom.cpp @@ -32,12 +32,14 @@ #include "Clipboard.h" #include "CompositionEvent.h" #include "CustomEvent.h" +#include "DeviceMotionEvent.h" #include "DeviceOrientationEvent.h" #include "Event.h" #include "JSBeforeLoadEvent.h" #include "JSClipboard.h" #include "JSCustomEvent.h" #include "JSCompositionEvent.h" +#include "JSDeviceMotionEvent.h" #include "JSDeviceOrientationEvent.h" #include "JSErrorEvent.h" #include "JSKeyboardEvent.h" @@ -173,6 +175,8 @@ JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Event* event) else if (event->isCustomEvent()) wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CustomEvent, event); #if ENABLE(DEVICE_ORIENTATION) + else if (event->isDeviceMotionEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, DeviceMotionEvent, event); else if (event->isDeviceOrientationEvent()) wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, DeviceOrientationEvent, event); #endif diff --git a/WebCore/bindings/js/JSEventTarget.cpp b/WebCore/bindings/js/JSEventTarget.cpp index c5fce64..c86845d 100644 --- a/WebCore/bindings/js/JSEventTarget.cpp +++ b/WebCore/bindings/js/JSEventTarget.cpp @@ -88,7 +88,7 @@ #include "WebSocket.h" #endif -#if ENABLE(FILE_READER) +#if ENABLE(BLOB) #include "JSFileReader.h" #include "FileReader.h" #endif @@ -164,7 +164,7 @@ JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget* targ return toJS(exec, webSocket); #endif -#if ENABLE(FILE_READER) +#if ENABLE(BLOB) if (FileReader* fileReader = target->toFileReader()) return toJS(exec, globalObject, fileReader); #endif diff --git a/WebCore/bindings/js/JSHTMLDocumentCustom.cpp b/WebCore/bindings/js/JSHTMLDocumentCustom.cpp index a0e189e..0b40ef0 100644 --- a/WebCore/bindings/js/JSHTMLDocumentCustom.cpp +++ b/WebCore/bindings/js/JSHTMLDocumentCustom.cpp @@ -150,7 +150,7 @@ static inline void documentWrite(ExecState* exec, HTMLDocument* document, Newlin } } if (addNewline) - segmentedString.append(SegmentedString(&newlineCharacter, 1)); + segmentedString.append(SegmentedString(String(&newlineCharacter, 1))); Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document(); document->write(segmentedString, activeDocument); diff --git a/WebCore/bindings/js/JSIDBAnyCustom.cpp b/WebCore/bindings/js/JSIDBAnyCustom.cpp index 92f725a..e428bf6 100644 --- a/WebCore/bindings/js/JSIDBAnyCustom.cpp +++ b/WebCore/bindings/js/JSIDBAnyCustom.cpp @@ -32,16 +32,18 @@ #include "JSIDBAny.h" #include "IDBAny.h" -#include "IDBDatabaseRequest.h" +#include "IDBCursor.h" +#include "IDBDatabase.h" #include "IDBFactory.h" #include "IDBIndex.h" #include "IDBKey.h" -#include "IDBObjectStoreRequest.h" -#include "JSIDBDatabaseRequest.h" +#include "IDBObjectStore.h" +#include "JSIDBCursor.h" +#include "JSIDBDatabase.h" #include "JSIDBFactory.h" #include "JSIDBIndex.h" #include "JSIDBKey.h" -#include "JSIDBObjectStoreRequest.h" +#include "JSIDBObjectStore.h" #include "SerializedScriptValue.h" using namespace JSC; @@ -58,14 +60,16 @@ JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, IDBAny* idbAny) return jsUndefined(); case IDBAny::NullType: return jsNull(); - case IDBAny::IDBDatabaseRequestType: - return toJS(exec, globalObject, idbAny->idbDatabaseRequest()); + case IDBAny::IDBCursorType: + return toJS(exec, globalObject, idbAny->idbCursor()); + case IDBAny::IDBDatabaseType: + return toJS(exec, globalObject, idbAny->idbDatabase()); case IDBAny::IDBIndexType: return toJS(exec, globalObject, idbAny->idbIndex()); case IDBAny::IDBKeyType: return toJS(exec, globalObject, idbAny->idbKey()); - case IDBAny::IDBObjectStoreRequestType: - return toJS(exec, globalObject, idbAny->idbObjectStoreRequest()); + case IDBAny::IDBObjectStoreType: + return toJS(exec, globalObject, idbAny->idbObjectStore()); case IDBAny::IDBFactoryType: return toJS(exec, globalObject, idbAny->idbFactory()); case IDBAny::SerializedScriptValueType: diff --git a/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp b/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp index a0d75f8..0c891a3 100644 --- a/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp +++ b/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp @@ -48,6 +48,7 @@ #include "InjectedScriptHost.h" #include "InspectorController.h" #include "InspectorResource.h" +#include "InspectorValues.h" #include "JSDOMWindow.h" #include "JSDOMWindowCustom.h" #include "JSNode.h" @@ -55,7 +56,6 @@ #include "Node.h" #include "Page.h" #if ENABLE(DOM_STORAGE) -#include "SerializedScriptValue.h" #include "Storage.h" #include "JSStorage.h" #endif @@ -103,23 +103,6 @@ ScriptObject InjectedScriptHost::createInjectedScript(const String& source, Scri return ScriptObject(); } -#if ENABLE(DATABASE) -JSValue JSInjectedScriptHost::databaseForId(ExecState* exec) -{ - if (exec->argumentCount() < 1) - return jsUndefined(); - - InspectorController* ic = impl()->inspectorController(); - if (!ic) - return jsUndefined(); - - Database* database = impl()->databaseForId(exec->argument(0).toInt32(exec)); - if (!database) - return jsUndefined(); - return toJS(exec, database); -} -#endif - #if ENABLE(JAVASCRIPT_DEBUGGER) JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec) { @@ -192,24 +175,6 @@ JSValue JSInjectedScriptHost::selectDOMStorage(ExecState* exec) } #endif -JSValue JSInjectedScriptHost::reportDidDispatchOnInjectedScript(ExecState* exec) -{ - if (exec->argumentCount() < 3) - return jsUndefined(); - - if (!exec->argument(0).isInt32()) - return jsUndefined(); - int callId = exec->argument(0).asInt32(); - - RefPtr<SerializedScriptValue> result(SerializedScriptValue::create(exec, exec->argument(1))); - - bool isException; - if (!exec->argument(2).getBoolean(isException)) - return jsUndefined(); - impl()->reportDidDispatchOnInjectedScript(callId, result.get(), isException); - return jsUndefined(); -} - InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* scriptState) { JSLock lock(SilenceAssertionsOnly); diff --git a/WebCore/bindings/js/JSMessagePortCustom.h b/WebCore/bindings/js/JSMessagePortCustom.h index 62ebef1..8396ae1 100644 --- a/WebCore/bindings/js/JSMessagePortCustom.h +++ b/WebCore/bindings/js/JSMessagePortCustom.h @@ -33,13 +33,12 @@ #include "MessagePort.h" #include <runtime/JSValue.h> +#include <wtf/Forward.h> namespace WebCore { typedef int ExceptionCode; - class String; - // Helper function which pulls the values out of a JS sequence and into a MessagePortArray. // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec. // May generate an exception via the passed ExecState. diff --git a/WebCore/bindings/js/JSSQLTransactionCustom.cpp b/WebCore/bindings/js/JSSQLTransactionCustom.cpp index 44ebb02..e32ea55 100644 --- a/WebCore/bindings/js/JSSQLTransactionCustom.cpp +++ b/WebCore/bindings/js/JSSQLTransactionCustom.cpp @@ -95,7 +95,7 @@ JSValue JSSQLTransaction::executeSql(ExecState* exec) return jsUndefined(); } - callback = JSSQLStatementCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); + callback = JSSQLStatementCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); } RefPtr<SQLStatementErrorCallback> errorCallback; @@ -106,7 +106,7 @@ JSValue JSSQLTransaction::executeSql(ExecState* exec) return jsUndefined(); } - errorCallback = JSSQLStatementErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); + errorCallback = JSSQLStatementErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); } ExceptionCode ec = 0; diff --git a/WebCore/bindings/js/JSWorkerContextCustom.cpp b/WebCore/bindings/js/JSWorkerContextCustom.cpp index b443f90..b8885cf 100644 --- a/WebCore/bindings/js/JSWorkerContextCustom.cpp +++ b/WebCore/bindings/js/JSWorkerContextCustom.cpp @@ -29,13 +29,6 @@ #include "JSWorkerContext.h" -#if ENABLE(DATABASE) -#include "Database.h" -#include "DatabaseSync.h" -#include "JSDatabase.h" -#include "JSDatabaseCallback.h" -#include "JSDatabaseSync.h" -#endif #include "ExceptionCode.h" #include "JSDOMBinding.h" #include "JSDOMGlobalObject.h" @@ -153,89 +146,6 @@ JSValue JSWorkerContext::messageChannel(ExecState* exec) const } #endif -#if ENABLE(DATABASE) -JSValue JSWorkerContext::openDatabase(ExecState* exec) -{ - if (exec->argumentCount() < 4) { - setDOMException(exec, SYNTAX_ERR); - return jsUndefined(); - } - - String name = ustringToString(exec->argument(0).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String version = ustringToString(exec->argument(1).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String displayName = ustringToString(exec->argument(2).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - // exec->argument(3) = estimated size - unsigned long estimatedSize = exec->argument(3).toUInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - RefPtr<DatabaseCallback> creationCallback; - if (exec->argumentCount() >= 5) { - if (!exec->argument(4).isObject()) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - creationCallback = JSDatabaseCallback::create(asObject(exec->argument(4)), globalObject()); - } - - ExceptionCode ec = 0; - JSValue result = toJS(exec, globalObject(), WTF::getPtr(impl()->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec))); - setDOMException(exec, ec); - return result; -} - -JSValue JSWorkerContext::openDatabaseSync(ExecState* exec) -{ - if (exec->argumentCount() < 4) { - setDOMException(exec, SYNTAX_ERR); - return jsUndefined(); - } - - String name = ustringToString(exec->argument(0).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String version = ustringToString(exec->argument(1).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - String displayName = ustringToString(exec->argument(2).toString(exec)); - if (exec->hadException()) - return jsUndefined(); - - // exec->argument(3) = estimated size - unsigned long estimatedSize = exec->argument(3).toUInt32(exec); - if (exec->hadException()) - return jsUndefined(); - - RefPtr<DatabaseCallback> creationCallback; - if (exec->argumentCount() >= 5) { - if (!exec->argument(4).isObject()) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); - } - - creationCallback = JSDatabaseCallback::create(asObject(exec->argument(4)), globalObject()); - } - - ExceptionCode ec = 0; - JSValue result = toJS(exec, globalObject(), WTF::getPtr(impl()->openDatabaseSync(name, version, displayName, estimatedSize, creationCallback.release(), ec))); - - setDOMException(exec, ec); - return result; -} -#endif - } // namespace WebCore #endif // ENABLE(WORKERS) diff --git a/WebCore/bindings/js/JavaScriptCallFrame.h b/WebCore/bindings/js/JavaScriptCallFrame.h index 574c782..c23a43d 100644 --- a/WebCore/bindings/js/JavaScriptCallFrame.h +++ b/WebCore/bindings/js/JavaScriptCallFrame.h @@ -30,13 +30,12 @@ #include <debugger/DebuggerCallFrame.h> #include <interpreter/CallFrame.h> +#include <wtf/Forward.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> namespace WebCore { -class String; - class JavaScriptCallFrame : public RefCounted<JavaScriptCallFrame> { public: static PassRefPtr<JavaScriptCallFrame> create(const JSC::DebuggerCallFrame& debuggerCallFrame, PassRefPtr<JavaScriptCallFrame> caller, intptr_t sourceID, int line) diff --git a/WebCore/bindings/js/ScheduledAction.cpp b/WebCore/bindings/js/ScheduledAction.cpp index f69f8bd..a9dc6a8 100644 --- a/WebCore/bindings/js/ScheduledAction.cpp +++ b/WebCore/bindings/js/ScheduledAction.cpp @@ -34,7 +34,6 @@ #include "ScriptController.h" #include "ScriptExecutionContext.h" #include "ScriptSourceCode.h" -#include "ScriptValue.h" #include <runtime/JSLock.h> #if ENABLE(WORKERS) diff --git a/WebCore/bindings/js/ScriptArray.cpp b/WebCore/bindings/js/ScriptArray.cpp deleted file mode 100644 index 119d303..0000000 --- a/WebCore/bindings/js/ScriptArray.cpp +++ /dev/null @@ -1,127 +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 "ScriptArray.h" - -#include "SerializedScriptValue.h" - -#include <runtime/JSLock.h> - -using namespace JSC; - -namespace WebCore { - -ScriptArray::ScriptArray(ScriptState* scriptState, JSArray* object) - : ScriptObject(scriptState, object) -{ -} - -static bool handleException(ScriptState* scriptState) -{ - if (!scriptState->hadException()) - return true; - - reportException(scriptState, scriptState->exception()); - return false; -} - -bool ScriptArray::set(unsigned index, const ScriptObject& value) -{ - if (value.scriptState() != m_scriptState) { - ASSERT_NOT_REACHED(); - return false; - } - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, value.jsObject()); - return handleException(m_scriptState); -} - -bool ScriptArray::set(unsigned index, SerializedScriptValue* value) -{ - ScriptValue scriptValue = ScriptValue::deserialize(m_scriptState, value); - if (scriptValue.hasNoValue()) { - ASSERT_NOT_REACHED(); - return false; - } - - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, scriptValue.jsValue()); - return handleException(m_scriptState); -} - -bool ScriptArray::set(unsigned index, const String& value) -{ - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, jsString(m_scriptState, value)); - return handleException(m_scriptState); -} - -bool ScriptArray::set(unsigned index, double value) -{ - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, jsNumber(m_scriptState, value)); - return handleException(m_scriptState); -} - -bool ScriptArray::set(unsigned index, long long value) -{ - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, jsNumber(m_scriptState, value)); - return handleException(m_scriptState); -} - -bool ScriptArray::set(unsigned index, int value) -{ - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, jsNumber(m_scriptState, value)); - return handleException(m_scriptState); -} - -bool ScriptArray::set(unsigned index, bool value) -{ - JSLock lock(SilenceAssertionsOnly); - jsArray()->put(m_scriptState, index, jsBoolean(value)); - return handleException(m_scriptState); -} - -unsigned ScriptArray::length() -{ - JSLock lock(SilenceAssertionsOnly); - return jsArray()->length(); -} - -ScriptArray ScriptArray::createNew(ScriptState* scriptState) -{ - JSLock lock(SilenceAssertionsOnly); - return ScriptArray(scriptState, constructEmptyArray(scriptState)); -} - -} // namespace WebCore diff --git a/WebCore/bindings/js/ScriptArray.h b/WebCore/bindings/js/ScriptArray.h deleted file mode 100644 index 2badd09..0000000 --- a/WebCore/bindings/js/ScriptArray.h +++ /dev/null @@ -1,61 +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 ScriptArray_h -#define ScriptArray_h - -#include "ScriptObject.h" -#include "ScriptState.h" - -#include <runtime/JSArray.h> - -namespace WebCore { -class SerializedScriptValue; - -class ScriptArray : public ScriptObject { -public: - ScriptArray(ScriptState*, JSC::JSArray*); - ScriptArray() {} - JSC::JSArray* jsArray() const { return asArray(jsValue()); } - - bool set(unsigned index, const ScriptObject&); - bool set(unsigned index, SerializedScriptValue*); - bool set(unsigned index, const String&); - bool set(unsigned index, double); - bool set(unsigned index, long long); - bool set(unsigned index, int); - bool set(unsigned index, bool); - unsigned length(); - - static ScriptArray createNew(ScriptState*); -}; -} - -#endif // ScriptArray_h diff --git a/WebCore/bindings/js/ScriptCallStack.h b/WebCore/bindings/js/ScriptCallStack.h index e461ac3..a45e65a 100644 --- a/WebCore/bindings/js/ScriptCallStack.h +++ b/WebCore/bindings/js/ScriptCallStack.h @@ -31,7 +31,6 @@ #ifndef ScriptCallStack_h #define ScriptCallStack_h -#include "ScriptArray.h" #include "ScriptCallFrame.h" #include "ScriptState.h" #include "ScriptString.h" diff --git a/WebCore/bindings/js/ScriptController.h b/WebCore/bindings/js/ScriptController.h index 80155e4..8dae637 100644 --- a/WebCore/bindings/js/ScriptController.h +++ b/WebCore/bindings/js/ScriptController.h @@ -26,6 +26,7 @@ #include "ScriptControllerBase.h" #include "ScriptInstance.h" #include <runtime/Protect.h> +#include <wtf/Forward.h> #include <wtf/RefPtr.h> #if PLATFORM(MAC) @@ -57,7 +58,6 @@ class Frame; class Node; class ScriptSourceCode; class ScriptValue; -class String; class Widget; class XSSAuditor; diff --git a/WebCore/bindings/js/ScriptControllerEfl.cpp b/WebCore/bindings/js/ScriptControllerEfl.cpp index 950c11e..fea172e 100644 --- a/WebCore/bindings/js/ScriptControllerEfl.cpp +++ b/WebCore/bindings/js/ScriptControllerEfl.cpp @@ -39,14 +39,10 @@ namespace WebCore { PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) { - return 0; - -#if 0 // FIXME: disabled until we have Plugin system done. if (!widget->isPluginView()) return 0; return static_cast<PluginView*>(widget)->bindingInstance(); -#endif } } diff --git a/WebCore/bindings/js/ScriptObject.cpp b/WebCore/bindings/js/ScriptObject.cpp index de397f7..e06eccb 100644 --- a/WebCore/bindings/js/ScriptObject.cpp +++ b/WebCore/bindings/js/ScriptObject.cpp @@ -59,96 +59,6 @@ static bool handleException(ScriptState* scriptState) return false; } -bool ScriptObject::set(const String& name, const String& value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, stringToUString(name)), jsString(m_scriptState, stringToUString(value)), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, const ScriptObject& value) -{ - if (value.scriptState() != m_scriptState) { - ASSERT_NOT_REACHED(); - return false; - } - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), value.jsObject(), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, const String& value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsString(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, double value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, long value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, long long value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, int value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, unsigned value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, unsigned long value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); - return handleException(m_scriptState); -} - -bool ScriptObject::set(const char* name, bool value) -{ - JSLock lock(SilenceAssertionsOnly); - PutPropertySlot slot; - jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsBoolean(value), slot); - return handleException(m_scriptState); -} - -ScriptObject ScriptObject::createNew(ScriptState* scriptState) -{ - JSLock lock(SilenceAssertionsOnly); - return ScriptObject(scriptState, constructEmptyObject(scriptState)); -} - bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, const ScriptObject& value) { JSLock lock(SilenceAssertionsOnly); diff --git a/WebCore/bindings/js/ScriptObject.h b/WebCore/bindings/js/ScriptObject.h index 9880976..f085e8b 100644 --- a/WebCore/bindings/js/ScriptObject.h +++ b/WebCore/bindings/js/ScriptObject.h @@ -48,19 +48,6 @@ namespace WebCore { JSC::JSObject* jsObject() const { return asObject(jsValue()); } ScriptState* scriptState() const { return m_scriptState; } - bool set(const String& name, const String&); - bool set(const char* name, const ScriptObject&); - bool set(const char* name, const String&); - bool set(const char* name, double); - bool set(const char* name, long); - bool set(const char* name, long long); - bool set(const char* name, int); - bool set(const char* name, unsigned); - bool set(const char* name, unsigned long); - bool set(const char* name, bool); - - static ScriptObject createNew(ScriptState*); - protected: ScriptState* m_scriptState; }; diff --git a/WebCore/bindings/js/ScriptProfile.cpp b/WebCore/bindings/js/ScriptProfile.cpp new file mode 100644 index 0000000..1fbd040 --- /dev/null +++ b/WebCore/bindings/js/ScriptProfile.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * 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: + * 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. 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 "ScriptProfile.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include "InspectorValues.h" +#include "JSDOMBinding.h" +#include <profiler/Profile.h> +#include <profiler/ProfileNode.h> + +namespace WebCore { + +PassRefPtr<ScriptProfile> ScriptProfile::create(PassRefPtr<JSC::Profile> profile) +{ + if (!profile) + return 0; + return adoptRef(new ScriptProfile(profile)); +} + +ScriptProfile::ScriptProfile(PassRefPtr<JSC::Profile> profile) + : m_profile(profile) +{ +} + +ScriptProfile::~ScriptProfile() +{ +} + +String ScriptProfile::title() const +{ + return ustringToString(m_profile->title()); +} + +unsigned int ScriptProfile::uid() const +{ + return m_profile->uid(); +} + +ScriptProfileNode* ScriptProfile::head() const +{ + return m_profile->head(); +} + +static PassRefPtr<InspectorObject> buildInspectorObjectFor(const JSC::ProfileNode* node) +{ + RefPtr<InspectorObject> result = InspectorObject::create(); + + result->setString("functionName", ustringToString(node->functionName())); + result->setString("url", ustringToString(node->url())); + result->setNumber("lineNumber", node->lineNumber()); + result->setNumber("totalTime", node->totalTime()); + result->setNumber("selfTime", node->selfTime()); + result->setNumber("numberOfCalls", node->numberOfCalls()); + result->setBool("visible", node->visible()); + result->setNumber("callUID", node->callIdentifier().hash()); + + RefPtr<InspectorArray> childrenArray = InspectorArray::create(); + typedef Vector<RefPtr<JSC::ProfileNode> > ProfileNodesList; + const ProfileNodesList& children = node->children(); + ProfileNodesList::const_iterator end = children.end(); + for (ProfileNodesList::const_iterator iter = children.begin(); iter != end; ++iter) + childrenArray->push(buildInspectorObjectFor(iter->get())); + result->set("children", childrenArray); + + return result; +} + +PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const +{ + return buildInspectorObjectFor(m_profile->head()); +} + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/WebCore/bindings/js/ScriptProfile.h b/WebCore/bindings/js/ScriptProfile.h index 32095e3..b39d2c9 100644 --- a/WebCore/bindings/js/ScriptProfile.h +++ b/WebCore/bindings/js/ScriptProfile.h @@ -28,11 +28,37 @@ #define ScriptProfile_h #if ENABLE(JAVASCRIPT_DEBUGGER) -#include <profiler/Profile.h> +#include "ScriptProfileNode.h" +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +namespace JSC { +class Profile; +} namespace WebCore { -typedef JSC::Profile ScriptProfile; +class InspectorObject; + +class ScriptProfile : public RefCounted<ScriptProfile> { +public: + static PassRefPtr<ScriptProfile> create(PassRefPtr<JSC::Profile> profile); + virtual ~ScriptProfile(); + + String title() const; + unsigned int uid() const; + ScriptProfileNode* head() const; + + PassRefPtr<InspectorObject> buildInspectorObjectForHead() const; + +private: + ScriptProfile(PassRefPtr<JSC::Profile> profile); + + RefPtr<JSC::Profile> m_profile; +}; + } // namespace WebCore diff --git a/WebCore/bindings/js/ScriptProfiler.cpp b/WebCore/bindings/js/ScriptProfiler.cpp index 5121232..f372c3c 100644 --- a/WebCore/bindings/js/ScriptProfiler.cpp +++ b/WebCore/bindings/js/ScriptProfiler.cpp @@ -42,7 +42,8 @@ void ScriptProfiler::start(ScriptState* state, const String& title) PassRefPtr<ScriptProfile> ScriptProfiler::stop(ScriptState* state, const String& title) { - return JSC::Profiler::profiler()->stopProfiling(state, stringToUString(title)); + RefPtr<JSC::Profile> profile = JSC::Profiler::profiler()->stopProfiling(state, stringToUString(title)); + return ScriptProfile::create(profile); } } // namespace WebCore diff --git a/WebCore/bindings/js/ScriptProfiler.h b/WebCore/bindings/js/ScriptProfiler.h index 16195a3..4fa331c 100644 --- a/WebCore/bindings/js/ScriptProfiler.h +++ b/WebCore/bindings/js/ScriptProfiler.h @@ -40,6 +40,7 @@ public: static void start(ScriptState* state, const String& title); static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title); static void takeHeapSnapshot() { } + static long getProfilerLogLines(long, String*) { return 0; } }; } // namespace WebCore diff --git a/WebCore/bindings/js/ScriptSourceProvider.h b/WebCore/bindings/js/ScriptSourceProvider.h index 2144169..de4e307 100644 --- a/WebCore/bindings/js/ScriptSourceProvider.h +++ b/WebCore/bindings/js/ScriptSourceProvider.h @@ -28,11 +28,10 @@ #define ScriptSourceProvider_h #include <parser/SourceProvider.h> +#include <wtf/Forward.h> namespace WebCore { - class String; - class ScriptSourceProvider : public JSC::SourceProvider { public: ScriptSourceProvider(const JSC::UString& url) diff --git a/WebCore/bindings/js/ScriptString.h b/WebCore/bindings/js/ScriptString.h index ad0ae95..558ad33 100644 --- a/WebCore/bindings/js/ScriptString.h +++ b/WebCore/bindings/js/ScriptString.h @@ -35,11 +35,10 @@ #include "PlatformString.h" #include <runtime/UString.h> #include <runtime/StringBuilder.h> +#include <wtf/Forward.h> namespace WebCore { -class String; - class ScriptString { public: ScriptString() {} diff --git a/WebCore/bindings/js/ScriptValue.cpp b/WebCore/bindings/js/ScriptValue.cpp index abc31e2..23934cd 100644 --- a/WebCore/bindings/js/ScriptValue.cpp +++ b/WebCore/bindings/js/ScriptValue.cpp @@ -143,6 +143,7 @@ static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, J } return inspectorObject; } + ASSERT_NOT_REACHED(); return 0; } diff --git a/WebCore/bindings/js/WorkerScriptController.h b/WebCore/bindings/js/WorkerScriptController.h index 60c3b04..be7da4d 100644 --- a/WebCore/bindings/js/WorkerScriptController.h +++ b/WebCore/bindings/js/WorkerScriptController.h @@ -30,6 +30,7 @@ #if ENABLE(WORKERS) #include <runtime/Protect.h> +#include <wtf/Forward.h> #include <wtf/Noncopyable.h> #include <wtf/Threading.h> @@ -42,7 +43,6 @@ namespace WebCore { class JSWorkerContext; class ScriptSourceCode; class ScriptValue; - class String; class WorkerContext; class WorkerScriptController : public Noncopyable { diff --git a/WebCore/bindings/objc/DOMHTML.mm b/WebCore/bindings/objc/DOMHTML.mm index 3488b35..db64afe 100644 --- a/WebCore/bindings/objc/DOMHTML.mm +++ b/WebCore/bindings/objc/DOMHTML.mm @@ -124,7 +124,7 @@ { WebCore::HTMLInputElement* inputElement = core(self); if (inputElement) { - WebCore::String newValue = inputElement->value(); + WTF::String newValue = inputElement->value(); newValue.replace(targetRange.location, targetRange.length, replacementString); inputElement->setValue(newValue); inputElement->setSelectionRange(index, newValue.length()); diff --git a/WebCore/bindings/objc/DOMImplementationFront.h b/WebCore/bindings/objc/DOMImplementationFront.h index 877a3b6..dabe90c 100644 --- a/WebCore/bindings/objc/DOMImplementationFront.h +++ b/WebCore/bindings/objc/DOMImplementationFront.h @@ -37,7 +37,6 @@ class Document; class DocumentType; class HTMLDocument; class JSDOMImplementation; -class String; typedef int ExceptionCode; diff --git a/WebCore/bindings/scripts/CodeGeneratorCPP.pm b/WebCore/bindings/scripts/CodeGeneratorCPP.pm index 27cf854..ff63615 100644 --- a/WebCore/bindings/scripts/CodeGeneratorCPP.pm +++ b/WebCore/bindings/scripts/CodeGeneratorCPP.pm @@ -261,7 +261,7 @@ sub GetCPPTypeGetter return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type); return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow"; - return "WebCore::SerializedScriptValue::create(WebCore::String($argName))" if $type eq "SerializedScriptValue"; + return "WebCore::SerializedScriptValue::create(WTF::String($argName))" if $type eq "SerializedScriptValue"; return "toWebCore($argName)"; } @@ -421,10 +421,14 @@ sub GenerateHeader foreach my $attribute (@{$dataNode->attributes}) { next if ShouldSkipTypeInHeader($attribute); + my $attributeConditionalString = GenerateConditionalString($attribute->signature); my $attributeName = $attribute->signature->name; my $attributeType = GetCPPType($attribute->signature->type, 0); my $attributeIsReadonly = ($attribute->type =~ /^readonly/); - my $property = " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName . "() const"; + my $property = ""; + + $property .= "#if ${attributeConditionalString}\n" if $attributeConditionalString; + $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName . "() const"; my $availabilityMacro = ""; my $declarationSuffix = ";\n"; @@ -439,10 +443,11 @@ sub GenerateHeader if (!$attributeIsReadonly and !$attribute->signature->extendedAttributes->{"Replaceable"}) { $property = " void $setterName($attributeType)"; $property .= $declarationSuffix; - push(@headerAttributes, $property); + push(@headerAttributes, $property); } - } + push(@headerAttributes, "#endif\n") if $attributeConditionalString; + } push(@headerContent, @headerAttributes) if @headerAttributes > 0; } @@ -554,7 +559,7 @@ sub AddReturnStatement # Used to invoke KURLs "const String&" operator if ($codeGenerator->IsStringType($typeInfo->signature->type)) { - return " return static_cast<const WebCore::String&>($returnValue);\n"; + return " return static_cast<const WTF::String&>($returnValue);\n"; } return " return $returnValue;\n"; @@ -677,7 +682,7 @@ sub GenerateImplementation # Special cases my @customGetterContent = (); if ($attribute->signature->extendedAttributes->{"ConvertToString"}) { - $getterContentHead = "WebCore::String::number(" . $getterContentHead; + $getterContentHead = "WTF::String::number(" . $getterContentHead; $getterContentTail .= ")"; } elsif ($attribute->signature->type eq "SerializedScriptValue") { $getterContentHead = "$getterContentHead"; @@ -731,7 +736,7 @@ sub GenerateImplementation # The definition of ConvertToString is flipped for the setter if ($attribute->signature->extendedAttributes->{"ConvertToString"}) { - $arg = "WebCore::String($arg).toInt()"; + $arg = "WTF::String($arg).toInt()"; } my $attributeType = GetCPPType($attribute->signature->type, 1); diff --git a/WebCore/bindings/scripts/CodeGeneratorGObject.pm b/WebCore/bindings/scripts/CodeGeneratorGObject.pm index bc5aace..5700ff7 100644 --- a/WebCore/bindings/scripts/CodeGeneratorGObject.pm +++ b/WebCore/bindings/scripts/CodeGeneratorGObject.pm @@ -126,6 +126,7 @@ sub ClassNameToGObjectType { $CLASS_NAME =~ s/DOMCDATA/DOM_CDATA/; $CLASS_NAME =~ s/DOMX_PATH/DOM_XPATH/; $CLASS_NAME =~ s/DOM_WEB_KIT/DOM_WEBKIT/; + $CLASS_NAME =~ s/DOMUI/DOM_UI/; return $CLASS_NAME; } @@ -207,6 +208,14 @@ sub SkipFunction { return 1; } + # Skip functions that have ["Callback"] parameters, because this + # code generator doesn't know how to auto-generate callbacks. + foreach my $param (@{$function->parameters}) { + if ($param->extendedAttributes->{"Callback"}) { + return 1; + } + } + return 0; } @@ -239,7 +248,7 @@ sub GetGlibTypeName { my $type = shift; my $name = GetClassName($type); - my %types = ("DOMString", "gchar* ", + my %types = ("DOMString", "gchar*", "DOMTimeStamp", "guint32", "CompareHow", "gushort", "float", "gfloat", @@ -258,7 +267,7 @@ sub GetGlibTypeName { "unsigned short", "gushort", "void", "void"); - return $types{$type} ? $types{$type} : "$name* "; + return $types{$type} ? $types{$type} : "$name*"; } sub IsGDOMClassType { @@ -360,7 +369,7 @@ sub GenerateProperty { my $convertFunction = ""; if ($gtype eq "string") { - $convertFunction = "WebCore::String::fromUTF8"; + $convertFunction = "WTF::String::fromUTF8"; } my $getterExpressionPrefix = $codeGenerator->GetterExpressionPrefix(\%implIncludes, $interfaceName, $attribute); @@ -802,9 +811,10 @@ sub GenerateFunction { } addIncludeInBody($paramIDLType); my $paramType = GetGlibTypeName($paramIDLType); + my $const = $paramType eq "gchar*" ? "const " : ""; my $paramName = decamelize($param->name); - $functionSig .= ", $paramType $paramName"; + $functionSig .= ", ${const}$paramType $paramName"; my $paramIsGDOMType = IsGDOMClassType($paramIDLType); if ($paramIsGDOMType) { @@ -892,7 +902,7 @@ sub GenerateFunction { my $paramIsGDOMType = IsGDOMClassType($paramIDLType); if ($paramIDLType eq "DOMString") { - push(@cBody, " WebCore::String converted_${paramName} = WebCore::String::fromUTF8($paramName);\n"); + push(@cBody, " WTF::String converted_${paramName} = WTF::String::fromUTF8($paramName);\n"); } elsif ($paramIDLType eq "CompareHow") { push(@cBody, " WebCore::Range::CompareHow converted_${paramName} = static_cast<WebCore::Range::CompareHow>($paramName);\n"); } elsif ($paramIsGDOMType) { @@ -1222,7 +1232,7 @@ EOF sub UsesManualKitImplementation { my $type = shift; - return 1 if $type eq "Node" or $type eq "Element"; + return 1 if $type eq "Node" or $type eq "Element" or $type eq "Event"; return 0; } diff --git a/WebCore/bindings/scripts/CodeGeneratorJS.pm b/WebCore/bindings/scripts/CodeGeneratorJS.pm index 247430f..200a95d 100644 --- a/WebCore/bindings/scripts/CodeGeneratorJS.pm +++ b/WebCore/bindings/scripts/CodeGeneratorJS.pm @@ -299,7 +299,7 @@ sub AddIncludesForSVGAnimatedType sub IsScriptProfileType { my $type = shift; - return 1 if ($type eq "ScriptProfile" or $type eq "ScriptProfileNode"); + return 1 if ($type eq "ScriptProfileNode"); return 0; } @@ -1853,12 +1853,20 @@ sub GenerateImplementation my $requiresAllArguments = $function->signature->extendedAttributes->{"RequiresAllArguments"}; if ($requiresAllArguments) { - push(@implContent, " if (exec->argumentCount() < $numParameters)\n"); - if ($requiresAllArguments eq "Raise") { - push(@implContent, " return throwVMError(exec, createSyntaxError(exec, \"Not enough arguments\"));\n"); + my $numMandatoryParams = @{$function->parameters}; + foreach my $param (reverse(@{$function->parameters})) { + if ($param->extendedAttributes->{"Optional"}) { + $numMandatoryParams--; } else { - push(@implContent, " return JSValue::encode(jsUndefined());\n"); + last; } + } + push(@implContent, " if (exec->argumentCount() < $numMandatoryParams)\n"); + if ($requiresAllArguments eq "Raise") { + push(@implContent, " return throwVMError(exec, createSyntaxError(exec, \"Not enough arguments\"));\n"); + } else { + push(@implContent, " return JSValue::encode(jsUndefined());\n"); + } } if (@{$function->raisesExceptions}) { @@ -1908,14 +1916,18 @@ sub GenerateImplementation $paramIndex++; } + $implIncludes{"ExceptionCode.h"} = 1; + $implIncludes{"JSDOMBinding.h"} = 1; foreach my $parameter (@{$function->parameters}) { - if ($parameter->extendedAttributes->{"Optional"}) { + # Optional callbacks should be treated differently, because they always have a default value (0), + # and we can reduce the number of overloaded functions that take a different number of parameters. + if ($parameter->extendedAttributes->{"Optional"} && !$parameter->extendedAttributes->{"Callback"}) { # Generate early call if there are enough parameters. if (!$hasOptionalArguments) { push(@implContent, "\n int argsCount = exec->argumentCount();\n"); $hasOptionalArguments = 1; } - push(@implContent, " if (argsCount < " . ($argsIndex + 1) . ") {\n"); + push(@implContent, " if (argsCount <= $argsIndex) {\n"); GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 2, $podType, $implClassName); push(@implContent, " }\n\n"); } @@ -1934,12 +1946,22 @@ sub GenerateImplementation } elsif ($parameter->extendedAttributes->{"Callback"}) { my $callbackClassName = GetCallbackClassName($parameter->type); $implIncludes{"$callbackClassName.h"} = 1; - $implIncludes{"ExceptionCode.h"} = 1; - push(@implContent, " if (exec->argumentCount() <= $argsIndex || !exec->argument($argsIndex).isObject()) {\n"); - push(@implContent, " setDOMException(exec, TYPE_MISMATCH_ERR);\n"); - push(@implContent, " return jsUndefined();\n"); - push(@implContent, " }\n"); - push(@implContent, " RefPtr<" . $parameter->type . "> $name = " . $callbackClassName . "::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n"); + if ($parameter->extendedAttributes->{"Optional"}) { + push(@implContent, " RefPtr<" . $parameter->type. "> $name;\n"); + push(@implContent, " if (exec->argumentCount() > $argsIndex && !exec->argument($argsIndex).isNull() && !exec->argument($argsIndex).isUndefined()) {\n"); + push(@implContent, " if (!exec->argument($argsIndex).isObject()) {\n"); + push(@implContent, " setDOMException(exec, TYPE_MISMATCH_ERR);\n"); + push(@implContent, " return JSValue::encode(jsUndefined());\n"); + push(@implContent, " }\n"); + push(@implContent, " $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n"); + push(@implContent, " }\n"); + } else { + push(@implContent, " if (exec->argumentCount() <= $argsIndex || !exec->argument($argsIndex).isObject()) {\n"); + push(@implContent, " setDOMException(exec, TYPE_MISMATCH_ERR);\n"); + push(@implContent, " return JSValue::encode(jsUndefined());\n"); + push(@implContent, " }\n"); + push(@implContent, " RefPtr<" . $parameter->type . "> $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n"); + } } else { push(@implContent, " " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, "exec->argument($argsIndex)") . ";\n"); @@ -1947,12 +1969,15 @@ sub GenerateImplementation # But this needs to be done in the bindings, because the type is unsigned and the fact that it # was negative will be lost by the time we're inside the DOM. if ($parameter->extendedAttributes->{"IsIndex"}) { - $implIncludes{"ExceptionCode.h"} = 1; push(@implContent, " if ($name < 0) {\n"); push(@implContent, " setDOMException(exec, INDEX_SIZE_ERR);\n"); push(@implContent, " return JSValue::encode(jsUndefined());\n"); push(@implContent, " }\n"); } + + # Check if the type conversion succeeded. + push(@implContent, " if (exec->hadException())\n"); + push(@implContent, " return JSValue::encode(jsUndefined());\n"); } $functionString .= ", " if $paramIndex; @@ -2084,12 +2109,13 @@ sub GenerateCallbackHeader # - Add default header template and header protection push(@headerContentHeader, GenerateHeaderContentHeader($dataNode)); + $headerIncludes{"ActiveDOMCallback.h"} = 1; $headerIncludes{"$interfaceName.h"} = 1; $headerIncludes{"JSCallbackData.h"} = 1; $headerIncludes{"<wtf/Forward.h>"} = 1; push(@headerContent, "\nnamespace WebCore {\n\n"); - push(@headerContent, "class $className : public $interfaceName {\n"); + push(@headerContent, "class $className : public $interfaceName, public ActiveDOMCallback {\n"); push(@headerContent, "public:\n"); # The static create() method. @@ -2112,10 +2138,13 @@ sub GenerateCallbackHeader push(@headerContent, " COMPILE_ASSERT(false)"); } - push(@headerContent, " virtual " . GetNativeType($function->signature->type) . " " . $function->signature->name . "(ScriptExecutionContext*"); + push(@headerContent, " virtual " . GetNativeType($function->signature->type) . " " . $function->signature->name . "("); + + my @args = (); foreach my $param (@params) { - push(@headerContent, ", " . GetNativeType($param->type) . " " . $param->name); + push(@args, GetNativeType($param->type) . " " . $param->name); } + push(@headerContent, join(", ", @args)); push(@headerContent, ");\n"); } @@ -2128,8 +2157,6 @@ sub GenerateCallbackHeader # Private members push(@headerContent, " JSCallbackData* m_data;\n"); - push(@headerContent, " RefPtr<DOMWrapperWorld> m_isolatedWorld;\n"); - push(@headerContent, " ScriptExecutionContext* m_scriptExecutionContext;\n"); push(@headerContent, "};\n\n"); push(@headerContent, "} // namespace WebCore\n\n"); @@ -2159,19 +2186,21 @@ sub GenerateCallbackImplementation # Constructor push(@implContent, "${className}::${className}(JSObject* callback, JSDOMGlobalObject* globalObject)\n"); - push(@implContent, " : m_data(new JSCallbackData(callback, globalObject))\n"); - push(@implContent, " , m_isolatedWorld(globalObject->world())\n"); - push(@implContent, " , m_scriptExecutionContext(globalObject->scriptExecutionContext())\n"); + push(@implContent, " : ActiveDOMCallback(globalObject->scriptExecutionContext())\n"); + push(@implContent, " , m_data(new JSCallbackData(callback, globalObject))\n"); push(@implContent, "{\n"); push(@implContent, "}\n\n"); # Destructor push(@implContent, "${className}::~${className}()\n"); push(@implContent, "{\n"); - push(@implContent, " if (m_scriptExecutionContext->isContextThread())\n"); + push(@implContent, " ScriptExecutionContext* context = scriptExecutionContext();\n"); + push(@implContent, " // When the context is destroyed, all tasks with a reference to a callback\n"); + push(@implContent, " // should be deleted. So if the context is 0, we are on the context thread.\n"); + push(@implContent, " if (!context || context->isContextThread())\n"); push(@implContent, " delete m_data;\n"); push(@implContent, " else\n"); - push(@implContent, " m_scriptExecutionContext->postTask(DeleteCallbackDataTask::create(m_data));\n"); + push(@implContent, " context->postTask(DeleteCallbackDataTask::create(m_data));\n"); push(@implContent, "#ifndef NDEBUG\n"); push(@implContent, " m_data = 0;\n"); push(@implContent, "#endif\n"); @@ -2189,24 +2218,22 @@ sub GenerateCallbackImplementation } AddIncludesForType($function->signature->type); - push(@implContent, "\n" . GetNativeType($function->signature->type) . " ${className}::" . $function->signature->name . "(ScriptExecutionContext* context"); + push(@implContent, "\n" . GetNativeType($function->signature->type) . " ${className}::" . $function->signature->name . "("); + my @args = (); foreach my $param (@params) { AddIncludesForType($param->type, 1); - push(@implContent, ", " . GetNativeType($param->type) . " " . $param->name); + push(@args, GetNativeType($param->type) . " " . $param->name); } - + push(@implContent, join(", ", @args)); push(@implContent, ")\n"); push(@implContent, "{\n"); - push(@implContent, " ASSERT(m_data);\n"); - push(@implContent, " ASSERT(context);\n\n"); + push(@implContent, " if (!canInvokeCallback())\n"); + push(@implContent, " return true;\n\n"); push(@implContent, " RefPtr<$className> protect(this);\n\n"); push(@implContent, " JSLock lock(SilenceAssertionsOnly);\n\n"); - push(@implContent, " JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, m_isolatedWorld.get());\n"); - push(@implContent, " if (!globalObject)\n"); - push(@implContent, " return true;\n\n"); - push(@implContent, " ExecState* exec = globalObject->globalExec();\n"); + push(@implContent, " ExecState* exec = m_data->globalObject()->globalExec();\n"); push(@implContent, " MarkedArgumentBuffer args;\n"); foreach my $param (@params) { @@ -2341,7 +2368,8 @@ sub JSValueToNative return "$value.toBoolean(exec)" if $type eq "boolean"; return "$value.toNumber(exec)" if $type eq "double"; return "$value.toFloat(exec)" if $type eq "float" or $type eq "SVGNumber"; - return "$value.toInt32(exec)" if $type eq "unsigned long" or $type eq "long" or $type eq "unsigned short"; + return "$value.toInt32(exec)" if $type eq "long"; + return "$value.toUInt32(exec)" if $type eq "unsigned long" or $type eq "unsigned short"; return "static_cast<$type>($value.toInteger(exec))" if $type eq "long long" or $type eq "unsigned long long"; return "valueToDate(exec, $value)" if $type eq "Date"; diff --git a/WebCore/bindings/scripts/CodeGeneratorObjC.pm b/WebCore/bindings/scripts/CodeGeneratorObjC.pm index 91cbd0b..7e17008 100644 --- a/WebCore/bindings/scripts/CodeGeneratorObjC.pm +++ b/WebCore/bindings/scripts/CodeGeneratorObjC.pm @@ -524,7 +524,7 @@ sub GetObjCTypeGetter if ($type eq "SerializedScriptValue") { $implIncludes{"SerializedScriptValue.h"} = 1; - return "WebCore::SerializedScriptValue::create(WebCore::String($argName))"; + return "WebCore::SerializedScriptValue::create(WTF::String($argName))"; } return "core($argName)"; } @@ -1242,7 +1242,7 @@ sub GenerateImplementation } $implIncludes{"DOMPrivate.h"} = 1; } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) { - $getterContentHead = "WebCore::String::number(" . $getterContentHead; + $getterContentHead = "WTF::String::number(" . $getterContentHead; $getterContentTail .= ")"; } elsif ($codeGenerator->IsPodType($idlType) or $idlType eq "Date") { $getterContentHead = "kit($getterContentHead"; @@ -1304,7 +1304,7 @@ sub GenerateImplementation # The definition of ConvertToString is flipped for the setter if ($attribute->signature->extendedAttributes->{"ConvertToString"}) { - $arg = "WebCore::String($arg).toInt()"; + $arg = "WTF::String($arg).toInt()"; } my $setterSig = "- (void)$setterName:($attributeType)$argName\n"; diff --git a/WebCore/bindings/scripts/CodeGeneratorV8.pm b/WebCore/bindings/scripts/CodeGeneratorV8.pm index c852f7b..f803c87 100644 --- a/WebCore/bindings/scripts/CodeGeneratorV8.pm +++ b/WebCore/bindings/scripts/CodeGeneratorV8.pm @@ -1106,7 +1106,15 @@ END my $requiresAllArguments = $function->signature->extendedAttributes->{"RequiresAllArguments"}; if ($requiresAllArguments) { - push(@implContentDecls, " if (args.Length() < $numParameters)\n"); + my $numMandatoryParams = @{$function->parameters}; + foreach my $param (reverse(@{$function->parameters})) { + if ($param->extendedAttributes->{"Optional"}) { + $numMandatoryParams--; + } else { + last; + } + } + push(@implContentDecls, " if (args.Length() < $numMandatoryParams)\n"); if ($requiresAllArguments eq "Raise") { push(@implContentDecls, " return throwError(\"Not enough arguments\", V8Proxy::SyntaxError);\n"); } else { @@ -1175,7 +1183,9 @@ END my $parameterName = $parameter->name; - if ($parameter->extendedAttributes->{"Optional"}) { + # Optional callbacks should be treated differently, because they always have a default value (0), + # and we can reduce the number of overloaded functions that take a different number of parameters. + if ($parameter->extendedAttributes->{"Optional"} && !$parameter->extendedAttributes->{"Callback"}) { # Generate early call if there are not enough parameters. push(@implContentDecls, " if (args.Length() <= $paramIndex) {\n"); my $functionCall = GenerateFunctionCallString($function, $paramIndex, " " x 2, $implClassName); @@ -1183,55 +1193,59 @@ END push(@implContentDecls, " }\n"); } + if (BasicTypeCanFailConversion($parameter)) { + push(@implContentDecls, " bool ${parameterName}Ok;\n"); + } + + $implIncludes{"ExceptionCode.h"} = 1; + my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex); if ($parameter->extendedAttributes->{"Callback"}) { my $className = GetCallbackClassName($parameter->type); $implIncludes{"$className.h"} = 1; - $implIncludes{"ExceptionCode.h"} = 1; - push(@implContentDecls, " if (args.Length() <= $paramIndex || !args[$paramIndex]->IsObject())\n"); - push(@implContentDecls, " return throwError(TYPE_MISMATCH_ERR);\n"); - if ($parameter->type eq "VoidCallback") { - push(@implContentDecls, " RefPtr<" . $parameter->type . "> $parameterName = " . $className . "::create(args[$paramIndex], getScriptExecutionContext());\n"); + if ($parameter->extendedAttributes->{"Optional"}) { + push(@implContentDecls, " RefPtr<" . $parameter->type . "> $parameterName;\n"); + push(@implContentDecls, " if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n"); + push(@implContentDecls, " if (!args[$paramIndex]->IsObject())\n"); + push(@implContentDecls, " return throwError(TYPE_MISMATCH_ERR);\n"); + push(@implContentDecls, " $parameterName = ${className}::create(args[$paramIndex], getScriptExecutionContext());\n"); + push(@implContentDecls, " }\n"); } else { - push(@implContentDecls, " RefPtr<" . $parameter->type . "> $parameterName = " . $className . "::create(args[$paramIndex]);\n"); + push(@implContentDecls, " if (args.Length() <= $paramIndex || !args[$paramIndex]->IsObject())\n"); + push(@implContentDecls, " return throwError(TYPE_MISMATCH_ERR);\n"); + push(@implContentDecls, " RefPtr<" . $parameter->type . "> $parameterName = ${className}::create(args[$paramIndex], getScriptExecutionContext());\n"); } - $paramIndex++; - next; - } - - if ($parameter->type eq "SerializedScriptValue") { + } elsif ($parameter->type eq "SerializedScriptValue") { $implIncludes{"SerializedScriptValue.h"} = 1; push(@implContentDecls, " bool ${parameterName}DidThrow = false;\n"); - } elsif (BasicTypeCanFailConversion($parameter)) { - push(@implContentDecls, " bool ${parameterName}Ok;\n"); - } - - push(@implContentDecls, " " . GetNativeTypeFromSignature($parameter, $paramIndex) . " $parameterName = "); - - if ($parameter->type eq "SerializedScriptValue") { - push(@implContentDecls, "SerializedScriptValue::create(args[$paramIndex], ${parameterName}DidThrow);\n"); + push(@implContentDecls, " $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], ${parameterName}DidThrow);\n"); push(@implContentDecls, " if (${parameterName}DidThrow)\n"); push(@implContentDecls, " return v8::Undefined();\n"); + } elsif (TypeCanFailConversion($parameter)) { + push(@implContentDecls, " $nativeType $parameterName = " . + JSValueToNative($parameter, "args[$paramIndex]", BasicTypeCanFailConversion($parameter) ? "${parameterName}Ok" : undef) . ";\n"); + push(@implContentDecls, " if (UNLIKELY(!$parameterName" . (BasicTypeCanFailConversion($parameter) ? "Ok" : "") . ")) {\n"); + push(@implContentDecls, " ec = TYPE_MISMATCH_ERR;\n"); + push(@implContentDecls, " goto fail;\n"); + push(@implContentDecls, " }\n"); + } elsif ($nativeType =~ /^V8Parameter/) { + my $value = JSValueToNative($parameter, "args[$paramIndex]", BasicTypeCanFailConversion($parameter) ? "${parameterName}Ok" : undef); + if ($parameter->type eq "DOMString") { + push(@implContentDecls, " STRING_TO_V8PARAMETER_EXCEPTION_BLOCK($nativeType, $parameterName, $value);\n"); + } else { + # Don't know how to properly check for conversion exceptions when $parameter->type is "DOMUserData" + push(@implContentDecls, " $nativeType $parameterName = $value;\n"); + } } else { - push(@implContentDecls, JSValueToNative($parameter, "args[$paramIndex]", - BasicTypeCanFailConversion($parameter) ? "${parameterName}Ok" : undef) . ";\n"); - } - - if (TypeCanFailConversion($parameter)) { - $implIncludes{"ExceptionCode.h"} = 1; - push(@implContentDecls, -" if (UNLIKELY(!$parameterName" . (BasicTypeCanFailConversion($parameter) ? "Ok" : "") . ")) {\n" . -" ec = TYPE_MISMATCH_ERR;\n" . -" goto fail;\n" . -" }\n"); + $implIncludes{"V8BindingMacros.h"} = 1; + push(@implContentDecls, " EXCEPTION_BLOCK($nativeType, $parameterName, " . + JSValueToNative($parameter, "args[$paramIndex]", BasicTypeCanFailConversion($parameter) ? "${parameterName}Ok" : undef) . ");\n"); } if ($parameter->extendedAttributes->{"IsIndex"}) { - $implIncludes{"ExceptionCode.h"} = 1; - push(@implContentDecls, -" if (UNLIKELY($parameterName < 0)) {\n" . -" ec = INDEX_SIZE_ERR;\n" . -" goto fail;\n" . -" }\n"); + push(@implContentDecls, " if (UNLIKELY($parameterName < 0)) {\n"); + push(@implContentDecls, " ec = INDEX_SIZE_ERR;\n"); + push(@implContentDecls, " goto fail;\n"); + push(@implContentDecls, " }\n"); } $paramIndex++; @@ -2129,25 +2143,25 @@ sub GenerateCallbackHeader # - Add default header template push(@headerContent, GenerateHeaderContentHeader($dataNode)); - if ("$interfaceName.h" lt "WorldContextHandle.h") { - push(@headerContent, "#include \"$interfaceName.h\"\n"); - push(@headerContent, "#include \"WorldContextHandle.h\"\n"); - } else { - push(@headerContent, "#include \"WorldContextHandle.h\"\n"); - push(@headerContent, "#include \"$interfaceName.h\"\n"); - } - push(@headerContent, "#include <v8.h>\n"); - push(@headerContent, "#include <wtf/Forward.h>\n"); + my @unsortedIncludes = (); + push(@unsortedIncludes, "#include \"ActiveDOMCallback.h\""); + push(@unsortedIncludes, "#include \"$interfaceName.h\""); + push(@unsortedIncludes, "#include \"WorldContextHandle.h\""); + push(@unsortedIncludes, "#include <v8.h>"); + push(@unsortedIncludes, "#include <wtf/Forward.h>"); + push(@headerContent, join("\n", sort @unsortedIncludes)); - push(@headerContent, "\nnamespace WebCore {\n\n"); - push(@headerContent, "class $className : public $interfaceName {\n"); + push(@headerContent, "\n\nnamespace WebCore {\n\n"); + push(@headerContent, "class ScriptExecutionContext;\n\n"); + push(@headerContent, "class $className : public $interfaceName, public ActiveDOMCallback {\n"); push(@headerContent, <<END); public: - static PassRefPtr<${className}> create(v8::Local<v8::Value> value) + static PassRefPtr<${className}> create(v8::Local<v8::Value> value, ScriptExecutionContext* context) { ASSERT(value->IsObject()); - return adoptRef(new ${className}(value->ToObject())); + ASSERT(context); + return adoptRef(new ${className}(value->ToObject(), context)); } virtual ~${className}(); @@ -2165,11 +2179,13 @@ END push(@headerContent, " COMPILE_ASSERT(false)"); } - push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "(ScriptExecutionContext*"); + push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "("); + + my @args = (); foreach my $param (@params) { - push(@headerContent, ", " . GetNativeTypeForCallbacks($param->type) . " " . $param->name); + push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name); } - + push(@headerContent, join(", ", @args)); push(@headerContent, ");\n"); } } @@ -2177,7 +2193,7 @@ END push(@headerContent, <<END); private: - ${className}(v8::Local<v8::Object>); + ${className}(v8::Local<v8::Object>, ScriptExecutionContext*); v8::Persistent<v8::Object> m_callback; WorldContextHandle m_worldContext; @@ -2209,8 +2225,9 @@ sub GenerateCallbackImplementation push(@implContent, "#include <wtf/Assertions.h>\n\n"); push(@implContent, "namespace WebCore {\n\n"); push(@implContent, <<END); -${className}::${className}(v8::Local<v8::Object> callback) - : m_callback(v8::Persistent<v8::Object>::New(callback)) +${className}::${className}(v8::Local<v8::Object> callback, ScriptExecutionContext* context) + : ActiveDOMCallback(context) + , m_callback(v8::Persistent<v8::Object>::New(callback)) , m_worldContext(UseCurrentWorld) { } @@ -2234,22 +2251,26 @@ END } AddIncludesForType($function->signature->type); - push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "(ScriptExecutionContext* context"); + push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "("); + my @args = (); foreach my $param (@params) { AddIncludesForType($param->type); - push(@implContent, ", " . GetNativeTypeForCallbacks($param->type) . " " . $param->name); + push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name); } + push(@implContent, join(", ", @args)); push(@implContent, ")\n"); push(@implContent, "{\n"); + push(@implContent, " if (!canInvokeCallback())\n"); + push(@implContent, " return true;\n\n"); push(@implContent, " v8::HandleScope handleScope;\n\n"); - push(@implContent, " v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext);\n"); + push(@implContent, " v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);\n"); push(@implContent, " if (v8Context.IsEmpty())\n"); push(@implContent, " return true;\n\n"); push(@implContent, " v8::Context::Scope scope(v8Context);\n\n"); - my @argvs = (); + @args = (); foreach my $param (@params) { my $paramName = $param->name; push(@implContent, " v8::Handle<v8::Value> ${paramName}Handle = toV8(${paramName});\n"); @@ -2257,14 +2278,14 @@ END push(@implContent, " CRASH();\n"); push(@implContent, " return true;\n"); push(@implContent, " }\n"); - push(@argvs, " ${paramName}Handle"); + push(@args, " ${paramName}Handle"); } push(@implContent, "\n v8::Handle<v8::Value> argv[] = {\n"); - push(@implContent, join(",\n", @argvs)); + push(@implContent, join(",\n", @args)); push(@implContent, "\n };\n\n"); push(@implContent, " bool callbackReturnValue = false;\n"); - push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, context);\n"); + push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n"); push(@implContent, "}\n"); } } @@ -2822,7 +2843,8 @@ sub JSValueToNative return "static_cast<$type>($value->NumberValue())" if $type eq "float" or $type eq "double"; return "$value->NumberValue()" if $type eq "SVGNumber"; - return "toInt32($value${maybeOkParam})" if $type eq "unsigned long" or $type eq "unsigned short" or $type eq "long"; + return "toInt32($value${maybeOkParam})" if $type eq "long"; + return "toUInt32($value${maybeOkParam})" if $type eq "unsigned long" or $type eq "unsigned short"; return "toInt64($value)" if $type eq "unsigned long long" or $type eq "long long"; return "static_cast<Range::CompareHow>($value->Int32Value())" if $type eq "CompareHow"; return "static_cast<SVGPaint::SVGPaintType>($value->ToInt32()->Int32Value())" if $type eq "SVGPaintType"; @@ -2952,7 +2974,7 @@ sub RequiresCustomSignature } foreach my $parameter (@{$function->parameters}) { - if ($parameter->extendedAttributes->{"Optional"}) { + if ($parameter->extendedAttributes->{"Optional"} || $parameter->extendedAttributes->{"Callback"}) { return 0; } } diff --git a/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp b/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp index b8c551e..20de4fc 100644 --- a/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp +++ b/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp @@ -85,7 +85,7 @@ WebDOMString WebDOMTestObj::readOnlyStringAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->readOnlyStringAttr()); + return static_cast<const WTF::String&>(impl()->readOnlyStringAttr()); } WebDOMTestObj WebDOMTestObj::readOnlyTestObjAttr() const @@ -149,7 +149,7 @@ WebDOMString WebDOMTestObj::stringAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->stringAttr()); + return static_cast<const WTF::String&>(impl()->stringAttr()); } void WebDOMTestObj::setStringAttr(const WebDOMString& newStringAttr) @@ -213,7 +213,7 @@ WebDOMString WebDOMTestObj::reflectedStringAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->getAttribute(WebCore::HTMLNames::reflectedstringattrAttr)); + return static_cast<const WTF::String&>(impl()->getAttribute(WebCore::HTMLNames::reflectedstringattrAttr)); } void WebDOMTestObj::setReflectedStringAttr(const WebDOMString& newReflectedStringAttr) @@ -261,7 +261,7 @@ WebDOMString WebDOMTestObj::reflectedURLAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->getURLAttribute(WebCore::HTMLNames::reflectedurlattrAttr)); + return static_cast<const WTF::String&>(impl()->getURLAttribute(WebCore::HTMLNames::reflectedurlattrAttr)); } void WebDOMTestObj::setReflectedURLAttr(const WebDOMString& newReflectedURLAttr) @@ -277,7 +277,7 @@ WebDOMString WebDOMTestObj::reflectedNonEmptyURLAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->getNonEmptyURLAttribute(WebCore::HTMLNames::reflectednonemptyurlattrAttr)); + return static_cast<const WTF::String&>(impl()->getNonEmptyURLAttribute(WebCore::HTMLNames::reflectednonemptyurlattrAttr)); } void WebDOMTestObj::setReflectedNonEmptyURLAttr(const WebDOMString& newReflectedNonEmptyURLAttr) @@ -293,7 +293,7 @@ WebDOMString WebDOMTestObj::reflectedStringAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->getAttribute(WebCore::HTMLNames::customContentStringAttrAttr)); + return static_cast<const WTF::String&>(impl()->getAttribute(WebCore::HTMLNames::customContentStringAttrAttr)); } void WebDOMTestObj::setReflectedStringAttr(const WebDOMString& newReflectedStringAttr) @@ -341,7 +341,7 @@ WebDOMString WebDOMTestObj::reflectedCustomURLAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->getURLAttribute(WebCore::HTMLNames::customContentURLAttrAttr)); + return static_cast<const WTF::String&>(impl()->getURLAttribute(WebCore::HTMLNames::customContentURLAttrAttr)); } void WebDOMTestObj::setReflectedCustomURLAttr(const WebDOMString& newReflectedCustomURLAttr) @@ -357,7 +357,7 @@ WebDOMString WebDOMTestObj::reflectedCustomNonEmptyURLAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->getNonEmptyURLAttribute(WebCore::HTMLNames::customContentNonEmptyURLAttrAttr)); + return static_cast<const WTF::String&>(impl()->getNonEmptyURLAttribute(WebCore::HTMLNames::customContentNonEmptyURLAttrAttr)); } void WebDOMTestObj::setReflectedCustomNonEmptyURLAttr(const WebDOMString& newReflectedCustomNonEmptyURLAttr) @@ -415,7 +415,7 @@ WebDOMString WebDOMTestObj::stringAttrWithGetterException() const WebCore::ExceptionCode ec = 0; WebDOMString result = impl()->stringAttrWithGetterException(ec); webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec)); - return static_cast<const WebCore::String&>(result); + return static_cast<const WTF::String&>(result); } void WebDOMTestObj::setStringAttrWithGetterException(const WebDOMString& newStringAttrWithGetterException) @@ -433,7 +433,7 @@ WebDOMString WebDOMTestObj::stringAttrWithSetterException() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->stringAttrWithSetterException()); + return static_cast<const WTF::String&>(impl()->stringAttrWithSetterException()); } void WebDOMTestObj::setStringAttrWithSetterException(const WebDOMString& newStringAttrWithSetterException) @@ -451,7 +451,7 @@ WebDOMString WebDOMTestObj::scriptStringAttr() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->scriptStringAttr()); + return static_cast<const WTF::String&>(impl()->scriptStringAttr()); } #if ENABLE(Condition1) @@ -537,7 +537,7 @@ WebDOMString WebDOMTestObj::hash() const if (!impl()) return WebDOMString(); - return static_cast<const WebCore::String&>(impl()->hash()); + return static_cast<const WTF::String&>(impl()->hash()); } void WebDOMTestObj::voidMethod() @@ -612,7 +612,7 @@ void WebDOMTestObj::serializedValue(const WebDOMString& serializedArg) if (!impl()) return; - impl()->serializedValue(WebCore::SerializedScriptValue::create(WebCore::String(serializedArg))); + impl()->serializedValue(WebCore::SerializedScriptValue::create(WTF::String(serializedArg))); } void WebDOMTestObj::idbKey(const WebDOMIDBKey& key) diff --git a/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.cpp b/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.cpp index 6581b1f..8f69a9f 100644 --- a/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.cpp +++ b/WebCore/bindings/scripts/test/GObject/WebKitDOMTestCallback.cpp @@ -78,7 +78,7 @@ webkit_dom_test_callback_callback_with_class2param(WebKitDOMTestCallback* self, g_return_val_if_fail(str_arg, 0); WebCore::Class2 * converted_class2param = WebKit::core(class2param); g_return_val_if_fail(converted_class2param, 0); - WebCore::String converted_str_arg = WebCore::String::fromUTF8(str_arg); + WTF::String converted_str_arg = WTF::String::fromUTF8(str_arg); gboolean res = item->callbackWithClass2Param(converted_class2param, converted_str_arg); return res; } diff --git a/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp b/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp index 6a8399e..8cad49d 100644 --- a/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp +++ b/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp @@ -69,7 +69,7 @@ webkit_dom_test_obj_void_method_with_args(WebKitDOMTestObj* self, glong int_arg, WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(str_arg); g_return_if_fail(obj_arg); - WebCore::String converted_str_arg = WebCore::String::fromUTF8(str_arg); + WTF::String converted_str_arg = WTF::String::fromUTF8(str_arg); WebCore::TestObj * converted_obj_arg = WebKit::core(obj_arg); g_return_if_fail(converted_obj_arg); item->voidMethodWithArgs(int_arg, converted_str_arg, converted_obj_arg); @@ -93,7 +93,7 @@ webkit_dom_test_obj_int_method_with_args(WebKitDOMTestObj* self, glong int_arg, WebCore::TestObj * item = WebKit::core(self); g_return_val_if_fail(str_arg, 0); g_return_val_if_fail(obj_arg, 0); - WebCore::String converted_str_arg = WebCore::String::fromUTF8(str_arg); + WTF::String converted_str_arg = WTF::String::fromUTF8(str_arg); WebCore::TestObj * converted_obj_arg = WebKit::core(obj_arg); g_return_val_if_fail(converted_obj_arg, 0); glong res = item->intMethodWithArgs(int_arg, converted_str_arg, converted_obj_arg); @@ -119,7 +119,7 @@ webkit_dom_test_obj_obj_method_with_args(WebKitDOMTestObj* self, glong int_arg, WebCore::TestObj * item = WebKit::core(self); g_return_val_if_fail(str_arg, 0); g_return_val_if_fail(obj_arg, 0); - WebCore::String converted_str_arg = WebCore::String::fromUTF8(str_arg); + WTF::String converted_str_arg = WTF::String::fromUTF8(str_arg); WebCore::TestObj * converted_obj_arg = WebKit::core(obj_arg); g_return_val_if_fail(converted_obj_arg, 0); PassRefPtr<WebCore::TestObj> g_res = WTF::getPtr(item->objMethodWithArgs(int_arg, converted_str_arg, converted_obj_arg)); @@ -135,7 +135,7 @@ webkit_dom_test_obj_method_that_requires_all_args(WebKitDOMTestObj* self, gchar* WebCore::TestObj * item = WebKit::core(self); g_return_val_if_fail(str_arg, 0); g_return_val_if_fail(obj_arg, 0); - WebCore::String converted_str_arg = WebCore::String::fromUTF8(str_arg); + WTF::String converted_str_arg = WTF::String::fromUTF8(str_arg); WebCore::TestObj * converted_obj_arg = WebKit::core(obj_arg); g_return_val_if_fail(converted_obj_arg, 0); PassRefPtr<WebCore::TestObj> g_res = WTF::getPtr(item->methodThatRequiresAllArgs(converted_str_arg, converted_obj_arg)); @@ -151,7 +151,7 @@ webkit_dom_test_obj_method_that_requires_all_args_and_throws(WebKitDOMTestObj* s WebCore::TestObj * item = WebKit::core(self); g_return_val_if_fail(str_arg, 0); g_return_val_if_fail(obj_arg, 0); - WebCore::String converted_str_arg = WebCore::String::fromUTF8(str_arg); + WTF::String converted_str_arg = WTF::String::fromUTF8(str_arg); WebCore::TestObj * converted_obj_arg = WebKit::core(obj_arg); g_return_val_if_fail(converted_obj_arg, 0); WebCore::ExceptionCode ec = 0; @@ -448,7 +448,7 @@ webkit_dom_test_obj_set_string_attr(WebKitDOMTestObj* self, gchar* value) g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setStringAttr(converted_value); } @@ -534,7 +534,7 @@ webkit_dom_test_obj_set_reflected_string_attr(WebKitDOMTestObj* self, gchar* va g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setAttribute(WebCore::HTMLNames::reflectedstringattrAttr, converted_value); } @@ -593,7 +593,7 @@ webkit_dom_test_obj_set_reflected_url_attr(WebKitDOMTestObj* self, gchar* value g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setAttribute(WebCore::HTMLNames::reflectedurlattrAttr, converted_value); } @@ -614,7 +614,7 @@ webkit_dom_test_obj_set_reflected_non_empty_url_attr(WebKitDOMTestObj* self, gch g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setAttribute(WebCore::HTMLNames::reflectednonemptyurlattrAttr, converted_value); } @@ -635,7 +635,7 @@ webkit_dom_test_obj_set_reflected_string_attr(WebKitDOMTestObj* self, gchar* va g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setAttribute(WebCore::HTMLNames::customContentStringAttrAttr, converted_value); } @@ -694,7 +694,7 @@ webkit_dom_test_obj_set_reflected_custom_url_attr(WebKitDOMTestObj* self, gchar* g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setAttribute(WebCore::HTMLNames::customContentURLAttrAttr, converted_value); } @@ -715,7 +715,7 @@ webkit_dom_test_obj_set_reflected_custom_non_empty_url_attr(WebKitDOMTestObj* se g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); item->setAttribute(WebCore::HTMLNames::customContentNonEmptyURLAttrAttr, converted_value); } @@ -793,7 +793,7 @@ webkit_dom_test_obj_set_string_attr_with_getter_exception(WebKitDOMTestObj* self g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); WebCore::ExceptionCode ec = 0; item->setStringAttrWithGetterException(converted_value, ec); if (ec) { @@ -820,7 +820,7 @@ webkit_dom_test_obj_set_string_attr_with_setter_exception(WebKitDOMTestObj* self g_return_if_fail(self); WebCore::TestObj * item = WebKit::core(self); g_return_if_fail(value); - WebCore::String converted_value = WebCore::String::fromUTF8(value); + WTF::String converted_value = WTF::String::fromUTF8(value); WebCore::ExceptionCode ec = 0; item->setStringAttrWithSetterException(converted_value, ec); if (ec) { @@ -1041,7 +1041,7 @@ static void webkit_dom_test_obj_set_property(GObject* object, guint prop_id, con } case PROP_STRING_ATTR: { - coreSelf->setStringAttr(WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setStringAttr(WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_CREATE: @@ -1051,7 +1051,7 @@ static void webkit_dom_test_obj_set_property(GObject* object, guint prop_id, con } case PROP_REFLECTED_STRING_ATTR: { - coreSelf->setAttribute(WebCore::HTMLNames::reflectedstringattrAttr, WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setAttribute(WebCore::HTMLNames::reflectedstringattrAttr, WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_REFLECTED_INTEGRAL_ATTR: @@ -1066,17 +1066,17 @@ static void webkit_dom_test_obj_set_property(GObject* object, guint prop_id, con } case PROP_REFLECTED_URL_ATTR: { - coreSelf->setAttribute(WebCore::HTMLNames::reflectedurlattrAttr, WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setAttribute(WebCore::HTMLNames::reflectedurlattrAttr, WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_REFLECTED_NON_EMPTY_URL_ATTR: { - coreSelf->setAttribute(WebCore::HTMLNames::reflectednonemptyurlattrAttr, WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setAttribute(WebCore::HTMLNames::reflectednonemptyurlattrAttr, WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_REFLECTED_STRING_ATTR: { - coreSelf->setAttribute(WebCore::HTMLNames::customContentStringAttrAttr, WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setAttribute(WebCore::HTMLNames::customContentStringAttrAttr, WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_REFLECTED_CUSTOM_INTEGRAL_ATTR: @@ -1091,12 +1091,12 @@ static void webkit_dom_test_obj_set_property(GObject* object, guint prop_id, con } case PROP_REFLECTED_CUSTOM_URL_ATTR: { - coreSelf->setAttribute(WebCore::HTMLNames::customContentURLAttrAttr, WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setAttribute(WebCore::HTMLNames::customContentURLAttrAttr, WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_REFLECTED_CUSTOM_NON_EMPTY_URL_ATTR: { - coreSelf->setAttribute(WebCore::HTMLNames::customContentNonEmptyURLAttrAttr, WebCore::String::fromUTF8(g_value_get_string(value))); + coreSelf->setAttribute(WebCore::HTMLNames::customContentNonEmptyURLAttrAttr, WTF::String::fromUTF8(g_value_get_string(value))); break; } case PROP_ATTR_WITH_GETTER_EXCEPTION: @@ -1114,13 +1114,13 @@ static void webkit_dom_test_obj_set_property(GObject* object, guint prop_id, con case PROP_STRING_ATTR_WITH_GETTER_EXCEPTION: { WebCore::ExceptionCode ec = 0; - coreSelf->setStringAttrWithGetterException(WebCore::String::fromUTF8(g_value_get_string(value)), ec); + coreSelf->setStringAttrWithGetterException(WTF::String::fromUTF8(g_value_get_string(value)), ec); break; } case PROP_STRING_ATTR_WITH_SETTER_EXCEPTION: { WebCore::ExceptionCode ec = 0; - coreSelf->setStringAttrWithSetterException(WebCore::String::fromUTF8(g_value_get_string(value)), ec); + coreSelf->setStringAttrWithSetterException(WTF::String::fromUTF8(g_value_get_string(value)), ec); break; } #if ENABLE(Condition1) diff --git a/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp b/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp index 6f6b568..069b8ae 100644 --- a/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp +++ b/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp @@ -35,18 +35,20 @@ using namespace JSC; namespace WebCore { JSTestCallback::JSTestCallback(JSObject* callback, JSDOMGlobalObject* globalObject) - : m_data(new JSCallbackData(callback, globalObject)) - , m_isolatedWorld(globalObject->world()) - , m_scriptExecutionContext(globalObject->scriptExecutionContext()) + : ActiveDOMCallback(globalObject->scriptExecutionContext()) + , m_data(new JSCallbackData(callback, globalObject)) { } JSTestCallback::~JSTestCallback() { - if (m_scriptExecutionContext->isContextThread()) + ScriptExecutionContext* context = scriptExecutionContext(); + // When the context is destroyed, all tasks with a reference to a callback + // should be deleted. So if the context is 0, we are on the context thread. + if (!context || context->isContextThread()) delete m_data; else - m_scriptExecutionContext->postTask(DeleteCallbackDataTask::create(m_data)); + context->postTask(DeleteCallbackDataTask::create(m_data)); #ifndef NDEBUG m_data = 0; #endif @@ -54,20 +56,16 @@ JSTestCallback::~JSTestCallback() // Functions -bool JSTestCallback::callbackWithClass1Param(ScriptExecutionContext* context, Class1* class1Param) +bool JSTestCallback::callbackWithClass1Param(Class1* class1Param) { - ASSERT(m_data); - ASSERT(context); + if (!canInvokeCallback()) + return true; RefPtr<JSTestCallback> protect(this); JSLock lock(SilenceAssertionsOnly); - JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, m_isolatedWorld.get()); - if (!globalObject) - return true; - - ExecState* exec = globalObject->globalExec(); + ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; args.append(toJS(exec, class1Param)); @@ -76,20 +74,16 @@ bool JSTestCallback::callbackWithClass1Param(ScriptExecutionContext* context, Cl return !raisedException; } -bool JSTestCallback::callbackWithClass2Param(ScriptExecutionContext* context, Class2* class2Param, const String& strArg) +bool JSTestCallback::callbackWithClass2Param(Class2* class2Param, const String& strArg) { - ASSERT(m_data); - ASSERT(context); + if (!canInvokeCallback()) + return true; RefPtr<JSTestCallback> protect(this); JSLock lock(SilenceAssertionsOnly); - JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, m_isolatedWorld.get()); - if (!globalObject) - return true; - - ExecState* exec = globalObject->globalExec(); + ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; args.append(toJS(exec, class2Param)); args.append(jsString(exec, strArg)); diff --git a/WebCore/bindings/scripts/test/JS/JSTestCallback.h b/WebCore/bindings/scripts/test/JS/JSTestCallback.h index 47a5e95..ae91a6c 100644 --- a/WebCore/bindings/scripts/test/JS/JSTestCallback.h +++ b/WebCore/bindings/scripts/test/JS/JSTestCallback.h @@ -23,13 +23,14 @@ #if ENABLE(DATABASE) +#include "ActiveDOMCallback.h" #include "JSCallbackData.h" #include "TestCallback.h" #include <wtf/Forward.h> namespace WebCore { -class JSTestCallback : public TestCallback { +class JSTestCallback : public TestCallback, public ActiveDOMCallback { public: static PassRefPtr<JSTestCallback> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject) { @@ -39,17 +40,15 @@ public: virtual ~JSTestCallback(); // Functions - virtual bool callbackWithClass1Param(ScriptExecutionContext*, Class1* class1Param); - virtual bool callbackWithClass2Param(ScriptExecutionContext*, Class2* class2Param, const String& strArg); - COMPILE_ASSERT(false) virtual int callbackWithNonBoolReturnType(ScriptExecutionContext*, Class3* class3Param); - virtual int customCallback(ScriptExecutionContext*, Class5* class5Param, Class6* class6Param); + virtual bool callbackWithClass1Param(Class1* class1Param); + virtual bool callbackWithClass2Param(Class2* class2Param, const String& strArg); + COMPILE_ASSERT(false) virtual int callbackWithNonBoolReturnType(Class3* class3Param); + virtual int customCallback(Class5* class5Param, Class6* class6Param); private: JSTestCallback(JSC::JSObject* callback, JSDOMGlobalObject*); JSCallbackData* m_data; - RefPtr<DOMWrapperWorld> m_isolatedWorld; - ScriptExecutionContext* m_scriptExecutionContext; }; } // namespace WebCore diff --git a/WebCore/bindings/scripts/test/JS/JSTestObj.cpp b/WebCore/bindings/scripts/test/JS/JSTestObj.cpp index 9c11bde..01a860c 100644 --- a/WebCore/bindings/scripts/test/JS/JSTestObj.cpp +++ b/WebCore/bindings/scripts/test/JS/JSTestObj.cpp @@ -25,6 +25,7 @@ #include "HTMLNames.h" #include "IDBBindingUtilities.h" #include "IDBKey.h" +#include "JSDOMBinding.h" #include "JSEventListener.h" #include "JSTestCallback.h" #include "JSTestObj.h" @@ -794,8 +795,14 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionVoidMethodWithArgs(ExecSt JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); const String& strArg = ustringToString(exec->argument(1).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); TestObj* objArg = toTestObj(exec->argument(2)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->voidMethodWithArgs(intArg, strArg, objArg); return JSValue::encode(jsUndefined()); @@ -822,8 +829,14 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionIntMethodWithArgs(ExecSta JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); const String& strArg = ustringToString(exec->argument(1).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); TestObj* objArg = toTestObj(exec->argument(2)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); JSC::JSValue result = jsNumber(exec, imp->intMethodWithArgs(intArg, strArg, objArg)); @@ -851,8 +864,14 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionObjMethodWithArgs(ExecSta JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); const String& strArg = ustringToString(exec->argument(1).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); TestObj* objArg = toTestObj(exec->argument(2)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->objMethodWithArgs(intArg, strArg, objArg))); @@ -869,7 +888,11 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodThatRequiresAllArgs if (exec->argumentCount() < 2) return JSValue::encode(jsUndefined()); const String& strArg = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); TestObj* objArg = toTestObj(exec->argument(1)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->methodThatRequiresAllArgs(strArg, objArg))); @@ -887,7 +910,11 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodThatRequiresAllArgs return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); ExceptionCode ec = 0; const String& strArg = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); TestObj* objArg = toTestObj(exec->argument(1)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->methodThatRequiresAllArgsAndThrows(strArg, objArg, ec))); @@ -903,6 +930,8 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionSerializedValue(ExecState JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); RefPtr<SerializedScriptValue> serializedArg = SerializedScriptValue::create(exec, exec->argument(0)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->serializedValue(serializedArg); return JSValue::encode(jsUndefined()); @@ -916,6 +945,8 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionIdbKey(ExecState* exec) JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); RefPtr<IDBKey> key = createIDBKeyFromValue(exec, exec->argument(0)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->idbKey(key); return JSValue::encode(jsUndefined()); @@ -963,6 +994,8 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionCustomArgsAndException(Ex ExceptionCode ec = 0; ScriptCallStack callStack(exec, 1); log* intArg = tolog(exec->argument(0)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->customArgsAndException(intArg, &callStack, ec); setDOMException(exec, ec); @@ -1023,6 +1056,8 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrameAndArg(Ex if (!dynamicFrame) return JSValue::encode(jsUndefined()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->withDynamicFrameAndArg(dynamicFrame, intArg); return JSValue::encode(jsUndefined()); @@ -1039,14 +1074,18 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrameAndOption if (!dynamicFrame) return JSValue::encode(jsUndefined()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); int argsCount = exec->argumentCount(); - if (argsCount < 2) { + if (argsCount <= 1) { imp->withDynamicFrameAndOptionalArg(dynamicFrame, intArg); return JSValue::encode(jsUndefined()); } int optionalArg = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->withDynamicFrameAndOptionalArg(dynamicFrame, intArg, optionalArg); return JSValue::encode(jsUndefined()); @@ -1063,6 +1102,8 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrameAndUserGe if (!dynamicFrame) return JSValue::encode(jsUndefined()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->withDynamicFrameAndUserGesture(dynamicFrame, intArg, processingUserGesture(exec)); return JSValue::encode(jsUndefined()); @@ -1079,14 +1120,18 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionWithDynamicFrameAndUserGe if (!dynamicFrame) return JSValue::encode(jsUndefined()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); int argsCount = exec->argumentCount(); - if (argsCount < 2) { + if (argsCount <= 1) { imp->withDynamicFrameAndUserGestureASAD(dynamicFrame, intArg); return JSValue::encode(jsUndefined()); } int optionalArg = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->withDynamicFrameAndUserGestureASAD(dynamicFrame, intArg, optionalArg, processingUserGesture(exec)); return JSValue::encode(jsUndefined()); @@ -1174,12 +1219,14 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalArg(Exe TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int argsCount = exec->argumentCount(); - if (argsCount < 1) { + if (argsCount <= 0) { imp->methodWithOptionalArg(); return JSValue::encode(jsUndefined()); } int opt = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->methodWithOptionalArg(opt); return JSValue::encode(jsUndefined()); @@ -1193,14 +1240,18 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonOptionalArgA JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int nonOpt = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); int argsCount = exec->argumentCount(); - if (argsCount < 2) { + if (argsCount <= 1) { imp->methodWithNonOptionalArgAndOptionalArg(nonOpt); return JSValue::encode(jsUndefined()); } int opt = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->methodWithNonOptionalArgAndOptionalArg(nonOpt, opt); return JSValue::encode(jsUndefined()); @@ -1214,15 +1265,21 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonOptionalArgA JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int nonOpt = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); int argsCount = exec->argumentCount(); - if (argsCount < 2) { + if (argsCount <= 1) { imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt); return JSValue::encode(jsUndefined()); } int opt1 = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); int opt2 = exec->argument(2).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2); return JSValue::encode(jsUndefined()); @@ -1237,7 +1294,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackArg(Exe TestObj* imp = static_cast<TestObj*>(castedThis->impl()); if (exec->argumentCount() <= 0 || !exec->argument(0).isObject()) { setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); + return JSValue::encode(jsUndefined()); } RefPtr<TestCallback> callback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject()); @@ -1253,9 +1310,11 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithNonCallbackArgA JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int nonCallback = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); if (exec->argumentCount() <= 1 || !exec->argument(1).isObject()) { setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); + return JSValue::encode(jsUndefined()); } RefPtr<TestCallback> callback = JSTestCallback::create(asObject(exec->argument(1)), castedThis->globalObject()); @@ -1270,18 +1329,14 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithCallbackAndOpti return throwVMTypeError(exec); JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); - - int argsCount = exec->argumentCount(); - if (argsCount < 1) { - imp->methodWithCallbackAndOptionalArg(); - return JSValue::encode(jsUndefined()); - } - - if (exec->argumentCount() <= 0 || !exec->argument(0).isObject()) { - setDOMException(exec, TYPE_MISMATCH_ERR); - return jsUndefined(); + RefPtr<TestCallback> callback; + if (exec->argumentCount() > 0 && !exec->argument(0).isNull() && !exec->argument(0).isUndefined()) { + if (!exec->argument(0).isObject()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return JSValue::encode(jsUndefined()); + } + callback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject()); } - RefPtr<TestCallback> callback = JSTestCallback::create(asObject(exec->argument(0)), castedThis->globalObject()); imp->methodWithCallbackAndOptionalArg(callback); return JSValue::encode(jsUndefined()); @@ -1295,7 +1350,11 @@ static EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethod1( JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); TestObj* objArg = toTestObj(exec->argument(0)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); const String& strArg = ustringToString(exec->argument(1).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->overloadedMethod(objArg, strArg); return JSValue::encode(jsUndefined()); @@ -1309,14 +1368,18 @@ static EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethod2( JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); TestObj* objArg = toTestObj(exec->argument(0)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); int argsCount = exec->argumentCount(); - if (argsCount < 2) { + if (argsCount <= 1) { imp->overloadedMethod(objArg); return JSValue::encode(jsUndefined()); } int intArg = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->overloadedMethod(objArg, intArg); return JSValue::encode(jsUndefined()); @@ -1330,6 +1393,8 @@ static EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethod3( JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); const String& strArg = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->overloadedMethod(strArg); return JSValue::encode(jsUndefined()); @@ -1343,6 +1408,8 @@ static EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionOverloadedMethod4( JSTestObj* castedThis = static_cast<JSTestObj*>(asObject(thisValue)); TestObj* imp = static_cast<TestObj*>(castedThis->impl()); int intArg = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); imp->overloadedMethod(intArg); return JSValue::encode(jsUndefined()); diff --git a/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm b/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm index 71d3508..01fcf34 100644 --- a/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm +++ b/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm @@ -500,7 +500,7 @@ - (void)serializedValue:(NSString *)serializedArg { WebCore::JSMainThreadNullState state; - IMPL->serializedValue(WebCore::SerializedScriptValue::create(WebCore::String(serializedArg))); + IMPL->serializedValue(WebCore::SerializedScriptValue::create(WTF::String(serializedArg))); } - (void)idbKey:(DOMIDBKey *)key diff --git a/WebCore/bindings/scripts/test/V8/V8TestCallback.cpp b/WebCore/bindings/scripts/test/V8/V8TestCallback.cpp index eff4ebd..c286c24 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestCallback.cpp +++ b/WebCore/bindings/scripts/test/V8/V8TestCallback.cpp @@ -34,8 +34,9 @@ namespace WebCore { -V8TestCallback::V8TestCallback(v8::Local<v8::Object> callback) - : m_callback(v8::Persistent<v8::Object>::New(callback)) +V8TestCallback::V8TestCallback(v8::Local<v8::Object> callback, ScriptExecutionContext* context) + : ActiveDOMCallback(context) + , m_callback(v8::Persistent<v8::Object>::New(callback)) , m_worldContext(UseCurrentWorld) { } @@ -47,11 +48,14 @@ V8TestCallback::~V8TestCallback() // Functions -bool V8TestCallback::callbackWithClass1Param(ScriptExecutionContext* context, Class1* class1Param) +bool V8TestCallback::callbackWithClass1Param(Class1* class1Param) { + if (!canInvokeCallback()) + return true; + v8::HandleScope handleScope; - v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; @@ -68,14 +72,17 @@ bool V8TestCallback::callbackWithClass1Param(ScriptExecutionContext* context, Cl }; bool callbackReturnValue = false; - return !invokeCallback(m_callback, 1, argv, callbackReturnValue, context); + return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext()); } -bool V8TestCallback::callbackWithClass2Param(ScriptExecutionContext* context, Class2* class2Param, const String& strArg) +bool V8TestCallback::callbackWithClass2Param(Class2* class2Param, const String& strArg) { + if (!canInvokeCallback()) + return true; + v8::HandleScope handleScope; - v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; @@ -98,7 +105,7 @@ bool V8TestCallback::callbackWithClass2Param(ScriptExecutionContext* context, Cl }; bool callbackReturnValue = false; - return !invokeCallback(m_callback, 2, argv, callbackReturnValue, context); + return !invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext()); } } // namespace WebCore diff --git a/WebCore/bindings/scripts/test/V8/V8TestCallback.h b/WebCore/bindings/scripts/test/V8/V8TestCallback.h index aed6b22..a105d75 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestCallback.h +++ b/WebCore/bindings/scripts/test/V8/V8TestCallback.h @@ -23,6 +23,7 @@ #ifndef V8TestCallback_h #define V8TestCallback_h +#include "ActiveDOMCallback.h" #include "TestCallback.h" #include "WorldContextHandle.h" #include <v8.h> @@ -30,24 +31,27 @@ namespace WebCore { -class V8TestCallback : public TestCallback { +class ScriptExecutionContext; + +class V8TestCallback : public TestCallback, public ActiveDOMCallback { public: - static PassRefPtr<V8TestCallback> create(v8::Local<v8::Value> value) + static PassRefPtr<V8TestCallback> create(v8::Local<v8::Value> value, ScriptExecutionContext* context) { ASSERT(value->IsObject()); - return adoptRef(new V8TestCallback(value->ToObject())); + ASSERT(context); + return adoptRef(new V8TestCallback(value->ToObject(), context)); } virtual ~V8TestCallback(); // Functions - virtual bool callbackWithClass1Param(ScriptExecutionContext*, Class1* class1Param); - virtual bool callbackWithClass2Param(ScriptExecutionContext*, Class2* class2Param, const String& strArg); - COMPILE_ASSERT(false) virtual int callbackWithNonBoolReturnType(ScriptExecutionContext*, Class3* class3Param); - virtual int customCallback(ScriptExecutionContext*, Class5* class5Param, Class6* class6Param); + virtual bool callbackWithClass1Param(Class1* class1Param); + virtual bool callbackWithClass2Param(Class2* class2Param, const String& strArg); + COMPILE_ASSERT(false) virtual int callbackWithNonBoolReturnType(Class3* class3Param); + virtual int customCallback(Class5* class5Param, Class6* class6Param); private: - V8TestCallback(v8::Local<v8::Object>); + V8TestCallback(v8::Local<v8::Object>, ScriptExecutionContext*); v8::Persistent<v8::Object> m_callback; WorldContextHandle m_worldContext; diff --git a/WebCore/bindings/scripts/test/V8/V8TestObj.cpp b/WebCore/bindings/scripts/test/V8/V8TestObj.cpp index 5584eaf..7428c93 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestObj.cpp +++ b/WebCore/bindings/scripts/test/V8/V8TestObj.cpp @@ -29,6 +29,7 @@ #include "ScriptCallStack.h" #include "SerializedScriptValue.h" #include "V8Binding.h" +#include "V8BindingMacros.h" #include "V8BindingState.h" #include "V8DOMWrapper.h" #include "V8IsolatedContext.h" @@ -556,9 +557,9 @@ static v8::Handle<v8::Value> voidMethodWithArgsCallback(const v8::Arguments& arg { INC_STATS("DOM.TestObj.voidMethodWithArgs"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); - V8Parameter<> strArg = args[1]; - TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0; + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[1]); + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0); imp->voidMethodWithArgs(intArg, strArg, objArg); return v8::Handle<v8::Value>(); } @@ -574,9 +575,9 @@ static v8::Handle<v8::Value> intMethodWithArgsCallback(const v8::Arguments& args { INC_STATS("DOM.TestObj.intMethodWithArgs"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); - V8Parameter<> strArg = args[1]; - TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0; + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[1]); + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0); return v8::Integer::New(imp->intMethodWithArgs(intArg, strArg, objArg)); } @@ -591,9 +592,9 @@ static v8::Handle<v8::Value> objMethodWithArgsCallback(const v8::Arguments& args { INC_STATS("DOM.TestObj.objMethodWithArgs"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); - V8Parameter<> strArg = args[1]; - TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0; + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[1]); + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0); return toV8(imp->objMethodWithArgs(intArg, strArg, objArg)); } @@ -603,8 +604,8 @@ static v8::Handle<v8::Value> methodThatRequiresAllArgsCallback(const v8::Argumen if (args.Length() < 2) return v8::Handle<v8::Value>(); TestObj* imp = V8TestObj::toNative(args.Holder()); - V8Parameter<> strArg = args[0]; - TestObj* objArg = V8TestObj::HasInstance(args[1]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[0]); + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[1]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0); return toV8(imp->methodThatRequiresAllArgs(strArg, objArg)); } @@ -616,8 +617,8 @@ static v8::Handle<v8::Value> methodThatRequiresAllArgsAndThrowsCallback(const v8 TestObj* imp = V8TestObj::toNative(args.Holder()); ExceptionCode ec = 0; { - V8Parameter<> strArg = args[0]; - TestObj* objArg = V8TestObj::HasInstance(args[1]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0; + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[0]); + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[1]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0); RefPtr<TestObj> result = imp->methodThatRequiresAllArgsAndThrows(strArg, objArg, ec); if (UNLIKELY(ec)) goto fail; @@ -644,7 +645,7 @@ static v8::Handle<v8::Value> idbKeyCallback(const v8::Arguments& args) { INC_STATS("DOM.TestObj.idbKey"); TestObj* imp = V8TestObj::toNative(args.Holder()); - RefPtr<IDBKey> key = createIDBKeyFromValue(args[0]); + EXCEPTION_BLOCK(RefPtr<IDBKey>, key, createIDBKeyFromValue(args[0])); imp->idbKey(key); return v8::Handle<v8::Value>(); } @@ -674,7 +675,7 @@ static v8::Handle<v8::Value> customArgsAndExceptionCallback(const v8::Arguments& OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, 1)); if (!callStack) return v8::Undefined(); - log* intArg = V8log::HasInstance(args[0]) ? V8log::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + EXCEPTION_BLOCK(log*, intArg, V8log::HasInstance(args[0]) ? V8log::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); imp->customArgsAndException(intArg, callStack.get(), ec); if (UNLIKELY(ec)) goto fail; @@ -722,7 +723,7 @@ static v8::Handle<v8::Value> withDynamicFrameAndArgCallback(const v8::Arguments& { INC_STATS("DOM.TestObj.withDynamicFrameAndArg"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); if (!enteredFrame) return v8::Undefined(); @@ -734,7 +735,7 @@ static v8::Handle<v8::Value> withDynamicFrameAndOptionalArgCallback(const v8::Ar { INC_STATS("DOM.TestObj.withDynamicFrameAndOptionalArg"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); if (args.Length() <= 1) { Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); if (!enteredFrame) @@ -742,7 +743,7 @@ static v8::Handle<v8::Value> withDynamicFrameAndOptionalArgCallback(const v8::Ar imp->withDynamicFrameAndOptionalArg(enteredFrame, intArg); return v8::Handle<v8::Value>(); } - int optionalArg = toInt32(args[1]); + EXCEPTION_BLOCK(int, optionalArg, toInt32(args[1])); Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); if (!enteredFrame) return v8::Undefined(); @@ -754,7 +755,7 @@ static v8::Handle<v8::Value> withDynamicFrameAndUserGestureCallback(const v8::Ar { INC_STATS("DOM.TestObj.withDynamicFrameAndUserGesture"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); if (!enteredFrame) return v8::Undefined(); @@ -766,7 +767,7 @@ static v8::Handle<v8::Value> withDynamicFrameAndUserGestureASADCallback(const v8 { INC_STATS("DOM.TestObj.withDynamicFrameAndUserGestureASAD"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); if (args.Length() <= 1) { Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); if (!enteredFrame) @@ -774,7 +775,7 @@ static v8::Handle<v8::Value> withDynamicFrameAndUserGestureASADCallback(const v8 imp->withDynamicFrameAndUserGestureASAD(enteredFrame, intArg, processingUserGesture()); return v8::Handle<v8::Value>(); } - int optionalArg = toInt32(args[1]); + EXCEPTION_BLOCK(int, optionalArg, toInt32(args[1])); Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); if (!enteredFrame) return v8::Undefined(); @@ -861,7 +862,7 @@ static v8::Handle<v8::Value> methodWithOptionalArgCallback(const v8::Arguments& imp->methodWithOptionalArg(); return v8::Handle<v8::Value>(); } - int opt = toInt32(args[0]); + EXCEPTION_BLOCK(int, opt, toInt32(args[0])); imp->methodWithOptionalArg(opt); return v8::Handle<v8::Value>(); } @@ -870,12 +871,12 @@ static v8::Handle<v8::Value> methodWithNonOptionalArgAndOptionalArgCallback(cons { INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndOptionalArg"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int nonOpt = toInt32(args[0]); + EXCEPTION_BLOCK(int, nonOpt, toInt32(args[0])); if (args.Length() <= 1) { imp->methodWithNonOptionalArgAndOptionalArg(nonOpt); return v8::Handle<v8::Value>(); } - int opt = toInt32(args[1]); + EXCEPTION_BLOCK(int, opt, toInt32(args[1])); imp->methodWithNonOptionalArgAndOptionalArg(nonOpt, opt); return v8::Handle<v8::Value>(); } @@ -884,13 +885,13 @@ static v8::Handle<v8::Value> methodWithNonOptionalArgAndTwoOptionalArgsCallback( { INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndTwoOptionalArgs"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int nonOpt = toInt32(args[0]); + EXCEPTION_BLOCK(int, nonOpt, toInt32(args[0])); if (args.Length() <= 1) { imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt); return v8::Handle<v8::Value>(); } - int opt1 = toInt32(args[1]); - int opt2 = toInt32(args[2]); + EXCEPTION_BLOCK(int, opt1, toInt32(args[1])); + EXCEPTION_BLOCK(int, opt2, toInt32(args[2])); imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2); return v8::Handle<v8::Value>(); } @@ -901,7 +902,7 @@ static v8::Handle<v8::Value> methodWithCallbackArgCallback(const v8::Arguments& TestObj* imp = V8TestObj::toNative(args.Holder()); if (args.Length() <= 0 || !args[0]->IsObject()) return throwError(TYPE_MISMATCH_ERR); - RefPtr<TestCallback> callback = V8TestCallback::create(args[0]); + RefPtr<TestCallback> callback = V8TestCallback::create(args[0], getScriptExecutionContext()); imp->methodWithCallbackArg(callback); return v8::Handle<v8::Value>(); } @@ -910,10 +911,10 @@ static v8::Handle<v8::Value> methodWithNonCallbackArgAndCallbackArgCallback(cons { INC_STATS("DOM.TestObj.methodWithNonCallbackArgAndCallbackArg"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int nonCallback = toInt32(args[0]); + EXCEPTION_BLOCK(int, nonCallback, toInt32(args[0])); if (args.Length() <= 1 || !args[1]->IsObject()) return throwError(TYPE_MISMATCH_ERR); - RefPtr<TestCallback> callback = V8TestCallback::create(args[1]); + RefPtr<TestCallback> callback = V8TestCallback::create(args[1], getScriptExecutionContext()); imp->methodWithNonCallbackArgAndCallbackArg(nonCallback, callback); return v8::Handle<v8::Value>(); } @@ -922,13 +923,12 @@ static v8::Handle<v8::Value> methodWithCallbackAndOptionalArgCallback(const v8:: { INC_STATS("DOM.TestObj.methodWithCallbackAndOptionalArg"); TestObj* imp = V8TestObj::toNative(args.Holder()); - if (args.Length() <= 0) { - imp->methodWithCallbackAndOptionalArg(); - return v8::Handle<v8::Value>(); + RefPtr<TestCallback> callback; + if (args.Length() > 0 && !args[0]->IsNull() && !args[0]->IsUndefined()) { + if (!args[0]->IsObject()) + return throwError(TYPE_MISMATCH_ERR); + callback = V8TestCallback::create(args[0], getScriptExecutionContext()); } - if (args.Length() <= 0 || !args[0]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - RefPtr<TestCallback> callback = V8TestCallback::create(args[0]); imp->methodWithCallbackAndOptionalArg(callback); return v8::Handle<v8::Value>(); } @@ -937,8 +937,8 @@ static v8::Handle<v8::Value> overloadedMethod1Callback(const v8::Arguments& args { INC_STATS("DOM.TestObj.overloadedMethod1"); TestObj* imp = V8TestObj::toNative(args.Holder()); - TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; - V8Parameter<> strArg = args[1]; + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[1]); imp->overloadedMethod(objArg, strArg); return v8::Handle<v8::Value>(); } @@ -947,12 +947,12 @@ static v8::Handle<v8::Value> overloadedMethod2Callback(const v8::Arguments& args { INC_STATS("DOM.TestObj.overloadedMethod2"); TestObj* imp = V8TestObj::toNative(args.Holder()); - TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + EXCEPTION_BLOCK(TestObj*, objArg, V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); if (args.Length() <= 1) { imp->overloadedMethod(objArg); return v8::Handle<v8::Value>(); } - int intArg = toInt32(args[1]); + EXCEPTION_BLOCK(int, intArg, toInt32(args[1])); imp->overloadedMethod(objArg, intArg); return v8::Handle<v8::Value>(); } @@ -961,7 +961,7 @@ static v8::Handle<v8::Value> overloadedMethod3Callback(const v8::Arguments& args { INC_STATS("DOM.TestObj.overloadedMethod3"); TestObj* imp = V8TestObj::toNative(args.Holder()); - V8Parameter<> strArg = args[0]; + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, strArg, args[0]); imp->overloadedMethod(strArg); return v8::Handle<v8::Value>(); } @@ -970,7 +970,7 @@ static v8::Handle<v8::Value> overloadedMethod4Callback(const v8::Arguments& args { INC_STATS("DOM.TestObj.overloadedMethod4"); TestObj* imp = V8TestObj::toNative(args.Holder()); - int intArg = toInt32(args[0]); + EXCEPTION_BLOCK(int, intArg, toInt32(args[0])); imp->overloadedMethod(intArg); return v8::Handle<v8::Value>(); } @@ -1088,6 +1088,8 @@ static const BatchedCallback TestObjCallbacks[] = { {"methodWithOptionalArg", TestObjInternal::methodWithOptionalArgCallback}, {"methodWithNonOptionalArgAndOptionalArg", TestObjInternal::methodWithNonOptionalArgAndOptionalArgCallback}, {"methodWithNonOptionalArgAndTwoOptionalArgs", TestObjInternal::methodWithNonOptionalArgAndTwoOptionalArgsCallback}, + {"methodWithCallbackArg", TestObjInternal::methodWithCallbackArgCallback}, + {"methodWithNonCallbackArgAndCallbackArg", TestObjInternal::methodWithNonCallbackArgAndCallbackArgCallback}, {"methodWithCallbackAndOptionalArg", TestObjInternal::methodWithCallbackAndOptionalArgCallback}, {"overloadedMethod", TestObjInternal::overloadedMethodCallback}, }; @@ -1161,18 +1163,6 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persi v8::Handle<v8::FunctionTemplate> customArgsAndExceptionArgv[customArgsAndExceptionArgc] = { V8log::GetRawTemplate() }; v8::Handle<v8::Signature> customArgsAndExceptionSignature = v8::Signature::New(desc, customArgsAndExceptionArgc, customArgsAndExceptionArgv); proto->Set(v8::String::New("customArgsAndException"), v8::FunctionTemplate::New(TestObjInternal::customArgsAndExceptionCallback, v8::Handle<v8::Value>(), customArgsAndExceptionSignature)); - - // Custom Signature 'methodWithCallbackArg' - const int methodWithCallbackArgArgc = 1; - v8::Handle<v8::FunctionTemplate> methodWithCallbackArgArgv[methodWithCallbackArgArgc] = { V8TestCallback::GetRawTemplate() }; - v8::Handle<v8::Signature> methodWithCallbackArgSignature = v8::Signature::New(desc, methodWithCallbackArgArgc, methodWithCallbackArgArgv); - proto->Set(v8::String::New("methodWithCallbackArg"), v8::FunctionTemplate::New(TestObjInternal::methodWithCallbackArgCallback, v8::Handle<v8::Value>(), methodWithCallbackArgSignature)); - - // Custom Signature 'methodWithNonCallbackArgAndCallbackArg' - const int methodWithNonCallbackArgAndCallbackArgArgc = 2; - v8::Handle<v8::FunctionTemplate> methodWithNonCallbackArgAndCallbackArgArgv[methodWithNonCallbackArgAndCallbackArgArgc] = { v8::Handle<v8::FunctionTemplate>(), V8TestCallback::GetRawTemplate() }; - v8::Handle<v8::Signature> methodWithNonCallbackArgAndCallbackArgSignature = v8::Signature::New(desc, methodWithNonCallbackArgAndCallbackArgArgc, methodWithNonCallbackArgAndCallbackArgArgv); - proto->Set(v8::String::New("methodWithNonCallbackArgAndCallbackArg"), v8::FunctionTemplate::New(TestObjInternal::methodWithNonCallbackArgAndCallbackArgCallback, v8::Handle<v8::Value>(), methodWithNonCallbackArgAndCallbackArgSignature)); batchConfigureConstants(desc, proto, TestObjConsts, sizeof(TestObjConsts) / sizeof(*TestObjConsts)); // Custom toString template diff --git a/WebCore/bindings/v8/ScheduledAction.cpp b/WebCore/bindings/v8/ScheduledAction.cpp index f511e2b..dcd0bb3 100644 --- a/WebCore/bindings/v8/ScheduledAction.cpp +++ b/WebCore/bindings/v8/ScheduledAction.cpp @@ -34,7 +34,6 @@ #include "Document.h" #include "ScriptExecutionContext.h" #include "ScriptSourceCode.h" -#include "ScriptValue.h" #include "V8Binding.h" #include "V8Proxy.h" diff --git a/WebCore/bindings/v8/ScheduledAction.h b/WebCore/bindings/v8/ScheduledAction.h index 003885f..aefe7ef 100644 --- a/WebCore/bindings/v8/ScheduledAction.h +++ b/WebCore/bindings/v8/ScheduledAction.h @@ -34,12 +34,12 @@ #include "OwnHandle.h" #include "ScriptSourceCode.h" #include "V8GCController.h" +#include <wtf/Forward.h> #include <v8.h> namespace WebCore { - class String; class ScriptExecutionContext; class V8Proxy; class WorkerContext; @@ -47,7 +47,7 @@ namespace WebCore { class ScheduledAction { public: ScheduledAction(v8::Handle<v8::Context>, v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); - explicit ScheduledAction(v8::Handle<v8::Context> context, const WebCore::String& code, const KURL& url = KURL()) + explicit ScheduledAction(v8::Handle<v8::Context> context, const WTF::String& code, const KURL& url = KURL()) : m_context(context) , m_argc(0) , m_argv(0) diff --git a/WebCore/bindings/v8/ScriptArray.cpp b/WebCore/bindings/v8/ScriptArray.cpp deleted file mode 100644 index 7119b27..0000000 --- a/WebCore/bindings/v8/ScriptArray.cpp +++ /dev/null @@ -1,120 +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 "ScriptArray.h" - -#include "Document.h" -#include "Frame.h" -#include "ScriptScope.h" -#include "ScriptState.h" -#include "SerializedScriptValue.h" -#include "V8Binding.h" -#include "V8Proxy.h" - -namespace WebCore { - -ScriptArray::ScriptArray(ScriptState* scriptState, v8::Handle<v8::Array> v8Array) - : ScriptObject(scriptState, v8Array) -{ -} - -bool ScriptArray::set(unsigned index, const ScriptObject& value) -{ - if (value.scriptState() != m_scriptState) { - ASSERT_NOT_REACHED(); - return false; - } - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), value.v8Value()); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, SerializedScriptValue* value) -{ - ScriptValue scriptValue = ScriptValue::deserialize(m_scriptState, value); - if (scriptValue.hasNoValue()) { - ASSERT_NOT_REACHED(); - return false; - } - - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), scriptValue.v8Value()); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, const String& value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8String(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, double value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, long long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, int value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptArray::set(unsigned index, bool value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::Integer::New(index), v8Boolean(value)); - return scope.success(); -} - -unsigned ScriptArray::length() -{ - ScriptScope scope(m_scriptState); - return v8::Array::Cast(*v8Value())->Length(); -} - -ScriptArray ScriptArray::createNew(ScriptState* scriptState) -{ - ScriptScope scope(scriptState); - return ScriptArray(scriptState, v8::Array::New()); -} - -} // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptCallStack.h b/WebCore/bindings/v8/ScriptCallStack.h index b608563..215cdec 100644 --- a/WebCore/bindings/v8/ScriptCallStack.h +++ b/WebCore/bindings/v8/ScriptCallStack.h @@ -31,7 +31,6 @@ #ifndef ScriptCallStack_h #define ScriptCallStack_h -#include "ScriptArray.h" #include "ScriptCallFrame.h" #include "ScriptState.h" #include "ScriptValue.h" diff --git a/WebCore/bindings/v8/ScriptController.h b/WebCore/bindings/v8/ScriptController.h index 04a15f6..cd20cda 100644 --- a/WebCore/bindings/v8/ScriptController.h +++ b/WebCore/bindings/v8/ScriptController.h @@ -39,6 +39,7 @@ #include <v8.h> +#include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> @@ -52,7 +53,6 @@ class Event; class Frame; class HTMLPlugInElement; class ScriptSourceCode; -class String; class Widget; class XSSAuditor; diff --git a/WebCore/bindings/v8/ScriptObject.cpp b/WebCore/bindings/v8/ScriptObject.cpp index 8f81537..3d38a9e 100644 --- a/WebCore/bindings/v8/ScriptObject.cpp +++ b/WebCore/bindings/v8/ScriptObject.cpp @@ -57,86 +57,6 @@ v8::Local<v8::Object> ScriptObject::v8Object() const return v8::Local<v8::Object>(v8::Object::Cast(*v8Value())); } -bool ScriptObject::set(const String& name, const String& value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8String(name), v8String(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, const ScriptObject& value) -{ - if (value.scriptState() != m_scriptState) { - ASSERT_NOT_REACHED(); - return false; - } - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), value.v8Value()); - return scope.success(); -} - -bool ScriptObject::set(const char* name, const String& value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8String(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, double value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, long long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, int value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, unsigned value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, unsigned long value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8::Number::New(value)); - return scope.success(); -} - -bool ScriptObject::set(const char* name, bool value) -{ - ScriptScope scope(m_scriptState); - v8Object()->Set(v8::String::New(name), v8Boolean(value)); - return scope.success(); -} - -ScriptObject ScriptObject::createNew(ScriptState* scriptState) -{ - ScriptScope scope(scriptState); - return ScriptObject(scriptState, v8::Object::New()); -} - bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, const ScriptObject& value) { ScriptScope scope(scriptState); diff --git a/WebCore/bindings/v8/ScriptObject.h b/WebCore/bindings/v8/ScriptObject.h index bee079c..6b78cfc 100644 --- a/WebCore/bindings/v8/ScriptObject.h +++ b/WebCore/bindings/v8/ScriptObject.h @@ -48,19 +48,6 @@ namespace WebCore { v8::Local<v8::Object> v8Object() const; ScriptState* scriptState() const { return m_scriptState; } - - bool set(const String& name, const String&); - bool set(const char* name, const ScriptObject&); - bool set(const char* name, const String&); - bool set(const char* name, double); - bool set(const char* name, long); - bool set(const char* name, long long); - bool set(const char* name, int); - bool set(const char* name, unsigned); - bool set(const char* name, unsigned long); - bool set(const char* name, bool); - - static ScriptObject createNew(ScriptState*); protected: ScriptState* m_scriptState; }; diff --git a/WebCore/bindings/v8/ScriptProfile.cpp b/WebCore/bindings/v8/ScriptProfile.cpp index 3b71d5f..32e0066 100644 --- a/WebCore/bindings/v8/ScriptProfile.cpp +++ b/WebCore/bindings/v8/ScriptProfile.cpp @@ -29,12 +29,13 @@ */ #include "config.h" - #include "ScriptProfile.h" +#include "InspectorValues.h" #include "V8Binding.h" - #include <v8-profiler.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> namespace WebCore { @@ -54,4 +55,32 @@ PassRefPtr<ScriptProfileNode> ScriptProfile::head() const return ScriptProfileNode::create(m_profile->GetTopDownRoot()); } +static PassRefPtr<InspectorObject> buildInspectorObjectFor(const v8::CpuProfileNode* node) +{ + v8::HandleScope handleScope; + RefPtr<InspectorObject> result = InspectorObject::create(); + result->setString("functionName", toWebCoreString(node->GetFunctionName())); + result->setString("url", toWebCoreString(node->GetScriptResourceName())); + result->setNumber("lineNumber", node->GetLineNumber()); + result->setNumber("totalTime", node->GetTotalTime()); + result->setNumber("selfTime", node->GetSelfTime()); + result->setNumber("numberOfCalls", 0); + result->setBool("visible", true); + result->setNumber("callUID", node->GetCallUid()); + + RefPtr<InspectorArray> children = InspectorArray::create(); + const int childrenCount = node->GetChildrenCount(); + for (int i = 0; i < childrenCount; i++) { + const v8::CpuProfileNode* child = node->GetChild(i); + children->push(buildInspectorObjectFor(child)); + } + result->set("children", children); + return result; +} + +PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const +{ + return buildInspectorObjectFor(m_profile->GetTopDownRoot()); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptProfile.h b/WebCore/bindings/v8/ScriptProfile.h index 2f42ad2..0182669 100644 --- a/WebCore/bindings/v8/ScriptProfile.h +++ b/WebCore/bindings/v8/ScriptProfile.h @@ -40,6 +40,8 @@ class CpuProfile; namespace WebCore { +class InspectorObject; + class ScriptProfile : public RefCounted<ScriptProfile> { public: static PassRefPtr<ScriptProfile> create(const v8::CpuProfile* profile) @@ -52,12 +54,13 @@ public: unsigned int uid() const; PassRefPtr<ScriptProfileNode> head() const; -protected: + PassRefPtr<InspectorObject> buildInspectorObjectForHead() const; + +private: ScriptProfile(const v8::CpuProfile* profile) : m_profile(profile) {} -private: const v8::CpuProfile* m_profile; }; diff --git a/WebCore/bindings/v8/ScriptProfiler.cpp b/WebCore/bindings/v8/ScriptProfiler.cpp index 4891892..9213774 100644 --- a/WebCore/bindings/v8/ScriptProfiler.cpp +++ b/WebCore/bindings/v8/ScriptProfiler.cpp @@ -59,4 +59,14 @@ void ScriptProfiler::takeHeapSnapshot() | v8::PROFILER_MODULE_JS_CONSTRUCTORS); } +long ScriptProfiler::getProfilerLogLines(long position, String* data) +{ + static char buffer[65536]; + const int readSize = v8::V8::GetLogLines(position, buffer, sizeof(buffer) - 1); + buffer[readSize] = '\0'; + position += readSize; + *data = buffer; + return position; +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptProfiler.h b/WebCore/bindings/v8/ScriptProfiler.h index aff3ce7..5c1054b 100644 --- a/WebCore/bindings/v8/ScriptProfiler.h +++ b/WebCore/bindings/v8/ScriptProfiler.h @@ -44,6 +44,7 @@ public: static void start(ScriptState* state, const String& title); static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title); static void takeHeapSnapshot(); + static long getProfilerLogLines(long position, String* data); }; } // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptStringImpl.h b/WebCore/bindings/v8/ScriptStringImpl.h index 8a47b4f..84a25c4 100644 --- a/WebCore/bindings/v8/ScriptStringImpl.h +++ b/WebCore/bindings/v8/ScriptStringImpl.h @@ -41,7 +41,7 @@ namespace WebCore { // This class is used for strings that tend to be shared with JavaScript frequently. The JSC implementation uses wtf::UString - see bindings/js/ScriptString.h // Currently XMLHttpRequest uses a ScriptString to build up the responseText attribute. As data arrives from the network, it is appended to the ScriptString // via operator+= and a JavaScript readystatechange event is fired. JavaScript can access the responseText attribute of the XMLHttpRequest object. JavaScript -// may also query the responseXML attribute of the XMLHttpRequest object which results in the responseText attribute being coerced into a WebCore::String and +// may also query the responseXML attribute of the XMLHttpRequest object which results in the responseText attribute being coerced into a WTF::String and // then parsed as an XML document. // This implementation optimizes for the common case where the responseText is built up with many calls to operator+= before the actual text is queried. class ScriptStringImpl : public RefCounted<ScriptStringImpl> { diff --git a/WebCore/bindings/v8/ScriptValue.cpp b/WebCore/bindings/v8/ScriptValue.cpp index 54f3860..6d3fe20 100755 --- a/WebCore/bindings/v8/ScriptValue.cpp +++ b/WebCore/bindings/v8/ScriptValue.cpp @@ -104,6 +104,9 @@ static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value uint32_t length = propertyNames->Length(); for (uint32_t i = 0; i < length; i++) { v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(i)); + // FIXME(yurys): v8::Object should support GetOwnPropertyNames + if (!object->HasRealNamedProperty(v8::Handle<v8::String>::Cast(name))) + continue; RefPtr<InspectorValue> propertyValue = v8ToInspectorValue(object->Get(name)); if (!propertyValue) { ASSERT_NOT_REACHED(); @@ -113,6 +116,7 @@ static PassRefPtr<InspectorValue> v8ToInspectorValue(v8::Handle<v8::Value> value } return inspectorObject; } + ASSERT_NOT_REACHED(); return 0; } diff --git a/WebCore/bindings/v8/V8Binding.h b/WebCore/bindings/v8/V8Binding.h index a15ece1..4656aa2 100644 --- a/WebCore/bindings/v8/V8Binding.h +++ b/WebCore/bindings/v8/V8Binding.h @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -40,7 +40,7 @@ #include <v8.h> namespace WebCore { - + class EventListener; class EventTarget; class V8BindingDOMWindow; @@ -50,6 +50,8 @@ namespace WebCore { public: typedef v8::Handle<v8::Value> Value; typedef V8BindingDOMWindow DOMWindow; + + static Value emptyScriptValue() { return v8::Local<v8::Value>(); } }; typedef BindingSecurity<V8Binding> V8BindingSecurity; @@ -61,7 +63,7 @@ namespace WebCore { template <typename StringType> StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external); - // Convert v8 types to a WebCore::String. If the V8 string is not already + // Convert v8 types to a WTF::String. If the V8 string is not already // an external string then it is transformed into an external string at this // point to avoid repeated conversions. inline String v8StringToWebCoreString(v8::Handle<v8::String> v8String) @@ -71,7 +73,7 @@ namespace WebCore { String v8NonStringValueToWebCoreString(v8::Handle<v8::Value>); String v8ValueToWebCoreString(v8::Handle<v8::Value> value); - // Convert v8 types to a WebCore::AtomicString. + // Convert v8 types to a WTF::AtomicString. inline AtomicString v8StringToAtomicWebCoreString(v8::Handle<v8::String> v8String) { return v8StringToWebCoreString<AtomicString>(v8String, Externalize); @@ -110,8 +112,8 @@ namespace WebCore { return v8ExternalString(string); } - // Enables caching v8 wrappers created for WebCore::StringImpl. Currently this cache requires - // all the calls (both to convert WebCore::String to v8::String and to GC the handle) + // Enables caching v8 wrappers created for WTF::StringImpl. Currently this cache requires + // all the calls (both to convert WTF::String to v8::String and to GC the handle) // to be performed on the main thread. void enableStringImplCache(); @@ -152,7 +154,7 @@ namespace WebCore { { return v8ValueToWebCoreString(object); } - + String toWebCoreString(const v8::Arguments&, int index); // The string returned by this function is still owned by the argument @@ -171,7 +173,7 @@ namespace WebCore { AtomicString toAtomicWebCoreStringWithNullCheck(v8::Handle<v8::Value> value); String toWebCoreStringWithNullOrUndefinedCheck(v8::Handle<v8::Value> value); - + v8::Handle<v8::String> v8UndetectableString(const String& str); v8::Handle<v8::Value> v8StringOrNull(const String& str); @@ -183,31 +185,31 @@ namespace WebCore { double toWebCoreDate(v8::Handle<v8::Value> object); v8::Handle<v8::Value> v8DateOrNull(double value); - + v8::Persistent<v8::FunctionTemplate> createRawTemplate(); struct BatchedAttribute; struct BatchedCallback; - + v8::Local<v8::Signature> configureTemplate(v8::Persistent<v8::FunctionTemplate>, const char* interfaceName, v8::Persistent<v8::FunctionTemplate> parentClass, int fieldCount, - const BatchedAttribute*, + const BatchedAttribute*, size_t attributeCount, const BatchedCallback*, size_t callbackCount); - + v8::Handle<v8::Value> getElementStringAttr(const v8::AccessorInfo&, const QualifiedName&); void setElementStringAttr(const v8::AccessorInfo&, const QualifiedName&, v8::Local<v8::Value>); - + v8::Persistent<v8::String> getToStringName(); v8::Persistent<v8::FunctionTemplate> getToStringTemplate(); - + // V8Parameter is an adapter class that converts V8 values to Strings // or AtomicStrings as appropriate, using multiple typecast operators. enum V8ParameterMode { @@ -218,13 +220,13 @@ namespace WebCore { template <V8ParameterMode MODE = DefaultMode> class V8Parameter { public: - V8Parameter (v8::Local<v8::Value> object) :m_v8Object(object) { } + V8Parameter(v8::Local<v8::Value> object = v8::Local<v8::Value>()) : m_v8Object(object) { } operator String(); operator AtomicString(); private: v8::Local<v8::Value> m_v8Object; }; - + template<> inline V8Parameter<DefaultMode>::operator String() { return toWebCoreString(m_v8Object); } template<> inline V8Parameter<WithNullCheck>::operator String() { return toWebCoreStringWithNullCheck(m_v8Object); } template<> inline V8Parameter<WithUndefinedOrNullCheck>::operator String() { return toWebCoreStringWithNullOrUndefinedCheck(m_v8Object); } diff --git a/WebCore/bindings/v8/V8DOMWindowShell.cpp b/WebCore/bindings/v8/V8DOMWindowShell.cpp index c7c77d3..6676f6c 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -86,7 +86,11 @@ static void reportFatalErrorInV8(const char* location, const char* message) // V8 is shutdown, we cannot use V8 api. // The only thing we can do is to disable JavaScript. // FIXME: clean up V8Proxy and disable JavaScript. - printf("V8 error: %s (%s)\n", message, location); + int memoryUsageMB = -1; +#if PLATFORM(CHROMIUM) + memoryUsageMB = ChromiumBridge::memoryUsageMB(); +#endif + printf("V8 error: %s (%s). Current memory usage: %d MB\n", message, location, memoryUsageMB); handleFatalErrorInV8(); } diff --git a/WebCore/bindings/v8/V8DOMWindowShell.h b/WebCore/bindings/v8/V8DOMWindowShell.h index f4eaff2..2ccb410 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.h +++ b/WebCore/bindings/v8/V8DOMWindowShell.h @@ -32,6 +32,7 @@ #define V8DOMWindowShell_h #include "WrapperTypeInfo.h" +#include <wtf/Forward.h> #include <wtf/HashMap.h> #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> @@ -41,7 +42,6 @@ namespace WebCore { class DOMWindow; class Frame; -class String; // V8WindowShell represents all the per-global object state for a Frame that // persist between navigations. diff --git a/WebCore/bindings/v8/V8DOMWrapper.cpp b/WebCore/bindings/v8/V8DOMWrapper.cpp index 4a09c34..d6f05f4 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.cpp +++ b/WebCore/bindings/v8/V8DOMWrapper.cpp @@ -423,7 +423,7 @@ v8::Handle<v8::Value> V8DOMWrapper::convertEventTargetToV8Object(EventTarget* ta return toV8(eventSource); #endif -#if ENABLE(FILE_READER) +#if ENABLE(BLOB) if (FileReader* fileReader = target->toFileReader()) return toV8(fileReader); #endif diff --git a/WebCore/bindings/v8/V8DOMWrapper.h b/WebCore/bindings/v8/V8DOMWrapper.h index 97e269a..943cb8a 100644 --- a/WebCore/bindings/v8/V8DOMWrapper.h +++ b/WebCore/bindings/v8/V8DOMWrapper.h @@ -35,7 +35,7 @@ #include "Event.h" #include "Node.h" #include "NodeFilter.h" -#include "PlatformString.h" // for WebCore::String +#include "PlatformString.h" #include "V8CustomXPathNSResolver.h" #include "V8DOMMap.h" #include "V8Event.h" diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h index 4dc28ef..94ff17c 100644 --- a/WebCore/bindings/v8/V8Proxy.h +++ b/WebCore/bindings/v8/V8Proxy.h @@ -42,6 +42,7 @@ #include "V8Utilities.h" #include "WrapperTypeInfo.h" #include <v8.h> +#include <wtf/Forward.h> #include <wtf/PassRefPtr.h> // so generated bindings don't have to #include <wtf/Vector.h> @@ -59,7 +60,6 @@ namespace WebCore { class Node; class SVGElement; class ScriptExecutionContext; - class String; class V8EventListener; class V8IsolatedContext; class WorldContextHandle; diff --git a/WebCore/bindings/v8/V8Utilities.cpp b/WebCore/bindings/v8/V8Utilities.cpp index f780218..2e5cf8b 100644 --- a/WebCore/bindings/v8/V8Utilities.cpp +++ b/WebCore/bindings/v8/V8Utilities.cpp @@ -38,6 +38,8 @@ #include "ScriptExecutionContext.h" #include "ScriptState.h" #include "V8Binding.h" +#include "V8BindingDOMWindow.h" // FIXME: remove when completeURL moves +#include "V8BindingState.h" #include "V8Proxy.h" #include "WorkerContext.h" #include "WorkerContextExecutionProxy.h" @@ -92,41 +94,25 @@ void transferHiddenDependency(v8::Handle<v8::Object> object, if (!newValue->IsNull() && !newValue->IsUndefined()) createHiddenDependency(object, newValue, cacheIndex); } - bool processingUserGesture() { - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - return frame && frame->script()->processingUserGesture(); + return V8BindingState::Only()->processingUserGesture(); } Frame* callingOrEnteredFrame() { - Frame* frame = V8Proxy::retrieveFrameForCallingContext(); - if (!frame) { - // Unfortunately, when processing script from a plug-in, we might not - // have a calling context. In those cases, we fall back to the - // entered context for security checks. - // FIXME: We need a better API for retrieving frames that abstracts - // away this concern. - frame = V8Proxy::retrieveFrameForEnteredContext(); - } - return frame; + return V8BindingState::Only()->getActiveFrame(); } bool shouldAllowNavigation(Frame* frame) { - Frame* callingOrEntered = callingOrEnteredFrame(); - return callingOrEntered && callingOrEntered->loader()->shouldAllowNavigation(frame); + return V8BindingSecurity::shouldAllowNavigation(V8BindingState::Only(), frame); } KURL completeURL(const String& relativeURL) { - // For histoical reasons, we need to complete the URL using the dynamic frame. - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - if (!frame) - return KURL(); - return frame->loader()->completeURL(relativeURL); + return V8BindingDOMWindow::completeURL(V8BindingState::Only(), relativeURL); } void navigateIfAllowed(Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList) diff --git a/WebCore/bindings/v8/V8Utilities.h b/WebCore/bindings/v8/V8Utilities.h index cbe7a7b..2b82f4d 100644 --- a/WebCore/bindings/v8/V8Utilities.h +++ b/WebCore/bindings/v8/V8Utilities.h @@ -31,6 +31,7 @@ #ifndef V8Utilities_h #define V8Utilities_h +#include <wtf/Forward.h> #include <v8.h> namespace WebCore { @@ -40,7 +41,6 @@ namespace WebCore { class KURL; class ScriptExecutionContext; class ScriptState; - class String; // Use an array to hold dependents. It works like a ref-counted scheme. A value can be added more than once to the DOM object. void createHiddenDependency(v8::Handle<v8::Object>, v8::Local<v8::Value>, int cacheIndex); diff --git a/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp b/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp index 501e5a2..305fb18 100644 --- a/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp +++ b/WebCore/bindings/v8/custom/V8ArrayBufferCustom.cpp @@ -34,6 +34,7 @@ #include "ArrayBuffer.h" +#include "ExceptionCode.h" #include "V8Binding.h" #include "V8ArrayBuffer.h" #include "V8Proxy.h" diff --git a/WebCore/bindings/v8/custom/V8BindingMacros.h b/WebCore/bindings/v8/custom/V8BindingMacros.h index 4c8ecd3..b569b10 100644 --- a/WebCore/bindings/v8/custom/V8BindingMacros.h +++ b/WebCore/bindings/v8/custom/V8BindingMacros.h @@ -37,12 +37,13 @@ return block.ReThrow(); \ } -#define TO_WEBCORE_STRING_EXCEPTION_BLOCK(var, value) \ - String var; \ - { \ - v8::TryCatch block; \ - v8::Handle<v8::String> v8String = (value)->ToString(); \ - if (block.HasCaught()) \ - return block.ReThrow(); \ - var = v8StringToWebCoreString<String>(v8String, DoNotExternalize); \ +#define STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(type, var, value) \ + type var; \ + { \ + v8::Local<v8::Value> v8Value = (value); \ + v8::TryCatch block; \ + (value)->ToString(); \ + if (block.HasCaught()) \ + return block.ReThrow(); \ + var = v8Value; \ } diff --git a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp index 6603344..17fca22 100644 --- a/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp +++ b/WebCore/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp @@ -43,11 +43,14 @@ namespace WebCore { -bool V8SQLStatementErrorCallback::handleEvent(ScriptExecutionContext* context, SQLTransaction* transaction, SQLError* error) +bool V8SQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) { + if (!canInvokeCallback()) + return true; + v8::HandleScope handleScope; - v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext); + v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; @@ -65,15 +68,12 @@ bool V8SQLStatementErrorCallback::handleEvent(ScriptExecutionContext* context, S errorHandle }; - // Protect the context until the callback returns. - RefPtr<ScriptExecutionContext> protector(context); - bool callbackReturnValue = false; // Step 6: If the error callback returns false, then move on to the next // statement, if any, or onto the next overall step otherwise. Otherwise, // the error callback did not return false, or there was no error callback. // Jump to the last step in the overall steps. - return invokeCallback(m_callback, 2, argv, callbackReturnValue, context) || callbackReturnValue; + return invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext()) || callbackReturnValue; } } // namespace WebCore diff --git a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h index cf84438..9677252 100644 --- a/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h +++ b/WebCore/bindings/v8/custom/V8CustomXPathNSResolver.h @@ -41,7 +41,6 @@ namespace WebCore { -class String; class V8Proxy; // V8CustomXPathNSResolver does not create a persistent handle to the diff --git a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp index d1e0701..a74faee 100644 --- a/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp +++ b/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp @@ -32,7 +32,6 @@ #include "V8DOMWindow.h" #include "Chrome.h" -#include "Database.h" #include "DOMTimer.h" #include "DOMWindow.h" #include "ExceptionCode.h" @@ -55,8 +54,6 @@ #include "V8BindingMacros.h" #include "V8BindingState.h" #include "V8CustomEventListener.h" -#include "V8Database.h" -#include "V8DatabaseCallback.h" #include "V8GCForContextDispose.h" #include "V8HiddenPropertyName.h" #include "V8HTMLAudioElementConstructor.h" @@ -82,10 +79,6 @@ #endif #include "WindowFeatures.h" -// Horizontal and vertical offset, from the parent content area, around newly -// opened popups that don't specify a location. -static const int popupTilePixels = 10; - namespace WebCore { v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singleShot) @@ -104,7 +97,7 @@ v8::Handle<v8::Value> WindowSetTimeoutImpl(const v8::Arguments& args, bool singl } v8::Handle<v8::Value> function = args[0]; - WebCore::String functionString; + WTF::String functionString; if (!function->IsFunction()) { if (function->IsString()) functionString = toWebCoreString(function); @@ -449,17 +442,6 @@ static bool canShowModalDialogNow(const Frame* frame) return frame->page()->chrome()->canRunModalNow(); } -static bool allowPopUp() -{ - Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); - - ASSERT(frame); - if (frame->script()->processingUserGesture()) - return true; - Settings* settings = frame->settings(); - return settings && settings->javaScriptCanOpenWindowsAutomatically(); -} - static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg) { HashMap<String, String> map; @@ -513,7 +495,7 @@ v8::Handle<v8::Value> V8DOMWindow::showModalDialogCallback(const v8::Arguments& if (!enteredFrame) return v8::Undefined(); - if (!canShowModalDialogNow(frame) || !allowPopUp()) + if (!canShowModalDialogNow(frame) || !V8BindingSecurity::allowPopUp(V8BindingState::Only())) return v8::Undefined(); const HashMap<String, String> features = parseModalDialogFeatures(featureArgs); @@ -584,134 +566,16 @@ v8::Handle<v8::Value> V8DOMWindow::openCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.open()"); + DOMWindow* parent = V8DOMWindow::toNative(args.Holder()); String urlString = toWebCoreStringWithNullOrUndefinedCheck(args[0]); AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_blank" : AtomicString(toWebCoreString(args[1])); - - DOMWindow* parent = V8DOMWindow::toNative(args.Holder()); - Frame* frame = parent->frame(); - - if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), frame, true)) - return v8::Undefined(); - - Frame* enteredFrame = V8Proxy::retrieveFrameForEnteredContext(); - if (!enteredFrame) - return v8::Undefined(); - - Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext(); - // We may not have a calling context if we are invoked by a plugin via NPAPI. - if (!callingFrame) - callingFrame = enteredFrame; - - Page* page = frame->page(); - if (!page) - return v8::Undefined(); - - // Because FrameTree::find() returns true for empty strings, we must check - // for empty framenames. Otherwise, illegitimate window.open() calls with - // no name will pass right through the popup blocker. - if (!allowPopUp() && - (frameName.isEmpty() || !frame->tree()->find(frameName))) { - return v8::Undefined(); - } - - // Get the target frame for the special cases of _top and _parent. In those - // cases, we can schedule a location change right now and return early. - bool topOrParent = false; - if (frameName == "_top") { - frame = frame->tree()->top(); - topOrParent = true; - } else if (frameName == "_parent") { - if (Frame* parent = frame->tree()->parent()) - frame = parent; - topOrParent = true; - } - if (topOrParent) { - if (!shouldAllowNavigation(frame)) - return v8::Undefined(); - - String completedUrl; - if (!urlString.isEmpty()) - completedUrl = completeURL(urlString); - - if (!completedUrl.isEmpty() && - (!protocolIsJavaScript(completedUrl) || ScriptController::isSafeScript(frame))) { - bool userGesture = processingUserGesture(); - - // For whatever reason, Firefox uses the entered frame to determine - // the outgoingReferrer. We replicate that behavior here. - String referrer = enteredFrame->loader()->outgoingReferrer(); - - frame->redirectScheduler()->scheduleLocationChange(completedUrl, referrer, false, false, userGesture); - } - return toV8(frame->domWindow()); - } - - // In the case of a named frame or a new window, we'll use the - // createWindow() helper. - - // Parse the values, and then work with a copy of the parsed values - // so we can restore the values we may not want to overwrite after - // we do the multiple monitor fixes. WindowFeatures rawFeatures(toWebCoreStringWithNullOrUndefinedCheck(args[2])); - WindowFeatures windowFeatures(rawFeatures); - FloatRect screenRect = screenAvailableRect(page->mainFrame()->view()); - - // Set default size and location near parent window if none were specified. - // These may be further modified by adjustWindowRect, below. - if (!windowFeatures.xSet) { - windowFeatures.x = parent->screenX() - screenRect.x() + popupTilePixels; - windowFeatures.xSet = true; - } - if (!windowFeatures.ySet) { - windowFeatures.y = parent->screenY() - screenRect.y() + popupTilePixels; - windowFeatures.ySet = true; - } - if (!windowFeatures.widthSet) { - windowFeatures.width = parent->innerWidth(); - windowFeatures.widthSet = true; - } - if (!windowFeatures.heightSet) { - windowFeatures.height = parent->innerHeight(); - windowFeatures.heightSet = true; - } - - FloatRect windowRect(windowFeatures.x, windowFeatures.y, windowFeatures.width, windowFeatures.height); - - // The new window's location is relative to its current screen, so shift - // it in case it's on a secondary monitor. See http://b/viewIssue?id=967905. - windowRect.move(screenRect.x(), screenRect.y()); - WebCore::DOMWindow::adjustWindowRect(screenRect, windowRect, windowRect); - - windowFeatures.x = windowRect.x(); - windowFeatures.y = windowRect.y(); - windowFeatures.height = windowRect.height(); - windowFeatures.width = windowRect.width(); - - // If either of the origin coordinates or dimensions weren't set in the original - // string, make sure they aren't set now. - if (!rawFeatures.xSet) { - windowFeatures.x = 0; - windowFeatures.xSet = false; - } - if (!rawFeatures.ySet) { - windowFeatures.y = 0; - windowFeatures.ySet = false; - } - if (!rawFeatures.widthSet) { - windowFeatures.width = 0; - windowFeatures.widthSet = false; - } - if (!rawFeatures.heightSet) { - windowFeatures.height = 0; - windowFeatures.heightSet = false; - } - - frame = V8BindingDOMWindow::createWindow(V8BindingState::Only(), callingFrame, enteredFrame, frame, urlString, frameName, windowFeatures, v8::Local<v8::Value>()); + DOMWindow* child = V8BindingDOMWindow::open(V8BindingState::Only(), parent, urlString, frameName, rawFeatures); - if (!frame) + if (!child) return v8::Undefined(); - return toV8(frame->domWindow()); + return toV8(child); } @@ -790,38 +654,6 @@ v8::Handle<v8::Value> V8DOMWindow::setIntervalCallback(const v8::Arguments& args return WindowSetTimeoutImpl(args, false); } -#if ENABLE(DATABASE) -v8::Handle<v8::Value> V8DOMWindow::openDatabaseCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DOMWindow.openDatabase"); - if (args.Length() < 4) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(name, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(version, args[1]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(displayName, args[2]); - EXCEPTION_BLOCK(unsigned long, estimatedSize, args[3]->Uint32Value()); - - DOMWindow* imp = V8DOMWindow::toNative(args.Holder()); - if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), true)) - return v8::Undefined(); - - RefPtr<DatabaseCallback> creationCallback; - if (args.Length() >= 5) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - creationCallback = V8DatabaseCallback::create(args[4]); - } - - ExceptionCode ec = 0; - v8::Handle<v8::Value> result = toV8(imp->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)); - - V8Proxy::setDOMException(ec); - return result; -} -#endif // ENABLE(DATABASE) - bool V8DOMWindow::namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) { v8::Handle<v8::Object> window = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), host); diff --git a/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp b/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp deleted file mode 100644 index 31406fb..0000000 --- a/WebCore/bindings/v8/custom/V8DatabaseCustom.cpp +++ /dev/null @@ -1,141 +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" - -#if ENABLE(DATABASE) -#include "V8Database.h" - -#include "Database.h" -#include "ExceptionCode.h" -#include "V8Binding.h" -#include "V8BindingMacros.h" -#include "V8SQLTransactionCallback.h" -#include "V8SQLTransactionErrorCallback.h" -#include "V8CustomVoidCallback.h" -#include "V8Proxy.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8Database::changeVersionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Database.changeVersion()"); - - if (args.Length() < 2) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(oldVersion, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(newVersion, args[1]); - - Database* database = V8Database::toNative(args.Holder()); - - ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext(); - if (!scriptExecutionContext) - return v8::Undefined(); - - RefPtr<V8SQLTransactionCallback> callback; - if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { - if (!args[2]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - callback = V8SQLTransactionCallback::create(args[2]); - } - - RefPtr<V8SQLTransactionErrorCallback> errorCallback; - if (args.Length() > 3 && !isUndefinedOrNull(args[3])) { - if (!args[3]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - errorCallback = V8SQLTransactionErrorCallback::create(args[3]); - } - - RefPtr<V8CustomVoidCallback> successCallback; - if (args.Length() > 4 && !isUndefinedOrNull(args[4])) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - successCallback = V8CustomVoidCallback::create(args[4], scriptExecutionContext); - } - - database->changeVersion(oldVersion, newVersion, callback.release(), errorCallback.release(), successCallback.release()); - - return v8::Undefined(); -} - -static v8::Handle<v8::Value> createTransaction(const v8::Arguments& args, bool readOnly) -{ - if (!args.Length()) - return throwError(SYNTAX_ERR); - - if (!args[0]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - Database* database = V8Database::toNative(args.Holder()); - - ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext(); - if (!scriptExecutionContext) - return v8::Undefined(); - RefPtr<V8SQLTransactionCallback> callback = V8SQLTransactionCallback::create(args[0]); - - RefPtr<V8SQLTransactionErrorCallback> errorCallback; - if (args.Length() > 1 && !isUndefinedOrNull(args[1])) { - if (!args[1]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - errorCallback = V8SQLTransactionErrorCallback::create(args[1]); - } - - RefPtr<V8CustomVoidCallback> successCallback; - if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { - if (!args[2]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - successCallback = V8CustomVoidCallback::create(args[2], scriptExecutionContext); - } - - database->transaction(callback.release(), errorCallback.release(), successCallback.release(), readOnly); - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8Database::transactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Database.transaction()"); - return createTransaction(args, false); -} - -v8::Handle<v8::Value> V8Database::readTransactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.Database.readTransaction()"); - return createTransaction(args, true); -} - -} // namespace WebCore - -#endif diff --git a/WebCore/bindings/v8/custom/V8DatabaseSyncCustom.cpp b/WebCore/bindings/v8/custom/V8DatabaseSyncCustom.cpp deleted file mode 100644 index 079f6e9..0000000 --- a/WebCore/bindings/v8/custom/V8DatabaseSyncCustom.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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" - -#if ENABLE(DATABASE) -#include "V8DatabaseSync.h" - -#include "DatabaseSync.h" -#include "ExceptionCode.h" -#include "V8Binding.h" -#include "V8BindingMacros.h" -#include "V8Proxy.h" -#include "V8SQLTransactionSyncCallback.h" - -namespace WebCore { - -v8::Handle<v8::Value> V8DatabaseSync::changeVersionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DatabaseSync.changeVersion()"); - - if (args.Length() < 2) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(oldVersion, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(newVersion, args[1]); - - DatabaseSync* database = V8DatabaseSync::toNative(args.Holder()); - - RefPtr<V8SQLTransactionSyncCallback> callback; - if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { - if (!args[2]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - callback = V8SQLTransactionSyncCallback::create(args[2]); - } - - ExceptionCode ec = 0; - database->changeVersion(oldVersion, newVersion, callback.release(), ec); - V8Proxy::setDOMException(ec); - - return v8::Undefined(); -} - -static v8::Handle<v8::Value> createTransaction(const v8::Arguments& args, bool readOnly) -{ - if (!args.Length()) - return throwError(SYNTAX_ERR); - - if (!args[0]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - DatabaseSync* database = V8DatabaseSync::toNative(args.Holder()); - - RefPtr<V8SQLTransactionSyncCallback> callback = V8SQLTransactionSyncCallback::create(args[0]); - - ExceptionCode ec = 0; - database->transaction(callback.release(), readOnly, ec); - V8Proxy::setDOMException(ec); - - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8DatabaseSync::transactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DatabaseSync.transaction()"); - return createTransaction(args, false); -} - -v8::Handle<v8::Value> V8DatabaseSync::readTransactionCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.DatabaseSync.readTransaction()"); - return createTransaction(args, true); -} - -} // namespace WebCore - -#endif diff --git a/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp new file mode 100644 index 0000000..39692b6 --- /dev/null +++ b/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2010 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: + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 "V8DeviceMotionEvent.h" + +#if ENABLE(DEVICE_ORIENTATION) + +#include "DeviceMotionData.h" +#include "V8Binding.h" +#include "V8Proxy.h" + +#include <v8.h> + +namespace WebCore { + +v8::Handle<v8::Value> V8DeviceMotionEvent::xAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.xAcceleration._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideXAcceleration()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->xAcceleration()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::yAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.yAcceleration._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideYAcceleration()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->yAcceleration()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::zAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.zAcceleration._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideZAcceleration()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->zAcceleration()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::xRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.xRotationRate._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideXRotationRate()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->xRotationRate()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::yRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.yRotationRate._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideYRotationRate()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->yRotationRate()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::zRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.zRotationRate._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideZRotationRate()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->zRotationRate()); +} + + +v8::Handle<v8::Value> V8DeviceMotionEvent::intervalAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.DeviceMotionEvent.interval._get"); + v8::Handle<v8::Object> holder = info.Holder(); + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder); + if (!imp->deviceMotionData()->canProvideInterval()) + return v8::Null(); + return v8::Number::New(imp->deviceMotionData()->interval()); +} + +v8::Handle<v8::Value> V8DeviceMotionEvent::initDeviceMotionEventCallback(const v8::Arguments& args) +{ + DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(args.Holder()); + V8Parameter<> type = args[0]; + bool bubbles = args[1]->BooleanValue(); + bool cancelable = args[2]->BooleanValue(); + // If any of the parameters are null or undefined, mark them as not provided. + // Otherwise, use the standard JavaScript conversion. + bool xAccelerationProvided = !isUndefinedOrNull(args[3]); + double xAcceleration = static_cast<double>(args[3]->NumberValue()); + bool yAccelerationProvided = !isUndefinedOrNull(args[4]); + double yAcceleration = static_cast<double>(args[4]->NumberValue()); + bool zAccelerationProvided = !isUndefinedOrNull(args[5]); + double zAcceleration = static_cast<double>(args[5]->NumberValue()); + bool xRotationRateProvided = !isUndefinedOrNull(args[6]); + double xRotationRate = static_cast<double>(args[6]->NumberValue()); + bool yRotationRateProvided = !isUndefinedOrNull(args[7]); + double yRotationRate = static_cast<double>(args[7]->NumberValue()); + bool zRotationRateProvided = !isUndefinedOrNull(args[8]); + double zRotationRate = static_cast<double>(args[8]->NumberValue()); + bool intervalProvided = !isUndefinedOrNull(args[9]); + double interval = static_cast<double>(args[9]->NumberValue()); + RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(xAccelerationProvided, xAcceleration, yAccelerationProvided, yAcceleration, zAccelerationProvided, zAcceleration, xRotationRateProvided, xRotationRate, yRotationRateProvided, yRotationRate, zRotationRateProvided, zRotationRate, intervalProvided, interval); + imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get()); + return v8::Handle<v8::Value>(); +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/WebCore/bindings/v8/custom/V8EventCustom.cpp b/WebCore/bindings/v8/custom/V8EventCustom.cpp index bce1561..e0bb02b 100644 --- a/WebCore/bindings/v8/custom/V8EventCustom.cpp +++ b/WebCore/bindings/v8/custom/V8EventCustom.cpp @@ -40,6 +40,7 @@ #include "V8Clipboard.h" #include "V8CompositionEvent.h" #include "V8CustomEvent.h" +#include "V8DeviceMotionEvent.h" #include "V8DeviceOrientationEvent.h" #include "V8ErrorEvent.h" #include "V8IDBErrorEvent.h" @@ -155,6 +156,8 @@ v8::Handle<v8::Value> toV8(Event* impl) if (impl->isBeforeLoadEvent()) return toV8(static_cast<BeforeLoadEvent*>(impl)); #if ENABLE(DEVICE_ORIENTATION) + if (impl->isDeviceMotionEvent()) + return toV8(static_cast<DeviceMotionEvent*>(impl)); if (impl->isDeviceOrientationEvent()) return toV8(static_cast<DeviceOrientationEvent*>(impl)); #endif diff --git a/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp b/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp index 2ec3dcd..3dffeb5 100644 --- a/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp +++ b/WebCore/bindings/v8/custom/V8IDBAnyCustom.cpp @@ -32,11 +32,12 @@ #include "V8IDBAny.h" #include "SerializedScriptValue.h" -#include "V8IDBDatabaseRequest.h" +#include "V8IDBCursor.h" +#include "V8IDBDatabase.h" #include "V8IDBFactory.h" #include "V8IDBIndex.h" #include "V8IDBKey.h" -#include "V8IDBObjectStoreRequest.h" +#include "V8IDBObjectStore.h" namespace WebCore { @@ -50,14 +51,16 @@ v8::Handle<v8::Value> toV8(IDBAny* impl) return v8::Undefined(); case IDBAny::NullType: return v8::Null(); - case IDBAny::IDBDatabaseRequestType: - return toV8(impl->idbDatabaseRequest()); + case IDBAny::IDBCursorType: + return toV8(impl->idbCursor()); + case IDBAny::IDBDatabaseType: + return toV8(impl->idbDatabase()); case IDBAny::IDBIndexType: return toV8(impl->idbIndex()); case IDBAny::IDBKeyType: return toV8(impl->idbKey()); - case IDBAny::IDBObjectStoreRequestType: - return toV8(impl->idbObjectStoreRequest()); + case IDBAny::IDBObjectStoreType: + return toV8(impl->idbObjectStore()); case IDBAny::IDBFactoryType: return toV8(impl->idbFactory()); case IDBAny::SerializedScriptValueType: diff --git a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp index c7cd54c..435cf73 100644 --- a/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp +++ b/WebCore/bindings/v8/custom/V8InjectedScriptHostCustom.cpp @@ -37,10 +37,10 @@ #include "InjectedScript.h" #include "InjectedScriptHost.h" #include "InspectorController.h" +#include "InspectorValues.h" #include "Node.h" #include "Page.h" #include "ScriptDebugServer.h" -#include "SerializedScriptValue.h" #include "V8Binding.h" #include "V8BindingState.h" @@ -164,19 +164,6 @@ v8::Handle<v8::Value> V8InjectedScriptHost::currentCallFrameCallback(const v8::A #endif #if ENABLE(DATABASE) -v8::Handle<v8::Value> V8InjectedScriptHost::databaseForIdCallback(const v8::Arguments& args) -{ - INC_STATS("InjectedScriptHost.databaseForId()"); - if (args.Length() < 1) - return v8::Undefined(); - - InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); - Database* database = host->databaseForId(args[0]->ToInt32()->Value()); - if (!database) - return v8::Undefined(); - return toV8(database); -} - v8::Handle<v8::Value> V8InjectedScriptHost::selectDatabaseCallback(const v8::Arguments& args) { INC_STATS("InjectedScriptHost.selectDatabase()"); @@ -208,19 +195,6 @@ v8::Handle<v8::Value> V8InjectedScriptHost::selectDOMStorageCallback(const v8::A } #endif -v8::Handle<v8::Value> V8InjectedScriptHost::reportDidDispatchOnInjectedScriptCallback(const v8::Arguments& args) -{ - INC_STATS("InjectedScriptHost.reportDidDispatchOnInjectedScript()"); - if (args.Length() < 3) - return v8::Undefined(); - InjectedScriptHost* host = V8InjectedScriptHost::toNative(args.Holder()); - int callId = args[0]->ToInt32()->Value(); - RefPtr<SerializedScriptValue> result(SerializedScriptValue::create(args[1])); - bool isException = args[2]->ToBoolean()->Value(); - host->reportDidDispatchOnInjectedScript(callId, result.get(), isException); - return v8::Undefined(); -} - InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* inspectedScriptState) { v8::HandleScope handleScope; diff --git a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp index 2ce4780..340f0a8 100644 --- a/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp +++ b/WebCore/bindings/v8/custom/V8NotificationCenterCustom.cpp @@ -83,6 +83,10 @@ v8::Handle<v8::Value> V8NotificationCenter::requestPermissionCallback(const v8:: NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder()); ScriptExecutionContext* context = notificationCenter->context(); + // Make sure that script execution context is valid. + if (!context) + return throwError(INVALID_STATE_ERR); + // Requesting permission is only valid from a page context. if (context->isWorkerContext()) return throwError(NOT_SUPPORTED_ERR); diff --git a/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp b/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp index e2a5070..af4185b 100644 --- a/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SQLTransactionCustom.cpp @@ -55,7 +55,7 @@ v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& if (args.Length() == 0) return throwError(SYNTAX_ERR); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(statement, args[0]); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, statement, args[0]); Vector<SQLValue> sqlValues; @@ -82,7 +82,7 @@ v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& EXCEPTION_BLOCK(double, sqlValue, value->NumberValue()); sqlValues.append(SQLValue(sqlValue)); } else { - TO_WEBCORE_STRING_EXCEPTION_BLOCK(sqlValue, value); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, sqlValue, value); sqlValues.append(SQLValue(sqlValue)); } } @@ -90,22 +90,22 @@ v8::Handle<v8::Value> V8SQLTransaction::executeSqlCallback(const v8::Arguments& SQLTransaction* transaction = V8SQLTransaction::toNative(args.Holder()); - ScriptExecutionContext* executionContext = getScriptExecutionContext(); - if (!executionContext) + ScriptExecutionContext* scriptExecutionContext = getScriptExecutionContext(); + if (!scriptExecutionContext) return v8::Undefined(); RefPtr<SQLStatementCallback> callback; if (args.Length() > 2 && !isUndefinedOrNull(args[2])) { if (!args[2]->IsObject()) return throwError(TYPE_MISMATCH_ERR); - callback = V8SQLStatementCallback::create(args[2]); + callback = V8SQLStatementCallback::create(args[2], scriptExecutionContext); } RefPtr<SQLStatementErrorCallback> errorCallback; if (args.Length() > 3 && !isUndefinedOrNull(args[3])) { if (!args[3]->IsObject()) return throwError(TYPE_MISMATCH_ERR); - errorCallback = V8SQLStatementErrorCallback::create(args[3]); + errorCallback = V8SQLStatementErrorCallback::create(args[3], scriptExecutionContext); } ExceptionCode ec = 0; diff --git a/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp b/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp index 495a8e4..8a57a9a 100644 --- a/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp +++ b/WebCore/bindings/v8/custom/V8SQLTransactionSyncCustom.cpp @@ -55,7 +55,7 @@ v8::Handle<v8::Value> V8SQLTransactionSync::executeSqlCallback(const v8::Argumen if (!args.Length()) return throwError(SYNTAX_ERR); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(statement, args[0]); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, statement, args[0]); Vector<SQLValue> sqlValues; @@ -82,7 +82,7 @@ v8::Handle<v8::Value> V8SQLTransactionSync::executeSqlCallback(const v8::Argumen EXCEPTION_BLOCK(double, sqlValue, value->NumberValue()); sqlValues.append(SQLValue(sqlValue)); } else { - TO_WEBCORE_STRING_EXCEPTION_BLOCK(sqlValue, value); + STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, sqlValue, value); sqlValues.append(SQLValue(sqlValue)); } } diff --git a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp index f66ff3d..53d731d 100755 --- a/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp +++ b/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp @@ -33,12 +33,6 @@ #if ENABLE(WORKERS) #include "V8WorkerContext.h" -#if ENABLE(DATABASE) -#include "Database.h" -#include "V8Database.h" -#include "V8DatabaseCallback.h" -#include "V8DatabaseSync.h" -#endif #include "DOMTimer.h" #include "ExceptionCode.h" #include "ScheduledAction.h" @@ -71,7 +65,7 @@ v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singl v8::Handle<v8::Context> v8Context = proxy->context(); if (function->IsString()) { - WebCore::String stringFunction = toWebCoreString(function); + WTF::String stringFunction = toWebCoreString(function); timerId = DOMTimer::install(workerContext, new ScheduledAction(v8Context, stringFunction, workerContext->url()), timeout, singleShot); } else if (function->IsFunction()) { size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; @@ -143,64 +137,6 @@ v8::Handle<v8::Value> toV8(WorkerContext* impl) return global; } -#if ENABLE(DATABASE) -v8::Handle<v8::Value> V8WorkerContext::openDatabaseCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.V8WorkerContext.openDatabase()"); - if (args.Length() < 4) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(name, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(version, args[1]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(displayName, args[2]); - EXCEPTION_BLOCK(unsigned long, estimatedSize, args[3]->Uint32Value()); - - WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); - - RefPtr<DatabaseCallback> creationCallback; - if (args.Length() >= 5) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - creationCallback = V8DatabaseCallback::create(args[4]); - } - - ExceptionCode ec = 0; - v8::Handle<v8::Value> result = toV8(workerContext->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)); - - V8Proxy::setDOMException(ec); - return result; -} - -v8::Handle<v8::Value> V8WorkerContext::openDatabaseSyncCallback(const v8::Arguments& args) -{ - INC_STATS("DOM.V8WorkerContext.openDatabaseSync()"); - if (args.Length() < 4) - return throwError(SYNTAX_ERR); - - TO_WEBCORE_STRING_EXCEPTION_BLOCK(name, args[0]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(version, args[1]); - TO_WEBCORE_STRING_EXCEPTION_BLOCK(displayName, args[2]); - EXCEPTION_BLOCK(unsigned long, estimatedSize, args[3]->Uint32Value()); - - WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder()); - - RefPtr<DatabaseCallback> creationCallback; - if (args.Length() >= 5) { - if (!args[4]->IsObject()) - return throwError(TYPE_MISMATCH_ERR); - - creationCallback = V8DatabaseCallback::create(args[4]); - } - - ExceptionCode ec = 0; - v8::Handle<v8::Value> result = toV8(workerContext->openDatabaseSync(name, version, displayName, estimatedSize, creationCallback.release(), ec)); - - V8Proxy::setDOMException(ec); - return result; -} -#endif - } // namespace WebCore #endif // ENABLE(WORKERS) diff --git a/WebCore/bindings/v8/specialization/V8BindingState.cpp b/WebCore/bindings/v8/specialization/V8BindingState.cpp index 4710271..d95d578 100644 --- a/WebCore/bindings/v8/specialization/V8BindingState.cpp +++ b/WebCore/bindings/v8/specialization/V8BindingState.cpp @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -31,6 +31,8 @@ #include "config.h" #include "V8BindingState.h" +#include "Frame.h" +#include "ScriptController.h" #include "V8Proxy.h" #include <wtf/StdLibExtras.h> @@ -53,9 +55,34 @@ DOMWindow* State<V8Binding>::getActiveWindow() return V8Proxy::retrieveWindow(activeContext); } +Frame* State<V8Binding>::getActiveFrame() +{ + Frame* frame = V8Proxy::retrieveFrameForCallingContext(); + if (!frame) { + // Unfortunately, when processing script from a plug-in, we might not + // have a calling context. In those cases, we fall back to the + // entered context for security checks. + // FIXME: We need a better API for retrieving frames that abstracts + // away this concern. + frame = V8Proxy::retrieveFrameForEnteredContext(); + } + return frame; +} + +Frame* State<V8Binding>::getFirstFrame() +{ + return V8Proxy::retrieveFrameForEnteredContext(); +} + void State<V8Binding>::immediatelyReportUnsafeAccessTo(Frame* target) { V8Proxy::reportUnsafeAccessTo(target, V8Proxy::ReportNow); } +bool State<V8Binding>::processingUserGesture() +{ + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); + return frame && frame->script()->processingUserGesture(); +} + } // namespace WebCore diff --git a/WebCore/bindings/v8/specialization/V8BindingState.h b/WebCore/bindings/v8/specialization/V8BindingState.h index f305c14..baba0c6 100644 --- a/WebCore/bindings/v8/specialization/V8BindingState.h +++ b/WebCore/bindings/v8/specialization/V8BindingState.h @@ -1,10 +1,10 @@ /* * 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 @@ -14,7 +14,7 @@ * * 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 @@ -36,6 +36,8 @@ namespace WebCore { +class Frame; + // Singleton implementation of State<V8Binding>. Uses V8's global data // structures to return information about relevant execution state. template <> @@ -44,11 +46,19 @@ public: // Singleton static State* Only(); + // Reports an error message (without delay) if the security check fails. + static void immediatelyReportUnsafeAccessTo(Frame*); + // The DOMWindow corresponding to the 'calling context' of execution. DOMWindow* getActiveWindow(); - // Reports an error message (without delay) if the security check fails. - static void immediatelyReportUnsafeAccessTo(Frame*); + // The frame corresponding to the 'calling context' of execution. + Frame* getActiveFrame(); + + // The first frame in which execution entered user script. + Frame* getFirstFrame(); + + bool processingUserGesture(); private: explicit State() {} |