Index: Source/bindings/v8/ScriptPromiseResolverWithContext.h |
diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.h b/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
index 39791f4fcd2623b827df7a692afb3af2603b64ed..1c834d4f5b0107249024e80f97e5505e951ef85a 100644 |
--- a/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
+++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
@@ -38,26 +38,30 @@ public: |
return resolver.release(); |
} |
+ // Anything that can be passed to ToV8Value::toV8Value can be passed to |
+ // this function. |
template <typename T> |
- void resolve(T value) |
+ void resolve(const T& value) |
{ |
if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
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::toV8Value can be passed to |
+ // this function. |
template <typename T> |
- void reject(T value) |
+ void reject(const T& value) |
{ |
if (m_state != Pending || !executionContext() || executionContext()->activeDOMObjectsAreStopped()) |
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); |
} |
@@ -85,30 +89,32 @@ private: |
}; |
explicit ScriptPromiseResolverWithContext(NewScriptState*); |
+ void resolveOrRejectImmediately(Timer<ScriptPromiseResolverWithContext>*); |
+ void clear(); |
+ template <typename T, bool toV8ValueNeedsCreationContext> |
+ struct ToV8ValueHelper; |
template <typename T> |
- v8::Handle<v8::Value> toV8(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) |
- { |
- ASSERT(m_scriptState); |
- return v8ArrayNoInline(value, m_scriptState->isolate()); |
- } |
- v8::Handle<v8::Value> toV8(ScriptValue value) |
+ struct ToV8ValueHelper<T, true> { |
+ static v8::Handle<v8::Value> toV8Value(const T& value, NewScriptState* scriptState) |
+ { |
+ return V8ValueTraits<T>::toV8Value(value, scriptState->context()->Global(), scriptState->isolate()); |
+ } |
+ }; |
+ template <typename T> |
+ struct ToV8ValueHelper<T, false> { |
+ static v8::Handle<v8::Value> toV8Value(const T& value, NewScriptState* scriptState) |
+ { |
+ return V8ValueTraits<T>::toV8Value(value, scriptState->isolate()); |
+ } |
+ }; |
+ |
+ template <typename T> |
+ v8::Handle<v8::Value> toV8Value(const T& value) |
{ |
- return value.v8Value(); |
+ return ToV8ValueHelper<T, V8ValueTraits<T>::toV8ValueNeedsCreationContext>::toV8Value(value, m_scriptState.get()); |
} |
- void resolveOrRejectImmediately(Timer<ScriptPromiseResolverWithContext>*); |
- void clear(); |
- |
ResolutionState m_state; |
RefPtr<NewScriptState> m_scriptState; |
Timer<ScriptPromiseResolverWithContext> m_timer; |