date: Wed Jun 05 14:17:35 2013 -0500

Bug 875433 - Array.prototype.iterator is the same function object as .values. r=jorendorff.
This commit is contained in:
Sankha Narayan Guria 2013-07-03 15:49:18 -05:00
parent 3d2ee579ab
commit a9ca65b76b
2 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,4 @@
// Array.prototype.iterator is the same function object as .values.
assertEq(Array.prototype.values, Array.prototype.iterator);
assertEq(Array.prototype.iterator.name, "values");

View File

@ -2732,7 +2732,6 @@ static const JSFunctionSpec array_methods[] = {
{"find", {NULL, NULL}, 1,0, "ArrayFind"},
{"findIndex", {NULL, NULL}, 1,0, "ArrayFindIndex"},
JS_FN("iterator", JS_ArrayIterator, 0,0),
JS_FS_END
};
@ -2865,6 +2864,14 @@ js_InitArrayClass(JSContext *cx, HandleObject obj)
if (!DefineConstructorAndPrototype(cx, global, JSProto_Array, ctor, arrayProto))
return NULL;
JSFunction *fun = JS_DefineFunction(cx, arrayProto, "values", JS_ArrayIterator, 0, 0);
if (!fun)
return NULL;
RootedValue funval(cx, ObjectValue(*fun));
if (!JS_DefineProperty(cx, arrayProto, "iterator", funval, NULL, NULL, 0))
return NULL;
return arrayProto;
}