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

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

Issue 238723009: Implement V8ValueTraits<T>::toV8Value conversion functions (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // its destruction. 78 // its destruction.
79 // A ScriptPromiseResolver can be destructed safely without 79 // A ScriptPromiseResolver can be destructed safely without
80 // entering a v8 context. 80 // entering a v8 context.
81 ~ScriptPromiseResolver(); 81 ~ScriptPromiseResolver();
82 82
83 // Returns the underlying Promise. 83 // Returns the underlying Promise.
84 // Note that the underlying Promise is cleared when |resolve| or |reject| 84 // Note that the underlying Promise is cleared when |resolve| or |reject|
85 // is called. 85 // is called.
86 ScriptPromise promise(); 86 ScriptPromise promise();
87 87
88 // To use following template methods, T must be a DOM class. 88 template <typename T>
89 template<typename T> 89 void resolve(T value)
90 void resolve(T* value, v8::Handle<v8::Object> creationContext) { resolve(toV 8NoInline(value, creationContext, m_isolate)); } 90 {
91 template<typename T> 91 ASSERT(m_isolate->InContext());
92 void reject(T* value, v8::Handle<v8::Object> creationContext) { reject(toV8N oInline(value, creationContext, m_isolate)); } 92 resolve(value, v8::Object::New(m_isolate));
haraken 2014/04/18 03:59:58 Do you want to create a new object just for gettin
93 }
94 template <typename T>
95 inline void reject(T value)
96 {
97 ASSERT(m_isolate->InContext());
98 reject(value, v8::Object::New(m_isolate));
haraken 2014/04/18 03:59:58 Ditto.
99 }
93 100
94 template<typename T> 101 template <typename T>
95 void resolve(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); } 102 inline void resolve(T value, ExecutionContext* context)
96 template<typename T> 103 {
97 void resolve(RawPtr<T> value, v8::Handle<v8::Object> creationContext) { reso lve(value.get(), creationContext); } 104 ASSERT(m_isolate->InContext());
98 template<typename T> 105 resolve(toV8Value(value, context));
99 void reject(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { r eject(value.get(), creationContext); } 106 }
100 template<typename T> 107 template <typename T>
101 void reject(RawPtr<T> value, v8::Handle<v8::Object> creationContext) { rejec t(value.get(), creationContext); } 108 inline void reject(T value, ExecutionContext* context)
102 109 {
103 template<typename T> 110 ASSERT(m_isolate->InContext());
104 inline void resolve(T* value, ExecutionContext*); 111 reject(toV8Value(value, context));
105 template<typename T> 112 }
106 inline void reject(T* value, ExecutionContext*); 113 template <typename T>
107 114 inline void resolve(T value, v8::Handle<v8::Object> creationContext)
108 template<typename T> 115 {
109 void resolve(PassRefPtr<T> value, ExecutionContext* context) { resolve(value .get(), context); } 116 ASSERT(m_isolate->InContext());
110 template<typename T> 117 resolve(toV8Value(value, creationContext));
111 void resolve(RawPtr<T> value, ExecutionContext* context) { resolve(value.get (), context); } 118 }
112 template<typename T> 119 template <typename T>
113 void reject(PassRefPtr<T> value, ExecutionContext* context) { reject(value.g et(), context); } 120 inline void reject(T value, v8::Handle<v8::Object> creationContext)
114 template<typename T> 121 {
115 void reject(RawPtr<T> value, ExecutionContext* context) { reject(value.get() , context); } 122 ASSERT(m_isolate->InContext());
116 123 reject(toV8Value(value, creationContext));
117 template<typename T> 124 }
118 inline void resolve(T* value);
119 template<typename T>
120 inline void reject(T* value);
121
122 template<typename T, size_t inlineCapacity>
123 void resolve(const Vector<T, inlineCapacity>& iterator) { resolve(v8ArrayNoI nline(iterator, m_isolate)); }
124 template<typename T, size_t inlineCapacity>
125 void reject(const Vector<T, inlineCapacity>& iterator) { reject(v8ArrayNoInl ine(iterator, m_isolate)); }
126
127 template<typename T>
128 void resolve(PassRefPtr<T> value) { resolve(value.get()); }
129 template<typename T>
130 void resolve(RawPtr<T> value) { resolve(value.get()); }
131 template<typename T>
132 void reject(PassRefPtr<T> value) { reject(value.get()); }
133 template<typename T>
134 void reject(RawPtr<T> value) { reject(value.get()); }
135
136 void resolve(ScriptValue);
137 void reject(ScriptValue);
138
139 v8::Isolate* isolate() const { return m_isolate; }
140 125
141 void resolve(v8::Handle<v8::Value>); 126 void resolve(v8::Handle<v8::Value>);
142 void reject(v8::Handle<v8::Value>); 127 void reject(v8::Handle<v8::Value>);
143 128
129 v8::Isolate* isolate() const { return m_isolate; }
130
144 private: 131 private:
132
133 template <typename T>
134 struct ToV8ValueHelper {
135 static v8::Handle<v8::Value> toV8Value(const T& value, ExecutionContext* context, v8::Isolate* isolate)
136 {
137 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperW orld::current(isolate));
haraken 2014/04/18 03:59:58 Not related to this CL, I think it's wrong to use
138 return V8ValueTraits<T>::toV8Value(value, v8Context->Global(), isola te);
139 }
140 static v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Ob ject> creationContext, v8::Isolate* isolate)
141 {
142 return V8ValueTraits<T>::toV8Value(value, creationContext, isolate);
143 }
144 static v8::Handle<v8::Value> toV8Value(const T& value, v8::Isolate* isol ate)
145 {
146 return V8ValueTraits<T>::toV8Value(value, isolate);
147 }
148 };
149
150 template <typename T>
151 v8::Handle<v8::Value> toV8Value(const T& value, ExecutionContext* context)
152 {
153 return WebCore::ToV8ValueHelper<ExecutionContext*, ToV8ValueHelper<T> >: :toV8Value(value, context, m_isolate);
154 }
155 template <typename T>
156 v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object> creat ionContext)
157 {
158 return WebCore::ToV8ValueHelper<v8::Handle<v8::Object>, ToV8ValueHelper< T> >::toV8Value(value, creationContext, m_isolate);
159 }
160
145 ScriptPromiseResolver(ExecutionContext*); 161 ScriptPromiseResolver(ExecutionContext*);
146 ScriptPromiseResolver(v8::Isolate*); 162 ScriptPromiseResolver(v8::Isolate*);
147 163
148 v8::Isolate* m_isolate; 164 v8::Isolate* m_isolate;
149 // Used when scriptPromiseOnV8Promise is disabled. 165 // Used when scriptPromiseOnV8Promise is disabled.
150 ScriptPromise m_promise; 166 ScriptPromise m_promise;
151 // Used when scriptPromiseOnV8Promise is enabled. 167 // Used when scriptPromiseOnV8Promise is enabled.
152 ScriptValue m_resolver; 168 ScriptValue m_resolver;
153 }; 169 };
154 170
155 template<typename T>
156 void ScriptPromiseResolver::resolve(T* value, ExecutionContext* context)
157 {
158 ASSERT(m_isolate->InContext());
159 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent(m_isolate));
160 resolve(value, v8Context->Global());
161 }
162
163 template<typename T>
164 void ScriptPromiseResolver::reject(T* value, ExecutionContext* context)
165 {
166 ASSERT(m_isolate->InContext());
167 v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::cu rrent(m_isolate));
168 reject(value, v8Context->Global());
169 }
170
171 template<typename T>
172 void ScriptPromiseResolver::resolve(T* value)
173 {
174 ASSERT(m_isolate->InContext());
175 resolve(value, v8::Object::New(m_isolate));
176 }
177
178 template<typename T>
179 void ScriptPromiseResolver::reject(T* value)
180 {
181 ASSERT(m_isolate->InContext());
182 reject(value, v8::Object::New(m_isolate));
183 }
184
185 } // namespace WebCore 171 } // namespace WebCore
186 172
187 173
188 #endif // ScriptPromiseResolver_h 174 #endif // ScriptPromiseResolver_h
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptPromiseResolver.cpp » ('j') | Source/bindings/v8/V8Binding.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698