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

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

Issue 78713009: Introduce toV8NoInline (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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
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 13 matching lines...) Expand all
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 #ifndef ScriptPromiseResolver_h 31 #ifndef ScriptPromiseResolver_h
32 #define ScriptPromiseResolver_h 32 #define ScriptPromiseResolver_h
33 33
34 #include "bindings/v8/DOMWrapperWorld.h"
34 #include "bindings/v8/ScopedPersistent.h" 35 #include "bindings/v8/ScopedPersistent.h"
35 #include "bindings/v8/ScriptObject.h" 36 #include "bindings/v8/ScriptObject.h"
36 #include "bindings/v8/ScriptPromise.h" 37 #include "bindings/v8/ScriptPromise.h"
37 #include "bindings/v8/ScriptState.h" 38 #include "bindings/v8/ScriptState.h"
38 #include "bindings/v8/ScriptValue.h" 39 #include "bindings/v8/ScriptValue.h"
40 #include "bindings/v8/V8Binding.h"
39 #include "wtf/RefPtr.h" 41 #include "wtf/RefPtr.h"
40 42
41 #include <v8.h> 43 #include <v8.h>
42 44
43 namespace WebCore { 45 namespace WebCore {
44 46
45 class ExecutionContext; 47 class ExecutionContext;
46 48
47 // ScriptPromiseResolver is a class for performing operations on Promise 49 // ScriptPromiseResolver is a class for performing operations on Promise
48 // (resolve / reject) from C++ world. 50 // (resolve / reject) from C++ world.
(...skipping 27 matching lines...) Expand all
76 78
77 // Return true if the promise object is in pending state. 79 // Return true if the promise object is in pending state.
78 bool isPending() const; 80 bool isPending() const;
79 81
80 ScriptPromise promise() 82 ScriptPromise promise()
81 { 83 {
82 ASSERT(v8::Context::InContext()); 84 ASSERT(v8::Context::InContext());
83 return m_promise; 85 return m_promise;
84 } 86 }
85 87
86 // Resolve with a C++ object which can be converted to a v8 object by toV8. 88 // To use following template methods, T must be a DOM interface with
89 // PromiseResolutionTarget attribute.
90
91 // This method will be implemented by the code generator.
87 template<typename T> 92 template<typename T>
88 inline void resolve(PassRefPtr<T>); 93 void resolve(T* value, v8::Handle<v8::Object> creationContext);
89 // Reject with a C++ object which can be converted to a v8 object by toV8. 94 // This method will be implemented by the code generator.
90 template<typename T> 95 template<typename T>
91 inline void reject(PassRefPtr<T>); 96 void reject(T* value, v8::Handle<v8::Object> creationContext);
97
98 template<typename T>
99 void resolve(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); }
100 template<typename T>
101 void reject(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { r eject(value.get(), creationContext); }
102
103 template<typename T>
104 inline void resolve(T* value, ExecutionContext*);
105 template<typename T>
106 inline void reject(T* value, ExecutionContext*);
107
108 template<typename T>
109 void resolve(PassRefPtr<T> value, ExecutionContext* context) { resolve(value .get(), context); }
110 template<typename T>
111 void reject(PassRefPtr<T> value, ExecutionContext* context) { reject(value.g et(), context); }
112
113 template<typename T>
114 inline void resolve(T* value);
115 template<typename T>
116 inline void reject(T* value);
117
118 template<typename T>
119 void resolve(PassRefPtr<T> value) { resolve(value.get()); }
120 template<typename T>
121 void reject(PassRefPtr<T> value) { reject(value.get()); }
92 122
93 void resolve(ScriptValue); 123 void resolve(ScriptValue);
94 void reject(ScriptValue); 124 void reject(ScriptValue);
95 125
126 // Only bindings code can use these methods.
127 void resolve(v8::Handle<v8::Value>);
128 void reject(v8::Handle<v8::Value>);
129
96 private: 130 private:
97 ScriptPromiseResolver(ScriptPromise, v8::Isolate*); 131 ScriptPromiseResolver(ScriptPromise, v8::Isolate*);
98 void resolve(v8::Handle<v8::Value>);
99 void reject(v8::Handle<v8::Value>);
100 132
101 v8::Isolate* m_isolate; 133 v8::Isolate* m_isolate;
102 ScriptPromise m_promise; 134 ScriptPromise m_promise;
103 }; 135 };
104 136
105 template<typename T> 137 template<typename T>
106 void ScriptPromiseResolver::resolve(PassRefPtr<T> value) 138 void ScriptPromiseResolver::resolve(T* value, ExecutionContext* context)
107 { 139 {
108 ASSERT(v8::Context::InContext()); 140 ASSERT(v8::Context::InContext());
109 resolve(toV8(value.get(), v8::Object::New(), m_isolate)); 141 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent());
142 resolve(value, v8Context->Global());
110 } 143 }
111 144
112 template<typename T> 145 template<typename T>
113 void ScriptPromiseResolver::reject(PassRefPtr<T> value) 146 void ScriptPromiseResolver::reject(T* value, ExecutionContext* context)
114 { 147 {
115 ASSERT(v8::Context::InContext()); 148 ASSERT(v8::Context::InContext());
116 reject(toV8(value.get(), v8::Object::New(), m_isolate)); 149 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent());
150 reject(value, v8Context->Global());
151 }
152
153 template<typename T>
154 void ScriptPromiseResolver::resolve(T* value)
155 {
156 ASSERT(v8::Context::InContext());
157 resolve(value, v8::Object::New());
158 }
159
160 template<typename T>
161 void ScriptPromiseResolver::reject(T* value)
162 {
163 ASSERT(v8::Context::InContext());
164 reject(value, v8::Object::New());
117 } 165 }
118 166
119 } // namespace WebCore 167 } // namespace WebCore
120 168
121 169
122 #endif // ScriptPromiseResolver_h 170 #endif // ScriptPromiseResolver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698