Fixing bug 417852. Push the context we're using to clear scopes on to make code down the road find the right context. r=dveditz@cruzio.com, sr=bzbarsky@mit.edu
authorjst@mozilla.org
Thu, 21 Feb 2008 15:51:02 -0800
changeset 12050 4d309364649346dc03d5641b226234bcb63ab970
parent 12049 f212da74389af8fa11930b0b6d51e5eb32e61010
child 12051 e7904d90ed93f50d390a449b57c7d456f02c151e
push idunknown
push userunknown
push dateunknown
reviewersdveditz, bzbarsky
bugs417852
milestone1.9b4pre
Fixing bug 417852. Push the context we're using to clear scopes on to make code down the road find the right context. r=dveditz@cruzio.com, sr=bzbarsky@mit.edu
dom/src/base/nsJSEnvironment.cpp
--- a/dom/src/base/nsJSEnvironment.cpp
+++ b/dom/src/base/nsJSEnvironment.cpp
@@ -1656,17 +1656,17 @@ nsJSContext::ExecuteScript(void *aScript
   // operation callback or from ScriptEvaluated.
   jsval val;
   JSBool ok;
 
   nsJSContext::TerminationFuncHolder holder(this);
   JSAutoRequest ar(mContext);
   ok = ::JS_ExecuteScript(mContext,
                           (JSObject *)aScopeObject,
-                          (JSScript*) ::JS_GetPrivate(mContext,
+                          (JSScript*)::JS_GetPrivate(mContext,
                           (JSObject*)aScriptObject),
                           &val);
 
   if (ok) {
     // If all went well, convert val to a string (XXXbe unless undefined?).
     rv = JSValueToAString(mContext, val, aRetValue, aIsUndefined);
   } else {
     if (aIsUndefined) {
@@ -3132,16 +3132,23 @@ nsJSContext::InitClasses(void *aGlobalOb
   JSOptionChangedCallback(js_options_dot_str, this);
     
   return rv;
 }
 
 void
 nsJSContext::ClearScope(void *aGlobalObj, PRBool aClearFromProtoChain)
 {
+  // Push our JSContext on our thread's context stack.
+  nsCOMPtr<nsIJSContextStack> stack =
+    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
+  if (stack && NS_FAILED(stack->Push(mContext))) {
+    stack = nsnull;
+  }
+
   if (aGlobalObj) {
     JSObject *obj = (JSObject *)aGlobalObj;
     JSAutoRequest ar(mContext);
     ::JS_ClearScope(mContext, obj);
 
     // Always clear watchpoints, to deal with two cases:
     // 1.  The first document for this window is loading, and a miscreant has
     //     preset watchpoints on the window object in order to attack the new
@@ -3162,18 +3169,22 @@ nsJSContext::ClearScope(void *aGlobalObj
       nsWindowSH::InvalidateGlobalScopePolluter(mContext, obj);
 
       // Clear up obj's prototype chain, but not Object.prototype.
       for (JSObject *o = ::JS_GetPrototype(mContext, obj), *next;
            o && (next = ::JS_GetPrototype(mContext, o)); o = next)
         ::JS_ClearScope(mContext, o);
     }
   }
+
   ::JS_ClearRegExpStatics(mContext);
 
+  if (stack) {
+    stack->Pop(nsnull);
+  }
 }
 
 void
 nsJSContext::WillInitializeContext()
 {
   mIsInitialized = PR_FALSE;
 }