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

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: Do not generate toV8Inline if CustomToV8 is specified. 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 class.
89
90 // This method will be implemented by the code generator.
87 template<typename T> 91 template<typename T>
88 inline void resolve(PassRefPtr<T>); 92 void resolve(T* value, v8::Handle<v8::Object> creationContext) { resolve(toV 8NoInline(value, creationContext, m_isolate)); }
89 // Reject with a C++ object which can be converted to a v8 object by toV8.
90 template<typename T> 93 template<typename T>
91 inline void reject(PassRefPtr<T>); 94 void reject(T* value, v8::Handle<v8::Object> creationContext) { reject(toV8N oInline(value, creationContext, m_isolate)); }
95
96 template<typename T>
97 void resolve(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); }
98 template<typename T>
99 void reject(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { r eject(value.get(), creationContext); }
100
101 template<typename T>
102 inline void resolve(T* value, ExecutionContext*);
103 template<typename T>
104 inline void reject(T* value, ExecutionContext*);
105
106 template<typename T>
107 void resolve(PassRefPtr<T> value, ExecutionContext* context) { resolve(value .get(), context); }
108 template<typename T>
109 void reject(PassRefPtr<T> value, ExecutionContext* context) { reject(value.g et(), context); }
110
111 template<typename T>
112 inline void resolve(T* value);
113 template<typename T>
114 inline void reject(T* value);
115
116 template<typename T>
117 void resolve(PassRefPtr<T> value) { resolve(value.get()); }
118 template<typename T>
119 void reject(PassRefPtr<T> value) { reject(value.get()); }
92 120
93 void resolve(ScriptValue); 121 void resolve(ScriptValue);
94 void reject(ScriptValue); 122 void reject(ScriptValue);
95 123
96 private: 124 private:
97 ScriptPromiseResolver(ScriptPromise, v8::Isolate*); 125 ScriptPromiseResolver(ScriptPromise, v8::Isolate*);
98 void resolve(v8::Handle<v8::Value>); 126 void resolve(v8::Handle<v8::Value>);
99 void reject(v8::Handle<v8::Value>); 127 void reject(v8::Handle<v8::Value>);
100 128
101 v8::Isolate* m_isolate; 129 v8::Isolate* m_isolate;
102 ScriptPromise m_promise; 130 ScriptPromise m_promise;
103 }; 131 };
104 132
105 template<typename T> 133 template<typename T>
106 void ScriptPromiseResolver::resolve(PassRefPtr<T> value) 134 void ScriptPromiseResolver::resolve(T* value, ExecutionContext* context)
107 { 135 {
108 ASSERT(v8::Context::InContext()); 136 ASSERT(v8::Context::InContext());
109 resolve(toV8(value.get(), v8::Object::New(), m_isolate)); 137 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent());
138 resolve(value, v8Context->Global());
110 } 139 }
111 140
112 template<typename T> 141 template<typename T>
113 void ScriptPromiseResolver::reject(PassRefPtr<T> value) 142 void ScriptPromiseResolver::reject(T* value, ExecutionContext* context)
114 { 143 {
115 ASSERT(v8::Context::InContext()); 144 ASSERT(v8::Context::InContext());
116 reject(toV8(value.get(), v8::Object::New(), m_isolate)); 145 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent());
146 reject(value, v8Context->Global());
147 }
148
149 template<typename T>
150 void ScriptPromiseResolver::resolve(T* value)
151 {
152 ASSERT(v8::Context::InContext());
153 resolve(value, v8::Object::New());
154 }
155
156 template<typename T>
157 void ScriptPromiseResolver::reject(T* value)
158 {
159 ASSERT(v8::Context::InContext());
160 reject(value, v8::Object::New());
117 } 161 }
118 162
119 } // namespace WebCore 163 } // namespace WebCore
120 164
121 165
122 #endif // ScriptPromiseResolver_h 166 #endif // ScriptPromiseResolver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698