Chromium Code Reviews| Index: Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| diff --git a/Source/bindings/v8/ScriptPromiseResolverWithContext.h b/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| index f373fa9f3e1347a6ea148a86c18c3db1f09632ff..dd429b5759b40aff93db554e1fcf0eb2c18eba97 100644 |
| --- a/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| +++ b/Source/bindings/v8/ScriptPromiseResolverWithContext.h |
| @@ -30,6 +30,10 @@ namespace WebCore { |
| class ScriptPromiseResolverWithContext FINAL : public ActiveDOMObject, public RefCounted<ScriptPromiseResolverWithContext> { |
| WTF_MAKE_NONCOPYABLE(ScriptPromiseResolverWithContext); |
| + class NullType { |
| + }; |
| + class UndefinedType { |
| + }; |
| public: |
| static PassRefPtr<ScriptPromiseResolverWithContext> create(NewScriptState* scriptState) |
| { |
| @@ -38,6 +42,8 @@ public: |
| return resolver.release(); |
| } |
| + // Anything that can be passed to one of toV8 functions defined in this |
|
eroman
2014/04/17 02:25:46
"one of toV8" --> "one of the toV8"
|
| + // class can be passed to this function. |
| template <typename T> |
| void resolve(T value) |
| { |
| @@ -50,6 +56,8 @@ public: |
| resolveOrRejectImmediately(&m_timer); |
| } |
| + // Anything that can be passed to one of toV8 functions defined in this |
|
eroman
2014/04/17 02:25:46
"one of toV8" --> "one of the toV8"
|
| + // class can be passed to this function. |
| template <typename T> |
| void reject(T value) |
| { |
| @@ -62,6 +70,14 @@ public: |
| resolveOrRejectImmediately(&m_timer); |
| } |
| + // null and undefined can be passed to resolve and reject functions. |
| + static NullType null() { return NullType(); } |
| + static UndefinedType undefined() { return UndefinedType(); } |
| + struct Boolean { |
| + explicit Boolean(bool value) : value(value) { } |
| + const bool value; |
| + }; |
| + |
| // Note that an empty ScriptPromise will be returned after resolve or |
| // reject is called. |
| ScriptPromise promise() |
| @@ -103,6 +119,28 @@ private: |
| { |
| return value.v8Value(); |
| } |
| + v8::Handle<v8::Value> toV8(v8::Handle<v8::Value> value) { return value; } |
| + v8::Handle<v8::Value> toV8(NullType) { return v8::Null(m_scriptState->isolate()); } |
| + v8::Handle<v8::Value> toV8(UndefinedType) { return v8::Undefined(m_scriptState->isolate()); } |
| + // We don't define toV8(bool) to avoid implicit conversion. |
| + v8::Handle<v8::Value> toV8(Boolean value) { return v8::Boolean::New(m_scriptState->isolate(), value.value); } |
| + v8::Handle<v8::Value> toV8(int8_t value) { return v8::Integer::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(uint8_t value) { return v8::Integer::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(int16_t value) { return v8::Integer::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(uint16_t value) { return v8::Integer::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(int32_t value) { return v8::Integer::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(uint32_t value) { return v8::Number::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(int64_t value) { return v8::Number::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(uint64_t value) { return v8::Number::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(double value) { return v8::Number::New(m_scriptState->isolate(), value); } |
| + v8::Handle<v8::Value> toV8(const char* value) |
| + { |
| + return v8::String::NewFromUtf8(m_scriptState->isolate(), value, v8::String::kInternalizedString, strlen(value)); |
| + } |
| + v8::Handle<v8::Value> toV8(const String& value) |
| + { |
| + return v8String(m_scriptState->isolate(), value); |
| + } |
| void resolveOrRejectImmediately(Timer<ScriptPromiseResolverWithContext>*); |
| void clear(); |