From 46e9fa479b8d634837d8dd4bf0972fdf7af8b099 Mon Sep 17 00:00:00 2001 From: Gabe Levi Date: Wed, 14 Sep 2016 09:40:22 -0400 Subject: [PATCH] Use the entire Promise.prototype.done polyfill --- packages/fbjs/src/core/Deferred.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/fbjs/src/core/Deferred.js b/packages/fbjs/src/core/Deferred.js index 0668a0d6..dfdc1af1 100644 --- a/packages/fbjs/src/core/Deferred.js +++ b/packages/fbjs/src/core/Deferred.js @@ -57,7 +57,16 @@ class Deferred { } done(): void { - Promise.prototype.then.apply(this._promise, arguments); + // Embed the polyfill for the non-standard Promise.prototype.done so that + // users of the open source fbjs don't need a custom lib for Promise + const self = arguments.length ? + this._promise.then.apply(this._promise, arguments) : + this._promise; + self.then(undefined, function(err) { + setTimeout(function() { + throw err; + }, 0); + }); } isSettled(): boolean {