Commit 730c3fa3 authored by adamk@chromium.org's avatar adamk@chromium.org

Don't expose Array.prototype.values as it breaks webcompat

Some versions of Outlook Web Access test for the existence of a 'values'
property on Array instances, so adding the 'values' iterator to the prototype
(even with @@unscopeables) causes breakage.

This matches Gecko: they ship Array.prototype.{keys,entries} but not 'values'.

BUG=409858
LOG=Y
R=arv@chromium.org, danno@chromium.org

Review URL: https://codereview.chromium.org/647703003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24706 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e3ad6930
......@@ -120,8 +120,8 @@ function ExtendArrayPrototype() {
%CheckIsBootstrapping();
InstallFunctions($Array.prototype, DONT_ENUM, $Array(
// No 'values' since it breaks webcompat: http://crbug.com/409858
'entries', ArrayEntries,
'values', ArrayValues,
'keys', ArrayKeys
));
......
......@@ -1499,7 +1499,6 @@ function SetUpArray() {
find: true,
findIndex: true,
keys: true,
values: true,
};
%AddNamedProperty($Array.prototype, symbolUnscopables, unscopables,
DONT_ENUM | READ_ONLY);
......
......@@ -16,8 +16,8 @@ function TestDirectArgumentsIteratorProperty() {
assertTrue(descriptor.writable);
assertFalse(descriptor.enumerable);
assertTrue(descriptor.configurable);
assertEquals(descriptor.value, [].values);
assertEquals(arguments[Symbol.iterator], [].values);
assertEquals(descriptor.value, [][Symbol.iterator]);
assertEquals(arguments[Symbol.iterator], [][Symbol.iterator]);
}
TestDirectArgumentsIteratorProperty();
......@@ -26,7 +26,7 @@ function TestIndirectArgumentsIteratorProperty() {
var o = arguments;
assertTrue(o.hasOwnProperty(Symbol.iterator));
assertFalse(o.propertyIsEnumerable(Symbol.iterator));
assertEquals(o[Symbol.iterator], [].values);
assertEquals(o[Symbol.iterator], [][Symbol.iterator]);
}
TestIndirectArgumentsIteratorProperty();
......@@ -204,27 +204,27 @@ function TestArgumentsAsProto() {
"use strict";
var o = {__proto__:arguments};
assertSame([].values, o[Symbol.iterator]);
assertSame([][Symbol.iterator], o[Symbol.iterator]);
// Make o dict-mode.
%OptimizeObjectForAddingMultipleProperties(o, 0);
assertFalse(o.hasOwnProperty(Symbol.iterator));
assertSame([].values, o[Symbol.iterator]);
assertSame([][Symbol.iterator], o[Symbol.iterator]);
o[Symbol.iterator] = 10;
assertTrue(o.hasOwnProperty(Symbol.iterator));
assertEquals(10, o[Symbol.iterator]);
assertSame([].values, arguments[Symbol.iterator]);
assertSame([][Symbol.iterator], arguments[Symbol.iterator]);
// Frozen o.
o = Object.freeze({__proto__:arguments});
assertSame([].values, o[Symbol.iterator]);
assertSame([][Symbol.iterator], o[Symbol.iterator]);
assertFalse(o.hasOwnProperty(Symbol.iterator));
assertSame([].values, o[Symbol.iterator]);
assertSame([][Symbol.iterator], o[Symbol.iterator]);
// This should throw, but currently it doesn't, because
// ExecutableAccessorInfo callbacks don't see the current strict mode.
// See note in accessors.cc:SetPropertyOnInstanceIfInherited.
o[Symbol.iterator] = 10;
assertFalse(o.hasOwnProperty(Symbol.iterator));
assertEquals([].values, o[Symbol.iterator]);
assertSame([].values, arguments[Symbol.iterator]);
assertEquals([][Symbol.iterator], o[Symbol.iterator]);
assertSame([][Symbol.iterator], arguments[Symbol.iterator]);
}
TestArgumentsAsProto();
......@@ -45,11 +45,8 @@ function assertHasOwnProperty(object, name, attrs) {
function TestArrayPrototype() {
assertHasOwnProperty(Array.prototype, 'entries', DONT_ENUM);
assertHasOwnProperty(Array.prototype, 'values', DONT_ENUM);
assertHasOwnProperty(Array.prototype, 'keys', DONT_ENUM);
assertHasOwnProperty(Array.prototype, Symbol.iterator, DONT_ENUM);
assertEquals(Array.prototype.values, Array.prototype[Symbol.iterator]);
}
TestArrayPrototype();
......@@ -61,7 +58,7 @@ function assertIteratorResult(value, done, result) {
function TestValues() {
var array = ['a', 'b', 'c'];
var iterator = array.values();
var iterator = array[Symbol.iterator]();
assertIteratorResult('a', false, iterator.next());
assertIteratorResult('b', false, iterator.next());
assertIteratorResult('c', false, iterator.next());
......@@ -75,7 +72,7 @@ TestValues();
function TestValuesMutate() {
var array = ['a', 'b', 'c'];
var iterator = array.values();
var iterator = array[Symbol.iterator]();
assertIteratorResult('a', false, iterator.next());
assertIteratorResult('b', false, iterator.next());
assertIteratorResult('c', false, iterator.next());
......@@ -142,17 +139,17 @@ TestEntriesMutate();
function TestArrayIteratorPrototype() {
var array = [];
var iterator = array.values();
var iterator = array.keys();
var ArrayIteratorPrototype = iterator.__proto__;
assertEquals(ArrayIteratorPrototype, array.values().__proto__);
assertEquals(ArrayIteratorPrototype, array[Symbol.iterator]().__proto__);
assertEquals(ArrayIteratorPrototype, array.keys().__proto__);
assertEquals(ArrayIteratorPrototype, array.entries().__proto__);
assertEquals(Object.prototype, ArrayIteratorPrototype.__proto__);
assertEquals('Array Iterator', %_ClassOf(array.values()));
assertEquals('Array Iterator', %_ClassOf(array[Symbol.iterator]()));
assertEquals('Array Iterator', %_ClassOf(array.keys()));
assertEquals('Array Iterator', %_ClassOf(array.entries()));
......@@ -169,7 +166,7 @@ function TestForArrayValues() {
var buffer = [];
var array = [0, 'a', true, false, null, /* hole */, undefined, NaN];
var i = 0;
for (var value of array.values()) {
for (var value of array[Symbol.iterator]()) {
buffer[i++] = value;
}
......@@ -239,7 +236,7 @@ TestForArrayValues();
function TestNonOwnSlots() {
var array = [0];
var iterator = array.values();
var iterator = array[Symbol.iterator]();
var object = {__proto__: iterator};
assertThrows(function() {
......
......@@ -21,9 +21,9 @@ function TestTypedArrayPrototype(constructor) {
assertFalse(constructor.prototype.propertyIsEnumerable(Symbol.iterator));
assertEquals(Array.prototype.entries, constructor.prototype.entries);
assertEquals(Array.prototype.values, constructor.prototype.values);
assertEquals(Array.prototype[Symbol.iterator], constructor.prototype.values);
assertEquals(Array.prototype.keys, constructor.prototype.keys);
assertEquals(Array.prototype.values, constructor.prototype[Symbol.iterator]);
assertEquals(Array.prototype[Symbol.iterator], constructor.prototype[Symbol.iterator]);
}
constructors.forEach(TestTypedArrayPrototype);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment