OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); | 73 v8::Local<v8::Object> promise = m_promise.v8Value().As<v8::Object>(); |
74 v8::Local<v8::Function> v8OnFulfilled = ScriptFunction::adoptByGarbageCollec
tor(onFulfilled); | 74 v8::Local<v8::Function> v8OnFulfilled = ScriptFunction::adoptByGarbageCollec
tor(onFulfilled); |
75 v8::Local<v8::Function> v8OnRejected = ScriptFunction::adoptByGarbageCollect
or(onRejected); | 75 v8::Local<v8::Function> v8OnRejected = ScriptFunction::adoptByGarbageCollect
or(onRejected); |
76 | 76 |
77 ASSERT(promise->IsPromise()); | 77 ASSERT(promise->IsPromise()); |
78 // Return this Promise if no handlers are given. | 78 // Return this Promise if no handlers are given. |
79 // In fact it is not the exact bahavior of Promise.prototype.then | 79 // In fact it is not the exact bahavior of Promise.prototype.then |
80 // but that is not a problem in this case. | 80 // but that is not a problem in this case. |
81 v8::Local<v8::Promise> resultPromise = promise.As<v8::Promise>(); | 81 v8::Local<v8::Promise> resultPromise = promise.As<v8::Promise>(); |
82 // FIXME: Use Then once it is introduced. | |
83 if (!v8OnFulfilled.IsEmpty()) { | 82 if (!v8OnFulfilled.IsEmpty()) { |
84 resultPromise = resultPromise->Chain(v8OnFulfilled); | 83 resultPromise = resultPromise->Then(v8OnFulfilled); |
85 if (resultPromise.IsEmpty()) { | 84 if (resultPromise.IsEmpty()) { |
86 // v8::Promise::Chain may return an empty value, for example when | 85 // v8::Promise::Then may return an empty value, for example when |
87 // the stack is exhausted. | 86 // the stack is exhausted. |
88 return ScriptPromise(); | 87 return ScriptPromise(); |
89 } | 88 } |
90 } | 89 } |
91 if (!v8OnRejected.IsEmpty()) | 90 if (!v8OnRejected.IsEmpty()) |
92 resultPromise = resultPromise->Catch(v8OnRejected); | 91 resultPromise = resultPromise->Catch(v8OnRejected); |
93 | 92 |
94 return ScriptPromise(m_scriptState.get(), resultPromise); | 93 return ScriptPromise(m_scriptState.get(), resultPromise); |
95 } | 94 } |
96 | 95 |
(...skipping 30 matching lines...) Expand all Loading... |
127 return promise; | 126 return promise; |
128 } | 127 } |
129 | 128 |
130 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
ssRefPtrWillBeRawPtr<DOMException> exception) | 129 ScriptPromise ScriptPromise::rejectWithDOMException(ScriptState* scriptState, Pa
ssRefPtrWillBeRawPtr<DOMException> exception) |
131 { | 130 { |
132 ASSERT(scriptState->isolate()->InContext()); | 131 ASSERT(scriptState->isolate()->InContext()); |
133 return reject(scriptState, ToV8Value<WithScriptState, v8::Handle<v8::Object>
>::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate(
))); | 132 return reject(scriptState, ToV8Value<WithScriptState, v8::Handle<v8::Object>
>::toV8Value(exception, scriptState->context()->Global(), scriptState->isolate(
))); |
134 } | 133 } |
135 | 134 |
136 } // namespace WebCore | 135 } // namespace WebCore |
OLD | NEW |