OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : | 210 return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) : |
211 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); | 211 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); |
212 }, | 212 }, |
213 onReject | 213 onReject |
214 ); | 214 ); |
215 } | 215 } |
216 | 216 |
217 PromiseCoerce.table = new $WeakMap; | 217 PromiseCoerce.table = new $WeakMap; |
218 | 218 |
219 function PromiseCoerce(constructor, x) { | 219 function PromiseCoerce(constructor, x) { |
220 if (!(IsPromise(x) || IS_NULL_OR_UNDEFINED(x))) { | 220 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) { |
221 var then = x.then; | 221 var then = x.then; |
222 if (typeof then === 'function') { | 222 if (typeof then === 'function') { |
223 if (PromiseCoerce.table.has(x)) { | 223 if (PromiseCoerce.table.has(x)) { |
224 return PromiseCoerce.table.get(x); | 224 return PromiseCoerce.table.get(x); |
225 } else { | 225 } else { |
226 var deferred = %_CallFunction(constructor, PromiseDeferred); | 226 var deferred = %_CallFunction(constructor, PromiseDeferred); |
227 PromiseCoerce.table.set(x, deferred.promise); | 227 PromiseCoerce.table.set(x, deferred.promise); |
228 try { | 228 try { |
229 %_CallFunction(x, deferred.resolve, deferred.reject, then); | 229 %_CallFunction(x, deferred.resolve, deferred.reject, then); |
230 } catch(e) { | 230 } catch(e) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 "cast", PromiseCast | 299 "cast", PromiseCast |
300 ]); | 300 ]); |
301 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 301 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
302 "chain", PromiseChain, | 302 "chain", PromiseChain, |
303 "then", PromiseThen, | 303 "then", PromiseThen, |
304 "catch", PromiseCatch | 304 "catch", PromiseCatch |
305 ]); | 305 ]); |
306 } | 306 } |
307 | 307 |
308 SetUpPromise(); | 308 SetUpPromise(); |
OLD | NEW |