├── .eslintrc ├── .github └── workflows │ ├── node-aught.yml │ ├── node-native.yml │ ├── node-pretest.yml │ ├── node-promise-shimmed.yml │ ├── node-tens.yml │ ├── rebase.yml │ └── require-allow-edits.yml ├── .gitignore ├── .npmrc ├── .nycrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── auto.js ├── implementation.js ├── index.js ├── package.json ├── polyfill.js ├── requirePromise.js ├── shim.js └── test ├── .eslintrc ├── builtin.js ├── implementation.js ├── index.js ├── native.js ├── promise-shimmed.js ├── shimmed.js └── tests.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "@ljharb", 5 | 6 | "rules": { 7 | "new-cap": [2, { 8 | "capIsNewExceptions": [ 9 | "GetIntrinsic", 10 | "PromiseResolve", 11 | "Type", 12 | ], 13 | }], 14 | "no-magic-numbers": 0, 15 | "sort-keys": 0, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/node-aught.yml: -------------------------------------------------------------------------------- 1 | 2 | name: 'Tests: node.js < 10' 3 | 4 | on: [pull_request, push] 5 | 6 | jobs: 7 | tests: 8 | uses: ljharb/actions/.github/workflows/node.yml@main 9 | with: 10 | range: '> 0.10 < 10' 11 | type: minors 12 | command: npm run tests-only 13 | 14 | node: 15 | name: 'node 0.11 - 10' 16 | needs: [tests] 17 | runs-on: ubuntu-latest 18 | steps: 19 | - run: 'echo tests completed' 20 | -------------------------------------------------------------------------------- /.github/workflows/node-native.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js: native' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '>= 12' 10 | type: majors 11 | command: npm run test:native 12 | 13 | node: 14 | name: 'node, native tests' 15 | needs: [tests] 16 | runs-on: ubuntu-latest 17 | steps: 18 | - run: 'echo tests completed' 19 | -------------------------------------------------------------------------------- /.github/workflows/node-pretest.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: pretest/posttest' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/pretest.yml@main 8 | -------------------------------------------------------------------------------- /.github/workflows/node-promise-shimmed.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js, promise-shimmed' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '0.10 || 0.12 || >= 1' 10 | type: majors 11 | command: npm run test:promise-shimmed 12 | 13 | node: 14 | name: 'node, promise-shimmed tests' 15 | needs: [tests] 16 | runs-on: ubuntu-latest 17 | steps: 18 | - run: 'echo tests completed' 19 | -------------------------------------------------------------------------------- /.github/workflows/node-tens.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js >= 10' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '>= 10' 10 | type: minors 11 | command: npm run tests-only 12 | 13 | node: 14 | name: 'node >= 10' 15 | needs: [tests] 16 | runs-on: ubuntu-latest 17 | steps: 18 | - run: 'echo tests completed' 19 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | name: Automatic Rebase 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | uses: ljharb/actions/.github/workflows/rebase.yml@main 8 | secrets: 9 | token: ${{ secrets.GITHUB_TOKEN }} 10 | -------------------------------------------------------------------------------- /.github/workflows/require-allow-edits.yml: -------------------------------------------------------------------------------- 1 | name: Require “Allow Edits” 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | name: "Require “Allow Edits”" 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: ljharb/require-allow-edits@main 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # Only apps should have lockfiles 64 | npm-shrinkwrap.json 65 | package-lock.json 66 | yarn.lock 67 | 68 | .npmignore 69 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | allow-same-version=true 3 | message=v%s 4 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "check-coverage": false, 4 | "reporter": ["text-summary", "text", "html", "json"], 5 | "exclude": [ 6 | "coverage", 7 | "test" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [v1.0.7](https://github.com/es-shims/Promise.allSettled/compare/v1.0.6...v1.0.7) - 2023-09-03 9 | 10 | ### Commits 11 | 12 | - [Deps] update `define-properties`, `es-abstract`, `get-intrinsic` [`c9d57a1`](https://github.com/es-shims/Promise.allSettled/commit/c9d57a1775a44dcb4b924c4599104ca2197781eb) 13 | - [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `es6-shim`, `tape` [`68f2785`](https://github.com/es-shims/Promise.allSettled/commit/68f27854b2ac4a9d6cdb58547e8e57df56377738) 14 | 15 | ## [v1.0.6](https://github.com/es-shims/Promise.allSettled/compare/v1.0.5...v1.0.6) - 2022-11-07 16 | 17 | ### Commits 18 | 19 | - [actions] reuse common workflows [`b9d78d9`](https://github.com/es-shims/Promise.allSettled/commit/b9d78d97ac4e5f774985532d0dd8024e770f5174) 20 | - [meta] use `npmignore` to autogenerate an npmignore file [`4507529`](https://github.com/es-shims/Promise.allSettled/commit/45075294f8ef95a75616396b3be4658d3baa4133) 21 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `safe-publish-latest`, `tape` [`6e2c01c`](https://github.com/es-shims/Promise.allSettled/commit/6e2c01c998e790f2ae85639a861dd5a00f00cb81) 22 | - [actions] update codecov uploader [`2a24151`](https://github.com/es-shims/Promise.allSettled/commit/2a2415155ee3941da4b9b10a014192f25218ed2e) 23 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `functions-have-names`, `tape` [`cfa4e59`](https://github.com/es-shims/Promise.allSettled/commit/cfa4e5949060e22ca0880a68d712aea7788b8f34) 24 | - [Deps] update `array.prototype.map`, `define-properties`, `es-abstract`, `get-intrinsic` [`c841f03`](https://github.com/es-shims/Promise.allSettled/commit/c841f039568e09383a747b8f33587181b801a235) 25 | - [actions] update rebase action to use reusable workflow [`9f663ac`](https://github.com/es-shims/Promise.allSettled/commit/9f663ac6b78848d8a1a959b50ec2cef7858f8253) 26 | 27 | ## [v1.0.5](https://github.com/es-shims/Promise.allSettled/compare/v1.0.4...v1.0.5) - 2021-10-03 28 | 29 | ### Commits 30 | 31 | - [actions] use `node/install` instead of `node/run`; use `codecov` action [`7d77553`](https://github.com/es-shims/Promise.allSettled/commit/7d77553474ee8370a2fabdceaf07c86e89a989df) 32 | - [actions] partial revert of 7d77553474ee8370a2fabdceaf07c86e89a989df; fix promise-shimmed tests [`760421a`](https://github.com/es-shims/Promise.allSettled/commit/760421a9e6806655b85d3a757d49a4b1effbd4ea) 33 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `auto-changelog`, `tape` [`95ed131`](https://github.com/es-shims/Promise.allSettled/commit/95ed131ca0d15ecb6ec6c507ce43fdcc999f9380) 34 | - [Deps] update `array.prototype.map`, `es-abstract` [`2cb2b26`](https://github.com/es-shims/Promise.allSettled/commit/2cb2b26b45fe8875acf948a752cc021e367eec5d) 35 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`e0d6e23`](https://github.com/es-shims/Promise.allSettled/commit/e0d6e2317a068441b9b4b42a0f73cb844a6db05f) 36 | - [readme] add github actions/codecov badges [`3796b86`](https://github.com/es-shims/Promise.allSettled/commit/3796b86abcc116c870088ff990ad030737e380e4) 37 | - [actions] update workflows [`170c0a9`](https://github.com/es-shims/Promise.allSettled/commit/170c0a9a61bbc7099abeadabac62d922bdf384a1) 38 | - [Deps] update `es-abstract`, `get-intrinsic` [`a148f57`](https://github.com/es-shims/Promise.allSettled/commit/a148f5735a63810c4146aad515a252f245bd91ba) 39 | - [meta] use `prepublishOnly` script for npm 7+ [`b09d1ee`](https://github.com/es-shims/Promise.allSettled/commit/b09d1eece27d5ba08848998b79c6d0947d4803e4) 40 | 41 | ## [v1.0.4](https://github.com/es-shims/Promise.allSettled/compare/v1.0.3...v1.0.4) - 2021-01-20 42 | 43 | ### Commits 44 | 45 | - [Fix] properly call-bind `Promise.all` and `Promise.reject` [`1f90b0e`](https://github.com/es-shims/Promise.allSettled/commit/1f90b0efc3208486709391ffe1dd16b79ca214d4) 46 | 47 | ## [v1.0.3](https://github.com/es-shims/Promise.allSettled/compare/v1.0.2...v1.0.3) - 2021-01-20 48 | 49 | ### Commits 50 | 51 | - [Tests] migrate tests to Github Actions [`a066121`](https://github.com/es-shims/Promise.allSettled/commit/a0661218570a7815a5328e36ee5b2378e16820d2) 52 | - [meta] use `auto-changelog` [`7b27067`](https://github.com/es-shims/Promise.allSettled/commit/7b270677baf74ddfedcf4869b869b44e89d30a28) 53 | - [meta] do not publish github action workflow files [`aae74fd`](https://github.com/es-shims/Promise.allSettled/commit/aae74fd7c0a1abf9a9609d7fcd9755b3a8d2a364) 54 | - [Tests] run `nyc` on all tests; use `tape` runner; add implementation tests [`fbd8198`](https://github.com/es-shims/Promise.allSettled/commit/fbd81984b88abb6fc2089e15090a4861f24642a8) 55 | - [Deps] update `array.prototype.map`, `es-abstract`; add `call-bind` [`424f760`](https://github.com/es-shims/Promise.allSettled/commit/424f7606f6ec04aefd36e61dcd83ba1a96d04bbb) 56 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `call-bind`, `functions-have-names`, `tape` [`47c5df1`](https://github.com/es-shims/Promise.allSettled/commit/47c5df1ddb55ae59bf57dabf62b6030a92a2adc4) 57 | - [actions] add "Allow Edits" workflow [`d931b6c`](https://github.com/es-shims/Promise.allSettled/commit/d931b6c00bab078e5562b7392374d48de9ffc1cd) 58 | - [Refactor] use es-abstract’s `callBind` instead of `function-bind` directly [`09c25e8`](https://github.com/es-shims/Promise.allSettled/commit/09c25e81af2050ade7d4be35a522753422e7843a) 59 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `functions-have-names`, `tape`; add `aud` [`03aedb0`](https://github.com/es-shims/Promise.allSettled/commit/03aedb0e6365f0ea6f76a373148f3e1ed2c6e8a2) 60 | - [Deps] update `array.prototype.map`, `es-abstract`, `iterate-value` [`f28e1aa`](https://github.com/es-shims/Promise.allSettled/commit/f28e1aa6a83d201de8a81862890c713f60c1680c) 61 | - [Tests] test in older nodes that 3e873f7 now supports [`5feffee`](https://github.com/es-shims/Promise.allSettled/commit/5feffeecb8d9a535cd24f6563023f841a455ebee) 62 | - [actions] switch Automatic Rebase workflow to `pull_request_target` event [`b30a268`](https://github.com/es-shims/Promise.allSettled/commit/b30a2686337efa13454ce754c32287b4aec11bdf) 63 | - [meta] only run `aud` on prod deps [`bf97e5f`](https://github.com/es-shims/Promise.allSettled/commit/bf97e5fad6e5ab554ec8780d1a5f0d955dbce4e4) 64 | - [Deps] update `es-abstract` [`6a6ae55`](https://github.com/es-shims/Promise.allSettled/commit/6a6ae556058aba575b8cd335618f846b3c1fe8c8) 65 | - [Deps] update `iterate-value` [`13507f3`](https://github.com/es-shims/Promise.allSettled/commit/13507f3b7b87de8b26ea3cd0d40949c8c9747f77) 66 | 67 | ## [v1.0.2](https://github.com/es-shims/Promise.allSettled/compare/v1.0.1...v1.0.2) - 2019-12-13 68 | 69 | ### Commits 70 | 71 | - [Tests] use shared travis-ci configs [`3a5a379`](https://github.com/es-shims/Promise.allSettled/commit/3a5a379ad6da1a7fe988e8e1eb708be4f7abb008) 72 | - [meta] move repo to es-shims org [`240a87c`](https://github.com/es-shims/Promise.allSettled/commit/240a87c480ab7a3119c192476c6317d5f5ce59e2) 73 | - [Fix] no longer require `Array.from`; works in older envs [`3e873f7`](https://github.com/es-shims/Promise.allSettled/commit/3e873f78e15b275d6e10db12ac6cde1716be2f60) 74 | - [actions] add automatic rebasing / merge commit blocking [`4ab52ef`](https://github.com/es-shims/Promise.allSettled/commit/4ab52efa9466c535cd15a1bcb54b3250c989b174) 75 | - [Tests] skip "`undefined` receiver" test [`9612591`](https://github.com/es-shims/Promise.allSettled/commit/96125915f35386940fce8eb52331346ffe3b45d6) 76 | - [Refactor] use split-up `es-abstract` (44% bundle size decrease) [`ed49521`](https://github.com/es-shims/Promise.allSettled/commit/ed49521b2f03a4a63ef0e15a017dc973217d03bb) 77 | - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `functions-have-names`, `safe-publish-latest` [`7f97708`](https://github.com/es-shims/Promise.allSettled/commit/7f977086e2f685d29d1ae821b4083c9b4e1256d8) 78 | - [Tests] temporarily comment out failing test in node 12+ [`275507f`](https://github.com/es-shims/Promise.allSettled/commit/275507f89a3c672acd867cbe7432c0c08f0abef9) 79 | - [meta] add `funding` field [`96b75aa`](https://github.com/es-shims/Promise.allSettled/commit/96b75aab5a8bb3586303baafe462b4b4114fb2da) 80 | - [Tests] suppress unhandled rejection warnings [`8ee2263`](https://github.com/es-shims/Promise.allSettled/commit/8ee226357bb92417ac5d596abaa86cc600c97aa1) 81 | - [Tests] use `functions-have-names` [`43ed9ca`](https://github.com/es-shims/Promise.allSettled/commit/43ed9ca63e41795c8f96764da33dee3d11fa533a) 82 | - [Dev Deps] update `tape` [`df12368`](https://github.com/es-shims/Promise.allSettled/commit/df123681fd26b8b18d0f89aa56e57d927fd63bc6) 83 | 84 | ## [v1.0.1](https://github.com/es-shims/Promise.allSettled/compare/v1.0.0...v1.0.1) - 2019-05-06 85 | 86 | ### Fixed 87 | 88 | - [Fix] when a promise has a poisoned `.then` method, reject the overarching promise [`#1`](https://github.com/es-shims/Promise.allSettled/issues/1) 89 | 90 | ### Commits 91 | 92 | - [Tests] up to `node` `v12.1`, `v11.15` [`4d76716`](https://github.com/es-shims/Promise.allSettled/commit/4d76716fc0a002af216962d177bd197688b27e1f) 93 | - [Dev Deps] update `eslint` [`fc23682`](https://github.com/es-shims/Promise.allSettled/commit/fc23682b807812ab5288d9a100b60f735f41f089) 94 | 95 | ## v1.0.0 - 2019-03-27 96 | 97 | ### Commits 98 | 99 | - [Tests] add `travis-ci` [`0201190`](https://github.com/es-shims/Promise.allSettled/commit/02011908060b52218b21b04c88d85fb521f09c93) 100 | - Initial tests [`1a519d1`](https://github.com/es-shims/Promise.allSettled/commit/1a519d1f7ae673a4b109baa81fa02fdd95bd5788) 101 | - Initial implementation [`562952d`](https://github.com/es-shims/Promise.allSettled/commit/562952d201c3d0c43b8549c6399cf56555125983) 102 | - Initial commit [`cee4c56`](https://github.com/es-shims/Promise.allSettled/commit/cee4c561deba91556b697d329149bfd9c32c7927) 103 | - readme [`60f133f`](https://github.com/es-shims/Promise.allSettled/commit/60f133f4b11d15b479b0c8d5de634005e4992ede) 104 | - package.json [`6b9cc53`](https://github.com/es-shims/Promise.allSettled/commit/6b9cc53e884da0847bebea738bfbb93d2993f060) 105 | - Require `Array.from`; fix tests [`53ff455`](https://github.com/es-shims/Promise.allSettled/commit/53ff455a67d06f86b250e4584d3de417c1937966) 106 | - [Tests] add `npm run lint` [`d61e9f7`](https://github.com/es-shims/Promise.allSettled/commit/d61e9f79ef7df73eb55caa95f552aea09559574e) 107 | - Only apps should have lockfiles [`cb2ea36`](https://github.com/es-shims/Promise.allSettled/commit/cb2ea3689931a5a4502e5f771347cff6919a0305) 108 | - [Tests] use `npx aud` for posttest, and `safe-publish-latest` for prepublish [`68995cd`](https://github.com/es-shims/Promise.allSettled/commit/68995cdf499a3d6e124c76e4e31c1daa55387c46) 109 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jordan Harband 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # promise.allsettled [![Version Badge][npm-version-svg]][package-url] 2 | 3 | [![github actions][actions-image]][actions-url] 4 | [![coverage][codecov-image]][codecov-url] 5 | [![dependency status][deps-svg]][deps-url] 6 | [![dev dependency status][dev-deps-svg]][dev-deps-url] 7 | [![License][license-image]][license-url] 8 | [![Downloads][downloads-image]][downloads-url] 9 | 10 | [![npm badge][npm-badge-png]][package-url] 11 | 12 | ES Proposal spec-compliant shim for Promise.allSettled. Invoke its "shim" method to shim `Promise.allSettled` if it is unavailable or noncompliant. **Note**: a global `Promise` must already exist: the [es6-shim](https://github.com/es-shims/es6-shim) is recommended. 13 | 14 | This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment that has `Promise` available globally, and complies with the [proposed spec](https://github.com/tc39/proposal-promise-allSettled). 15 | 16 | Most common usage: 17 | ```js 18 | var assert = require('assert'); 19 | var allSettled = require('promise.allsettled'); 20 | 21 | var resolved = Promise.resolve(42); 22 | var rejected = Promise.reject(-1); 23 | 24 | allSettled([resolved, rejected]).then(function (results) { 25 | assert.deepEqual(results, [ 26 | { status: 'fulfilled', value: 42 }, 27 | { status: 'rejected', reason: -1 } 28 | ]); 29 | }); 30 | 31 | allSettled.shim(); // will be a no-op if not needed 32 | 33 | Promise.allSettled([resolved, rejected]).then(function (results) { 34 | assert.deepEqual(results, [ 35 | { status: 'fulfilled', value: 42 }, 36 | { status: 'rejected', reason: -1 } 37 | ]); 38 | }); 39 | ``` 40 | 41 | ## Tests 42 | Simply clone the repo, `npm install`, and run `npm test` 43 | 44 | [package-url]: https://npmjs.com/package/promise.allsettled 45 | [npm-version-svg]: http://versionbadg.es/es-shims/Promise.allSettled.svg 46 | [travis-svg]: https://travis-ci.org/es-shims/Promise.allSettled.svg 47 | [travis-url]: https://travis-ci.org/es-shims/Promise.allSettled 48 | [deps-svg]: https://david-dm.org/es-shims/Promise.allSettled.svg 49 | [deps-url]: https://david-dm.org/es-shims/Promise.allSettled 50 | [dev-deps-svg]: https://david-dm.org/es-shims/Promise.allSettled/dev-status.svg 51 | [dev-deps-url]: https://david-dm.org/es-shims/Promise.allSettled#info=devDependencies 52 | [npm-badge-png]: https://nodei.co/npm/promise.allsettled.png?downloads=true&stars=true 53 | [license-image]: http://img.shields.io/npm/l/promise.allsettled.svg 54 | [license-url]: LICENSE 55 | [downloads-image]: http://img.shields.io/npm/dm/promise.allsettled.svg 56 | [downloads-url]: http://npm-stat.com/charts.html?package=promise.allsettled 57 | [codecov-image]: https://codecov.io/gh/es-shims/Promise.allSettled/branch/main/graphs/badge.svg 58 | [codecov-url]: https://app.codecov.io/gh/es-shims/Promise.allSettled/ 59 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Promise.allSettled 60 | [actions-url]: https://github.com/es-shims/Promise.allSettled/actions 61 | -------------------------------------------------------------------------------- /auto.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('./shim')(); 4 | -------------------------------------------------------------------------------- /implementation.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var requirePromise = require('./requirePromise'); 4 | 5 | requirePromise(); 6 | 7 | var PromiseResolve = require('es-abstract/2023/PromiseResolve'); 8 | var Type = require('es-abstract/2023/Type'); 9 | var iterate = require('iterate-value'); 10 | var map = require('array.prototype.map'); 11 | var GetIntrinsic = require('get-intrinsic'); 12 | var callBind = require('call-bind'); 13 | 14 | var all = callBind(GetIntrinsic('%Promise.all%')); 15 | var reject = callBind(GetIntrinsic('%Promise.reject%')); 16 | 17 | module.exports = function allSettled(iterable) { 18 | var C = this; 19 | if (Type(C) !== 'Object') { 20 | throw new TypeError('`this` value must be an object'); 21 | } 22 | var values = iterate(iterable); 23 | return all(C, map(values, function (item) { 24 | var onFulfill = function (value) { 25 | return { status: 'fulfilled', value: value }; 26 | }; 27 | var onReject = function (reason) { 28 | return { status: 'rejected', reason: reason }; 29 | }; 30 | var itemPromise = PromiseResolve(C, item); 31 | try { 32 | return itemPromise.then(onFulfill, onReject); 33 | } catch (e) { 34 | return reject(C, e); 35 | } 36 | })); 37 | }; 38 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var callBind = require('call-bind'); 4 | var define = require('define-properties'); 5 | 6 | var requirePromise = require('./requirePromise'); 7 | var implementation = require('./implementation'); 8 | var getPolyfill = require('./polyfill'); 9 | var shim = require('./shim'); 10 | 11 | requirePromise(); 12 | var bound = callBind(getPolyfill()); 13 | 14 | var rebindable = function allSettled(iterable) { 15 | // eslint-disable-next-line no-invalid-this 16 | return bound(typeof this === 'undefined' ? Promise : this, iterable); 17 | }; 18 | 19 | define(rebindable, { 20 | getPolyfill: getPolyfill, 21 | implementation: implementation, 22 | shim: shim 23 | }); 24 | 25 | module.exports = rebindable; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "promise.allsettled", 3 | "version": "1.0.7", 4 | "author": "Jordan Harband ", 5 | "funding": { 6 | "url": "https://github.com/sponsors/ljharb" 7 | }, 8 | "contributors": [ 9 | { 10 | "name": "Jordan Harband", 11 | "email": "ljharb@gmail.com", 12 | "url": "http://ljharb.codes" 13 | } 14 | ], 15 | "description": "ES Proposal spec-compliant shim for Promise.allSettled", 16 | "license": "MIT", 17 | "main": "index.js", 18 | "scripts": { 19 | "prepack": "npmignore --auto --commentLines=autogenerated", 20 | "prepublish": "not-in-publish || npm run prepublishOnly", 21 | "prepublishOnly": "safe-publish-latest", 22 | "pretest": "npm run --silent lint && es-shim-api --bound", 23 | "test": "npm run --silent tests-only && npm run test:promise-shimmed", 24 | "posttest": "npx aud --production", 25 | "tests-only": "nyc tape test/{implementation,index,shimmed}.js", 26 | "test:promise-shimmed": "nyc node test/promise-shimmed", 27 | "test:native": "nyc node test/native", 28 | "lint": "eslint --ext=js,mjs .", 29 | "version": "auto-changelog && git add CHANGELOG.md", 30 | "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" 31 | }, 32 | "repository": { 33 | "type": "git", 34 | "url": "git://github.com/es-shims/Promise.allSettled.git" 35 | }, 36 | "keywords": [ 37 | "Promise", 38 | "promises", 39 | "allsettled", 40 | "settled", 41 | "fulfilled", 42 | "resolved", 43 | "rejected", 44 | "promise.allsettled", 45 | "shim", 46 | "polyfill", 47 | "es-shim", 48 | "API" 49 | ], 50 | "bugs": { 51 | "url": "https://github.com/es-shims/promise.allsettled/issues" 52 | }, 53 | "homepage": "https://github.com/es-shims/promise.allsettled#readme", 54 | "engines": { 55 | "node": ">= 0.4" 56 | }, 57 | "dependencies": { 58 | "array.prototype.map": "^1.0.5", 59 | "call-bind": "^1.0.2", 60 | "define-properties": "^1.2.0", 61 | "es-abstract": "^1.22.1", 62 | "get-intrinsic": "^1.2.1", 63 | "iterate-value": "^1.0.2" 64 | }, 65 | "devDependencies": { 66 | "@es-shims/api": "^2.4.2", 67 | "@ljharb/eslint-config": "^21.1.0", 68 | "aud": "^2.0.3", 69 | "auto-changelog": "^2.4.0", 70 | "es6-shim": "^0.35.8", 71 | "eslint": "=8.8.0", 72 | "functions-have-names": "^1.2.3", 73 | "in-publish": "^2.0.1", 74 | "npmignore": "^0.3.0", 75 | "nyc": "^10.3.2", 76 | "safe-publish-latest": "^2.0.0", 77 | "tape": "^5.6.6" 78 | }, 79 | "auto-changelog": { 80 | "output": "CHANGELOG.md", 81 | "template": "keepachangelog", 82 | "unreleased": false, 83 | "commitLimit": false, 84 | "backfillLimit": false, 85 | "hideCredit": true 86 | }, 87 | "publishConfig": { 88 | "ignore": [ 89 | ".github/workflows" 90 | ] 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /polyfill.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var requirePromise = require('./requirePromise'); 4 | 5 | var implementation = require('./implementation'); 6 | 7 | module.exports = function getPolyfill() { 8 | requirePromise(); 9 | return typeof Promise.allSettled === 'function' ? Promise.allSettled : implementation; 10 | }; 11 | -------------------------------------------------------------------------------- /requirePromise.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function requirePromise() { 4 | if (typeof Promise !== 'function') { 5 | throw new TypeError('`Promise.allSettled` requires a global `Promise` be available.'); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /shim.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var requirePromise = require('./requirePromise'); 4 | 5 | var getPolyfill = require('./polyfill'); 6 | var define = require('define-properties'); 7 | 8 | module.exports = function shimAllSettled() { 9 | requirePromise(); 10 | 11 | var polyfill = getPolyfill(); 12 | define(Promise, { allSettled: polyfill }, { 13 | allSettled: function testAllSettled() { 14 | return Promise.allSettled !== polyfill; 15 | } 16 | }); 17 | return polyfill; 18 | }; 19 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "array-bracket-newline": 0, 4 | "max-lines-per-function": 0, 5 | "max-params": 0, 6 | "max-nested-callbacks": 0, 7 | "max-statements": 0, 8 | "max-statements-per-line": 0, 9 | "no-invalid-this": 1, 10 | "prefer-promise-reject-errors": 0, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/builtin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var defineProperties = require('define-properties'); 4 | var isEnumerable = Object.prototype.propertyIsEnumerable; 5 | var functionsHaveNames = require('functions-have-names')(); 6 | 7 | var runTests = require('./tests'); 8 | 9 | module.exports = function (t) { 10 | t.equal(Promise.allSettled.length, 1, 'Promise.allSettled has a length of 1'); 11 | t.test('Function name', { skip: !functionsHaveNames }, function (st) { 12 | st.equal(Promise.allSettled.name, 'allSettled', 'Promise.allSettled has name "allSettled"'); 13 | st.end(); 14 | }); 15 | 16 | t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) { 17 | et.equal(false, isEnumerable.call(Promise, 'allSettled'), 'Promise.allSettled is not enumerable'); 18 | et.end(); 19 | }); 20 | 21 | var supportsStrictMode = (function () { return typeof this === 'undefined'; }()); 22 | 23 | t.test('bad object value', { skip: !supportsStrictMode }, function (st) { 24 | st['throws'](function () { return Promise.allSettled.call(undefined); }, TypeError, 'undefined is not an object'); 25 | st['throws'](function () { return Promise.allSettled.call(null); }, TypeError, 'null is not an object'); 26 | st.end(); 27 | }); 28 | 29 | runTests(function allSettled(iterable) { return Promise.allSettled.call(typeof this === 'undefined' ? Promise : this, iterable); }, t); 30 | }; 31 | -------------------------------------------------------------------------------- /test/implementation.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | var callBind = require('call-bind'); 5 | 6 | var allSettled = require('../implementation'); 7 | var runTests = require('./tests'); 8 | 9 | var bound = callBind(allSettled); 10 | 11 | // eslint-disable-next-line no-shadow 12 | var rebindable = function allSettled(iterable) { 13 | // eslint-disable-next-line no-invalid-this 14 | return bound(typeof this === 'undefined' ? Promise : this, iterable); 15 | }; 16 | 17 | test('as a function', function (t) { 18 | t.test('bad Promise/this value', function (st) { 19 | // eslint-disable-next-line no-useless-call 20 | st['throws'](function () { allSettled.call(undefined, []); }, TypeError, 'undefined is not an object'); 21 | 22 | // eslint-disable-next-line no-useless-call 23 | st['throws'](function () { allSettled.call(null, []); }, TypeError, 'null is not an object'); 24 | st.end(); 25 | }); 26 | 27 | runTests(rebindable, t); 28 | 29 | t.end(); 30 | }); 31 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var allSettled = require('..'); 4 | var test = require('tape'); 5 | var runTests = require('./tests'); 6 | 7 | test('as a function', function (t) { 8 | t.test('bad Promise/this value', function (st) { 9 | // below test is skipped, because for convenience, i'm explicitly turning `undefined` into `Promise` in the main export 10 | // eslint-disable-next-line no-useless-call 11 | // st['throws'](function () { any.call(undefined, []); }, TypeError, 'undefined is not an object'); 12 | 13 | // eslint-disable-next-line no-useless-call 14 | st['throws'](function () { allSettled.call(null, []); }, TypeError, 'null is not an object'); 15 | st.end(); 16 | }); 17 | 18 | runTests(allSettled, t); 19 | 20 | t.end(); 21 | }); 22 | -------------------------------------------------------------------------------- /test/native.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | 5 | var runTests = require('./builtin'); 6 | 7 | test('shimmed', function (t) { 8 | runTests(t); 9 | 10 | t.end(); 11 | }); 12 | -------------------------------------------------------------------------------- /test/promise-shimmed.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('es6-shim'); 4 | 5 | require('./'); 6 | 7 | require('./shimmed'); 8 | -------------------------------------------------------------------------------- /test/shimmed.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('../auto'); 4 | 5 | var test = require('tape'); 6 | 7 | var runTests = require('./builtin'); 8 | 9 | test('shimmed', function (t) { 10 | runTests(t); 11 | 12 | t.end(); 13 | }); 14 | -------------------------------------------------------------------------------- /test/tests.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | if (typeof process !== 'undefined') { 4 | process.on('unhandledRejection', function () {}); 5 | } 6 | 7 | var assertArray = function (t, value, length, assertType) { 8 | t.ok(Array.isArray(value), 'value is an array'); 9 | t.equal(value.length, length, 'length is ' + length); 10 | if (typeof assertType === 'function') { 11 | for (var i = 0; i < value.length; i += 1) { 12 | assertType(value[i]); 13 | } 14 | } 15 | }; 16 | 17 | var yes = function makeFulfilledResult(value) { 18 | return { status: 'fulfilled', value: value }; 19 | }; 20 | var no = function makeRejectedResult(reason) { 21 | return { status: 'rejected', reason: reason }; 22 | }; 23 | 24 | module.exports = function (allSettled, t) { 25 | if (typeof Promise !== 'function') { 26 | return t.skip('No global Promise detected'); 27 | } 28 | 29 | var a = {}; 30 | var b = {}; 31 | var c = {}; 32 | 33 | t.test('no promise values', function (st) { 34 | st.plan(1); 35 | allSettled([a, b, c]).then(function (results) { 36 | st.deepEqual(results, [yes(a), yes(b), yes(c)]); 37 | }); 38 | }); 39 | 40 | t.test('all fulfilled', function (st) { 41 | st.plan(1); 42 | allSettled([ 43 | Promise.resolve(a), 44 | Promise.resolve(b), 45 | Promise.resolve(c) 46 | ]).then(function (results) { 47 | st.deepEqual(results, [ 48 | yes(a), 49 | yes(b), 50 | yes(c) 51 | ]); 52 | }); 53 | }); 54 | 55 | t.test('all rejected', function (st) { 56 | st.plan(1); 57 | allSettled([ 58 | Promise.reject(a), 59 | Promise.reject(b), 60 | Promise.reject(c) 61 | ]).then(function (results) { 62 | st.deepEqual(results, [ 63 | no(a), 64 | no(b), 65 | no(c) 66 | ]); 67 | }); 68 | }); 69 | 70 | t.test('mixed', function (st) { 71 | st.plan(1); 72 | allSettled([ 73 | a, 74 | Promise.resolve(b), 75 | Promise.reject(c) 76 | ]).then(function (results) { 77 | st.deepEqual(results, [ 78 | yes(a), 79 | yes(b), 80 | no(c) 81 | ]); 82 | }); 83 | }); 84 | 85 | t.test('poisoned .then', function (st) { 86 | st.plan(1); 87 | var promise = new Promise(function () {}); 88 | promise.then = function () { throw new EvalError(); }; 89 | allSettled([promise]).then(function () { 90 | st.fail('should not reach here'); 91 | }, function (reason) { 92 | st.equal(reason instanceof EvalError, true, 'expected error was thrown'); 93 | }); 94 | }); 95 | 96 | var Subclass = (function () { 97 | try { 98 | // eslint-disable-next-line no-new-func 99 | return Function('class Subclass extends Promise { constructor(...args) { super(...args); this.thenArgs = []; } then(...args) { Subclass.thenArgs.push(args); this.thenArgs.push(args); return super.then(...args); } } Subclass.thenArgs = []; return Subclass;')(); 100 | } catch (e) { /**/ } 101 | 102 | return false; 103 | }()); 104 | t.test('inheritance', { skip: !Subclass }, function (st) { 105 | st.test('preserves correct subclass', function (s2t) { 106 | var promise = allSettled.call(Subclass, [1]); 107 | s2t.ok(promise instanceof Subclass, 'promise is instanceof Subclass'); 108 | s2t.equal(promise.constructor, Subclass, 'promise.constructor is Subclass'); 109 | 110 | s2t.end(); 111 | }); 112 | 113 | st.test('invokes the subclass’ then', function (s2t) { 114 | Subclass.thenArgs.length = 0; 115 | 116 | var original = Subclass.resolve(); 117 | assertArray(s2t, Subclass.thenArgs, 0); 118 | assertArray(s2t, original.thenArgs, 0); 119 | 120 | allSettled.call(Subclass, [original]); 121 | 122 | assertArray(s2t, original.thenArgs, 1); 123 | /* 124 | * TODO: uncomment. node v12+'s native implementation fails this check. 125 | * Either v8's impl is wrong, or this package's impl is wrong - figure out which. 126 | * assertArray(s2t, Subclass.thenArgs, 2); 127 | */ 128 | 129 | s2t.end(); 130 | }); 131 | }); 132 | 133 | return t.comment('tests completed'); 134 | }; 135 | --------------------------------------------------------------------------------