main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
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/iterator-define');
|
---|
6 | var createIterResultObject = require('../internals/create-iter-result-object');
|
---|
7 |
|
---|
8 | var STRING_ITERATOR = 'String Iterator';
|
---|
9 | var setInternalState = InternalStateModule.set;
|
---|
10 | var getInternalState = InternalStateModule.getterFor(STRING_ITERATOR);
|
---|
11 |
|
---|
12 | // `String.prototype[@@iterator]` method
|
---|
13 | // https://tc39.es/ecma262/#sec-string.prototype-@@iterator
|
---|
14 | defineIterator(String, 'String', function (iterated) {
|
---|
15 | setInternalState(this, {
|
---|
16 | type: STRING_ITERATOR,
|
---|
17 | string: toString(iterated),
|
---|
18 | index: 0
|
---|
19 | });
|
---|
20 | // `%StringIteratorPrototype%.next` method
|
---|
21 | // https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next
|
---|
22 | }, function next() {
|
---|
23 | var state = getInternalState(this);
|
---|
24 | var string = state.string;
|
---|
25 | var index = state.index;
|
---|
26 | var point;
|
---|
27 | if (index >= string.length) return createIterResultObject(undefined, true);
|
---|
28 | point = charAt(string, index);
|
---|
29 | state.index += point.length;
|
---|
30 | return createIterResultObject(point, false);
|
---|
31 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.