2016-03-03 06:44:11 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2016 Realm Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var arrayPrototype = Array.prototype;
|
|
|
|
|
2016-03-20 02:55:19 +00:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
var iteratorPrototype = {};
|
|
|
|
|
2016-12-20 18:56:51 +00:00
|
|
|
// These iterators should themselves be iterable.
|
|
|
|
Object.defineProperty(iteratorPrototype, Symbol.iterator, {
|
|
|
|
value: function() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
2016-03-20 02:55:19 +00:00
|
|
|
|
2016-03-03 06:44:11 +00:00
|
|
|
[
|
2017-06-20 11:09:01 +00:00
|
|
|
'toString',
|
|
|
|
'toLocaleString',
|
|
|
|
'concat',
|
2016-03-03 06:44:11 +00:00
|
|
|
'join',
|
|
|
|
'slice',
|
2017-06-20 11:09:01 +00:00
|
|
|
'lastIndexOf',
|
2016-03-03 06:44:11 +00:00
|
|
|
'every',
|
|
|
|
'some',
|
2017-06-20 11:09:01 +00:00
|
|
|
'forEach',
|
2016-03-03 06:44:11 +00:00
|
|
|
'find',
|
|
|
|
'findIndex',
|
|
|
|
'map',
|
2017-06-20 11:09:01 +00:00
|
|
|
'filter',
|
2016-03-03 06:44:11 +00:00
|
|
|
'reduce',
|
|
|
|
'reduceRight',
|
|
|
|
].forEach(function(methodName) {
|
|
|
|
var method = arrayPrototype[methodName];
|
|
|
|
if (method) {
|
2016-09-08 22:33:42 +00:00
|
|
|
exports[methodName] = {value: method, configurable: true, writable: true};
|
2016-03-03 06:44:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
['entries', 'keys', 'values'].forEach(function(methodName) {
|
|
|
|
var method = function() {
|
2017-10-02 21:15:19 +00:00
|
|
|
var self = this.snapshot();
|
2016-03-03 06:44:11 +00:00
|
|
|
var index = 0;
|
|
|
|
|
2016-03-20 02:55:19 +00:00
|
|
|
return Object.create(iteratorPrototype, {
|
|
|
|
next: {
|
|
|
|
value: function() {
|
|
|
|
if (!self || index >= self.length) {
|
|
|
|
self = null;
|
|
|
|
return {done: true, value: undefined};
|
|
|
|
}
|
2016-03-03 06:44:11 +00:00
|
|
|
|
2016-03-20 02:55:19 +00:00
|
|
|
var value;
|
|
|
|
switch (methodName) {
|
|
|
|
case 'entries':
|
|
|
|
value = [index, self[index]];
|
|
|
|
break;
|
|
|
|
case 'keys':
|
|
|
|
value = index;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
value = self[index];
|
|
|
|
}
|
2016-03-03 06:44:11 +00:00
|
|
|
|
2016-03-20 02:55:19 +00:00
|
|
|
index++;
|
|
|
|
return {done: false, value: value};
|
|
|
|
}
|
2016-03-03 06:44:11 +00:00
|
|
|
}
|
2016-03-20 02:55:19 +00:00
|
|
|
});
|
2016-03-03 06:44:11 +00:00
|
|
|
};
|
|
|
|
|
2016-09-08 22:33:42 +00:00
|
|
|
exports[methodName] = {value: method, configurable: true, writable: true};
|
2016-03-03 06:44:11 +00:00
|
|
|
});
|
2016-03-03 07:00:53 +00:00
|
|
|
|
2016-12-20 18:56:51 +00:00
|
|
|
exports[Symbol.iterator] = exports.values;
|