Changeset 57203 in webkit


Ignore:
Timestamp:
Apr 7, 2010 4:39:31 AM (14 years ago)
Author:
jorlow@chromium.org
Message:

2010-04-06 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Adam Barth.

V8CustomIDBCallbacks<> should not hold a reference to the frame
https://bugs.webkit.org/show_bug.cgi?id=37154

Don't hold on to a Frame reference.
Instead, be an ActiveDOMObject and use scriptExecutionContext()
to get the v8 context.
Factor the guts of onSuccess and onError out.

Doesn't work enough to test yet.

  • bindings/v8/custom/V8CustomIDBCallbacks.h: (WebCore::V8CustomIDBCallbacks::create): (WebCore::V8CustomIDBCallbacks::onSuccess): (WebCore::V8CustomIDBCallbacks::onError): (WebCore::V8CustomIDBCallbacks::V8CustomIDBCallbacks): (WebCore::V8CustomIDBCallbacks::onEvent):
  • bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp: (WebCore::V8IndexedDatabaseRequest::openCallback):
  • storage/IDBCallbacks.h: (WebCore::IDBCallbacks::IDBCallbacks):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57201 r57203  
     12010-04-06  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        V8CustomIDBCallbacks<> should not hold a reference to the frame
     6        https://bugs.webkit.org/show_bug.cgi?id=37154
     7
     8        Don't hold on to a Frame reference.
     9        Instead, be an ActiveDOMObject and use scriptExecutionContext()
     10        to get the v8 context.
     11        Factor the guts of onSuccess and onError out.
     12
     13        Doesn't work enough to test yet.
     14
     15        * bindings/v8/custom/V8CustomIDBCallbacks.h:
     16        (WebCore::V8CustomIDBCallbacks::create):
     17        (WebCore::V8CustomIDBCallbacks::onSuccess):
     18        (WebCore::V8CustomIDBCallbacks::onError):
     19        (WebCore::V8CustomIDBCallbacks::V8CustomIDBCallbacks):
     20        (WebCore::V8CustomIDBCallbacks::onEvent):
     21        * bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp:
     22        (WebCore::V8IndexedDatabaseRequest::openCallback):
     23        * storage/IDBCallbacks.h:
     24        (WebCore::IDBCallbacks::IDBCallbacks):
     25
    1262010-04-07  Sheriff Bot  <webkit.review.bot@gmail.com>
    227
  • trunk/WebCore/bindings/v8/custom/V8CustomIDBCallbacks.h

    r56907 r57203  
    3232#define V8CustomIDBCallbacks_h
    3333
     34#include "Document.h"
    3435#include "Frame.h"
    3536#include "IDBDatabaseError.h"
    3637#include "V8CustomVoidCallback.h"
    3738#include "V8IDBDatabaseError.h"
     39#include "WorldContextHandle.h"
    3840#include <v8.h>
    3941#include <wtf/PassRefPtr.h>
     
    4951class V8CustomIDBCallbacks : public IDBCallbacks<ResultType> {
    5052public:
    51     static PassRefPtr<V8CustomIDBCallbacks> create(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, Frame* frame)
     53    static PassRefPtr<V8CustomIDBCallbacks> create(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, ScriptExecutionContext* scriptExecutionContext)
    5254    {
    53         return adoptRef(new V8CustomIDBCallbacks(onSuccess, onError, frame));
     55        return adoptRef(new V8CustomIDBCallbacks(onSuccess, onError, scriptExecutionContext));
    5456    }
    5557
     
    6264    virtual void onSuccess(PassRefPtr<ResultType> result)
    6365    {
    64         if (m_onSuccess.IsEmpty())
     66        onEvent(m_onSuccess, ResultWrapperType::create(result));
     67    }
     68
     69    virtual void onError(PassRefPtr<IDBDatabaseError> error)
     70    {
     71        onEvent(m_onError, error);
     72    }
     73
     74    // FIXME: Handle suspend/resume correctly.
     75
     76private:
     77    V8CustomIDBCallbacks(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, ScriptExecutionContext* scriptExecutionContext)
     78        : IDBCallbacks<ResultType>(scriptExecutionContext, this)
     79        , m_onSuccess(onSuccess->IsObject() ? v8::Persistent<v8::Object>::New(onSuccess->ToObject()) : v8::Persistent<v8::Object>())
     80        , m_onError(onError->IsObject() ? v8::Persistent<v8::Object>::New(onError->ToObject()) : v8::Persistent<v8::Object>())
     81        , m_worldContext(UseCurrentWorld)
     82    {
     83    }
     84
     85    template <typename Type>
     86    void onEvent(v8::Persistent<v8::Object> callback, PassRefPtr<Type> value)
     87    {
     88        if (!ActiveDOMObject::scriptExecutionContext())
    6589            return;
     90        if (callback.IsEmpty())
     91            return;
     92
    6693        v8::HandleScope handleScope;
    67         v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get());
     94        v8::Handle<v8::Context> context = toV8Context(ActiveDOMObject::scriptExecutionContext(), m_worldContext);
    6895        if (context.IsEmpty())
    6996            return;
     
    7198        v8::Context::Scope scope(context);
    7299        v8::Handle<v8::Value> argv[] = {
    73             toV8(ResultWrapperType::create(result))
     100            toV8(value)
    74101        };
    75         RefPtr<Frame> protector(m_frame);
     102
     103        // FIXME: Make this work for workers.
     104        ASSERT(ActiveDOMObject::scriptExecutionContext()->isDocument());
     105        RefPtr<Frame> protector(static_cast<Document*>(ActiveDOMObject::scriptExecutionContext())->frame());
     106
    76107        bool callbackReturnValue = false;
    77108        // FIXME: Do we care if this thing returns true (i.e. it raised an exception)?
    78         invokeCallback(m_onSuccess, 1, argv, callbackReturnValue);
     109        invokeCallback(callback, 1, argv, callbackReturnValue);
    79110    }
    80111
    81     virtual void onError(PassRefPtr<IDBDatabaseError> error)
    82     {
    83         if (m_onError.IsEmpty())
    84             return;
    85         v8::HandleScope handleScope;
    86         v8::Handle<v8::Context> context = V8Proxy::context(m_frame.get());
    87         if (context.IsEmpty())
    88             return;
    89 
    90         v8::Context::Scope scope(context);
    91         v8::Handle<v8::Value> argv[] = {
    92             toV8(error)
    93         };
    94         RefPtr<Frame> protector(m_frame);
    95         bool callbackReturnValue = false;
    96         // FIXME: Do we care if this thing returns true (i.e. it raised an exception)?
    97         invokeCallback(m_onError, 1, argv, callbackReturnValue);
    98     }
    99 
    100 private:
    101     V8CustomIDBCallbacks(v8::Local<v8::Value> onSuccess, v8::Local<v8::Value> onError, Frame* frame)
    102         : m_onSuccess(onSuccess->IsObject() ? v8::Persistent<v8::Object>::New(onSuccess->ToObject()) : v8::Persistent<v8::Object>())
    103         , m_onError(onError->IsObject() ? v8::Persistent<v8::Object>::New(onError->ToObject()) : v8::Persistent<v8::Object>())
    104         , m_frame(frame)
    105     {
    106     }
    107 
    108     // FIXME: Should these be v8::Functions?  For some reason, VoidCallback (which this copied) uses v8::Objects.
     112    // FIXME: Use OwnHandles.
    109113    v8::Persistent<v8::Object> m_onSuccess;
    110114    v8::Persistent<v8::Object> m_onError;
    111     RefPtr<Frame> m_frame;
     115
     116    WorldContextHandle m_worldContext;
    112117};
    113118
  • trunk/WebCore/bindings/v8/custom/V8IndexedDatabaseRequestCustom.cpp

    r56834 r57203  
    7373    Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
    7474    RefPtr<V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest> > callbacks =
    75         V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest>::create(onSuccess, onError, frame);
     75        V8CustomIDBCallbacks<IDBDatabase, IDBDatabaseRequest>::create(onSuccess, onError, frame->document());
    7676
    7777    ExceptionCode ec = 0;
  • trunk/WebCore/storage/IDBCallbacks.h

    r56713 r57203  
    3030#define IDBCallbacks_h
    3131
     32#include "ActiveDOMObject.h"
    3233#include <wtf/PassRefPtr.h>
    3334#include <wtf/RefCounted.h>
     
    3839
    3940template <typename ResultType>
    40 class IDBCallbacks : public RefCounted<IDBCallbacks<ResultType> > {
     41class IDBCallbacks : public RefCounted<IDBCallbacks<ResultType> >, public ActiveDOMObject {
    4142public:
     43    IDBCallbacks(ScriptExecutionContext* scriptExecutionContext, void* upcastPointer)
     44        : ActiveDOMObject(scriptExecutionContext, upcastPointer) { }
    4245    virtual ~IDBCallbacks() { }
    4346
Note: See TracChangeset for help on using the changeset viewer.