Skip to content

Commit 3447e6a

Browse files
author
Forbes Lindesay
committed
Include polyfills (to be served on promisejs.org)
The polyfills are for browser use, so do not include node.js extensions, but do include a minimal implementation of `Promise.prototype.done` as I believe that it is a feature that will be needed in browsers for the forseable future, and will hopefully eventually make it into the spec.
1 parent a3ac525 commit 3447e6a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

polyfill-done.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// should work in any browser without browserify
2+
3+
if (typeof Promise.prototype.done !== 'function') {
4+
Promise.prototype.done = function (onFulfilled, onRejected) {
5+
var self = arguments.length ? this.then.apply(this, arguments) : this
6+
self.then(null, function (err) {
7+
setTimeout(function () {
8+
throw err
9+
}, 0)
10+
})
11+
}
12+
}

polyfill.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// not "use strict" so we can declare global "Promise"
2+
3+
var asap = require('asap');
4+
5+
if (typeof Promise === 'undefined') {
6+
Promise = require('./lib/core.js')
7+
require('./lib/es6-extensions.js')
8+
}
9+
10+
require('./polfill-done.js');

0 commit comments

Comments
 (0)