-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
188 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
'use strict' | ||
|
||
const impl = require('./implementation') | ||
const Iterator = require('../Iterator/implementation') | ||
|
||
module.exports = function getPolyfill() { | ||
return typeof Iterator.concat === 'function' ? Iterator.concat : impl | ||
return impl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 34 additions & 16 deletions
50
packages/npm/es-iterator-helpers/Iterator.from/implementation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,41 @@ | ||
'use strict' | ||
|
||
const IteratorCtor = require('../Iterator/implementation') | ||
const { | ||
ReflectApply, | ||
IteratorCtor: IteratorCtorRaw, | ||
ObjectCreate, | ||
TypeErrorCtor, | ||
createIteratorFromClosure, | ||
WrapForValidIteratorPrototype, | ||
getIteratorFlattenable, | ||
setUnderlyingIterator | ||
setIterated | ||
} = require('../shared') | ||
|
||
module.exports = function from(O) { | ||
if (new.target) { | ||
throw new TypeErrorCtor('`Iterator.from` is not a constructor') | ||
} | ||
const { iterator, next } = getIteratorFlattenable(O) | ||
const wrapper = createIteratorFromClosure({ | ||
next() { | ||
return ReflectApply(next, iterator, []) | ||
} | ||
}) | ||
setUnderlyingIterator(wrapper, iterator) | ||
return wrapper | ||
} | ||
const IteratorFrom = IteratorCtorRaw?.from | ||
|
||
// Based specification text: | ||
// https://tc39.es/ecma262/#sec-iterator.from | ||
module.exports = | ||
typeof IteratorFrom === 'function' | ||
? IteratorFrom | ||
: function from(O) { | ||
// Built-in functions that are not identified as constructors do | ||
// not implement [[Construct]] unless otherwise specified. | ||
// https://tc39.es/ecma262/#sec-ecmascript-standard-built-in-objects | ||
if (new.target) { | ||
throw new TypeErrorCtor('`Iterator.from` is not a constructor') | ||
} | ||
// Step 1: Let iteratorRecord be GetIteratorFlattenable(O, iterate-string-primitives). | ||
const { iterator, next } = getIteratorFlattenable(O, true) | ||
// Step 2: Let hasInstance be OrdinaryHasInstance(%Iterator%, iteratorRecord.[[Iterator]]). | ||
// Step 3: If hasInstance is true, then | ||
if (iterator instanceof IteratorCtor) { | ||
// Step 3.a: Return iteratorRecord.[[Iterator]]. | ||
return iterator | ||
} | ||
// Step 4: Let wrapper be OrdinaryObjectCreate(%WrapForValidIteratorPrototype%, << [[Iterated]] >>). | ||
const wrapper = ObjectCreate(WrapForValidIteratorPrototype) | ||
// Step 5: Set wrapper.[[Iterated]] to iteratorRecord. | ||
setIterated(wrapper, { iterator, next }) | ||
// Step 6: Return wrapper. | ||
return wrapper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.