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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/bindings/v8/ScriptPromiseResolver.cpp » ('j') | Source/bindings/v8/V8Binding.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/ScriptPromiseResolver.h
diff --git a/Source/bindings/v8/ScriptPromiseResolver.h b/Source/bindings/v8/ScriptPromiseResolver.h
index a4131babaf2de8f58507e433b80d720fad8075a4..6ac30464ee89cc6417a2c84743c2f9258e051128 100644
--- a/Source/bindings/v8/ScriptPromiseResolver.h
+++ b/Source/bindings/v8/ScriptPromiseResolver.h
@@ -85,63 +85,79 @@ public:
// is called.
ScriptPromise promise();
- // To use following template methods, T must be a DOM class.
- template<typename T>
- void resolve(T* value, v8::Handle<v8::Object> creationContext) { resolve(toV8NoInline(value, creationContext, m_isolate)); }
- template<typename T>
- void reject(T* value, v8::Handle<v8::Object> creationContext) { reject(toV8NoInline(value, creationContext, m_isolate)); }
-
- template<typename T>
- void resolve(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); }
- template<typename T>
- void resolve(RawPtr<T> value, v8::Handle<v8::Object> creationContext) { resolve(value.get(), creationContext); }
- template<typename T>
- void reject(PassRefPtr<T> value, v8::Handle<v8::Object> creationContext) { reject(value.get(), creationContext); }
- template<typename T>
- void reject(RawPtr<T> value, v8::Handle<v8::Object> creationContext) { reject(value.get(), creationContext); }
-
- template<typename T>
- inline void resolve(T* value, ExecutionContext*);
- template<typename T>
- inline void reject(T* value, ExecutionContext*);
-
- template<typename T>
- void resolve(PassRefPtr<T> value, ExecutionContext* context) { resolve(value.get(), context); }
- template<typename T>
- void resolve(RawPtr<T> value, ExecutionContext* context) { resolve(value.get(), context); }
- template<typename T>
- void reject(PassRefPtr<T> value, ExecutionContext* context) { reject(value.get(), context); }
- template<typename T>
- void reject(RawPtr<T> value, ExecutionContext* context) { reject(value.get(), context); }
-
- template<typename T>
- inline void resolve(T* value);
- template<typename T>
- inline void reject(T* value);
-
- template<typename T, size_t inlineCapacity>
- void resolve(const Vector<T, inlineCapacity>& iterator) { resolve(v8ArrayNoInline(iterator, m_isolate)); }
- template<typename T, size_t inlineCapacity>
- void reject(const Vector<T, inlineCapacity>& iterator) { reject(v8ArrayNoInline(iterator, m_isolate)); }
-
- template<typename T>
- void resolve(PassRefPtr<T> value) { resolve(value.get()); }
- template<typename T>
- void resolve(RawPtr<T> value) { resolve(value.get()); }
- template<typename T>
- void reject(PassRefPtr<T> value) { reject(value.get()); }
- template<typename T>
- void reject(RawPtr<T> value) { reject(value.get()); }
-
- void resolve(ScriptValue);
- void reject(ScriptValue);
-
- v8::Isolate* isolate() const { return m_isolate; }
+ template <typename T>
+ void resolve(T value)
+ {
+ ASSERT(m_isolate->InContext());
+ 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
+ }
+ template <typename T>
+ inline void reject(T value)
+ {
+ ASSERT(m_isolate->InContext());
+ reject(value, v8::Object::New(m_isolate));
haraken 2014/04/18 03:59:58 Ditto.
+ }
+
+ template <typename T>
+ inline void resolve(T value, ExecutionContext* context)
+ {
+ ASSERT(m_isolate->InContext());
+ resolve(toV8Value(value, context));
+ }
+ template <typename T>
+ inline void reject(T value, ExecutionContext* context)
+ {
+ ASSERT(m_isolate->InContext());
+ reject(toV8Value(value, context));
+ }
+ template <typename T>
+ inline void resolve(T value, v8::Handle<v8::Object> creationContext)
+ {
+ ASSERT(m_isolate->InContext());
+ resolve(toV8Value(value, creationContext));
+ }
+ template <typename T>
+ inline void reject(T value, v8::Handle<v8::Object> creationContext)
+ {
+ ASSERT(m_isolate->InContext());
+ reject(toV8Value(value, creationContext));
+ }
void resolve(v8::Handle<v8::Value>);
void reject(v8::Handle<v8::Value>);
+ v8::Isolate* isolate() const { return m_isolate; }
+
private:
+
+ template <typename T>
+ struct ToV8ValueHelper {
+ static v8::Handle<v8::Value> toV8Value(const T& value, ExecutionContext* context, v8::Isolate* isolate)
+ {
+ v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::current(isolate));
haraken 2014/04/18 03:59:58 Not related to this CL, I think it's wrong to use
+ return V8ValueTraits<T>::toV8Value(value, v8Context->Global(), isolate);
+ }
+ static v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+ {
+ return V8ValueTraits<T>::toV8Value(value, creationContext, isolate);
+ }
+ static v8::Handle<v8::Value> toV8Value(const T& value, v8::Isolate* isolate)
+ {
+ return V8ValueTraits<T>::toV8Value(value, isolate);
+ }
+ };
+
+ template <typename T>
+ v8::Handle<v8::Value> toV8Value(const T& value, ExecutionContext* context)
+ {
+ return WebCore::ToV8ValueHelper<ExecutionContext*, ToV8ValueHelper<T> >::toV8Value(value, context, m_isolate);
+ }
+ template <typename T>
+ v8::Handle<v8::Value> toV8Value(const T& value, v8::Handle<v8::Object> creationContext)
+ {
+ return WebCore::ToV8ValueHelper<v8::Handle<v8::Object>, ToV8ValueHelper<T> >::toV8Value(value, creationContext, m_isolate);
+ }
+
ScriptPromiseResolver(ExecutionContext*);
ScriptPromiseResolver(v8::Isolate*);
@@ -152,36 +168,6 @@ private:
ScriptValue m_resolver;
};
-template<typename T>
-void ScriptPromiseResolver::resolve(T* value, ExecutionContext* context)
-{
- ASSERT(m_isolate->InContext());
- v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::current(m_isolate));
- resolve(value, v8Context->Global());
-}
-
-template<typename T>
-void ScriptPromiseResolver::reject(T* value, ExecutionContext* context)
-{
- ASSERT(m_isolate->InContext());
- v8::Handle<v8::Context> v8Context = toV8Context(context, DOMWrapperWorld::current(m_isolate));
- reject(value, v8Context->Global());
-}
-
-template<typename T>
-void ScriptPromiseResolver::resolve(T* value)
-{
- ASSERT(m_isolate->InContext());
- resolve(value, v8::Object::New(m_isolate));
-}
-
-template<typename T>
-void ScriptPromiseResolver::reject(T* value)
-{
- ASSERT(m_isolate->InContext());
- reject(value, v8::Object::New(m_isolate));
-}
-
} // namespace WebCore
« 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