Adjust compartment assertions in the new implementations of jsdbgapi.h Trap entry points. Some are tightened up, but JS_ClearScriptTraps no longer asserts, as that caused a test to fail in debug builds.
authorJason Orendorff <jorendorff@mozilla.com>
Wed, 29 Jun 2011 10:16:55 -0500
changeset 74492 ba9d8b33753c45c21443be2d78ef2348ffe58395
parent 74491 63ee1fe5025c99e88e20847e1e533d2af9117cb8
child 74493 8fb3609398571bce63e8186109360e24c860859c
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
milestone7.0a1
Adjust compartment assertions in the new implementations of jsdbgapi.h Trap entry points. Some are tightened up, but JS_ClearScriptTraps no longer asserts, as that caused a test to fail in debug builds.
js/src/jsdbgapi.cpp
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -205,18 +205,19 @@ JS_SetSingleStepMode(JSContext *cx, JSSc
         return JS_FALSE;
 
     return js_SetSingleStepMode(cx, script, singleStep);
 }
 
 jsbytecode *
 js_UntrapScriptCode(JSContext *cx, JSScript *script)
 {
+    assertSameCompartment(cx, script);
+
     jsbytecode *code = script->code;
-
     BreakpointSiteMap &sites = script->compartment->breakpointSites;
     for (BreakpointSiteMap::Range r = sites.all(); !r.empty(); r.popFront()) {
         BreakpointSite *site = r.front().value;
         if (site->script == script && size_t(site->pc - script->code) < script->length) {
             if (code == script->code) {
                 size_t nbytes = script->length * sizeof(jsbytecode);
                 jssrcnote *notes = script->notes();
                 jssrcnote *sn;
@@ -256,30 +257,37 @@ JS_GetTrapOpcode(JSContext *cx, JSScript
     BreakpointSite *site = script->compartment->getBreakpointSite(pc);
     return site ? site->realOpcode : JSOp(*pc);
 }
 
 JS_PUBLIC_API(void)
 JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
              JSTrapHandler *handlerp, jsval *closurep)
 {
+    assertSameCompartment(cx, script);
+
     if (BreakpointSite *site = script->compartment->getBreakpointSite(pc)) {
         site->clearTrap(cx, NULL, handlerp, Valueify(closurep));
     } else {
         if (handlerp)
             *handlerp = NULL;
         if (closurep)
             *closurep = JSVAL_VOID;
     }
 }
 
 JS_PUBLIC_API(void)
 JS_ClearScriptTraps(JSContext *cx, JSScript *script)
 {
-    assertSameCompartment(cx, script);
+    /*
+     * No assertSameCompartment here, because this can be called during
+     * GC. Rather than require the caller to figure out whether GC is going on
+     * and conditionally enter a cross-compartment call, we simply omit the
+     * assertion.
+     */
     script->compartment->clearTraps(cx, script);
 }
 
 JS_PUBLIC_API(void)
 JS_ClearAllTrapsForCompartment(JSContext *cx)
 {
     cx->compartment->clearTraps(cx, NULL);
 }