Bug 566846 - Make sure the engine knows that wrapper iterators are real iterators. r=gal

This commit is contained in:
Blake Kaplan 2010-05-28 15:20:52 -07:00
Родитель 16f5b6375a
Коммит 36a634d5ff
2 изменённых файлов: 35 добавлений и 9 удалений

Просмотреть файл

@ -154,14 +154,28 @@ IteratorNext(JSContext *cx, uintN argc, jsval *vp)
return JS_TRUE;
}
static JSClass IteratorClass = {
"XOW iterator", JSCLASS_HAS_RESERVED_SLOTS(3),
static JSObject *
IteratorIterator(JSContext *, JSObject *obj, JSBool)
{
return obj;
}
static JSExtendedClass IteratorClass = {
{ "Wrapper iterator",
JSCLASS_HAS_RESERVED_SLOTS(3) | JSCLASS_IS_EXTENDED,
JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub,
JS_ConvertStub, IteratorFinalize,
JSCLASS_NO_OPTIONAL_MEMBERS
},
nsnull, // equality
nsnull, nsnull, // innerObject/outerObject
IteratorIterator,
nsnull, // wrappedObject
JSCLASS_NO_RESERVED_MEMBERS
};
JSBool
@ -317,7 +331,7 @@ CreateIteratorObj(JSContext *cx, JSObject *tempWrapper,
// delegates (via the __proto__ link) to the wrapper.
JSObject *iterObj =
JS_NewObjectWithGivenProto(cx, &IteratorClass, tempWrapper, wrapperObj);
JS_NewObjectWithGivenProto(cx, &IteratorClass.base, tempWrapper, wrapperObj);
if (!iterObj) {
return nsnull;
}
@ -380,7 +394,7 @@ JSObject *
CreateSimpleIterator(JSContext *cx, JSObject *scope, JSBool keysonly,
JSObject *propertyContainer)
{
JSObject *iterObj = JS_NewObjectWithGivenProto(cx, &IteratorClass,
JSObject *iterObj = JS_NewObjectWithGivenProto(cx, &IteratorClass.base,
propertyContainer, scope);
if (!iterObj) {
return nsnull;

Просмотреть файл

@ -47,6 +47,18 @@
xpcnw_expected.sort().toString(),
'enumeration over XPCNWs walks the prototype chain');
var for_each_expected = [];
for each (let i in new XPCNativeWrapper(location))
for_each_expected.push(typeof i);
var for_each_answer = [];
for each (let i in Iterator(new XPCNativeWrapper(location)))
for_each_answer.push(typeof i);
is(for_each_answer.sort().toString(),
for_each_expected.sort().toString(),
'wrapper iterators are properly iterators');
let sjow_answer = [];
let (obj = { a: 3, next:1 }) {
for (let i in XPCSafeJSObjectWrapper({ __proto__: obj}))