Bug 1304528 - Remove an overzealous compartment assert. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 29 Sep 2016 15:26:07 +0200
changeset 315825 2af19b7c731b363ff93fed151aee22979f8f44c9
parent 315824 a13cbb3da4019d38f8426b323be5ff8a198d5f4d
child 315826 98eb5919336965816379b64f68c732e4d19b66fe
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1304528
milestone52.0a1
Bug 1304528 - Remove an overzealous compartment assert. r=jonco
js/src/jsiter.cpp
--- a/js/src/jsiter.cpp
+++ b/js/src/jsiter.cpp
@@ -818,22 +818,16 @@ CanCacheIterableObject(JSContext* cx, JS
         }
     }
     return true;
 }
 
 bool
 js::GetIterator(JSContext* cx, HandleObject obj, unsigned flags, MutableHandleObject objp)
 {
-#ifdef DEBUG
-    auto assertCompartment = mozilla::MakeScopeExit([&] {
-        assertSameCompartment(cx, objp);
-    });
-#endif
-
     if (obj->is<PropertyIteratorObject>() || obj->is<LegacyGeneratorObject>()) {
         objp.set(obj);
         return true;
     }
 
     // We should only call the enumerate trap for "for-in".
     // Or when we call GetIterator from the Proxy [[Enumerate]] hook.
     // JSITER_ENUMERATE is just an optimization and the same
@@ -855,16 +849,17 @@ js::GetIterator(JSContext* cx, HandleObj
                 ReceiverGuard(obj) == lastni->guard_array[0])
             {
                 JSObject* proto = obj->staticPrototype();
                 if (CanCompareIterableObjectToCache(proto) &&
                     ReceiverGuard(proto) == lastni->guard_array[1] &&
                     !proto->staticPrototype())
                 {
                     objp.set(last);
+                    assertSameCompartment(cx, objp);
                     UpdateNativeIterator(lastni, obj);
                     RegisterEnumerator(cx, last, lastni);
                     return true;
                 }
             }
         }
 
         // The iterator object for JSITER_ENUMERATE never escapes, so we don't
@@ -905,18 +900,20 @@ js::GetIterator(JSContext* cx, HandleObj
                 return true;
             }
         }
     }
 
   miss:
     if (!GetCustomIterator(cx, obj, flags, objp))
         return false;
-    if (objp)
+    if (objp) {
+        assertSameCompartment(cx, objp);
         return true;
+    }
 
     AutoIdVector keys(cx);
     if (flags & JSITER_FOREACH) {
         MOZ_ASSERT(guards.empty());
 
         if (!Snapshot(cx, obj, flags, &keys))
             return false;
         if (!VectorToValueIterator(cx, obj, flags, keys, objp))
@@ -924,16 +921,17 @@ js::GetIterator(JSContext* cx, HandleObj
     } else {
         if (!Snapshot(cx, obj, flags, &keys))
             return false;
         if (!VectorToKeyIterator(cx, obj, flags, keys, guards.length(), key, objp))
             return false;
     }
 
     PropertyIteratorObject* iterobj = &objp->as<PropertyIteratorObject>();
+    assertSameCompartment(cx, iterobj);
 
     /* Cache the iterator object if possible. */
     if (guards.length())
         cx->caches.nativeIterCache.set(key, iterobj);
 
     if (guards.length() == 2)
         cx->compartment()->lastCachedNativeIterator = iterobj;
     return true;