init
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"plugins": [
|
||||
"import",
|
||||
],
|
||||
|
||||
"globals": {
|
||||
"Iterator": false,
|
||||
},
|
||||
|
||||
"rules": {
|
||||
"array-bracket-newline": 0,
|
||||
"func-name-matching": 0,
|
||||
"id-length": 0,
|
||||
"max-lines-per-function": 0,
|
||||
"max-statements": 0,
|
||||
"multiline-comment-style": 0,
|
||||
"new-cap": [2, {
|
||||
"capIsNewExceptions": [
|
||||
"Call",
|
||||
"CreateDataPropertyOrThrow",
|
||||
"CreateIteratorFromClosure",
|
||||
"CreateIterResultObject",
|
||||
"GeneratorResume",
|
||||
"GeneratorResumeAbrupt",
|
||||
"GeneratorStart",
|
||||
"GeneratorValidate",
|
||||
"Get",
|
||||
"GetIntrinsic",
|
||||
"GetIterator",
|
||||
"GetIteratorDirect",
|
||||
"GetIteratorFlattenable",
|
||||
"GetMethod",
|
||||
"GetOptionsObject",
|
||||
"IfAbruptCloseIterators",
|
||||
"IsAccessorDescriptor",
|
||||
"IsArray",
|
||||
"IsCallable",
|
||||
"IsDataDescriptor",
|
||||
"IteratorClose",
|
||||
"IteratorCloseAll",
|
||||
"IteratorStep",
|
||||
"IteratorStepValue",
|
||||
"IteratorZip",
|
||||
"NormalCompletion",
|
||||
"OrdinaryHasInstance",
|
||||
"OrdinaryObjectCreate",
|
||||
"ReturnCompletion",
|
||||
"StringToCodePoints",
|
||||
"ThrowCompletion",
|
||||
"ToBoolean",
|
||||
"ToIntegerOrInfinity",
|
||||
"ToNumber",
|
||||
"Type",
|
||||
],
|
||||
}],
|
||||
"no-negated-condition": 1,
|
||||
"object-curly-newline": 0,
|
||||
"sort-keys": 0,
|
||||
"import/no-extraneous-dependencies": 2,
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"eqeqeq": ["error", "allow-null"],
|
||||
"max-params": 0,
|
||||
"import/no-extraneous-dependencies": [2, { "devDependencies": true }],
|
||||
},
|
||||
},
|
||||
{
|
||||
"files": "Iterator.zip*/implementation.js",
|
||||
"rules": {
|
||||
"complexity": "off",
|
||||
"max-depth": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
"files": "aos/IteratorZip.js",
|
||||
"rules": {
|
||||
"max-depth": "off",
|
||||
"max-params": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.2.0](https://github.com/es-shims/iterator-helpers/compare/v1.1.0...v1.2.0) - 2024-11-04
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add `Iterator.zip`, `Iterator.zipKeyed` [`d11073f`](https://github.com/es-shims/iterator-helpers/commit/d11073fd27fcdaf696c3d9b00634b6a5144f75b1)
|
||||
- [Fix] `concat`: add missing slot for `.return`; convert singular slot to plural slot [`cc4b586`](https://github.com/es-shims/iterator-helpers/commit/cc4b586cdb0ad6ba540043077c3d71ff79d528cd)
|
||||
- [Dev Deps] update `@es-shims/api` [`dd14f1b`](https://github.com/es-shims/iterator-helpers/commit/dd14f1b9f06c37f3bcb0a20bacd6e7f031c0724d)
|
||||
|
||||
## [v1.1.0](https://github.com/es-shims/iterator-helpers/compare/v1.0.19...v1.1.0) - 2024-10-09
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add `Iterator.concat` [`1c07c21`](https://github.com/es-shims/iterator-helpers/commit/1c07c21d42fa6f3de516191a2b7fb848679314e7)
|
||||
- [readme] add ESM and CJS examples [`ae0b60c`](https://github.com/es-shims/iterator-helpers/commit/ae0b60cae42a5e6174809859e29d16085042e3b2)
|
||||
- [Dev Deps] update `@es-shims/api`, `auto-changelog`, `es-value-fixtures`, `eslint-plugin-import`, `tape` [`bd34766`](https://github.com/es-shims/iterator-helpers/commit/bd34766d527cc625dcbc242297290a793f21b055)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `mock-property`, `object-inspect`, `tape` [`2016080`](https://github.com/es-shims/iterator-helpers/commit/201608082a32bc1fa114c012eeb72744e1bf5bfa)
|
||||
- [readme] fix copy-paste errors [`799255c`](https://github.com/es-shims/iterator-helpers/commit/799255ce358f9f19ab54cc2377aafb404463d917)
|
||||
- [Tests] replace `aud` with `npm audit` [`4c48a77`](https://github.com/es-shims/iterator-helpers/commit/4c48a77d90a6894863ad160fd0f88b3fc76653b6)
|
||||
- [Deps] update `globalthis` [`14d9e97`](https://github.com/es-shims/iterator-helpers/commit/14d9e971f976da482cbb7ee76b583db9ce17e056)
|
||||
- [Dev Deps] update `@es-shims/api` [`15d84bb`](https://github.com/es-shims/iterator-helpers/commit/15d84bbbe1864dfd028f30f98251cbdf19e74908)
|
||||
- [Dev Deps] add missing peer dep [`34559b9`](https://github.com/es-shims/iterator-helpers/commit/34559b9a263dfbc3551fd0ff586639692c04e514)
|
||||
|
||||
## [v1.0.19](https://github.com/es-shims/iterator-helpers/compare/v1.0.18...v1.0.19) - 2024-04-24
|
||||
|
||||
### Commits
|
||||
|
||||
- [patch] remove unused AOs [`698cef7`](https://github.com/es-shims/iterator-helpers/commit/698cef79757378a74500690d5a5dc2a6b86cd304)
|
||||
- [Fix] `drop`, `filter`, `flatMap`, `map`: rpatch a v8 bug when polyfilling [`3670395`](https://github.com/es-shims/iterator-helpers/commit/36703956321c201933c4c701c78304669a46947b)
|
||||
- [Deps] update `es-abstract` [`d2b47a5`](https://github.com/es-shims/iterator-helpers/commit/d2b47a5f46d3f874aad67375346cb58bf8c9e8b2)
|
||||
|
||||
## [v1.0.18](https://github.com/es-shims/iterator-helpers/compare/v1.0.17...v1.0.18) - 2024-03-15
|
||||
|
||||
### Commits
|
||||
|
||||
- [Deps] update `es-abstract` [`6b45f15`](https://github.com/es-shims/iterator-helpers/commit/6b45f150e939cfbf93b816431a407c0838250e85)
|
||||
- [Deps] update `es-set-tostringtag`, `has-proto`, `safe-array-concat` [`6350106`](https://github.com/es-shims/iterator-helpers/commit/6350106c9e5c18a67754ced3fd90465b0032f1e3)
|
||||
- [Dev Deps] update `tape` [`5509b40`](https://github.com/es-shims/iterator-helpers/commit/5509b408791402d2f7d7882f905741e5a5dd805b)
|
||||
- [Deps] remove an unused dep [`78e34a5`](https://github.com/es-shims/iterator-helpers/commit/78e34a5452e7b7ef3dc239a62dd8a7324fbb2305)
|
||||
|
||||
## [v1.0.17](https://github.com/es-shims/iterator-helpers/compare/v1.0.16...v1.0.17) - 2024-02-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- [Fix] avoid use of internal `assertRecord` helper from `es-abstract` [`#5`](https://github.com/es-shims/iterator-helpers/issues/5)
|
||||
|
||||
### Commits
|
||||
|
||||
- [Deps] update `call-bind`, `es-abstract`, `has-property-descriptors` [`e563ee7`](https://github.com/es-shims/iterator-helpers/commit/e563ee7230897c41f7f3623a11fc0ecc6862ee1c)
|
||||
|
||||
## [v1.0.16](https://github.com/es-shims/iterator-helpers/compare/v1.0.15...v1.0.16) - 2024-02-09
|
||||
|
||||
### Commits
|
||||
|
||||
- [Refactor] use `IteratorStepValue` [`aa62d72`](https://github.com/es-shims/iterator-helpers/commit/aa62d72c52d86218942b4792c7131f72d939b733)
|
||||
- [Refactor] use `es-errors` instead of `get-intrinsic` where possible [`05a25ae`](https://github.com/es-shims/iterator-helpers/commit/05a25aeccd0523df86b401c771d88fbea06558c9)
|
||||
- [Deps] update `call-bind`, `es-abstract`, `es-set-tostringtag`, `function-bind`, `get-intrinsic`, `has-property-descriptors`, `internal-slot`, `safe-array-concat` [`6aeee43`](https://github.com/es-shims/iterator-helpers/commit/6aeee435ed5956b7c5ee66a51b86c26827874eae)
|
||||
- [Dev Deps] update `aud`, `eslint-plugin-import`, `mock-property`, `npmignore`, `object-inspect`, `tape` [`0a21fdb`](https://github.com/es-shims/iterator-helpers/commit/0a21fdb4a59d25c248561b7f476fc9670b411855)
|
||||
- [Deps] update `call-bind`, `es-errors`, `get-intrinsic`, `internal-slot` [`5b10625`](https://github.com/es-shims/iterator-helpers/commit/5b106251dad4252a744b2e0aa0d1be4c1c62b779)
|
||||
- [meta] add missing `engines.node` [`1534039`](https://github.com/es-shims/iterator-helpers/commit/1534039eca062429c0df68dcc3459ce9ba7c69be)
|
||||
- [Deps] update `get-intrinsic` [`37da5f2`](https://github.com/es-shims/iterator-helpers/commit/37da5f201940c78526de647ef9ba84d9152349c1)
|
||||
- [Dev Deps] update `has-tostringtag` [`a7cac51`](https://github.com/es-shims/iterator-helpers/commit/a7cac51cc027e6274918cb1ea0cf1fa1a194fcd9)
|
||||
|
||||
## [v1.0.15](https://github.com/es-shims/iterator-helpers/compare/v1.0.14...v1.0.15) - 2023-09-13
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add `Iterator.prototype` shim [`c4a6203`](https://github.com/es-shims/iterator-helpers/commit/c4a6203a0ac87bf0a33835e775c207ff1911225d)
|
||||
- [Tests] add passing tests for native generators [`57bae8c`](https://github.com/es-shims/iterator-helpers/commit/57bae8ccbeb27ed0e6c449f35cddbda6cf6757e8)
|
||||
- [Deps] update `define-properties`, `iterator.prototype`, `safe-array-concat` [`56ca087`](https://github.com/es-shims/iterator-helpers/commit/56ca087f924dbefee47f0a1cb3b8468de76cd234)
|
||||
|
||||
## [v1.0.14](https://github.com/es-shims/iterator-helpers/compare/v1.0.13...v1.0.14) - 2023-08-26
|
||||
|
||||
### Commits
|
||||
|
||||
- [Deps] update `es-abstract` [`477b123`](https://github.com/es-shims/iterator-helpers/commit/477b1233acd36fdbbccd79fbb69cde325bc3e6a9)
|
||||
- [Dev Deps] update `aud`, `eslint-plugin-import`, `tape` [`e4ea414`](https://github.com/es-shims/iterator-helpers/commit/e4ea4146feffb72fd828e5d883e960e0ad589a35)
|
||||
|
||||
## [v1.0.13](https://github.com/es-shims/iterator-helpers/compare/v1.0.12...v1.0.13) - 2023-08-16
|
||||
|
||||
### Fixed
|
||||
|
||||
- [Deps] add missing deps; add eslint-plugin-import [`#3`](https://github.com/es-shims/iterator-helpers/issues/3)
|
||||
|
||||
## [v1.0.12](https://github.com/es-shims/iterator-helpers/compare/v1.0.11...v1.0.12) - 2023-07-14
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] avoid creating string wrapper objects with sloppy mode flatMap mappers [`db16b34`](https://github.com/es-shims/iterator-helpers/commit/db16b34aec554934ec2bfd62629fb66cebc311f8)
|
||||
- [Deps] update `es-abstract` [`f002147`](https://github.com/es-shims/iterator-helpers/commit/f002147f0afbb2cd7c2d2e1207685f52e33abf0f)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `aud [`42064e8`](https://github.com/es-shims/iterator-helpers/commit/42064e80e0cc37f5e4676c2133dacae7456e313f)
|
||||
- [meta] fix tidelift funding identifier [`896fd4f`](https://github.com/es-shims/iterator-helpers/commit/896fd4f2e4b419945bfbd85024a2c96248323151)
|
||||
|
||||
## [v1.0.11](https://github.com/es-shims/iterator-helpers/compare/v1.0.10...v1.0.11) - 2023-05-22
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] iterator helpers are not a constructor [`8a7f999`](https://github.com/es-shims/iterator-helpers/commit/8a7f9996ba3600ef30f3a9c75f9f994e88d075c6)
|
||||
|
||||
## [v1.0.10](https://github.com/es-shims/iterator-helpers/compare/v1.0.9...v1.0.10) - 2023-05-18
|
||||
|
||||
### Commits
|
||||
|
||||
- [patch] remove IsCallable check on NextMethod, deferring errors to callsite [`bbb7efa`](https://github.com/es-shims/iterator-helpers/commit/bbb7efac8349273fe17c86194ef13af45bcb8e24)
|
||||
- [patch] change Symbol.iterator fallback from callable check to nullish check [`ec3e255`](https://github.com/es-shims/iterator-helpers/commit/ec3e255dfe30ea6650d8a697e6c4f16fa393e923)
|
||||
- [Tests] add test cases [`5117c47`](https://github.com/es-shims/iterator-helpers/commit/5117c477348407ebdfc9410dd437a68634c39a8e)
|
||||
- [Dev Deps] update `@es-shims/api` [`9fa13a0`](https://github.com/es-shims/iterator-helpers/commit/9fa13a0739f353536de58b2b648aa9eacfa49479)
|
||||
- [Dev Deps] update `@es-shims/api` [`b74b0ac`](https://github.com/es-shims/iterator-helpers/commit/b74b0ac2bd7e920f760bae7ba7c6c5310f5123d8)
|
||||
|
||||
## [v1.0.9](https://github.com/es-shims/iterator-helpers/compare/v1.0.8...v1.0.9) - 2023-05-02
|
||||
|
||||
### Commits
|
||||
|
||||
- [Refactor] use 2022 AO instead of 2015 AO [`75ee5c4`](https://github.com/es-shims/iterator-helpers/commit/75ee5c4dea0037f02a61c240114bb6bd8c8b48f1)
|
||||
|
||||
## [v1.0.8](https://github.com/es-shims/iterator-helpers/compare/v1.0.7...v1.0.8) - 2023-05-02
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] `flatMap`: close the inner iterator when applicable [`4dc94e0`](https://github.com/es-shims/iterator-helpers/commit/4dc94e0117e34b4c99f9ed96c4fe306896c47da1)
|
||||
|
||||
## [v1.0.7](https://github.com/es-shims/iterator-helpers/compare/v1.0.6...v1.0.7) - 2023-05-01
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] `flatMap`: properly handle yielded iterables [`3a78767`](https://github.com/es-shims/iterator-helpers/commit/3a78767e86394d45b212a225e4253745f8b1dc8d)
|
||||
- [Fix] `flatMap`: only increment the count when iterating the outer iterator [`955d0b0`](https://github.com/es-shims/iterator-helpers/commit/955d0b00f5660db0d9febef2a16426dfc32e8be4)
|
||||
|
||||
## [v1.0.6](https://github.com/es-shims/iterator-helpers/compare/v1.0.5...v1.0.6) - 2023-04-20
|
||||
|
||||
### Commits
|
||||
|
||||
- [Refactor] `GetIteratorFlattenable`: remove hint [`781fc7c`](https://github.com/es-shims/iterator-helpers/commit/781fc7c28615aaaef139cbcd9e6ade513419bea1)
|
||||
- [Refactor] `GetIteratorFlattenable`: use `GetIteratorDirect` [`026118b`](https://github.com/es-shims/iterator-helpers/commit/026118b8c884adaee5ab0eb12de838ef9abdbb6f)
|
||||
- [Refactor] use `safe-array-concat` [`1d985a4`](https://github.com/es-shims/iterator-helpers/commit/1d985a449be212523f05ba4a359a162931ddf3d3)
|
||||
|
||||
## [v1.0.5](https://github.com/es-shims/iterator-helpers/compare/v1.0.4...v1.0.5) - 2023-03-22
|
||||
|
||||
### Commits
|
||||
|
||||
- [Tests] add passing tests for 4240029 [`c2082fe`](https://github.com/es-shims/iterator-helpers/commit/c2082fee3e73dc1998a67fbe0014e3ebdceb8ec0)
|
||||
- [Fix] properly allow subclasses of Iterator to be constructed [`5cebe2a`](https://github.com/es-shims/iterator-helpers/commit/5cebe2a5767393696d0ce4e9325edf78c300f938)
|
||||
|
||||
## [v1.0.4](https://github.com/es-shims/iterator-helpers/compare/v1.0.3...v1.0.4) - 2023-03-21
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] validate arguments first [`4240029`](https://github.com/es-shims/iterator-helpers/commit/42400297454909ddccc899a012dc55bbd403eb8b)
|
||||
- [Fix] close underlying iterator when helper is closed [`f5372c7`](https://github.com/es-shims/iterator-helpers/commit/f5372c78cafff64bfda5849386538f806916049a)
|
||||
- [Tests] `Iterator`: remove an unnecessary call-bind [`7d0ba59`](https://github.com/es-shims/iterator-helpers/commit/7d0ba59f672e690b189f91e0348f6b5e00f934e1)
|
||||
|
||||
## [v1.0.3](https://github.com/es-shims/iterator-helpers/compare/v1.0.2...v1.0.3) - 2023-03-17
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] `drop`/`filter`/`flatMap`/`map`/`take`: properly IfAbruptCloseIterator [`ff643a0`](https://github.com/es-shims/iterator-helpers/commit/ff643a0b7c4e5c2b00e794ba9b988b47e783f235)
|
||||
- [Refactor] use `NormalCompletion`/`ThrowCompletion` instead of thunks [`68fd937`](https://github.com/es-shims/iterator-helpers/commit/68fd937b53c107481a9f868bda5b2bd5cbc00142)
|
||||
- [Fix] `filter`: IteratorClose needs to rethrow the error [`200474f`](https://github.com/es-shims/iterator-helpers/commit/200474ff289dea77c696c0c025f4602405cf3fff)
|
||||
- [Fix] `filter`: properly increment the counter [`14aa2d8`](https://github.com/es-shims/iterator-helpers/commit/14aa2d8b75fd16378c2be183fd5b008712547ed4)
|
||||
- [Fix] `Iterator` can not be `new`ed or invoked directly [`6fbd68e`](https://github.com/es-shims/iterator-helpers/commit/6fbd68e778dd455c4aa63f4e1f39e0b583610509)
|
||||
- [Fix] `Iterator.prototype` should be non-writable [`1080288`](https://github.com/es-shims/iterator-helpers/commit/108028858067e40ea56dca9a68dd6cea4966e904)
|
||||
- [Deps] update `es-abstract` [`b7913da`](https://github.com/es-shims/iterator-helpers/commit/b7913da9cddef1ec40b4827821c6069019b79093)
|
||||
- [Dev Deps] update `@es-shims/api` [`0071bed`](https://github.com/es-shims/iterator-helpers/commit/0071bed9e13231317d2cdb9ae0ecb6603784ad1f)
|
||||
|
||||
## [v1.0.2](https://github.com/es-shims/iterator-helpers/compare/v1.0.1...v1.0.2) - 2023-02-09
|
||||
|
||||
### Commits
|
||||
|
||||
- [Refactor] inline 2023 impls of Iterator AOs until es-abstract is published with them [`b9c80c5`](https://github.com/es-shims/iterator-helpers/commit/b9c80c5aba0deaaabef7e650fe7ec231fdc695e3)
|
||||
- [Fix] ensure calling `.return` does not invoke the next iteration [`9e28ed5`](https://github.com/es-shims/iterator-helpers/commit/9e28ed5af44a660a0d2e80684cb9a4bf3d86e09a)
|
||||
- [Fix] `map`: pass the proper index argument to the mapper [`125e3ca`](https://github.com/es-shims/iterator-helpers/commit/125e3cac192ef650a88f774a5a2dd9afe395a5b8)
|
||||
- [Deps] update `internal-slot` [`43351b6`](https://github.com/es-shims/iterator-helpers/commit/43351b63545e3698f54daf5dc0652a7b2fb7cb28)
|
||||
|
||||
## [v1.0.1](https://github.com/es-shims/iterator-helpers/compare/v1.0.0...v1.0.1) - 2023-02-07
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] `Iterator`: throw when Iterator() is called without new [`a6fc7e7`](https://github.com/es-shims/iterator-helpers/commit/a6fc7e768cbf4d43117365ec2f1bd300247d8dfd)
|
||||
|
||||
## v1.0.0 - 2023-02-05
|
||||
|
||||
### Commits
|
||||
|
||||
- Initial implementation, tests, readme [`650713e`](https://github.com/es-shims/iterator-helpers/commit/650713eecc9d4dab28d5ba3dc5afcbdb8ff99b5a)
|
||||
- Initial commit [`2379dfd`](https://github.com/es-shims/iterator-helpers/commit/2379dfdad70f64efb31e342a4a7779b1140b2481)
|
||||
- npm init [`f77411a`](https://github.com/es-shims/iterator-helpers/commit/f77411a443f1a103dbb92a69210228d4fc1e6d04)
|
||||
- Only apps should have lockfiles [`313dcf5`](https://github.com/es-shims/iterator-helpers/commit/313dcf5211e99569ad275885728b5ac7af30f4ec)
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var AdvanceStringIndex = require('es-abstract/2024/AdvanceStringIndex');
|
||||
var Call = require('es-abstract/2024/Call');
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
|
||||
var GetIteratorDirect = require('../aos/GetIteratorDirect');
|
||||
var GetMethod = require('es-abstract/2024/GetMethod');
|
||||
var IsArray = require('es-abstract/2024/IsArray');
|
||||
var IteratorCloseAll = require('../aos/IteratorCloseAll');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var forEach = require('es-abstract/helpers/forEach');
|
||||
var getIteratorMethod = require('es-abstract/helpers/getIteratorMethod');
|
||||
|
||||
var callBound = require('call-bind/callBound');
|
||||
var $indexOf = callBound('Array.prototype.indexOf');
|
||||
var $splice = callBound('Array.prototype.splice');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function concat() {
|
||||
if (this instanceof concat) {
|
||||
throw new $TypeError('`Iterator.concat` is not a constructor');
|
||||
}
|
||||
|
||||
var iterables = []; // step 1
|
||||
|
||||
forEach(arguments, function (item) { // step 2
|
||||
if (Type(item) !== 'Object') {
|
||||
throw new $TypeError('`Iterator.concat` requires all arguments to be objects'); // step 2.1
|
||||
}
|
||||
// var method = GetMethod(item, Symbol.iterator); // step 2.2
|
||||
var method = getIteratorMethod(
|
||||
{
|
||||
AdvanceStringIndex: AdvanceStringIndex,
|
||||
GetMethod: GetMethod,
|
||||
IsArray: IsArray
|
||||
},
|
||||
item
|
||||
);
|
||||
if (typeof method === 'undefined') {
|
||||
throw new $TypeError('`Iterator.concat` requires all arguments to be iterable'); // step 2.3
|
||||
}
|
||||
iterables[iterables.length] = { '[[OpenMethod]]': method, '[[Iterable]]': item }; // step 2.4
|
||||
});
|
||||
|
||||
var openIters = []; // step 3
|
||||
var sentinel = {};
|
||||
var closeIfAbrupt = function (abruptCompletion) {
|
||||
if (!(abruptCompletion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('`abruptCompletion` must be a Completion Record');
|
||||
}
|
||||
if (openIters.length > 0) {
|
||||
IteratorCloseAll(
|
||||
openIters,
|
||||
abruptCompletion
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var index = 0;
|
||||
var closure = function () { // step 4
|
||||
if (index < iterables.length) {
|
||||
// forEach(iterables, function (iterable) { // step 4.a
|
||||
var iteratorRecord;
|
||||
if (openIters.length === 0) {
|
||||
var iterable = iterables[index];
|
||||
var iter = Call(iterable['[[OpenMethod]]'], iterable['[[Iterable]]']); // step 4.a.i
|
||||
if (Type(iter) !== 'Object') {
|
||||
closeIfAbrupt(ThrowCompletion(new $TypeError('???'))); // step 4.a.ii
|
||||
}
|
||||
iteratorRecord = GetIteratorDirect(iter); // step 4.a.iii
|
||||
iteratorRecord.obj = iterable['[[Iterable]]'];
|
||||
openIters[openIters.length] = iteratorRecord; // step 4.a.iv
|
||||
} else {
|
||||
iteratorRecord = openIters[0];
|
||||
}
|
||||
|
||||
// var innerAlive = true; // step 4.a.v
|
||||
// while (innerAlive) { // step 4.a.vi
|
||||
{ // eslint-disable-line no-lone-blocks
|
||||
// step 4.a.vi.3.a
|
||||
var innerValue;
|
||||
try {
|
||||
innerValue = IteratorStepValue(iteratorRecord); // step 5.b.ix.4.a
|
||||
} catch (e) {
|
||||
// innerAlive = false;
|
||||
$splice(openIters, $indexOf(openIters, iteratorRecord), 1); // step 4.a.vi.2.a
|
||||
index += 1;
|
||||
closeIfAbrupt(ThrowCompletion(e)); // step 4.a.vi.3.b
|
||||
}
|
||||
if (iteratorRecord['[[Done]]']) {
|
||||
// innerAlive = false;
|
||||
$splice(openIters, $indexOf(openIters, iteratorRecord), 1);
|
||||
index += 1;
|
||||
return closure();
|
||||
}
|
||||
return innerValue; // // step 4.a.vi.3.a
|
||||
}
|
||||
// });
|
||||
}
|
||||
|
||||
// return ReturnCompletion(undefined); // step 4.b
|
||||
return sentinel;
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
|
||||
|
||||
var gen = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 5
|
||||
SLOT.set(gen, '[[UnderlyingIterators]]', []); // step 6
|
||||
return gen; // step 7
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var GetIteratorFlattenable = require('../aos/GetIteratorFlattenable');
|
||||
var OrdinaryHasInstance = require('es-abstract/2024/OrdinaryHasInstance');
|
||||
var OrdinaryObjectCreate = require('es-abstract/2024/OrdinaryObjectCreate');
|
||||
|
||||
var $Iterator = require('../Iterator/polyfill')();
|
||||
var $WrapForValidIteratorPrototype = require('../WrapForValidIteratorPrototype');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function from(O) {
|
||||
if (this instanceof from) {
|
||||
throw new $TypeError('`Iterator.from` is not a constructor');
|
||||
}
|
||||
|
||||
var iteratorRecord = GetIteratorFlattenable(O, 'ITERATE-STRINGS'); // step 1
|
||||
|
||||
var hasInstance = OrdinaryHasInstance($Iterator, iteratorRecord['[[Iterator]]']); // step 2
|
||||
|
||||
if (hasInstance) { // step 3
|
||||
return iteratorRecord['[[Iterator]]']; // step 3.a
|
||||
}
|
||||
|
||||
var wrapper = OrdinaryObjectCreate($WrapForValidIteratorPrototype); // , ['[[Iterated]]']); // step 4
|
||||
|
||||
SLOT.set(wrapper, '[[Iterated]]', iteratorRecord); // step 5
|
||||
|
||||
return wrapper; // step 6
|
||||
};
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
|
||||
var GetIteratorDirect = require('../aos/GetIteratorDirect');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var IteratorStep = require('es-abstract/2024/IteratorStep');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity');
|
||||
var ToNumber = require('es-abstract/2024/ToNumber');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var isNaN = require('es-abstract/helpers/isNaN');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function drop(limit) {
|
||||
if (this instanceof drop) {
|
||||
throw new $TypeError('`drop` is not a constructor');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('`this` value must be an Object'); // step 2
|
||||
}
|
||||
|
||||
var numLimit = ToNumber(limit); // step 2
|
||||
if (isNaN(numLimit)) {
|
||||
throw new $RangeError('`limit` must be a non-NaN number'); // step 3
|
||||
}
|
||||
|
||||
var iterated = GetIteratorDirect(O); // step 4
|
||||
|
||||
var integerLimit = ToIntegerOrInfinity(numLimit); // step 4
|
||||
if (integerLimit < 0) {
|
||||
throw new $RangeError('`limit` must be a >= 0'); // step 5
|
||||
}
|
||||
|
||||
var closeIfAbrupt = function (abruptCompletion) {
|
||||
if (!(abruptCompletion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('`abruptCompletion` must be a Completion Record');
|
||||
}
|
||||
IteratorClose(
|
||||
iterated,
|
||||
abruptCompletion
|
||||
);
|
||||
};
|
||||
|
||||
var sentinel = {};
|
||||
var remaining = integerLimit; // step 6.a
|
||||
var closure = function () { // step 6
|
||||
var next;
|
||||
while (remaining > 0) { // step 6.b
|
||||
if (remaining !== Infinity) { // step 6.b.i
|
||||
remaining -= 1; // step 6.b.i.1
|
||||
}
|
||||
|
||||
next = IteratorStep(iterated); // step 6.b.ii
|
||||
if (!next) {
|
||||
// return void undefined; // step 6.b.iii
|
||||
return sentinel;
|
||||
}
|
||||
}
|
||||
// while (true) { // step 6.c
|
||||
try {
|
||||
var value = IteratorStepValue(iterated); // step 6.b.i
|
||||
if (iterated['[[Done]]']) {
|
||||
return sentinel; // step 6.b.ii
|
||||
}
|
||||
return value;
|
||||
} catch (e) {
|
||||
// close iterator // step 6.c.icv
|
||||
closeIfAbrupt(ThrowCompletion(e));
|
||||
throw e;
|
||||
}
|
||||
// }
|
||||
// return void undefined;
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
|
||||
|
||||
var result = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 4
|
||||
|
||||
SLOT.set(result, '[[UnderlyingIterators]]', [iterated]); // step 5
|
||||
|
||||
return result; // step 6
|
||||
};
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Call = require('es-abstract/2024/Call');
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
|
||||
var GetIteratorDirect = require('../aos/GetIteratorDirect');
|
||||
var IsCallable = require('es-abstract/2024/IsCallable');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var ToBoolean = require('es-abstract/2024/ToBoolean');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function filter(predicate) {
|
||||
if (this instanceof filter) {
|
||||
throw new $TypeError('`filter` is not a constructor');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('`this` value must be an Object'); // step 2
|
||||
}
|
||||
|
||||
if (!IsCallable(predicate)) {
|
||||
throw new $TypeError('`predicate` must be a function'); // step 3
|
||||
}
|
||||
|
||||
var iterated = GetIteratorDirect(O); // step 4
|
||||
|
||||
var closeIfAbrupt = function (abruptCompletion) {
|
||||
if (!(abruptCompletion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('`abruptCompletion` must be a Completion Record');
|
||||
}
|
||||
IteratorClose(
|
||||
iterated,
|
||||
abruptCompletion
|
||||
);
|
||||
};
|
||||
|
||||
var sentinel = {};
|
||||
var counter = 0; // step 6.a
|
||||
var closure = function () {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) { // step 6.b
|
||||
var value = IteratorStepValue(iterated); // step 6.b.i
|
||||
if (iterated['[[Done]]']) {
|
||||
return sentinel; // step 6.b.ii
|
||||
}
|
||||
|
||||
var selected;
|
||||
try {
|
||||
selected = Call(predicate, void undefined, [value, counter]); // step 6.b.iv
|
||||
// yield mapped // step 6.b.vi
|
||||
if (ToBoolean(selected)) {
|
||||
return value;
|
||||
}
|
||||
} catch (e) {
|
||||
// close iterator // step 6.b.v, 6.b.vii
|
||||
closeIfAbrupt(ThrowCompletion(e));
|
||||
throw e;
|
||||
} finally {
|
||||
counter += 1; // step 6.b.viii
|
||||
}
|
||||
}
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
|
||||
|
||||
var result = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 7
|
||||
|
||||
SLOT.set(result, '[[UnderlyingIterators]]', [iterated]); // step 8
|
||||
|
||||
return result; // step 9
|
||||
};
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Call = require('es-abstract/2024/Call');
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
|
||||
var GetIteratorDirect = require('../aos/GetIteratorDirect');
|
||||
var GetIteratorFlattenable = require('../aos/GetIteratorFlattenable');
|
||||
var IsCallable = require('es-abstract/2024/IsCallable');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function flatMap(mapper) {
|
||||
if (this instanceof flatMap) {
|
||||
throw new $TypeError('`flatMap` is not a constructor');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('`this` value must be an Object'); // step 2
|
||||
}
|
||||
|
||||
if (!IsCallable(mapper)) {
|
||||
throw new $TypeError('`mapper` must be a function'); // step 3
|
||||
}
|
||||
|
||||
var iterated = GetIteratorDirect(O); // step 4
|
||||
|
||||
var sentinel = { sentinel: true };
|
||||
var innerIterator = sentinel;
|
||||
|
||||
var closeIfAbrupt = function (abruptCompletion) {
|
||||
if (!(abruptCompletion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('`abruptCompletion` must be a Completion Record');
|
||||
}
|
||||
try {
|
||||
if (innerIterator !== sentinel) {
|
||||
IteratorClose(
|
||||
innerIterator,
|
||||
abruptCompletion
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
innerIterator = sentinel;
|
||||
|
||||
IteratorClose(
|
||||
iterated,
|
||||
abruptCompletion
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var counter = 0; // step 5.a
|
||||
var innerAlive = false;
|
||||
var closure = function () {
|
||||
// while (true) { // step 5.b
|
||||
if (innerIterator === sentinel) {
|
||||
var value = IteratorStepValue(iterated); // step 5.b.i
|
||||
if (iterated['[[Done]]']) {
|
||||
innerAlive = false;
|
||||
innerIterator = sentinel;
|
||||
// return void undefined; // step 5.b.ii
|
||||
return sentinel;
|
||||
}
|
||||
}
|
||||
|
||||
if (innerIterator === sentinel) {
|
||||
innerAlive = true; // step 5.b.viii
|
||||
try {
|
||||
var mapped = Call(mapper, void undefined, [value, counter]); // step 5.b.iv
|
||||
// yield mapped // step 5.b.vi
|
||||
innerIterator = GetIteratorFlattenable(mapped, 'REJECT-STRINGS'); // step 5.b.vi
|
||||
} catch (e) {
|
||||
innerAlive = false;
|
||||
innerIterator = sentinel;
|
||||
closeIfAbrupt(ThrowCompletion(e)); // steps 5.b.v, 5.b.vii
|
||||
} finally {
|
||||
counter += 1; // step 5.b.x
|
||||
}
|
||||
}
|
||||
// while (innerAlive) { // step 5.b.ix
|
||||
if (innerAlive) {
|
||||
// step 5.b.ix.4
|
||||
var innerValue;
|
||||
try {
|
||||
innerValue = IteratorStepValue(innerIterator); // step 5.b.ix.4.a
|
||||
} catch (e) {
|
||||
innerAlive = false;
|
||||
innerIterator = sentinel;
|
||||
closeIfAbrupt(ThrowCompletion(e)); // step 5.b.ix.4.b
|
||||
}
|
||||
if (innerIterator['[[Done]]']) {
|
||||
innerAlive = false;
|
||||
innerIterator = sentinel;
|
||||
return closure();
|
||||
}
|
||||
return innerValue; // step 5.b.ix.4.c
|
||||
}
|
||||
// }
|
||||
// return void undefined;
|
||||
return sentinel;
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
|
||||
|
||||
var result = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 7
|
||||
|
||||
SLOT.set(result, '[[UnderlyingIterators]]', [iterated]); // step 8
|
||||
|
||||
return result; // step 9
|
||||
};
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Call = require('es-abstract/2024/Call');
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
|
||||
var GetIteratorDirect = require('../aos/GetIteratorDirect');
|
||||
var IsCallable = require('es-abstract/2024/IsCallable');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function map(mapper) {
|
||||
if (this instanceof map) {
|
||||
throw new $TypeError('`map` is not a constructor');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('`this` value must be an Object'); // step 2
|
||||
}
|
||||
|
||||
if (!IsCallable(mapper)) {
|
||||
throw new $TypeError('`mapper` must be a function'); // step 3
|
||||
}
|
||||
|
||||
var iterated = GetIteratorDirect(O); // step 4
|
||||
|
||||
var closeIfAbrupt = function (abruptCompletion) {
|
||||
if (!(abruptCompletion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('`abruptCompletion` must be a Completion Record');
|
||||
}
|
||||
IteratorClose(
|
||||
iterated,
|
||||
abruptCompletion
|
||||
);
|
||||
};
|
||||
|
||||
var sentinel = {};
|
||||
var counter = 0; // step 6.a
|
||||
var closure = function () {
|
||||
// while (true) { // step 6.b
|
||||
var value = IteratorStepValue(iterated); // step 6.b.i
|
||||
if (iterated['[[Done]]']) {
|
||||
return sentinel; // step 6.b.ii
|
||||
}
|
||||
|
||||
var mapped;
|
||||
try {
|
||||
mapped = Call(mapper, void undefined, [value, counter]); // step 6.b.iii
|
||||
// yield mapped // step 6.b.vi
|
||||
return mapped;
|
||||
} catch (e) {
|
||||
// close iterator // step 6.b.v, 6.b.vii
|
||||
closeIfAbrupt(ThrowCompletion(e));
|
||||
throw e;
|
||||
} finally {
|
||||
counter += 1; // step 6.b.viii
|
||||
}
|
||||
// }
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
|
||||
|
||||
var result = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 7
|
||||
|
||||
SLOT.set(result, '[[UnderlyingIterators]]', [iterated]); // step 8
|
||||
|
||||
return result; // step 9
|
||||
};
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure');
|
||||
var GetIteratorDirect = require('../aos/GetIteratorDirect');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var NormalCompletion = require('es-abstract/2024/NormalCompletion');
|
||||
var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity');
|
||||
var ToNumber = require('es-abstract/2024/ToNumber');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var isNaN = require('es-abstract/helpers/isNaN');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
module.exports = function take(limit) {
|
||||
if (this instanceof take) {
|
||||
throw new $TypeError('`take` is not a constructor');
|
||||
}
|
||||
|
||||
var O = this; // step 1
|
||||
if (Type(O) !== 'Object') {
|
||||
throw new $TypeError('`this` value must be an Object'); // step 2
|
||||
}
|
||||
|
||||
var numLimit = ToNumber(limit); // step 2
|
||||
if (isNaN(numLimit)) {
|
||||
throw new $RangeError('`limit` must be a non-NaN number'); // step 3
|
||||
}
|
||||
|
||||
var iterated = GetIteratorDirect(O); // step 4
|
||||
|
||||
var integerLimit = ToIntegerOrInfinity(numLimit); // step 7
|
||||
if (integerLimit < 0) {
|
||||
throw new $RangeError('`limit` must be a >= 0'); // step 8
|
||||
}
|
||||
|
||||
var closeIfAbrupt = function (abruptCompletion) {
|
||||
if (!(abruptCompletion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('`abruptCompletion` must be a Completion Record');
|
||||
}
|
||||
IteratorClose(
|
||||
iterated,
|
||||
abruptCompletion
|
||||
);
|
||||
};
|
||||
|
||||
var sentinel = {};
|
||||
var remaining = integerLimit; // step 9.a
|
||||
var closure = function () { // step 9
|
||||
// while (true) { // step 9.b
|
||||
if (remaining === 0) { // step 9.b.i
|
||||
return IteratorClose( // step 9.b.i.1
|
||||
iterated,
|
||||
NormalCompletion(sentinel)
|
||||
);
|
||||
}
|
||||
if (remaining !== Infinity) { // step 9.b.ii
|
||||
remaining -= 1; // step 9.b.ii.1
|
||||
}
|
||||
|
||||
var value = IteratorStepValue(iterated); // step 6.b.i
|
||||
if (iterated['[[Done]]']) {
|
||||
return sentinel; // step 6.b.ii
|
||||
}
|
||||
|
||||
return value; // step 9.b.iv
|
||||
// }
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', closeIfAbrupt); // for the userland implementation
|
||||
|
||||
var result = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 7
|
||||
|
||||
SLOT.set(result, '[[UnderlyingIterators]]', [iterated]); // step 8
|
||||
|
||||
return result; // step 9
|
||||
};
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Get = require('es-abstract/2024/Get');
|
||||
var GetIterator = require('es-abstract/2024/GetIterator');
|
||||
var GetIteratorFlattenable = require('../aos/GetIteratorFlattenable');
|
||||
var GetOptionsObject = require('../aos/GetOptionsObject');
|
||||
var IfAbruptCloseIterators = require('../aos/IfAbruptCloseIterators');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var IteratorZip = require('../aos/IteratorZip');
|
||||
var NormalCompletion = require('es-abstract/2024/NormalCompletion');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
module.exports = function zip(iterables) {
|
||||
if (this instanceof zip) {
|
||||
throw new $TypeError('`Iterator.zip` is not a constructor');
|
||||
}
|
||||
|
||||
if (Type(iterables) !== 'Object') {
|
||||
throw new $TypeError('`iterables` must be an Object'); // step 1
|
||||
}
|
||||
|
||||
var options = GetOptionsObject(arguments.length > 1 ? arguments[1] : undefined); // step 2
|
||||
|
||||
var mode = Get(options, 'mode'); // step 3
|
||||
|
||||
if (typeof mode === 'undefined') {
|
||||
mode = 'shortest'; // step 4
|
||||
}
|
||||
|
||||
if (mode !== 'shortest' && mode !== 'longest' && mode !== 'strict') {
|
||||
throw new $TypeError('`mode` must be one of "shortest", "longest", or "strict"'); // step 5
|
||||
}
|
||||
|
||||
var paddingOption; // step 6
|
||||
|
||||
if (mode === 'longest') {
|
||||
paddingOption = Get(options, 'padding'); // step 7
|
||||
if (typeof paddingOption !== 'undefined' && Type(paddingOption) !== 'Object') {
|
||||
throw new $TypeError('`padding` option must be an Object'); // step 7.1
|
||||
}
|
||||
}
|
||||
|
||||
var iters = []; // step 8
|
||||
|
||||
var padding = []; // step 9
|
||||
|
||||
var inputIter = GetIterator(iterables, 'SYNC'); // step 10
|
||||
|
||||
var next; // = 'NOT-STARTED'; // step 11
|
||||
|
||||
while (!inputIter['[[Done]]']) { // step 12
|
||||
try {
|
||||
next = IteratorStepValue(inputIter); // step 12.a
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 12.b
|
||||
}
|
||||
|
||||
if (!inputIter['[[Done]]']) { // step 12.c
|
||||
var iter;
|
||||
try {
|
||||
iter = GetIteratorFlattenable(next, 'REJECT-STRINGS'); // step 12.c.i
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), [].concat(inputIter, iters)); // step 12.c.ii
|
||||
}
|
||||
iters[iters.length] = iter; // step 12.c.iii
|
||||
}
|
||||
}
|
||||
|
||||
var iterCount = iters.length; // step 13
|
||||
|
||||
if (mode === 'longest') { // step 14
|
||||
if (typeof paddingOption === 'undefined') { // step 14.a
|
||||
for (var i = 0; i < iterCount; i++) { // step 14.a.i
|
||||
padding[padding.length] = void undefined; // step 14.a.i.1
|
||||
}
|
||||
} else { // step 14.b
|
||||
var paddingIter;
|
||||
try {
|
||||
paddingIter = GetIterator(paddingOption, 'SYNC'); // step 14.b.i
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 14.b.ii
|
||||
}
|
||||
var usingIterator = true; // step 14.b.iii
|
||||
for (var j = 0; j < iterCount; j++) { // step 14.b.iv
|
||||
if (usingIterator) { // step 14.b.iv.1
|
||||
try {
|
||||
next = IteratorStepValue(paddingIter); // step 14.b.iv.1.a
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 14.b.iv.1.b
|
||||
}
|
||||
if (paddingIter['[[Done]]']) { // step 14.b.iv.1.c
|
||||
usingIterator = false; // step 14.b.iv.1.c.i
|
||||
} else { // step 14.b.iv.1.d
|
||||
padding[padding.length] = next; // step 14.b.iv.1.d.i
|
||||
}
|
||||
}
|
||||
if (!usingIterator) {
|
||||
padding[padding.length] = void undefined; // step 14.b.iv.2
|
||||
}
|
||||
}
|
||||
|
||||
if (usingIterator) { // step 14.b.v
|
||||
try {
|
||||
IteratorClose(paddingIter, NormalCompletion(undefined)); // step 14.b.v.1
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 14.b.v.2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-sequences
|
||||
var finishResults = (0, function (results) { // step 15
|
||||
return results; // step 15.1
|
||||
});
|
||||
|
||||
return IteratorZip(iters, mode, padding, finishResults); // step 16
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var implementation = require('./implementation');
|
||||
|
||||
var $Iterator = require('../Iterator');
|
||||
|
||||
module.exports = function getPolyfill() {
|
||||
return typeof $Iterator.zip === 'function' ? $Iterator.zip : implementation;
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var getPolyfill = require('./polyfill');
|
||||
var define = require('define-properties');
|
||||
|
||||
var getIteratorPolyfill = require('../Iterator/polyfill');
|
||||
|
||||
module.exports = function shimIteratorZip() {
|
||||
var $Iterator = getIteratorPolyfill();
|
||||
var polyfill = getPolyfill();
|
||||
define(
|
||||
$Iterator,
|
||||
{ zip: polyfill },
|
||||
{ zip: function () { return $Iterator.zip !== polyfill; } }
|
||||
);
|
||||
|
||||
return polyfill;
|
||||
};
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var Call = require('es-abstract/2024/Call');
|
||||
var CreateDataPropertyOrThrow = require('es-abstract/2024/CreateDataPropertyOrThrow');
|
||||
var Get = require('es-abstract/2024/Get');
|
||||
var GetIteratorFlattenable = require('../aos/GetIteratorFlattenable');
|
||||
var GetOptionsObject = require('../aos/GetOptionsObject');
|
||||
var IfAbruptCloseIterators = require('../aos/IfAbruptCloseIterators');
|
||||
var IsAccessorDescriptor = require('es-abstract/2024/IsAccessorDescriptor');
|
||||
var IsDataDescriptor = require('es-abstract/2024/IsDataDescriptor');
|
||||
var IteratorZip = require('../aos/IteratorZip');
|
||||
var OrdinaryObjectCreate = require('es-abstract/2024/OrdinaryObjectCreate');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var forEach = require('es-abstract/helpers/forEach');
|
||||
var ownKeys = require('es-abstract/helpers/OwnPropertyKeys');
|
||||
|
||||
var gOPD = require('gopd');
|
||||
|
||||
module.exports = function zipKeyed(iterables) {
|
||||
if (this instanceof zipKeyed) {
|
||||
throw new $TypeError('`Iterator.zip` is not a constructor');
|
||||
}
|
||||
|
||||
if (Type(iterables) !== 'Object') {
|
||||
throw new $TypeError('`iterables` must be an Object'); // step 1
|
||||
}
|
||||
|
||||
var options = GetOptionsObject(arguments.length > 1 ? arguments[1] : undefined); // step 2
|
||||
|
||||
var mode = Get(options, 'mode'); // step 3
|
||||
|
||||
if (typeof mode === 'undefined') {
|
||||
mode = 'shortest'; // step 4
|
||||
}
|
||||
|
||||
if (mode !== 'shortest' && mode !== 'longest' && mode !== 'strict') {
|
||||
throw new $TypeError('`mode` must be one of "shortest", "longest", or "strict"'); // step 5
|
||||
}
|
||||
|
||||
var paddingOption; // step 6
|
||||
|
||||
if (mode === 'longest') {
|
||||
paddingOption = Get(options, 'padding'); // step 7
|
||||
if (typeof paddingOption !== 'undefined' && Type(paddingOption) !== 'Object') {
|
||||
throw new $TypeError('`padding` option must be an Object'); // step 7.1
|
||||
}
|
||||
}
|
||||
|
||||
var iters = []; // step 8
|
||||
|
||||
var padding = []; // step 9
|
||||
|
||||
var allKeys = ownKeys(iterables); // step 10
|
||||
|
||||
var keys = []; // step 11
|
||||
|
||||
forEach(allKeys, function (key) { // step 12
|
||||
var desc;
|
||||
try {
|
||||
desc = gOPD(iterables, key); // step 12.a
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 12.b
|
||||
}
|
||||
|
||||
if (typeof desc !== 'undefined' && desc['[[Enumerable]]'] === true) { // step 12.c
|
||||
var value; // step 12.c.i
|
||||
if (IsDataDescriptor(desc)) { // step 12.c.ii
|
||||
value = desc['[[Value]]']; // step 12.c.ii.1
|
||||
} else {
|
||||
if (!IsAccessorDescriptor(desc)) {
|
||||
throw new $TypeError('Assertion failed: IsAccessorDescriptor(desc) is not true'); // step 12.c.ii.1
|
||||
}
|
||||
var getter = desc['[[Get]]']; // step 12.c.iii.2
|
||||
if (typeof getter !== 'undefined') { // step 12.c.iii.3
|
||||
var getterResult;
|
||||
try {
|
||||
getterResult = Call(getter, iterables); // step 12.c.iii.3.a
|
||||
} catch (e) {
|
||||
// step 12.c.iii.3.b
|
||||
// 2. IfAbruptCloseIterators(e, iters).
|
||||
}
|
||||
value = getterResult; // step 12.c.iii.3.c
|
||||
}
|
||||
}
|
||||
if (typeof value !== 'undefined') { // step 12.c.iv
|
||||
keys[keys.length] = key; // step 12.c.iv.1
|
||||
var iter;
|
||||
try {
|
||||
iter = GetIteratorFlattenable(value, 'REJECT-STRINGS'); // step 12.c.iv.2
|
||||
} catch (e) {
|
||||
// step 12.c.iv.3
|
||||
// 3. IfAbruptCloseIterators(e, iters).
|
||||
}
|
||||
iters[iters.length] = iter; // step 12.c.iv.4
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var iterCount = iters.length; // step 13
|
||||
|
||||
if (mode === 'longest') { // step 14
|
||||
if (typeof paddingOption === 'undefined') { // step 14.a
|
||||
for (var j = 0; j < iterCount; j += 1) { // step 14.a.i
|
||||
padding[padding.length] = void undefined; // step 14.a.i.1
|
||||
}
|
||||
} else { // step 14.b
|
||||
forEach(keys, function (key) { // step 14.b.i
|
||||
var value;
|
||||
try {
|
||||
value = Get(paddingOption, key); // step 14.b.i.1
|
||||
} catch (e) {
|
||||
IfAbruptCloseIterators(ThrowCompletion(e), iters); // step 14.b.i.2
|
||||
}
|
||||
padding[padding.length] = value; // step 14.b.i.3
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-sequences
|
||||
var finishResults = (0, function (results) { // step 15
|
||||
var obj = OrdinaryObjectCreate(null); // step 15.a
|
||||
for (var i = 0; i < iterCount; i += 1) { // step 15.b
|
||||
CreateDataPropertyOrThrow(obj, keys[i], results[i]); // step 15.b.i
|
||||
}
|
||||
return obj; // step 15.c
|
||||
});
|
||||
|
||||
return IteratorZip(iters, mode, padding, finishResults); // step 16
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var getPolyfill = require('./polyfill');
|
||||
|
||||
module.exports = getPolyfill();
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var implementation = require('./implementation');
|
||||
|
||||
var $Iterator = require('../Iterator');
|
||||
|
||||
module.exports = function getPolyfill() {
|
||||
return typeof $Iterator.zipKeyed === 'function' ? $Iterator.zipKeyed : implementation;
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var getPolyfill = require('./polyfill');
|
||||
var define = require('define-properties');
|
||||
|
||||
var getIteratorPolyfill = require('../Iterator/polyfill');
|
||||
|
||||
module.exports = function shimIteratorZipKeyed() {
|
||||
var $Iterator = getIteratorPolyfill();
|
||||
var polyfill = getPolyfill();
|
||||
define(
|
||||
$Iterator,
|
||||
{ zipKeyed: polyfill },
|
||||
{ zipKeyed: function () { return $Iterator.zipKeyed !== polyfill; } }
|
||||
);
|
||||
|
||||
return polyfill;
|
||||
};
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
var setToStringTag = require('es-set-tostringtag');
|
||||
var hasProto = require('has-proto')();
|
||||
var iterProto = require('../Iterator.prototype/implementation');
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
var CreateIterResultObject = require('es-abstract/2024/CreateIterResultObject');
|
||||
var GeneratorResume = require('../aos/GeneratorResume');
|
||||
var GeneratorResumeAbrupt = require('../aos/GeneratorResumeAbrupt');
|
||||
var IteratorCloseAll = require('../aos/IteratorCloseAll');
|
||||
var NormalCompletion = require('es-abstract/2024/NormalCompletion');
|
||||
var ReturnCompletion = require('../aos/ReturnCompletion');
|
||||
|
||||
var implementation;
|
||||
if (hasProto) {
|
||||
implementation = {
|
||||
__proto__: iterProto,
|
||||
next: function next() {
|
||||
return GeneratorResume(this, void undefined, 'Iterator Helper');
|
||||
},
|
||||
'return': function () {
|
||||
var O = this; // step 1
|
||||
|
||||
SLOT.assert(O, '[[UnderlyingIterators]]'); // step 2
|
||||
|
||||
SLOT.assert(O, '[[GeneratorState]]'); // step 3
|
||||
|
||||
if (SLOT.get(O, '[[GeneratorState]]') === 'suspendedStart') { // step 4
|
||||
SLOT.set(O, '[[GeneratorState]]', 'completed'); // step 4.a
|
||||
IteratorCloseAll(SLOT.get(O, '[[UnderlyingIterators]]'), NormalCompletion('unused')); // step 4.c
|
||||
return CreateIterResultObject(void undefined, true); // step 4.d
|
||||
}
|
||||
|
||||
var C = ReturnCompletion(void undefined); // step 5
|
||||
|
||||
return GeneratorResumeAbrupt(O, C, 'Iterator Helper'); // step 6
|
||||
}
|
||||
};
|
||||
setToStringTag(implementation, 'Iterator Helper');
|
||||
} else {
|
||||
var IteratorHelper = function IteratorHelper() {};
|
||||
IteratorHelper.prototype = iterProto;
|
||||
implementation = new IteratorHelper();
|
||||
delete implementation.constructor;
|
||||
implementation.next = function next() {
|
||||
return GeneratorResume(this, void undefined, 'Iterator Helper');
|
||||
};
|
||||
implementation['return'] = function () {
|
||||
var C = ReturnCompletion(void undefined); // step 1
|
||||
return GeneratorResumeAbrupt(this, C, 'Iterator Helper');
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = implementation;
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var AdvanceStringIndex = require('es-abstract/2024/AdvanceStringIndex');
|
||||
var Call = require('es-abstract/2024/Call');
|
||||
var GetIteratorDirect = require('./GetIteratorDirect');
|
||||
var GetMethod = require('es-abstract/2024/GetMethod');
|
||||
var IsArray = require('es-abstract/2024/IsArray');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
var getIteratorMethod = require('es-abstract/helpers/getIteratorMethod');
|
||||
|
||||
// https://tc39.es/proposal-iterator-helpers/#sec-getiteratorflattenable
|
||||
|
||||
module.exports = function GetIteratorFlattenable(obj, stringHandling) {
|
||||
if (stringHandling !== 'REJECT-STRINGS' && stringHandling !== 'ITERATE-STRINGS') {
|
||||
throw new $TypeError('Assertion failed: `stringHandling` must be "REJECT-STRINGS" or "ITERATE-STRINGS"');
|
||||
}
|
||||
|
||||
if (Type(obj) !== 'Object') {
|
||||
if (stringHandling === 'REJECT-STRINGS' || typeof obj !== 'string') {
|
||||
throw new $TypeError('obj must be an Object'); // step 1.a
|
||||
}
|
||||
}
|
||||
|
||||
var method = void undefined; // step 2
|
||||
|
||||
// method = GetMethod(obj, Symbol.iterator); // step 5.a
|
||||
method = getIteratorMethod(
|
||||
{
|
||||
AdvanceStringIndex: AdvanceStringIndex,
|
||||
GetMethod: GetMethod,
|
||||
IsArray: IsArray
|
||||
},
|
||||
obj
|
||||
);
|
||||
|
||||
var iterator;
|
||||
if (typeof method === 'undefined') { // step 3
|
||||
iterator = obj; // step 3.a
|
||||
} else { // step 4
|
||||
iterator = Call(method, obj); // step 4.a
|
||||
}
|
||||
|
||||
if (Type(iterator) !== 'Object') {
|
||||
throw new $TypeError('iterator must be an Object'); // step 5
|
||||
}
|
||||
return GetIteratorDirect(iterator); // step 6
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
// var OrdinaryObjectCreate = require('es-abstract/2024/OrdinaryObjectCreate');
|
||||
var Type = require('es-abstract/2024/Type');
|
||||
|
||||
// https://tc39.es/proposal-joint-iteration/#sec-getoptionsobject
|
||||
|
||||
module.exports = function GetOptionsObject(options) {
|
||||
if (typeof options === 'undefined') { // step 1
|
||||
// return OrdinaryObjectCreate(null); // step 1.a
|
||||
return { __proto__: null }; // step 1.a
|
||||
}
|
||||
if (Type(options) === 'Object') { // step 2
|
||||
return options; // step 2.a
|
||||
}
|
||||
|
||||
throw new $TypeError('`options` must be an Object or undefined'); // step 3
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var IteratorCloseAll = require('./IteratorCloseAll');
|
||||
|
||||
// https://tc39.es/proposal-joint-iteration/#sec-ifabruptcloseiterators
|
||||
|
||||
module.exports = function IfAbruptCloseIterators(value, iteratorRecords) {
|
||||
if (!(value instanceof CompletionRecord)) {
|
||||
throw new $TypeError('Assertion failed: `value` must be a Completion Record'); // step 1
|
||||
}
|
||||
if (value.type() === 'throw') {
|
||||
return IteratorCloseAll(iteratorRecords, value); // step 2
|
||||
}
|
||||
|
||||
return value['!'](); // step
|
||||
};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
var IteratorClose = require('es-abstract/2024/IteratorClose');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
|
||||
var IsArray = require('es-abstract/helpers/IsArray');
|
||||
var every = require('es-abstract/helpers/every');
|
||||
|
||||
var isIteratorRecord = require('es-abstract/helpers/records/iterator-record');
|
||||
|
||||
// https://tc39.es/proposal-joint-iteration/#sec-closeall
|
||||
|
||||
module.exports = function IteratorCloseAll(iters, completion) {
|
||||
if (!IsArray(iters) || !every(iters, isIteratorRecord)) {
|
||||
throw new $TypeError('Assertion failed: `iters` must be a List of IteratorRecords');
|
||||
}
|
||||
if (!(completion instanceof CompletionRecord)) {
|
||||
throw new $TypeError('Assertion failed: `completion` must be a Completion Record');
|
||||
}
|
||||
|
||||
for (var i = iters.length - 1; i >= 0; i -= 1) { // step 1
|
||||
try {
|
||||
IteratorClose(iters[i], completion); // step 1.a
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
completion = ThrowCompletion(e); // step 1.a
|
||||
}
|
||||
}
|
||||
|
||||
return completion['?'](); // step 2
|
||||
};
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var CreateIteratorFromClosure = require('./CreateIteratorFromClosure');
|
||||
var IteratorCloseAll = require('./IteratorCloseAll');
|
||||
var IteratorStep = require('es-abstract/2024/IteratorStep');
|
||||
var IteratorStepValue = require('es-abstract/2024/IteratorStepValue');
|
||||
var NormalCompletion = require('es-abstract/2024/NormalCompletion');
|
||||
var ThrowCompletion = require('es-abstract/2024/ThrowCompletion');
|
||||
|
||||
var isAbstractClosure = require('es-abstract/helpers/isAbstractClosure');
|
||||
var IsArray = require('es-abstract/helpers/IsArray');
|
||||
var isIteratorRecord = require('es-abstract/helpers/records/iterator-record');
|
||||
var some = require('es-abstract/helpers/some');
|
||||
|
||||
var callBound = require('call-bind/callBound');
|
||||
|
||||
var $indexOf = callBound('Array.prototype.indexOf');
|
||||
var $slice = callBound('Array.prototype.slice');
|
||||
var $splice = callBound('Array.prototype.splice');
|
||||
|
||||
var iterHelperProto = require('../IteratorHelperPrototype');
|
||||
|
||||
var SLOT = require('internal-slot');
|
||||
|
||||
// https://tc39.es/proposal-joint-iteration/#sec-IteratorZip
|
||||
|
||||
module.exports = function IteratorZip(iters, mode, padding, finishResults) {
|
||||
if (!IsArray(iters) || !some(iters, isIteratorRecord)) {
|
||||
throw new $TypeError('`iters` must be a List of IteratorRecords');
|
||||
}
|
||||
|
||||
if (mode !== 'shortest' && mode !== 'longest' && mode !== 'strict') {
|
||||
throw new $TypeError('`mode` must be one of "shortest", "longest", or "strict"');
|
||||
}
|
||||
|
||||
if (!IsArray(padding)) {
|
||||
throw new $TypeError('`padding` must be a List');
|
||||
}
|
||||
|
||||
if (!isAbstractClosure(finishResults)) {
|
||||
throw new $TypeError('`finishResults` must be an Abstract Closure');
|
||||
}
|
||||
|
||||
var iterCount = iters.length; // step 1
|
||||
|
||||
var openIters = $slice(iters); // step 2
|
||||
|
||||
var sentinel = {};
|
||||
var closure = function () {
|
||||
if (iterCount === 0) {
|
||||
// 1. If iterCount = 0, return ReturnCompletion(undefined).
|
||||
return sentinel; // step 1
|
||||
}
|
||||
// while (true) {
|
||||
{ // eslint-disable-line no-lone-blocks
|
||||
var results = []; // step 3.b.i
|
||||
if (openIters.length === 0) {
|
||||
throw new $TypeError('Assertion failed: `openIters` is empty'); // step 3.b.ii
|
||||
}
|
||||
for (var i = 0; i < iterCount; ++i) { // step 3.b.iii
|
||||
// for (var i = 0; i < iterCount; i += 1) { // step 3.b.iii
|
||||
var result;
|
||||
|
||||
var iter = iters[i];
|
||||
if (iter === null) { // step 3.b.iii.1
|
||||
if (mode !== 'longest') {
|
||||
throw new $TypeError('Assertion failed: `mode` is not "longest"'); // step 3.b.iii.1.a
|
||||
}
|
||||
result = padding[i]; // step 3.b.iii.1.b
|
||||
} else { // step 2
|
||||
try {
|
||||
result = IteratorStepValue(iter); // step 3.b.iii.2.a, 3.b.iii.2.c
|
||||
} catch (e) { // step 3.b.iii.2.b
|
||||
$splice(openIters, $indexOf(openIters, iter), 1); // step 3.b.iii.2.b.i
|
||||
return IteratorCloseAll(openIters, ThrowCompletion(e)); // step 3.b.iii.2.b.ii
|
||||
}
|
||||
if (iter['[[Done]]']) { // step 3.b.iii.2.d
|
||||
$splice(openIters, $indexOf(openIters, iter), 1); // step 3.b.iii.2.d.i
|
||||
if (mode === 'shortest') { // step 3.b.iii.2.d.ii
|
||||
IteratorCloseAll(openIters, NormalCompletion(undefined)); // step 3.b.iii.2.d.ii.i
|
||||
return sentinel;
|
||||
} else if (mode === 'strict') { // step 3.b.iii.2.d.iii
|
||||
if (i !== 0) { // step 3.b.iii.2.d.iii.i
|
||||
return IteratorCloseAll(
|
||||
openIters,
|
||||
ThrowCompletion(new $TypeError('Assertion failed: `i` is not 0'))
|
||||
); // step 3.b.iii.2.d.iii.i.i
|
||||
}
|
||||
for (var k = 1; k < iterCount; k += 1) { // step 3.b.iii.2.d.iii.ii
|
||||
if (iters[k] === null) {
|
||||
throw new $TypeError('Assertion failed: `iters[k]` is `null`'); // step 3.b.iii.2.d.iii.ii.i
|
||||
}
|
||||
try {
|
||||
result = IteratorStep(iters[k]); // step 3.b.iii.2.d.iii.ii.ii, 3.b.iii.2.d.iii.ii.iii.ii.iv
|
||||
} catch (e) { // step 3.b.iii.2.d.iii.ii.iii
|
||||
return IteratorCloseAll(openIters, ThrowCompletion(e)); // step 3.b.iii.2.d.iii.ii.iii.ii
|
||||
}
|
||||
|
||||
// if (open === false) { // step 3.b.iii.2.d.iii.ii.v
|
||||
if (iters[k]['[[Done]]']) { // step 3.b.iii.2.d.iii.ii.v
|
||||
$splice(openIters, $indexOf(openIters, iters[k]), 1); // step 3.b.iii.2.d.iii.ii.v.i
|
||||
} else { // step 3.b.iii.2.d.iii.ii.vi
|
||||
return IteratorCloseAll(
|
||||
openIters,
|
||||
ThrowCompletion(new $TypeError('Assertion failed: `open` is not `false`'))
|
||||
); // step 3.b.iii.2.d.iii.ii.vi.i
|
||||
}
|
||||
}
|
||||
} else { // step 3.b.iii.2.d.iv
|
||||
if (mode !== 'longest') {
|
||||
throw new $TypeError('Assertion failed: `mode` is not "longest"'); // step 3.b.iii.2.d.iv.i
|
||||
}
|
||||
|
||||
if (openIters.length === 0) {
|
||||
return sentinel; // ReturnCompletion(undefined); // step 3.b.iii.2.d.iv.ii
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
iters[i] = null; // step 3.b.iii.2.d.iv.iii
|
||||
// i += 1;
|
||||
|
||||
result = padding[i]; // step 3.b.iii.2.d.iv.iv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results[results.length] = result; // step 3.b.iii.3
|
||||
|
||||
// 5. Let completion be Completion(Yield(results)).
|
||||
// 6. If completion is an abrupt completion, then
|
||||
// 1. Return ? IteratorCloseAll(openIters, completion).
|
||||
}
|
||||
}
|
||||
|
||||
return finishResults(results); // step 3.b.iv
|
||||
};
|
||||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation
|
||||
SLOT.set(closure, '[[CloseIfAbrupt]]', finishResults); // for the userland implementation
|
||||
|
||||
var gen = CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto, ['[[UnderlyingIterators]]']); // step 4
|
||||
|
||||
SLOT.set(gen, '[[UnderlyingIterators]]', openIters); // step 5
|
||||
|
||||
return gen; // step 6
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var CompletionRecord = require('es-abstract/2024/CompletionRecord');
|
||||
|
||||
// https://tc39.es/ecma262/#sec-returncompletion
|
||||
|
||||
module.exports = function ReturnCompletion(value) {
|
||||
return new CompletionRecord('return', value);
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
[
|
||||
"Iterator",
|
||||
"Iterator.concat",
|
||||
"Iterator.from",
|
||||
"Iterator.zip",
|
||||
"Iterator.zipKeyed",
|
||||
"Iterator.prototype",
|
||||
"Iterator.prototype.constructor",
|
||||
"Iterator.prototype.drop",
|
||||
"Iterator.prototype.every",
|
||||
"Iterator.prototype.filter",
|
||||
"Iterator.prototype.find",
|
||||
"Iterator.prototype.flatMap",
|
||||
"Iterator.prototype.forEach",
|
||||
"Iterator.prototype.map",
|
||||
"Iterator.prototype.reduce",
|
||||
"Iterator.prototype.some",
|
||||
"Iterator.prototype.take",
|
||||
"Iterator.prototype.toArray"
|
||||
]
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
{
|
||||
"name": "es-iterator-helpers",
|
||||
"version": "1.2.0",
|
||||
"description": "An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3.",
|
||||
"main": "index.json",
|
||||
"exports": {
|
||||
".": "./index.json",
|
||||
"./auto": "./auto.js",
|
||||
"./shim": "./shim.js",
|
||||
"./Iterator": "./Iterator/index.js",
|
||||
"./Iterator/auto": "./Iterator/auto.js",
|
||||
"./Iterator/polyfill": "./Iterator/polyfill.js",
|
||||
"./Iterator/implementation": "./Iterator/implementation.js",
|
||||
"./Iterator/shim": "./Iterator/shim.js",
|
||||
"./Iterator.prototype": "./Iterator.prototype/index.js",
|
||||
"./Iterator.prototype/auto": "./Iterator.prototype/auto.js",
|
||||
"./Iterator.prototype/polyfill": "./Iterator.prototype/polyfill.js",
|
||||
"./Iterator.prototype/implementation": "./Iterator.prototype/implementation.js",
|
||||
"./Iterator.prototype/shim": "./Iterator.prototype/shim.js",
|
||||
"./Iterator.concat": "./Iterator.concat/index.js",
|
||||
"./Iterator.concat/auto": "./Iterator.concat/auto.js",
|
||||
"./Iterator.concat/polyfill": "./Iterator.concat/polyfill.js",
|
||||
"./Iterator.concat/implementation": "./Iterator.concat/implementation.js",
|
||||
"./Iterator.concat/shim": "./Iterator.concat/shim.js",
|
||||
"./Iterator.from": "./Iterator.from/index.js",
|
||||
"./Iterator.from/auto": "./Iterator.from/auto.js",
|
||||
"./Iterator.from/polyfill": "./Iterator.from/polyfill.js",
|
||||
"./Iterator.from/implementation": "./Iterator.from/implementation.js",
|
||||
"./Iterator.from/shim": "./Iterator.from/shim.js",
|
||||
"./Iterator.zip": "./Iterator.zip/index.js",
|
||||
"./Iterator.zip/auto": "./Iterator.zip/auto.js",
|
||||
"./Iterator.zip/polyfill": "./Iterator.zip/polyfill.js",
|
||||
"./Iterator.zip/implementation": "./Iterator.zip/implementation.js",
|
||||
"./Iterator.zip/shim": "./Iterator.zip/shim.js",
|
||||
"./Iterator.zipKeyed": "./Iterator.zipKeyed/index.js",
|
||||
"./Iterator.zipKeyed/auto": "./Iterator.zipKeyed/auto.js",
|
||||
"./Iterator.zipKeyed/polyfill": "./Iterator.zipKeyed/polyfill.js",
|
||||
"./Iterator.zipKeyed/implementation": "./Iterator.zipKeyed/implementation.js",
|
||||
"./Iterator.zipKeyed/shim": "./Iterator.zipKeyed/shim.js",
|
||||
"./Iterator.prototype.constructor": "./Iterator.prototype.constructor/index.js",
|
||||
"./Iterator.prototype.constructor/auto": "./Iterator.prototype.constructor/auto.js",
|
||||
"./Iterator.prototype.constructor/polyfill": "./Iterator.prototype.constructor/polyfill.js",
|
||||
"./Iterator.prototype.constructor/implementation": "./Iterator.prototype.constructor/implementation.js",
|
||||
"./Iterator.prototype.constructor/shim": "./Iterator.prototype.constructor/shim.js",
|
||||
"./Iterator.prototype.map": "./Iterator.prototype.map/index.js",
|
||||
"./Iterator.prototype.map/auto": "./Iterator.prototype.map/auto.js",
|
||||
"./Iterator.prototype.map/polyfill": "./Iterator.prototype.map/polyfill.js",
|
||||
"./Iterator.prototype.map/implementation": "./Iterator.prototype.map/implementation.js",
|
||||
"./Iterator.prototype.map/shim": "./Iterator.prototype.map/shim.js",
|
||||
"./Iterator.prototype.filter": "./Iterator.prototype.filter/index.js",
|
||||
"./Iterator.prototype.filter/auto": "./Iterator.prototype.filter/auto.js",
|
||||
"./Iterator.prototype.filter/polyfill": "./Iterator.prototype.filter/polyfill.js",
|
||||
"./Iterator.prototype.filter/implementation": "./Iterator.prototype.filter/implementation.js",
|
||||
"./Iterator.prototype.filter/shim": "./Iterator.prototype.filter/shim.js",
|
||||
"./Iterator.prototype.take": "./Iterator.prototype.take/index.js",
|
||||
"./Iterator.prototype.take/auto": "./Iterator.prototype.take/auto.js",
|
||||
"./Iterator.prototype.take/polyfill": "./Iterator.prototype.take/polyfill.js",
|
||||
"./Iterator.prototype.take/implementation": "./Iterator.prototype.take/implementation.js",
|
||||
"./Iterator.prototype.take/shim": "./Iterator.prototype.take/shim.js",
|
||||
"./Iterator.prototype.drop": "./Iterator.prototype.drop/index.js",
|
||||
"./Iterator.prototype.drop/auto": "./Iterator.prototype.drop/auto.js",
|
||||
"./Iterator.prototype.drop/polyfill": "./Iterator.prototype.drop/polyfill.js",
|
||||
"./Iterator.prototype.drop/implementation": "./Iterator.prototype.drop/implementation.js",
|
||||
"./Iterator.prototype.drop/shim": "./Iterator.prototype.drop/shim.js",
|
||||
"./Iterator.prototype.flatMap": "./Iterator.prototype.flatMap/index.js",
|
||||
"./Iterator.prototype.flatMap/auto": "./Iterator.prototype.flatMap/auto.js",
|
||||
"./Iterator.prototype.flatMap/polyfill": "./Iterator.prototype.flatMap/polyfill.js",
|
||||
"./Iterator.prototype.flatMap/implementation": "./Iterator.prototype.flatMap/implementation.js",
|
||||
"./Iterator.prototype.flatMap/shim": "./Iterator.prototype.flatMap/shim.js",
|
||||
"./Iterator.prototype.reduce": "./Iterator.prototype.reduce/index.js",
|
||||
"./Iterator.prototype.reduce/auto": "./Iterator.prototype.reduce/auto.js",
|
||||
"./Iterator.prototype.reduce/polyfill": "./Iterator.prototype.reduce/polyfill.js",
|
||||
"./Iterator.prototype.reduce/implementation": "./Iterator.prototype.reduce/implementation.js",
|
||||
"./Iterator.prototype.reduce/shim": "./Iterator.prototype.reduce/shim.js",
|
||||
"./Iterator.prototype.toArray": "./Iterator.prototype.toArray/index.js",
|
||||
"./Iterator.prototype.toArray/auto": "./Iterator.prototype.toArray/auto.js",
|
||||
"./Iterator.prototype.toArray/polyfill": "./Iterator.prototype.toArray/polyfill.js",
|
||||
"./Iterator.prototype.toArray/implementation": "./Iterator.prototype.toArray/implementation.js",
|
||||
"./Iterator.prototype.toArray/shim": "./Iterator.prototype.toArray/shim.js",
|
||||
"./Iterator.prototype.forEach": "./Iterator.prototype.forEach/index.js",
|
||||
"./Iterator.prototype.forEach/auto": "./Iterator.prototype.forEach/auto.js",
|
||||
"./Iterator.prototype.forEach/polyfill": "./Iterator.prototype.forEach/polyfill.js",
|
||||
"./Iterator.prototype.forEach/implementation": "./Iterator.prototype.forEach/implementation.js",
|
||||
"./Iterator.prototype.forEach/shim": "./Iterator.prototype.forEach/shim.js",
|
||||
"./Iterator.prototype.some": "./Iterator.prototype.some/index.js",
|
||||
"./Iterator.prototype.some/auto": "./Iterator.prototype.some/auto.js",
|
||||
"./Iterator.prototype.some/polyfill": "./Iterator.prototype.some/polyfill.js",
|
||||
"./Iterator.prototype.some/implementation": "./Iterator.prototype.some/implementation.js",
|
||||
"./Iterator.prototype.some/shim": "./Iterator.prototype.some/shim.js",
|
||||
"./Iterator.prototype.every": "./Iterator.prototype.every/index.js",
|
||||
"./Iterator.prototype.every/auto": "./Iterator.prototype.every/auto.js",
|
||||
"./Iterator.prototype.every/polyfill": "./Iterator.prototype.every/polyfill.js",
|
||||
"./Iterator.prototype.every/implementation": "./Iterator.prototype.every/implementation.js",
|
||||
"./Iterator.prototype.every/shim": "./Iterator.prototype.every/shim.js",
|
||||
"./Iterator.prototype.find": "./Iterator.prototype.find/index.js",
|
||||
"./Iterator.prototype.find/auto": "./Iterator.prototype.find/auto.js",
|
||||
"./Iterator.prototype.find/polyfill": "./Iterator.prototype.find/polyfill.js",
|
||||
"./Iterator.prototype.find/implementation": "./Iterator.prototype.find/implementation.js",
|
||||
"./Iterator.prototype.find/shim": "./Iterator.prototype.find/shim.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"prelint": "es-shim-api --type=multi --ignore-dirs=WrapForValidIteratorPrototype,IteratorHelperPrototype",
|
||||
"lint": "eslint --ext=js,mjs .",
|
||||
"postlint": "evalmd README.md",
|
||||
"pretest": "npm run lint",
|
||||
"test": "npm run tests-only",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"posttest": "npx npm@'>=10.2' audit --production",
|
||||
"version": "auto-changelog && git add CHANGELOG.md",
|
||||
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/es-shims/iterator-helpers.git"
|
||||
},
|
||||
"keywords": [
|
||||
"javascript",
|
||||
"ecmascript",
|
||||
"polyfill",
|
||||
"shim",
|
||||
"es-shims",
|
||||
"es-shim API",
|
||||
"Iterator",
|
||||
"helpers",
|
||||
"from",
|
||||
"map",
|
||||
"filter",
|
||||
"take",
|
||||
"drop",
|
||||
"flatMap",
|
||||
"reduce",
|
||||
"toArray",
|
||||
"forEach",
|
||||
"some",
|
||||
"every",
|
||||
"find"
|
||||
],
|
||||
"author": "Jordan Harband <ljharb@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/es-shims/iterator-helpers/issues"
|
||||
},
|
||||
"homepage": "https://github.com/es-shims/iterator-helpers#readme",
|
||||
"dependencies": {
|
||||
"call-bind": "^1.0.7",
|
||||
"define-properties": "^1.2.1",
|
||||
"es-abstract": "^1.23.3",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-set-tostringtag": "^2.0.3",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-intrinsic": "^1.2.4",
|
||||
"globalthis": "^1.0.4",
|
||||
"gopd": "^1.0.1",
|
||||
"has-property-descriptors": "^1.0.2",
|
||||
"has-proto": "^1.0.3",
|
||||
"has-symbols": "^1.0.3",
|
||||
"internal-slot": "^1.0.7",
|
||||
"iterator.prototype": "^1.1.3",
|
||||
"safe-array-concat": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@es-shims/api": "^3.0.1",
|
||||
"@ljharb/eslint-config": "^21.1.1",
|
||||
"auto-changelog": "^2.5.0",
|
||||
"encoding": "^0.1.13",
|
||||
"es-value-fixtures": "^1.5.0",
|
||||
"eslint": "=8.8.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"evalmd": "^0.0.19",
|
||||
"for-each": "^0.3.3",
|
||||
"functions-have-names": "^1.2.3",
|
||||
"has-strict-mode": "^1.0.1",
|
||||
"has-tostringtag": "^1.0.2",
|
||||
"in-publish": "^2.0.1",
|
||||
"iterate-iterator": "^1.0.2",
|
||||
"make-generator-function": "^2.0.0",
|
||||
"mock-property": "^1.1.0",
|
||||
"npmignore": "^0.3.1",
|
||||
"nyc": "^10.3.2",
|
||||
"object-inspect": "^1.13.2",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.9.0"
|
||||
},
|
||||
"auto-changelog": {
|
||||
"output": "CHANGELOG.md",
|
||||
"template": "keepachangelog",
|
||||
"unreleased": false,
|
||||
"commitLimit": false,
|
||||
"backfillLimit": false,
|
||||
"hideCredit": true
|
||||
},
|
||||
"publishConfig": {
|
||||
"ignore": [
|
||||
".github/workflows"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var shimIterator = require('./Iterator/shim');
|
||||
var shimIteratorFrom = require('./Iterator.from/shim');
|
||||
var shimIteratorConcat = require('./Iterator.concat/shim');
|
||||
var shimZip = require('./Iterator.zip/shim');
|
||||
var shimZipKeyed = require('./Iterator.zipKeyed/shim');
|
||||
var shimIteratorProto = require('./Iterator.prototype/shim');
|
||||
var shimIteratorCtor = require('./Iterator.prototype.constructor/shim');
|
||||
var shimIteratorDrop = require('./Iterator.prototype.drop/shim');
|
||||
var shimIteratorEvery = require('./Iterator.prototype.every/shim');
|
||||
var shimIteratorFilter = require('./Iterator.prototype.filter/shim');
|
||||
var shimIteratorFind = require('./Iterator.prototype.find/shim');
|
||||
var shimIteratorFlatMap = require('./Iterator.prototype.flatMap/shim');
|
||||
var shimIteratorForEach = require('./Iterator.prototype.forEach/shim');
|
||||
var shimIteratorMap = require('./Iterator.prototype.map/shim');
|
||||
var shimIteratorReduce = require('./Iterator.prototype.reduce/shim');
|
||||
var shimIteratorSome = require('./Iterator.prototype.some/shim');
|
||||
var shimIteratorTake = require('./Iterator.prototype.take/shim');
|
||||
var shimIteratorToArray = require('./Iterator.prototype.toArray/shim');
|
||||
|
||||
module.exports = function shimIteratorHelpers() {
|
||||
shimIterator();
|
||||
shimIteratorProto();
|
||||
shimIteratorFrom();
|
||||
shimIteratorConcat();
|
||||
shimZip();
|
||||
shimZipKeyed();
|
||||
shimIteratorCtor();
|
||||
shimIteratorDrop();
|
||||
shimIteratorEvery();
|
||||
shimIteratorFilter();
|
||||
shimIteratorFind();
|
||||
shimIteratorFlatMap();
|
||||
shimIteratorForEach();
|
||||
shimIteratorMap();
|
||||
shimIteratorReduce();
|
||||
shimIteratorSome();
|
||||
shimIteratorTake();
|
||||
shimIteratorToArray();
|
||||
};
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
'use strict';
|
||||
|
||||
var defineProperties = require('define-properties');
|
||||
var test = require('tape');
|
||||
var callBind = require('call-bind');
|
||||
var functionsHaveNames = require('functions-have-names')();
|
||||
var forEach = require('for-each');
|
||||
var debug = require('object-inspect');
|
||||
var v = require('es-value-fixtures');
|
||||
var hasSymbols = require('has-symbols/shams')();
|
||||
var mockProperty = require('mock-property');
|
||||
|
||||
var index = require('../Iterator.zip');
|
||||
var impl = require('../Iterator.zip/implementation');
|
||||
var from = require('../Iterator.from/polyfill')();
|
||||
|
||||
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
||||
|
||||
var testIterator = require('./helpers/testIterator');
|
||||
|
||||
module.exports = {
|
||||
tests: function (zip, name, t) {
|
||||
t['throws'](
|
||||
function () { return new zip(); }, // eslint-disable-line new-cap
|
||||
TypeError,
|
||||
'`' + name + '` itself is not a constructor'
|
||||
);
|
||||
t['throws'](
|
||||
function () { return new zip({}); }, // eslint-disable-line new-cap
|
||||
TypeError,
|
||||
'`' + name + '` itself is not a constructor, with an argument'
|
||||
);
|
||||
|
||||
forEach(v.primitives.concat(v.objects), function (nonIterator) {
|
||||
t['throws'](
|
||||
function () { zip(nonIterator, []); },
|
||||
TypeError,
|
||||
debug(nonIterator) + ' is not an iterable Object'
|
||||
);
|
||||
});
|
||||
|
||||
t.test('actual iteration', { skip: !hasSymbols }, function (st) {
|
||||
forEach(v.nonFunctions, function (nonFunction) {
|
||||
var badIterable = {};
|
||||
badIterable[Symbol.iterator] = nonFunction;
|
||||
st['throws'](
|
||||
function () { zip([[], badIterable, []]).next(); },
|
||||
TypeError,
|
||||
debug(badIterable) + ' is not a function'
|
||||
);
|
||||
});
|
||||
|
||||
forEach(v.strings, function (string) {
|
||||
st['throws'](
|
||||
function () { zip([string]); },
|
||||
TypeError,
|
||||
'non-objects are not considered iterable'
|
||||
);
|
||||
});
|
||||
|
||||
var arrayIt = zip([[1, 2, 3]]);
|
||||
st.equal(typeof arrayIt.next, 'function', 'has a `next` function');
|
||||
|
||||
st.test('real iterators', { skip: !hasSymbols }, function (s2t) {
|
||||
var iter = [1, 2][Symbol.iterator]();
|
||||
testIterator(zip([iter, [3, 4]]), [[1, 3], [2, 4]], s2t, 'array iterator + array yields combined results');
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
st.test('observability in a replaced String iterator', function (s2t) {
|
||||
var originalStringIterator = String.prototype[Symbol.iterator];
|
||||
var observedType;
|
||||
s2t.teardown(mockProperty(String.prototype, Symbol.iterator, {
|
||||
get: function () {
|
||||
'use strict'; // eslint-disable-line strict, lines-around-directive
|
||||
|
||||
observedType = typeof this;
|
||||
return originalStringIterator;
|
||||
}
|
||||
}));
|
||||
|
||||
zip([from('')]);
|
||||
s2t.equal(observedType, 'string', 'string primitive -> primitive receiver in Symbol.iterator getter');
|
||||
zip([from(Object(''))]);
|
||||
s2t.equal(observedType, 'object', 'boxed string -> boxed string in Symbol.iterator getter');
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
st.end();
|
||||
});
|
||||
},
|
||||
index: function () {
|
||||
test('Iterator.zip: index', function (t) {
|
||||
module.exports.tests(index, 'Iterator.zip', t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
},
|
||||
implementation: function () {
|
||||
test('Iterator.zip: implementation', function (t) {
|
||||
module.exports.tests(impl, 'Iterator.zip', t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
},
|
||||
shimmed: function () {
|
||||
test('Iterator.zip: shimmed', function (t) {
|
||||
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
|
||||
st.equal(Iterator.zip.name, 'zip', 'Iterator.zip has name "zip"');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
|
||||
et.equal(false, isEnumerable.call(Iterator, 'zip'), 'Iterator.zip is not enumerable');
|
||||
et.end();
|
||||
});
|
||||
|
||||
module.exports.tests(callBind(Iterator.zip, Iterator), 'Iterator.zip', t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user