Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: Source/bindings/v8/UnsafePersistent.h

Issue 14443007: Get rid of usages of ScriptWrappable::wrapper(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/ScriptWrappable.h ('k') | Source/bindings/v8/V8GCController.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/UnsafePersistent.h
diff --git a/Source/modules/webmidi/MIDIErrorCallback.cpp b/Source/bindings/v8/UnsafePersistent.h
similarity index 63%
copy from Source/modules/webmidi/MIDIErrorCallback.cpp
copy to Source/bindings/v8/UnsafePersistent.h
index 0557f1d01c17606f418bf1f5fccdf495e6707cc0..711583fa2527b1c0e64bd8b41e33bd305fbd7f22 100644
--- a/Source/modules/webmidi/MIDIErrorCallback.cpp
+++ b/Source/bindings/v8/UnsafePersistent.h
@@ -28,44 +28,41 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config.h"
-#include "modules/webmidi/MIDIErrorCallback.h"
+#ifndef UnsafePersistent_h
+#define UnsafePersistent_h
-#include "core/dom/DOMError.h"
-#include "core/dom/ScriptExecutionContext.h"
+#include <v8.h>
namespace WebCore {
-namespace {
+// An unsafe way to pass Persistent handles around. Do not use unless you know
+// what you're doing. UnsafePersistent is only safe to use when we know that the
+// memory pointed by the it is not going away: 1) When GC cannot happen while
+// the UnsafePersistent is alive or 2) when there is a strong Persistent keeping
+// the memory alive while the UnsafePersistent is alive.
-class DispatchCallbackTask : public ScriptExecutionContext::Task {
+// FIXME: assert that GC doesn't happen during the lifetime of UnsafePersistent.
+template<typename T> class UnsafePersistent {
public:
- static PassOwnPtr<DispatchCallbackTask> create(PassRefPtr<MIDIErrorCallback> callback, PassRefPtr<DOMError> error)
- {
- return adoptPtr(new DispatchCallbackTask(callback, error));
- }
+ UnsafePersistent(T* value) : m_value(value) { }
- virtual void performTask(ScriptExecutionContext*)
+ // The end result is generally unsafe to use, see the class level comment
+ // for when it's safe to use.
+ void copyTo(v8::Persistent<T>* handle) const
{
- m_callback->handleEvent(m_error.get());
+ T** rawValue = reinterpret_cast<T**>(handle);
+ *rawValue = m_value;
}
-private:
- DispatchCallbackTask(PassRefPtr<MIDIErrorCallback> callback, PassRefPtr<DOMError> error)
- : m_callback(callback)
- , m_error(error)
+ T* value() const
{
+ return m_value;
}
- RefPtr<MIDIErrorCallback> m_callback;
- RefPtr<DOMError> m_error;
+private:
+ T* m_value;
};
-} // namespace
-
-void MIDIErrorCallback::scheduleCallback(ScriptExecutionContext* context, PassRefPtr<DOMError> error)
-{
- context->postTask(DispatchCallbackTask::create(this, error));
-}
-
} // namespace WebCore
+
+#endif // UnsafePersistent_h
« no previous file with comments | « Source/bindings/v8/ScriptWrappable.h ('k') | Source/bindings/v8/V8GCController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698