Last change
on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | var charAt = require('../internals/string-multibyte').charAt;
|
---|
| 3 | var toString = require('../internals/to-string');
|
---|
| 4 | var InternalStateModule = require('../internals/internal-state');
|
---|
| 5 | var defineIterator = require('../internals/define-iterator');
|
---|
| 6 |
|
---|
| 7 | var STRING_ITERATOR = 'String Iterator';
|
---|
| 8 | var setInternalState = InternalStateModule.set;
|
---|
| 9 | var getInternalState = InternalStateModule.getterFor(STRING_ITERATOR);
|
---|
| 10 |
|
---|
| 11 | // `String.prototype[@@iterator]` method
|
---|
| 12 | // https://tc39.es/ecma262/#sec-string.prototype-@@iterator
|
---|
| 13 | defineIterator(String, 'String', function (iterated) {
|
---|
| 14 | setInternalState(this, {
|
---|
| 15 | type: STRING_ITERATOR,
|
---|
| 16 | string: toString(iterated),
|
---|
| 17 | index: 0
|
---|
| 18 | });
|
---|
| 19 | // `%StringIteratorPrototype%.next` method
|
---|
| 20 | // https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next
|
---|
| 21 | }, function next() {
|
---|
| 22 | var state = getInternalState(this);
|
---|
| 23 | var string = state.string;
|
---|
| 24 | var index = state.index;
|
---|
| 25 | var point;
|
---|
| 26 | if (index >= string.length) return { value: undefined, done: true };
|
---|
| 27 | point = charAt(string, index);
|
---|
| 28 | state.index += point.length;
|
---|
| 29 | return { value: point, done: false };
|
---|
| 30 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.