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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #ifndef UnsafePersistent_h
32 #include "modules/webmidi/MIDIErrorCallback.h" 32 #define UnsafePersistent_h
33 33
34 #include "core/dom/DOMError.h" 34 #include <v8.h>
35 #include "core/dom/ScriptExecutionContext.h"
36 35
37 namespace WebCore { 36 namespace WebCore {
38 37
39 namespace { 38 // An unsafe way to pass Persistent handles around. Do not use unless you know
39 // what you're doing. UnsafePersistent is only safe to use when we know that the
40 // memory pointed by the it is not going away: 1) When GC cannot happen while
41 // the UnsafePersistent is alive or 2) when there is a strong Persistent keeping
42 // the memory alive while the UnsafePersistent is alive.
40 43
41 class DispatchCallbackTask : public ScriptExecutionContext::Task { 44 // TODO: assert that GC doesn't happen during the lifetime of UnsafePersistent.
abarth-chromium 2013/04/29 17:47:33 TODO -> FIXME
marja 2013/04/30 08:55:50 Done.
45 template<typename T> class UnsafePersistent {
abarth-chromium 2013/04/29 17:47:33 I probably would have called this class UnsafeHand
marja 2013/04/30 08:55:50 After the future renaming, Local will be called Ha
42 public: 46 public:
43 static PassOwnPtr<DispatchCallbackTask> create(PassRefPtr<MIDIErrorCallback> callback, PassRefPtr<DOMError> error) 47 UnsafePersistent(T* value) : m_value(value) { }
48
49 // The end result is generally unsafe to use, see the class level comment
50 // for when it's safe to use.
51 void makePersistentHandle(v8::Persistent<T>* handle) const
abarth-chromium 2013/04/29 17:47:33 copyTo ?
marja 2013/04/30 08:55:50 Done.
44 { 52 {
45 return adoptPtr(new DispatchCallbackTask(callback, error)); 53 T** rawValue = reinterpret_cast<T**>(handle);
abarth-chromium 2013/04/29 17:47:33 Wow, that's scary stuff.
54 *rawValue = m_value;
46 } 55 }
47 56
48 virtual void performTask(ScriptExecutionContext*) 57 T* value() const
49 { 58 {
50 m_callback->handleEvent(m_error.get()); 59 return m_value;
51 } 60 }
52 61
53 private: 62 private:
54 DispatchCallbackTask(PassRefPtr<MIDIErrorCallback> callback, PassRefPtr<DOME rror> error) 63 T* m_value;
55 : m_callback(callback)
56 , m_error(error)
57 {
58 }
59
60 RefPtr<MIDIErrorCallback> m_callback;
61 RefPtr<DOMError> m_error;
62 }; 64 };
63 65
64 } // namespace 66 } // namespace WebCore
65 67
66 void MIDIErrorCallback::scheduleCallback(ScriptExecutionContext* context, PassRe fPtr<DOMError> error) 68 #endif // UnsafePersistent_h
67 {
68 context->postTask(DispatchCallbackTask::create(this, error));
69 }
70
71 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698