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

View File

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