Nh/symbol iterator android (#732)

* Fix Symbol.iterator on Android
This commit is contained in:
Nabil Hachicha 2016-12-20 18:56:51 +00:00 committed by GitHub
parent 63cd9013cc
commit 43dabf5cbd
2 changed files with 12 additions and 21 deletions

View File

@ -21,17 +21,14 @@
var arrayPrototype = Array.prototype; var arrayPrototype = Array.prototype;
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
var iteratorSymbol = typeof Symbol != 'undefined' && Symbol.iterator;
var iteratorPrototype = {}; var iteratorPrototype = {};
if (iteratorSymbol) {
// These iterators should themselves be iterable. // These iterators should themselves be iterable.
Object.defineProperty(iteratorPrototype, iteratorSymbol, { Object.defineProperty(iteratorPrototype, Symbol.iterator, {
value: function() { value: function() {
return this; return this;
} }
}); });
}
[ [
'join', 'join',
@ -86,6 +83,4 @@ if (iteratorSymbol) {
exports[methodName] = {value: method, configurable: true, writable: true}; exports[methodName] = {value: method, configurable: true, writable: true};
}); });
if (iteratorSymbol) { exports[Symbol.iterator] = exports.values;
exports[iteratorSymbol] = exports.values;
}

View File

@ -588,22 +588,18 @@ module.exports = {
TestCase.assertEqual(list.reduceRight(function(n, p) {return n + p.age}, 0), 33); TestCase.assertEqual(list.reduceRight(function(n, p) {return n + p.age}, 0), 33);
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
var iteratorSymbol = typeof Symbol != 'undefined' && Symbol.iterator;
var iteratorMethodNames = ['entries', 'keys', 'values']; var iteratorMethodNames = ['entries', 'keys', 'values'];
if (iteratorSymbol) { iteratorMethodNames.push(Symbol.iterator);
iteratorMethodNames.push(iteratorSymbol);
}
iteratorMethodNames.forEach(function(methodName) { iteratorMethodNames.forEach(function(methodName) {
var iterator = list[methodName](); var iterator = list[methodName]();
var count = 0; var count = 0;
var result; var result;
if (iteratorSymbol) {
// This iterator should itself be iterable. // This iterator should itself be iterable.
TestCase.assertEqual(iterator[iteratorSymbol](), iterator); // TestCase.assertEqual(iterator[iteratorSymbol](), iterator);
} TestCase.assertEqual(iterator[Symbol.iterator](), iterator);
while ((result = iterator.next()) && !result.done) { while ((result = iterator.next()) && !result.done) {
var value = result.value; var value = result.value;