Bug 688571 - JS_PropertyIterator is broken. r=Waldo.
authorJason Orendorff <jorendorff@mozilla.com>
Thu, 29 Sep 2011 15:05:07 -0500
changeset 77880 071c48a989bb43092da6db95f2f4358ef6e16b97
parent 77879 77b3b28682690a9a0d35d719a4ff09715d2319aa
child 77881 ba2d3e4cd88a56d679be1577ab907e15cdb6f2d1
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersWaldo
bugs688571
milestone10.0a1
Bug 688571 - JS_PropertyIterator is broken. r=Waldo.
js/src/jsapi-tests/testDebugger.cpp
js/src/jsdbgapi.cpp
--- a/js/src/jsapi-tests/testDebugger.cpp
+++ b/js/src/jsapi-tests/testDebugger.cpp
@@ -287,8 +287,37 @@ BEGIN_TEST(testDebugger_singleStepThrow)
     }
 
     static JSTrapStatus
     onStep(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval, void *closure)
     {
         return JSTRAP_CONTINUE;
     }
 END_TEST(testDebugger_singleStepThrow)
+
+BEGIN_TEST(testDebugger_emptyObjectPropertyIterator)
+{
+    JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
+    JSScopeProperty *prop = NULL;
+    CHECK_EQUAL(JS_PropertyIterator(obj, &prop), NULL);
+    CHECK_EQUAL(prop, NULL);
+
+    return true;
+}
+END_TEST(testDebugger_emptyObjectPropertyIterator)
+
+BEGIN_TEST(testDebugger_nonEmptyObjectPropertyIterator)
+{
+    jsval v;
+    EVAL("({a: 15})", &v);
+    JSObject *obj = JSVAL_TO_OBJECT(v);
+    JSScopeProperty *prop = NULL;
+    CHECK(JS_PropertyIterator(obj, &prop));
+    JSPropertyDesc desc;
+    CHECK(JS_GetPropertyDesc(cx, obj, prop, &desc));
+    CHECK_EQUAL(JSVAL_IS_INT(desc.value), true);
+    CHECK_EQUAL(JSVAL_TO_INT(desc.value), 15);
+    CHECK_EQUAL(JS_PropertyIterator(obj, &prop), NULL);
+    CHECK_EQUAL(prop, NULL);
+
+    return true;
+}
+END_TEST(testDebugger_nonEmptyObjectPropertyIterator)
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -842,24 +842,24 @@ JS_EvaluateInStackFrame(JSContext *cx, J
 
 JS_PUBLIC_API(JSScopeProperty *)
 JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp)
 {
     const Shape *shape;
 
     /* The caller passes null in *iteratorp to get things started. */
     shape = (Shape *) *iteratorp;
-    if (!shape) {
+    if (!shape)
         shape = obj->lastProperty();
-    } else {
+    else
         shape = shape->previous();
-        if (!shape->previous()) {
-            JS_ASSERT(JSID_IS_EMPTY(shape->propid));
-            shape = NULL;
-        }
+
+    if (!shape->previous()) {
+        JS_ASSERT(JSID_IS_EMPTY(shape->propid));
+        shape = NULL;
     }
 
     return *iteratorp = reinterpret_cast<JSScopeProperty *>(const_cast<Shape *>(shape));
 }
 
 JS_PUBLIC_API(JSBool)
 JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
                    JSPropertyDesc *pd)