-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
508 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// `Promise.prototype.catch` method implementation | ||
// https://tc39.es/ecma262/#sec-promise.prototype.catch | ||
module.exports = function (onRejected) { | ||
return this.then(undefined, onRejected); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var call = require('../internals/function-call'); | ||
var aCallable = require('../internals/a-callable'); | ||
var newPromiseCapabilityModule = require('../internals/new-promise-capability'); | ||
var perform = require('../internals/perform'); | ||
var iterate = require('../internals/iterate'); | ||
var PROMISE_STATICS_INCORRECT_ITERATION = require('../internals/promise-statics-incorrect-iteration'); | ||
|
||
// `Promise.all` method | ||
// https://tc39.es/ecma262/#sec-promise.all | ||
$({ target: 'Promise', stat: true, forced: PROMISE_STATICS_INCORRECT_ITERATION }, { | ||
all: function all(iterable) { | ||
var C = this; | ||
var capability = newPromiseCapabilityModule.f(C); | ||
var resolve = capability.resolve; | ||
var reject = capability.reject; | ||
var result = perform(function () { | ||
var $promiseResolve = aCallable(C.resolve); | ||
var values = []; | ||
var counter = 0; | ||
var remaining = 1; | ||
iterate(iterable, function (promise) { | ||
var index = counter++; | ||
var alreadyCalled = false; | ||
remaining++; | ||
call($promiseResolve, C, promise).then(function (value) { | ||
if (alreadyCalled) return; | ||
alreadyCalled = true; | ||
values[index] = value; | ||
--remaining || resolve(values); | ||
}, reject); | ||
}); | ||
--remaining || resolve(values); | ||
}); | ||
if (result.error) reject(result.value); | ||
return capability.promise; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var promiseCatchImplementation = require('../internals/promise-catch-implementation'); | ||
var FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR; | ||
|
||
// `Promise.prototype.catch` method | ||
// https://tc39.es/ecma262/#sec-promise.prototype.catch | ||
$({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR, real: true }, { | ||
'catch': promiseCatchImplementation | ||
}); |
Oops, something went wrong.