| 268 | } |
| 269 | |
| 270 | function handleForeignThenable(promise, thenable, then) { |
| 271 | asap(function (promise) { |
| 272 | var sealed = false; |
| 273 | var error = tryThen(then, thenable, function (value) { |
| 274 | if (sealed) { |
| 275 | return; |
| 276 | } |
| 277 | sealed = true; |
| 278 | if (thenable !== value) { |
| 279 | _resolve(promise, value); |
| 280 | } else { |
| 281 | fulfill(promise, value); |
| 282 | } |
| 283 | }, function (reason) { |
| 284 | if (sealed) { |
| 285 | return; |
| 286 | } |
| 287 | sealed = true; |
| 288 | |
| 289 | _reject(promise, reason); |
| 290 | }, 'Settle: ' + (promise._label || ' unknown promise')); |
| 291 | |
| 292 | if (!sealed && error) { |
| 293 | sealed = true; |
| 294 | _reject(promise, error); |
| 295 | } |
| 296 | }, promise); |
| 297 | } |
| 298 | |
| 299 | function handleOwnThenable(promise, thenable) { |
| 300 | if (thenable._state === FULFILLED) { |