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

Side by Side Diff: Source/bindings/v8/ScriptPromiseResolver.h

Issue 23479016: Introduce Promise mapping to the IDL generator (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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
« no previous file with comments | « Source/bindings/v8/ScriptPromise.h ('k') | Source/bindings/v8/ScriptPromiseResolver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 15 matching lines...) Expand all
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 #ifndef ScriptPromiseResolver_h 31 #ifndef ScriptPromiseResolver_h
32 #define ScriptPromiseResolver_h 32 #define ScriptPromiseResolver_h
33 33
34 #include "bindings/v8/ScopedPersistent.h" 34 #include "bindings/v8/ScopedPersistent.h"
35 #include "bindings/v8/ScriptObject.h" 35 #include "bindings/v8/ScriptObject.h"
36 #include "bindings/v8/ScriptPromise.h"
36 #include "bindings/v8/ScriptState.h" 37 #include "bindings/v8/ScriptState.h"
37 #include "bindings/v8/ScriptValue.h" 38 #include "bindings/v8/ScriptValue.h"
38 #include "wtf/RefPtr.h" 39 #include "wtf/RefPtr.h"
39 40
40 #include <v8.h> 41 #include <v8.h>
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
44 class ScriptExecutionContext; 45 class ScriptExecutionContext;
45 46
(...skipping 30 matching lines...) Expand all
76 77
77 // Detach the promise object. 78 // Detach the promise object.
78 void detachPromise() { m_promise.clear(); } 79 void detachPromise() { m_promise.clear(); }
79 80
80 // Return true if the following conditions are met: 81 // Return true if the following conditions are met:
81 // - The resolver object is not detached. 82 // - The resolver object is not detached.
82 // - The resolver's promise object is in pending state. 83 // - The resolver's promise object is in pending state.
83 // - The resolver's resolved flag is not set. 84 // - The resolver's resolved flag is not set.
84 bool isPending() const; 85 bool isPending() const;
85 86
86 ScriptObject promise() 87 ScriptPromise promise()
87 { 88 {
88 ASSERT(v8::Context::InContext()); 89 ASSERT(v8::Context::InContext());
89 return ScriptObject(ScriptState::current(), m_promise.newLocal(m_isolate )); 90 return m_promise;
90 } 91 }
91 92
92 // Fulfill with a C++ object which can be converted to a v8 object by toV8. 93 // Fulfill with a C++ object which can be converted to a v8 object by toV8.
93 template<typename T> 94 template<typename T>
94 inline void fulfill(PassRefPtr<T>); 95 inline void fulfill(PassRefPtr<T>);
95 // Resolve with a C++ object which can be converted to a v8 object by toV8. 96 // Resolve with a C++ object which can be converted to a v8 object by toV8.
96 template<typename T> 97 template<typename T>
97 inline void resolve(PassRefPtr<T>); 98 inline void resolve(PassRefPtr<T>);
98 // Reject with a C++ object which can be converted to a v8 object by toV8. 99 // Reject with a C++ object which can be converted to a v8 object by toV8.
99 template<typename T> 100 template<typename T>
100 inline void reject(PassRefPtr<T>); 101 inline void reject(PassRefPtr<T>);
101 102
102 void fulfill(ScriptValue); 103 void fulfill(ScriptValue);
103 void resolve(ScriptValue); 104 void resolve(ScriptValue);
104 void reject(ScriptValue); 105 void reject(ScriptValue);
105 106
106 private: 107 private:
107 ScriptPromiseResolver(v8::Handle<v8::Object> creationContext, v8::Isolate*); 108 ScriptPromiseResolver(v8::Handle<v8::Object> creationContext, v8::Isolate*);
108 void fulfill(v8::Handle<v8::Value>); 109 void fulfill(v8::Handle<v8::Value>);
109 void resolve(v8::Handle<v8::Value>); 110 void resolve(v8::Handle<v8::Value>);
110 void reject(v8::Handle<v8::Value>); 111 void reject(v8::Handle<v8::Value>);
111 112
112 v8::Isolate* m_isolate; 113 v8::Isolate* m_isolate;
113 ScopedPersistent<v8::Object> m_promise; 114 ScriptPromise m_promise;
haraken 2013/09/03 17:03:07 I still don't fully understand why this doesn't ca
yhirano 2013/09/04 02:14:15 Users of ScriptPromiseResolver should call detachP
114 ScopedPersistent<v8::Object> m_resolver; 115 ScopedPersistent<v8::Object> m_resolver;
115 bool isPendingInternal() const; 116 bool isPendingInternal() const;
116 }; 117 };
117 118
118 template<typename T> 119 template<typename T>
119 void ScriptPromiseResolver::fulfill(PassRefPtr<T> value) 120 void ScriptPromiseResolver::fulfill(PassRefPtr<T> value)
120 { 121 {
121 ASSERT(v8::Context::InContext()); 122 ASSERT(v8::Context::InContext());
122 fulfill(toV8(value.get(), v8::Object::New(), m_isolate)); 123 fulfill(toV8(value.get(), v8::Object::New(), m_isolate));
123 } 124 }
124 125
125 template<typename T> 126 template<typename T>
126 void ScriptPromiseResolver::resolve(PassRefPtr<T> value) 127 void ScriptPromiseResolver::resolve(PassRefPtr<T> value)
127 { 128 {
128 ASSERT(v8::Context::InContext()); 129 ASSERT(v8::Context::InContext());
129 resolve(toV8(value.get(), v8::Object::New(), m_isolate)); 130 resolve(toV8(value.get(), v8::Object::New(), m_isolate));
130 } 131 }
131 132
132 template<typename T> 133 template<typename T>
133 void ScriptPromiseResolver::reject(PassRefPtr<T> value) 134 void ScriptPromiseResolver::reject(PassRefPtr<T> value)
134 { 135 {
135 ASSERT(v8::Context::InContext()); 136 ASSERT(v8::Context::InContext());
136 reject(toV8(value.get(), v8::Object::New(), m_isolate)); 137 reject(toV8(value.get(), v8::Object::New(), m_isolate));
137 } 138 }
138 139
139 } // namespace WebCore 140 } // namespace WebCore
140 141
141 142
142 #endif // ScriptPromiseResolver_h 143 #endif // ScriptPromiseResolver_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptPromise.h ('k') | Source/bindings/v8/ScriptPromiseResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698