Commit 6717ac65 authored by adamk@chromium.org's avatar adamk@chromium.org

Array Iterator next should check for own property

Since we are using private symbols for the internal slots we need to
check for a local property.

BUG=None
LOG=Y
R=rossberg@chromium.org

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

Patch from Erik Arvidsson <arv@chromium.org>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21399 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 910050e6
......@@ -38,12 +38,17 @@ function CreateIteratorResultObject(value, done) {
// 15.4.5.2.2 ArrayIterator.prototype.next( )
function ArrayIteratorNext() {
var iterator = ToObject(this);
var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol);
if (!array) {
if (!HAS_PRIVATE(iterator, arrayIteratorObjectSymbol)) {
throw MakeTypeError('incompatible_method_receiver',
['Array Iterator.prototype.next']);
}
var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol);
if (IS_UNDEFINED(array)) {
return CreateIteratorResultObject(UNDEFINED, true);
}
var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol);
var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol);
var length = TO_UINT32(array.length);
......@@ -51,17 +56,19 @@ function ArrayIteratorNext() {
// "sparse" is never used.
if (index >= length) {
SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY);
SET_PRIVATE(iterator, arrayIteratorObjectSymbol, UNDEFINED);
return CreateIteratorResultObject(UNDEFINED, true);
}
SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1);
if (itemKind == ITERATOR_KIND_VALUES)
if (itemKind == ITERATOR_KIND_VALUES) {
return CreateIteratorResultObject(array[index], false);
}
if (itemKind == ITERATOR_KIND_ENTRIES)
if (itemKind == ITERATOR_KIND_ENTRIES) {
return CreateIteratorResultObject([index, array[index]], false);
}
return CreateIteratorResultObject(index, false);
}
......
......@@ -214,3 +214,15 @@ function TestForArrayEntries() {
}
}
TestForArrayEntries();
function TestNonOwnSlots() {
var array = [0];
var iterator = array.values();
var object = {__proto__: iterator};
assertThrows(function() {
object.next();
}, TypeError);
}
TestNonOwnSlots();
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