Title: [134523] trunk/Source
Revision
134523
Author
alecfl...@chromium.org
Date
2012-11-13 19:41:51 -0800 (Tue, 13 Nov 2012)

Log Message

Add DOMRequestState to maintain world/ScriptExecutionContext state
https://bugs.webkit.org/show_bug.cgi?id=102102

Reviewed by Adam Barth.

Introduce DOMRequestState, and convert IndexedDB over.

No new tests, this is an abstraction layer for existing code.

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::IDBRequest):
(WebCore::IDBRequest::onSuccess):
(WebCore::IDBRequest::dispatchEvent):
* Modules/indexeddb/IDBRequest.h:
(IDBRequest):
* WebCore.gypi:
* bindings/v8/DOMRequestState.h: Added.
(WebCore):
(DOMRequestState):
(WebCore::DOMRequestState::DOMRequestState):
(Scope):
(WebCore::DOMRequestState::Scope::Scope):
(WebCore::DOMRequestState::scope):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (134522 => 134523)


--- trunk/Source/WebCore/ChangeLog	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/ChangeLog	2012-11-14 03:41:51 UTC (rev 134523)
@@ -1,3 +1,29 @@
+2012-11-13  Alec Flett  <alecfl...@chromium.org>
+
+        Add DOMRequestState to maintain world/ScriptExecutionContext state
+        https://bugs.webkit.org/show_bug.cgi?id=102102
+
+        Reviewed by Adam Barth.
+
+        Introduce DOMRequestState, and convert IndexedDB over.
+
+        No new tests, this is an abstraction layer for existing code.
+
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::IDBRequest):
+        (WebCore::IDBRequest::onSuccess):
+        (WebCore::IDBRequest::dispatchEvent):
+        * Modules/indexeddb/IDBRequest.h:
+        (IDBRequest):
+        * WebCore.gypi:
+        * bindings/v8/DOMRequestState.h: Added.
+        (WebCore):
+        (DOMRequestState):
+        (WebCore::DOMRequestState::DOMRequestState):
+        (Scope):
+        (WebCore::DOMRequestState::Scope::Scope):
+        (WebCore::DOMRequestState::scope):
+
 2012-11-13  Robert Sesek  <rse...@chromium.org>
 
         Sever Chromium's dependence on WebKitSystemInterface media control drawing functions in RenderThemeMac

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp (134522 => 134523)


--- trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp	2012-11-14 03:41:51 UTC (rev 134523)
@@ -257,13 +257,13 @@
     }
 }
 
-void IDBCursor::setValueReady(ScriptExecutionContext* context, PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, ScriptValue& value)
+void IDBCursor::setValueReady(DOMRequestState* state, PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, ScriptValue& value)
 {
     m_currentKey = key;
-    m_currentKeyValue = idbKeyToScriptValue(context, m_currentKey);
+    m_currentKeyValue = idbKeyToScriptValue(state, m_currentKey);
 
     m_currentPrimaryKey = primaryKey;
-    m_currentPrimaryKeyValue = idbKeyToScriptValue(context, m_currentPrimaryKey);
+    m_currentPrimaryKeyValue = idbKeyToScriptValue(state, m_currentPrimaryKey);
 
     if (!isKeyCursor()) {
         RefPtr<IDBObjectStore> objectStore = effectiveObjectStore();

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBCursor.h (134522 => 134523)


--- trunk/Source/WebCore/Modules/indexeddb/IDBCursor.h	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBCursor.h	2012-11-14 03:41:51 UTC (rev 134523)
@@ -38,6 +38,7 @@
 
 namespace WebCore {
 
+class DOMRequestState;
 class IDBAny;
 class IDBCallbacks;
 class IDBCursorBackendInterface;
@@ -84,7 +85,7 @@
 
     void postSuccessHandlerCallback();
     void close();
-    void setValueReady(ScriptExecutionContext*, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, ScriptValue&);
+    void setValueReady(DOMRequestState*, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, ScriptValue&);
     PassRefPtr<IDBKey> idbPrimaryKey() { return m_currentPrimaryKey; }
 
 protected:

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp (134522 => 134523)


--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp	2012-11-14 03:41:51 UTC (rev 134523)
@@ -42,9 +42,6 @@
 #include "IDBTracing.h"
 #include "IDBTransaction.h"
 #include "ScriptExecutionContext.h"
-#if USE(V8)
-#include "V8Binding.h"
-#endif
 
 namespace WebCore {
 
@@ -79,9 +76,7 @@
     , m_pendingCursor(0)
     , m_didFireUpgradeNeededEvent(false)
     , m_preventPropagation(false)
-#if USE(V8)
-    , m_worldContextHandle(UseCurrentWorld)
-#endif
+    , m_requestState(context)
 {
     if (m_transaction) {
         m_transaction->registerRequest(this);
@@ -290,15 +285,8 @@
     if (!shouldEnqueueEvent())
         return;
 
-#if USE(V8)
-    v8::HandleScope handleScope;
-    v8::Local<v8::Context> context = toV8Context(scriptExecutionContext(), m_worldContextHandle);
-    if (context.IsEmpty())
-        CRASH();
-    v8::Context::Scope contextScope(context);
-#endif
-
-    ScriptValue value = deserializeIDBValue(scriptExecutionContext(), serializedValue);
+    DOMRequestState::Scope scope(m_requestState);
+    ScriptValue value = deserializeIDBValue(&m_requestState, serializedValue);
     ASSERT(m_cursorType != IDBCursorBackendInterface::InvalidCursorType);
     RefPtr<IDBCursor> cursor;
     if (m_cursorType == IDBCursorBackendInterface::IndexKeyCursor)
@@ -354,15 +342,8 @@
     if (!shouldEnqueueEvent())
         return;
 
-#if USE(V8)
-    v8::HandleScope handleScope;
-    v8::Local<v8::Context> context = toV8Context(scriptExecutionContext(), m_worldContextHandle);
-    if (context.IsEmpty())
-        CRASH();
-    v8::Context::Scope contextScope(context);
-#endif
-
-    ScriptValue value = deserializeIDBValue(scriptExecutionContext(), serializedScriptValue);
+    DOMRequestState::Scope scope(m_requestState);
+    ScriptValue value = deserializeIDBValue(&m_requestState, serializedScriptValue);
     onSuccessInternal(value);
 }
 
@@ -385,18 +366,11 @@
     if (!shouldEnqueueEvent())
         return;
 
-#if USE(V8)
-    v8::HandleScope handleScope;
-    v8::Local<v8::Context> context = toV8Context(scriptExecutionContext(), m_worldContextHandle);
-    if (context.IsEmpty())
-        CRASH();
-    v8::Context::Scope contextScope(context);
-#endif
-
 #ifndef NDEBUG
     ASSERT(keyPath == effectiveObjectStore(m_source)->keyPath());
 #endif
-    ScriptValue value = deserializeIDBValue(scriptExecutionContext(), prpSerializedScriptValue);
+    DOMRequestState::Scope scope(m_requestState);
+    ScriptValue value = deserializeIDBValue(&m_requestState, prpSerializedScriptValue);
 
     RefPtr<IDBKey> primaryKey = prpPrimaryKey;
 #ifndef NDEBUG
@@ -434,15 +408,8 @@
     if (!shouldEnqueueEvent())
         return;
 
-#if USE(V8)
-    v8::HandleScope handleScope;
-    v8::Local<v8::Context> context = toV8Context(scriptExecutionContext(), m_worldContextHandle);
-    if (context.IsEmpty())
-        CRASH();
-    v8::Context::Scope contextScope(context);
-#endif
-
-    ScriptValue value = deserializeIDBValue(scriptExecutionContext(), serializedValue);
+    DOMRequestState::Scope scope(m_requestState);
+    ScriptValue value = deserializeIDBValue(&m_requestState, serializedValue);
     ASSERT(m_pendingCursor);
     setResultCursor(m_pendingCursor.release(), key, primaryKey, value);
     enqueueEvent(createSuccessEvent());
@@ -463,6 +430,7 @@
         return;
 
     m_contextStopped = true;
+    m_requestState.clear();
     if (m_readyState == PENDING)
         markEarlyDeath();
 }
@@ -488,13 +456,7 @@
     ASSERT(event->target() == this);
     ASSERT_WITH_MESSAGE(m_readyState < DONE, "When dispatching event %s, m_readyState < DONE(%d), was %d", event->type().string().utf8().data(), DONE, m_readyState);
 
-#if USE(V8)
-    v8::HandleScope handleScope;
-    v8::Local<v8::Context> context = toV8Context(scriptExecutionContext(), m_worldContextHandle);
-    if (context.IsEmpty())
-        CRASH();
-    v8::Context::Scope contextScope(context);
-#endif
+    DOMRequestState::Scope scope(m_requestState);
 
     if (event->type() != eventNames().blockedEvent)
         m_readyState = DONE;
@@ -520,7 +482,7 @@
     if (event->type() == eventNames().successEvent) {
         cursorToNotify = getResultCursor();
         if (cursorToNotify) {
-            cursorToNotify->setValueReady(scriptExecutionContext(), m_cursorKey.release(), m_cursorPrimaryKey.release(), m_cursorValue);
+            cursorToNotify->setValueReady(&m_requestState, m_cursorKey.release(), m_cursorPrimaryKey.release(), m_cursorValue);
             m_cursorValue.clear();
         }
     }

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h (134522 => 134523)


--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h	2012-11-14 03:41:51 UTC (rev 134523)
@@ -33,6 +33,7 @@
 
 #include "ActiveDOMObject.h"
 #include "DOMError.h"
+#include "DOMRequestState.h"
 #include "DOMStringList.h"
 #include "Event.h"
 #include "EventListener.h"
@@ -159,9 +160,7 @@
     bool m_preventPropagation;
 
     EventTargetData m_eventTargetData;
-#if USE(V8)
-    WorldContextHandle m_worldContextHandle;
-#endif
+    DOMRequestState m_requestState;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/WebCore.gypi (134522 => 134523)


--- trunk/Source/WebCore/WebCore.gypi	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/WebCore.gypi	2012-11-14 03:41:51 UTC (rev 134523)
@@ -31,6 +31,7 @@
             'accessibility/AccessibilityObject.h',
             'bindings/ScriptControllerBase.h',
             'bindings/js/DOMObjectHashTableMap.h',
+            'bindings/js/DOMRequestState.h',
             'bindings/js/DOMWrapperWorld.h',
             'bindings/js/GCController.h',
             'bindings/js/JSDOMBinding.h',
@@ -2200,6 +2201,7 @@
             'bindings/v8/BindingState.h',
             'bindings/v8/DOMDataStore.cpp',
             'bindings/v8/DOMDataStore.h',
+            'bindings/v8/DOMRequestState.h',
             'bindings/v8/DOMWrapperMap.h',
             'bindings/v8/DOMWrapperWorld.cpp',
             'bindings/v8/DOMWrapperWorld.h',

Copied: trunk/Source/WebCore/bindings/v8/DOMRequestState.h (from rev 134522, trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.h) (0 => 134523)


--- trunk/Source/WebCore/bindings/v8/DOMRequestState.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/v8/DOMRequestState.h	2012-11-14 03:41:51 UTC (rev 134523)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 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 AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DOMRequestState_h
+#define DOMRequestState_h
+
+#include "V8Binding.h"
+#include "WorldContextHandle.h"
+#include "v8.h"
+
+namespace WebCore {
+
+class ScriptExecutionContext;
+
+class DOMRequestState {
+public:
+    explicit DOMRequestState(ScriptExecutionContext* scriptExecutionContext)
+        : m_worldContextHandle(UseCurrentWorld)
+        , m_scriptExecutionContext(scriptExecutionContext)
+    {
+    }
+
+    void clear()
+    {
+        m_scriptExecutionContext = 0;
+    }
+
+    class Scope {
+    public:
+        explicit Scope(DOMRequestState& state)
+            : m_contextScope(state.context())
+        {
+        }
+    private:
+        v8::HandleScope m_handleScope;
+        v8::Context::Scope m_contextScope;
+    };
+
+    v8::Local<v8::Context> context()
+    {
+        return toV8Context(m_scriptExecutionContext, m_worldContextHandle);
+    }
+
+private:
+    WorldContextHandle m_worldContextHandle;
+    ScriptExecutionContext* m_scriptExecutionContext;
+};
+
+}
+#endif

Modified: trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (134522 => 134523)


--- trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp	2012-11-14 03:41:51 UTC (rev 134523)
@@ -35,7 +35,6 @@
 #include "SerializedScriptValue.h"
 #include "V8Binding.h"
 #include "V8IDBKey.h"
-#include "WorldContextHandle.h"
 #include <wtf/MathExtras.h>
 #include <wtf/Vector.h>
 
@@ -213,7 +212,7 @@
     return createIDBKeyFromScriptValueAndKeyPath(value, keyPath.string());
 }
 
-ScriptValue deserializeIDBValue(ScriptExecutionContext* scriptContext, PassRefPtr<SerializedScriptValue> prpValue)
+ScriptValue deserializeIDBValue(DOMRequestState* state, PassRefPtr<SerializedScriptValue> prpValue)
 {
     ASSERT(v8::Context::InContext());
     v8::HandleScope handleScope;
@@ -265,7 +264,7 @@
     return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1);
 }
 
-ScriptValue idbKeyToScriptValue(ScriptExecutionContext* scriptContext, PassRefPtr<IDBKey> key)
+ScriptValue idbKeyToScriptValue(DOMRequestState* state, PassRefPtr<IDBKey> key)
 {
     ASSERT(v8::Context::InContext());
     v8::HandleScope handleScope;

Modified: trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.h (134522 => 134523)


--- trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.h	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.h	2012-11-14 03:41:51 UTC (rev 134523)
@@ -34,6 +34,7 @@
 
 namespace WebCore {
 
+class DOMRequestState;
 class IDBKey;
 class IDBKeyPath;
 class SerializedScriptValue;
@@ -43,8 +44,8 @@
 bool injectIDBKeyIntoScriptValue(PassRefPtr<IDBKey>, ScriptValue&, const IDBKeyPath&);
 PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue&, const IDBKeyPath&);
 bool canInjectIDBKeyIntoScriptValue(const ScriptValue&, const IDBKeyPath&);
-ScriptValue deserializeIDBValue(ScriptExecutionContext*, PassRefPtr<SerializedScriptValue>);
-ScriptValue idbKeyToScriptValue(ScriptExecutionContext*, PassRefPtr<IDBKey>);
+ScriptValue deserializeIDBValue(DOMRequestState*, PassRefPtr<SerializedScriptValue>);
+ScriptValue idbKeyToScriptValue(DOMRequestState*, PassRefPtr<IDBKey>);
 
 }
 

Modified: trunk/Source/WebKit/chromium/src/WebIDBKey.cpp (134522 => 134523)


--- trunk/Source/WebKit/chromium/src/WebIDBKey.cpp	2012-11-14 03:38:18 UTC (rev 134522)
+++ trunk/Source/WebKit/chromium/src/WebIDBKey.cpp	2012-11-14 03:41:51 UTC (rev 134523)
@@ -30,7 +30,6 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "IDBBindingUtilities.h"
 #include "IDBKey.h"
 
 using namespace WebCore;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to