| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); | 220 IsPromise(x) ? x.then(onResolve, onReject) : onResolve(x); |
| 221 }, | 221 }, |
| 222 onReject | 222 onReject |
| 223 ); | 223 ); |
| 224 } | 224 } |
| 225 | 225 |
| 226 PromiseCoerce.table = new $WeakMap; | 226 PromiseCoerce.table = new $WeakMap; |
| 227 | 227 |
| 228 function PromiseCoerce(constructor, x) { | 228 function PromiseCoerce(constructor, x) { |
| 229 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) { | 229 if (!IsPromise(x) && IS_SPEC_OBJECT(x)) { |
| 230 var then = x.then; | 230 var then; |
| 231 try { |
| 232 then = x.then; |
| 233 } catch(e) { |
| 234 var deferred = %_CallFunction(constructor, PromiseDeferred); |
| 235 PromiseCoerce.table.set(x, deferred.promise); |
| 236 deferred.reject(e); |
| 237 return deferred.promise; |
| 238 } |
| 231 if (typeof then === 'function') { | 239 if (typeof then === 'function') { |
| 232 if (PromiseCoerce.table.has(x)) { | 240 if (PromiseCoerce.table.has(x)) { |
| 233 return PromiseCoerce.table.get(x); | 241 return PromiseCoerce.table.get(x); |
| 234 } else { | 242 } else { |
| 235 var deferred = %_CallFunction(constructor, PromiseDeferred); | 243 var deferred = %_CallFunction(constructor, PromiseDeferred); |
| 236 PromiseCoerce.table.set(x, deferred.promise); | 244 PromiseCoerce.table.set(x, deferred.promise); |
| 237 try { | 245 try { |
| 238 %_CallFunction(x, deferred.resolve, deferred.reject, then); | 246 %_CallFunction(x, deferred.resolve, deferred.reject, then); |
| 239 } catch(e) { | 247 } catch(e) { |
| 240 deferred.reject(e); | 248 deferred.reject(e); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 "cast", PromiseCast | 324 "cast", PromiseCast |
| 317 ]); | 325 ]); |
| 318 InstallFunctions($Promise.prototype, DONT_ENUM, [ | 326 InstallFunctions($Promise.prototype, DONT_ENUM, [ |
| 319 "chain", PromiseChain, | 327 "chain", PromiseChain, |
| 320 "then", PromiseThen, | 328 "then", PromiseThen, |
| 321 "catch", PromiseCatch | 329 "catch", PromiseCatch |
| 322 ]); | 330 ]); |
| 323 } | 331 } |
| 324 | 332 |
| 325 SetUpPromise(); | 333 SetUpPromise(); |
| OLD | NEW |