Bug 536137 - SJOWs don't enumerate properties named 'next'. r=jst
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 04 Jan 2010 22:59:46 -0800
changeset 39403 050abb8ffcd75c72e8183adc5f54f499c266be6c
parent 39402 28be6df4ba1227ba53a6394e0379f01962edfe9f
child 39404 563a0f2f93c1a4668c7b54d570ffd92af7c470e4
push id12176
push usermrbkap@mozilla.com
push dateSat, 13 Mar 2010 20:50:12 +0000
treeherdermozilla-central@333589ef694b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs536137
milestone1.9.3a3pre
Bug 536137 - SJOWs don't enumerate properties named 'next'. r=jst
js/src/xpconnect/src/XPCWrapper.cpp
js/src/xpconnect/tests/mochitest/test_wrappers.html
--- a/js/src/xpconnect/src/XPCWrapper.cpp
+++ b/js/src/xpconnect/src/XPCWrapper.cpp
@@ -195,22 +195,16 @@ CreateIteratorObj(JSContext *cx, JSObjec
   JSAutoTempValueRooter tvr(cx, OBJECT_TO_JSVAL(iterObj));
 
   // Do this sooner rather than later to avoid complications in
   // IteratorFinalize.
   if (!JS_SetReservedSlot(cx, iterObj, 0, PRIVATE_TO_JSVAL(nsnull))) {
     return nsnull;
   }
 
-  // Initialize iterObj.
-  if (!JS_DefineFunction(cx, iterObj, "next", (JSNative)IteratorNext, 0,
-                         JSFUN_FAST_NATIVE)) {
-    return nsnull;
-  }
-
   if (XPCNativeWrapper::IsNativeWrapper(wrapperObj)) {
     // For native wrappers, expandos on the wrapper itself aren't propagated
     // to the wrapped object, so we have to actually iterate the wrapper here.
     // In order to do so, we set the prototype of the iter to the wrapper,
     // call enumerate, and then re-set the prototype. As we do this, we have
     // to protec the temporary wrapper from garbage collection.
 
     JSAutoTempValueRooter tvr(cx, tempWrapper);
@@ -228,16 +222,22 @@ CreateIteratorObj(JSContext *cx, JSObjec
     }
   } while ((innerObj = STOBJ_GET_PROTO(innerObj)) != nsnull);
 
   JSIdArray *ida = JS_Enumerate(cx, iterObj);
   if (!ida) {
     return nsnull;
   }
 
+  // Initialize iterObj.
+  if (!JS_DefineFunction(cx, iterObj, "next", (JSNative)IteratorNext, 0,
+                         JSFUN_FAST_NATIVE)) {
+    return nsnull;
+  }
+
   if (!JS_SetReservedSlot(cx, iterObj, 0, PRIVATE_TO_JSVAL(ida)) ||
       !JS_SetReservedSlot(cx, iterObj, 1, JSVAL_ZERO) ||
       !JS_SetReservedSlot(cx, iterObj, 2, BOOLEAN_TO_JSVAL(keysonly))) {
     return nsnull;
   }
 
   if (!JS_SetPrototype(cx, iterObj, nsnull)) {
     return nsnull;
--- a/js/src/xpconnect/tests/mochitest/test_wrappers.html
+++ b/js/src/xpconnect/tests/mochitest/test_wrappers.html
@@ -43,20 +43,20 @@
        expected.sort().toString(),
        'enumeration over XOWs walks the prototype chain');
 
     is(xpcnw_answer.sort().toString(),
        xpcnw_expected.sort().toString(),
        'enumeration over XPCNWs walks the prototype chain');
 
     let sjow_answer = [];
-    let (obj = { a: 3 }) {
+    let (obj = { a: 3, next:1 }) {
         for (let i in XPCSafeJSObjectWrapper({ __proto__: obj}))
             sjow_answer.push(i);
-        is(sjow_answer.toString(), 'a',
+        is(sjow_answer.sort().toString(), ['a', 'next'].sort().toString(),
            'enumeration over SJOWs walks the prototype chain');
     }
 
     sjow_answer = [];
     for (let i in XPCSafeJSObjectWrapper(location))
         sjow_answer.push(i);
 
     is(sjow_answer.sort().toString(),