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

Unified Diff: Source/bindings/v8/ScriptPromiseResolverWithContext.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 | « Source/bindings/v8/ScriptPromiseResolver.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/ScriptPromiseResolverWithContext.h
diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.h b/Source/bindings/v8/ScriptPromiseResolverWithContext.h
index 39791f4fcd2623b827df7a692afb3af2603b64ed..708b609afd814a1c2abc6301fec9a1eb87a10052 100644
--- a/Source/bindings/v8/ScriptPromiseResolverWithContext.h
+++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.h
@@ -38,6 +38,7 @@ public:
return resolver.release();
}
+ // Anything that can be passed to toV8Value can be passed to this function.
template <typename T>
void resolve(T value)
{
@@ -45,11 +46,12 @@ public:
return;
m_state = Resolving;
NewScriptState::Scope scope(m_scriptState.get());
- m_value.set(m_scriptState->isolate(), toV8(value));
+ m_value.set(m_scriptState->isolate(), toV8Value(value));
if (!executionContext()->activeDOMObjectsAreSuspended())
resolveOrRejectImmediately(&m_timer);
}
+ // Anything that can be passed to toV8Value can be passed to this function.
template <typename T>
void reject(T value)
{
@@ -57,7 +59,7 @@ public:
return;
m_state = Rejecting;
NewScriptState::Scope scope(m_scriptState.get());
- m_value.set(m_scriptState->isolate(), toV8(value));
+ m_value.set(m_scriptState->isolate(), toV8Value(value));
if (!executionContext()->activeDOMObjectsAreSuspended())
resolveOrRejectImmediately(&m_timer);
}
@@ -86,25 +88,35 @@ private:
explicit ScriptPromiseResolverWithContext(NewScriptState*);
+ template<typename T>
+ v8::Handle<v8::Value> toV8Value(const T& value)
+ {
+ // Default implementaion: for types that don't need the
+ // creation context.
+ return V8ValueTraits<T>::toV8Value(value, m_scriptState->isolate());
+ }
+
+ // Pointer specializations.
template <typename T>
- v8::Handle<v8::Value> toV8(T* value)
+ v8::Handle<v8::Value> toV8Value(T* value)
{
- ASSERT(m_scriptState);
ASSERT(!m_scriptState->contextIsEmpty());
return toV8NoInline(value, m_scriptState->context()->Global(), m_scriptState->isolate());
}
- template <typename T> v8::Handle<v8::Value> toV8(PassRefPtr<T> value) { return toV8(value.get()); }
- template <typename T> v8::Handle<v8::Value> toV8(RawPtr<T> value) { return toV8(value.get()); }
- template <typename T, size_t inlineCapacity>
- v8::Handle<v8::Value> toV8(const Vector<T, inlineCapacity>& value)
+ template<typename T> v8::Handle<v8::Value> toV8Value(RefPtr<T> value) { return toV8Value(value.get()); }
+ template<typename T> v8::Handle<v8::Value> toV8Value(PassRefPtr<T> value) { return toV8Value(value.get()); }
+ template<typename T> v8::Handle<v8::Value> toV8Value(OwnPtr<T> value) { return toV8Value(value.get()); }
+ template<typename T> v8::Handle<v8::Value> toV8Value(PassOwnPtr<T> value) { return toV8Value(value.get()); }
+ template<typename T> v8::Handle<v8::Value> toV8Value(RawPtr<T> value) { return toV8Value(value.get()); }
+
+ // const char* should use V8ValueTraits.
+ v8::Handle<v8::Value> toV8Value(const char* value) { return V8ValueTraits<const char*>::toV8Value(value, m_scriptState->isolate()); }
+
+ template<typename T, size_t inlineCapacity>
+ v8::Handle<v8::Value> toV8Value(const Vector<T, inlineCapacity>& value)
{
- ASSERT(m_scriptState);
return v8ArrayNoInline(value, m_scriptState->isolate());
}
- v8::Handle<v8::Value> toV8(ScriptValue value)
- {
- return value.v8Value();
- }
void resolveOrRejectImmediately(Timer<ScriptPromiseResolverWithContext>*);
void clear();
« no previous file with comments | « Source/bindings/v8/ScriptPromiseResolver.cpp ('k') | Source/bindings/v8/V8Binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698