Commits

ms2ger committed 17ac0fc

Landed all patches.

Comments (0)

Files changed (30)

AutoIdVector

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part y: Move AutoIdVector to jsapi.h; r=evilpie
-
-diff --git a/js/src/jsapi.h b/js/src/jsapi.h
---- a/js/src/jsapi.h
-+++ b/js/src/jsapi.h
-@@ -51,16 +51,17 @@
- #include "js-config.h"
- #include "jspubtd.h"
- #include "jsutil.h"
- #include "jsval.h"
- 
- #include "js/Utility.h"
- 
- #ifdef __cplusplus
-+#include "jsalloc.h"
- #include "js/Vector.h"
- #include "mozilla/Attributes.h"
- #endif
- 
- /************************************************************************/
- 
- /* JS::Value can store a full int32_t. */
- #define JSVAL_INT_BITS          32
-@@ -1131,16 +1132,29 @@ class AutoValueVector : public AutoVecto
-         : AutoVectorRooter<Value>(cx, VALVECTOR)
-     {
-         JS_GUARD_OBJECT_NOTIFIER_INIT;
-     }
- 
-     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
- };
- 
-+class AutoIdVector : public AutoVectorRooter<jsid>
-+{
-+  public:
-+    explicit AutoIdVector(JSContext *cx
-+                          JS_GUARD_OBJECT_NOTIFIER_PARAM)
-+        : AutoVectorRooter<jsid>(cx, IDVECTOR)
-+    {
-+        JS_GUARD_OBJECT_NOTIFIER_INIT;
-+    }
-+
-+    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
-+};
-+
- }  /* namespace JS */
- 
- /************************************************************************/
- 
- /*
-  * JS::Value and jsval are the same type; jsval is the old name, kept around
-  * for backwards compatibility along with all the JSVAL_* operations below.
-  * jsval_layout is an implementation detail and should not be used externally.
-diff --git a/js/src/jsclass.h b/js/src/jsclass.h
---- a/js/src/jsclass.h
-+++ b/js/src/jsclass.h
-@@ -47,17 +47,16 @@
-  */
- #include "jsapi.h"
- #include "jsprvtd.h"
- 
- #ifdef __cplusplus
- 
- namespace js {
- 
--class AutoIdVector;
- class PropertyName;
- class SpecialId;
- 
- static JS_ALWAYS_INLINE jsid
- SPECIALID_TO_JSID(const SpecialId &sid);
- 
- /*
-  * We partition the ways to refer to a property into three: by an index
-diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
---- a/js/src/jscntxt.h
-+++ b/js/src/jscntxt.h
-@@ -2097,29 +2097,16 @@ class AutoObjectVector : public AutoVect
-         : AutoVectorRooter<JSObject *>(cx, OBJVECTOR)
-     {
-         JS_GUARD_OBJECT_NOTIFIER_INIT;
-     }
- 
-     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
- };
- 
--class AutoIdVector : public AutoVectorRooter<jsid>
--{
--  public:
--    explicit AutoIdVector(JSContext *cx
--                          JS_GUARD_OBJECT_NOTIFIER_PARAM)
--        : AutoVectorRooter<jsid>(cx, IDVECTOR)
--    {
--        JS_GUARD_OBJECT_NOTIFIER_INIT;
--    }
--
--    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
--};
--
- class AutoShapeVector : public AutoVectorRooter<const Shape *>
- {
-   public:
-     explicit AutoShapeVector(JSContext *cx
-                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
-         : AutoVectorRooter<const Shape *>(cx, SHAPEVECTOR)
-     {
-         JS_GUARD_OBJECT_NOTIFIER_INIT;
-diff --git a/js/src/jsgc.h b/js/src/jsgc.h
---- a/js/src/jsgc.h
-+++ b/js/src/jsgc.h
-@@ -1305,18 +1305,16 @@ struct WrapperHasher
-         return uint32_t(bits) ^ uint32_t(bits >> 32);
-     }
- 
-     static bool match(const Value &l, const Value &k) { return l == k; }
- };
- 
- typedef HashMap<Value, Value, WrapperHasher, SystemAllocPolicy> WrapperMap;
- 
--class AutoIdVector;
--
- } /* namespace js */
- 
- #ifdef DEBUG
- extern bool
- CheckAllocation(JSContext *cx);
- #endif
- 
- extern JS_FRIEND_API(JSGCTraceKind)
-diff --git a/js/xpconnect/src/dombindings.cpp b/js/xpconnect/src/dombindings.cpp
---- a/js/xpconnect/src/dombindings.cpp
-+++ b/js/xpconnect/src/dombindings.cpp
-@@ -45,21 +45,19 @@
- #include "XPCQuickStubs.h"
- #include "XPCWrapper.h"
- #include "WrapperFactory.h"
- #include "nsDOMClassInfo.h"
- #include "nsGlobalWindow.h"
- #include "nsWrapperCacheInlines.h"
- 
- #include "jsapi.h"
--
--#include "jscntxt.h" // js::AutoIdVector
-+#include "jsatom.h"
- 
- using namespace JS;
--using js::AutoIdVector;
- 
- namespace mozilla {
- namespace dom {
- namespace binding {
- 
- 
- static jsid s_constructor_id = JSID_VOID;
- static jsid s_prototype_id = JSID_VOID;
-@@ -737,17 +735,17 @@ ListBase<LC>::getOwnPropertyNames(JSCont
-     JS_ASSERT(int32_t(length) >= 0);
-     for (int32_t i = 0; i < int32_t(length); ++i) {
-         if (!props.append(INT_TO_JSID(i)))
-             return false;
-     }
- 
-     JSObject *expando;
-     if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = getExpandoObject(proxy)) &&
--        !GetPropertyNames(cx, expando, JSITER_OWNONLY | JSITER_HIDDEN, &props))
-+        !js::GetPropertyNames(cx, expando, JSITER_OWNONLY | JSITER_HIDDEN, &props))
-         return false;
- 
-     // FIXME: Add named items
-     return true;
- }
- 
- template<class LC>
- bool
-diff --git a/js/xpconnect/src/dombindings.h b/js/xpconnect/src/dombindings.h
---- a/js/xpconnect/src/dombindings.h
-+++ b/js/xpconnect/src/dombindings.h
-@@ -213,29 +213,29 @@ public:
-     static JSObject *getPrototype(JSContext *cx, XPCWrappedNativeScope *scope, bool *enabled);
- 
-     bool getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
-                                JSPropertyDescriptor *desc);
-     bool getOwnPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id, bool set,
-                                   JSPropertyDescriptor *desc);
-     bool defineProperty(JSContext *cx, JSObject *proxy, jsid id,
-                         JSPropertyDescriptor *desc);
--    bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
-+    bool getOwnPropertyNames(JSContext *cx, JSObject *proxy, JS::AutoIdVector &props);
-     bool delete_(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
--    bool enumerate(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
-+    bool enumerate(JSContext *cx, JSObject *proxy, JS::AutoIdVector &props);
-     bool fix(JSContext *cx, JSObject *proxy, JS::Value *vp);
- 
-     bool has(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
-     bool hasOwn(JSContext *cx, JSObject *proxy, jsid id, bool *bp);
-     bool get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, JS::Value *vp);
-     bool getElementIfPresent(JSContext *cx, JSObject *proxy, JSObject *receiver,
-                              uint32_t index, JS::Value *vp, bool *present);
-     bool set(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, bool strict,
-              JS::Value *vp);
--    bool keys(JSContext *cx, JSObject *proxy, js::AutoIdVector &props);
-+    bool keys(JSContext *cx, JSObject *proxy, JS::AutoIdVector &props);
-     bool iterate(JSContext *cx, JSObject *proxy, uintN flags, JS::Value *vp);
- 
-     /* Spidermonkey extensions. */
-     bool hasInstance(JSContext *cx, JSObject *proxy, const JS::Value *vp, bool *bp);
-     JSString *obj_toString(JSContext *cx, JSObject *proxy);
-     void finalize(JSContext *cx, JSObject *proxy);
- 
-     static bool proxyHandlerIsList(js::ProxyHandler *handler) {
-diff --git a/js/xpconnect/wrappers/FilteringWrapper.cpp b/js/xpconnect/wrappers/FilteringWrapper.cpp
---- a/js/xpconnect/wrappers/FilteringWrapper.cpp
-+++ b/js/xpconnect/wrappers/FilteringWrapper.cpp
-@@ -40,17 +40,17 @@
- #include "FilteringWrapper.h"
- #include "AccessCheck.h"
- #include "CrossOriginWrapper.h"
- #include "XrayWrapper.h"
- #include "WrapperFactory.h"
- 
- #include "XPCWrapper.h"
- 
--#include "jscntxt.h" // js::AutoIdVector
-+#include "jsapi.h"
- 
- using namespace js;
- 
- namespace xpc {
- 
- template <typename Base, typename Policy>
- FilteringWrapper<Base, Policy>::FilteringWrapper(uintN flags) : Base(flags)
- {
-diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp
---- a/js/xpconnect/wrappers/XrayWrapper.cpp
-+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
-@@ -44,17 +44,17 @@
- #include "WrapperFactory.h"
- 
- #include "nsINode.h"
- #include "nsIDocument.h"
- 
- #include "XPCWrapper.h"
- #include "xpcprivate.h"
- 
--#include "jscntxt.h" // js::AutoIdVector
-+#include "jsapi.h"
- 
- namespace xpc {
- 
- using namespace js;
- 
- static const uint32_t JSSLOT_WN = 0;
- static const uint32_t JSSLOT_RESOLVING = 1;
- static const uint32_t JSSLOT_EXPANDO = 2;
-@@ -829,17 +829,17 @@ XrayWrapper<Base>::defineProperty(JSCont
-     if (!expando)
-         return false;
- 
-     return JS_DefinePropertyById(cx, expando, id, jsdesc->value, jsdesc->getter, jsdesc->setter,
-                                  jsdesc->attrs);
- }
- 
- static bool
--EnumerateNames(JSContext *cx, JSObject *wrapper, uintN flags, js::AutoIdVector &props)
-+EnumerateNames(JSContext *cx, JSObject *wrapper, uintN flags, JS::AutoIdVector &props)
- {
-     JSObject *holder = GetHolder(wrapper);
- 
-     JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
- 
-     // Redirect access straight to the wrapper if we should be transparent.
-     if (XrayUtils::IsTransparent(cx, wrapper)) {
-         JSAutoEnterCompartment ac;
-@@ -855,17 +855,17 @@ EnumerateNames(JSContext *cx, JSObject *
-     }
- 
-     // Enumerate expando properties first.
-     JSObject *expando = GetExpandoObject(holder);
-     if (expando && !js::GetPropertyNames(cx, expando, flags, &props))
-         return false;
- 
-     // Force all native properties to be materialized onto the wrapped native.
--    js::AutoIdVector wnProps(cx);
-+    JS::AutoIdVector wnProps(cx);
-     {
-         JSAutoEnterCompartment ac;
-         if (!ac.enter(cx, wnObject))
-             return false;
-         if (!js::GetPropertyNames(cx, wnObject, flags, &wnProps))
-             return false;
-     }
- 
-@@ -879,17 +879,17 @@ EnumerateNames(JSContext *cx, JSObject *
-             props.append(id);
-     }
-     return true;
- }
- 
- template <typename Base>
- bool
- XrayWrapper<Base>::getOwnPropertyNames(JSContext *cx, JSObject *wrapper,
--                                       js::AutoIdVector &props)
-+                                       JS::AutoIdVector &props)
- {
-     return EnumerateNames(cx, wrapper, JSITER_OWNONLY | JSITER_HIDDEN, props);
- }
- 
- template <typename Base>
- bool
- XrayWrapper<Base>::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
- {
-@@ -920,17 +920,17 @@ XrayWrapper<Base>::delete_(JSContext *cx
-     }
- 
-     *bp = !!b;
-     return true;
- }
- 
- template <typename Base>
- bool
--XrayWrapper<Base>::enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props)
-+XrayWrapper<Base>::enumerate(JSContext *cx, JSObject *wrapper, JS::AutoIdVector &props)
- {
-     return EnumerateNames(cx, wrapper, 0, props);
- }
- 
- template <typename Base>
- bool
- XrayWrapper<Base>::fix(JSContext *cx, JSObject *proxy, js::Value *vp)
- {
-@@ -973,17 +973,17 @@ bool
- XrayWrapper<Base>::hasOwn(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
- {
-     // Skip our Base if it isn't already ProxyHandler.
-     return ProxyHandler::hasOwn(cx, wrapper, id, bp);
- }
- 
- template <typename Base>
- bool
--XrayWrapper<Base>::keys(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props)
-+XrayWrapper<Base>::keys(JSContext *cx, JSObject *wrapper, JS::AutoIdVector &props)
- {
-     // Skip our Base if it isn't already ProxyHandler.
-     return ProxyHandler::keys(cx, wrapper, props);
- }
- 
- template <typename Base>
- bool
- XrayWrapper<Base>::iterate(JSContext *cx, JSObject *wrapper, uintN flags, js::Value *vp)
-@@ -1253,17 +1253,17 @@ XrayProxy::defineProperty(JSContext *cx,
-     if (existing_desc.obj && (existing_desc.attrs & JSPROP_PERMANENT))
-         return true; // silently ignore attempt to overwrite native property
- 
-     return JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter, desc->setter,
-                                  desc->attrs);
- }
- 
- static bool
--EnumerateProxyNames(JSContext *cx, JSObject *wrapper, uintN flags, js::AutoIdVector &props)
-+EnumerateProxyNames(JSContext *cx, JSObject *wrapper, uintN flags, JS::AutoIdVector &props)
- {
-     JSObject *obj = &js::GetProxyPrivate(wrapper).toObject();
- 
-     // Redirect access straight to the wrapper if we should be transparent.
-     if (XrayUtils::IsTransparent(cx, wrapper)) {
-         JSAutoEnterCompartment ac;
-         if (!ac.enter(cx, obj))
-             return false;
-@@ -1278,17 +1278,17 @@ EnumerateProxyNames(JSContext *cx, JSObj
- 
-     if (flags & (JSITER_OWNONLY | JSITER_HIDDEN))
-         return js::GetProxyHandler(obj)->getOwnPropertyNames(cx, wrapper, props);
- 
-     return js::GetProxyHandler(obj)->enumerate(cx, wrapper, props);
- }
- 
- bool
--XrayProxy::getOwnPropertyNames(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props)
-+XrayProxy::getOwnPropertyNames(JSContext *cx, JSObject *wrapper, JS::AutoIdVector &props)
- {
-     return EnumerateProxyNames(cx, wrapper, JSITER_OWNONLY | JSITER_HIDDEN, props);
- }
- 
- bool
- XrayProxy::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
- {
-     JSObject *obj = &js::GetProxyPrivate(wrapper).toObject();
-@@ -1313,17 +1313,17 @@ XrayProxy::delete_(JSContext *cx, JSObje
-     JSObject *holder;
-     if (*bp && (holder = GetHolderObject(cx, wrapper, false)))
-         JS_DeletePropertyById(cx, holder, id);
- 
-     return true;
- }
- 
- bool
--XrayProxy::enumerate(JSContext *cx, JSObject *wrapper, js::AutoIdVector &props)
-+XrayProxy::enumerate(JSContext *cx, JSObject *wrapper, JS::AutoIdVector &props)
- {
-     return EnumerateProxyNames(cx, wrapper, 0, props);
- }
- 
- XrayProxy
- XrayProxy::singleton(0);
- 
- 

AutoLockGC

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part a: Move AutoLockGC to jsfriendapi.h; r=igor
-
-diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
---- a/js/src/jscntxt.h
-+++ b/js/src/jscntxt.h
-@@ -1613,48 +1613,16 @@ class AutoXMLRooter : private AutoGCRoot
-     friend void JS::MarkRuntime(JSTracer *trc);
- 
-   private:
-     JSXML * const xml;
-     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
- };
- #endif /* JS_HAS_XML_SUPPORT */
- 
--class AutoLockGC {
--  public:
--    explicit AutoLockGC(JSRuntime *rt = NULL
--                        JS_GUARD_OBJECT_NOTIFIER_PARAM)
--      : runtime(rt)
--    {
--        JS_GUARD_OBJECT_NOTIFIER_INIT;
--        if (rt)
--            JS_LOCK_GC(rt);
--    }
--
--    bool locked() const {
--        return !!runtime;
--    }
--
--    void lock(JSRuntime *rt) {
--        JS_ASSERT(rt);
--        JS_ASSERT(!runtime);
--        runtime = rt;
--        JS_LOCK_GC(rt);
--    }
--
--    ~AutoLockGC() {
--        if (runtime)
--            JS_UNLOCK_GC(runtime);
--    }
--
--  private:
--    JSRuntime *runtime;
--    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
--};
--
- class AutoUnlockGC {
-   private:
-     JSRuntime *rt;
-     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
- 
-   public:
-     explicit AutoUnlockGC(JSRuntime *rt
-                           JS_GUARD_OBJECT_NOTIFIER_PARAM)
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -38,16 +38,18 @@
-  * ***** END LICENSE BLOCK ***** */
- 
- #include "jscntxt.h"
- #include "jscompartment.h"
- #include "jsfriendapi.h"
- #include "jswrapper.h"
- #include "jsweakmap.h"
- 
-+#include "mozilla/GuardObjects.h"
-+
- #include "jsobjinlines.h"
- 
- using namespace js;
- using namespace JS;
- 
- JS_FRIEND_API(void)
- JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data)
- {
-@@ -462,16 +464,39 @@ js::DumpHeapComplete(JSContext *cx, FILE
- 
-     dtrc.visited.finish();
- }
- 
- #endif
- 
- namespace js {
- 
-+/* static */ void
-+AutoLockGC::LockGC(JSRuntime *rt)
-+{
-+    JS_ASSERT(rt);
-+    JS_LOCK_GC(rt);
-+}
-+
-+/* static */ void
-+AutoLockGC::UnlockGC(JSRuntime *rt)
-+{
-+    JS_ASSERT(rt);
-+    JS_UNLOCK_GC(rt);
-+}
-+
-+void
-+AutoLockGC::lock(JSRuntime *rt)
-+{
-+    JS_ASSERT(rt);
-+    JS_ASSERT(!runtime);
-+    runtime = rt;
-+    JS_LOCK_GC(rt);
-+}
-+
- #ifdef JS_THREADSAFE
- JSThread *
- GetContextThread(const JSContext *cx)
- {
-     return cx->thread();
- }
- #endif
- 
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -39,16 +39,18 @@
- 
- #ifndef jsfriendapi_h___
- #define jsfriendapi_h___
- 
- #include "jsclass.h"
- #include "jspubtd.h"
- #include "jsprvtd.h"
- 
-+#include "mozilla/GuardObjects.h"
-+
- JS_BEGIN_EXTERN_C
- 
- extern JS_FRIEND_API(void)
- JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
- 
- extern JS_FRIEND_API(JSString *)
- JS_GetAnonymousString(JSRuntime *rt);
- 
-@@ -448,16 +450,47 @@ GetPCCountScriptSummary(JSContext *cx, s
- JS_FRIEND_API(JSString *)
- GetPCCountScriptContents(JSContext *cx, size_t script);
- 
- #ifdef JS_THREADSAFE
- JS_FRIEND_API(JSThread *)
- GetContextThread(const JSContext *cx);
- #endif
- 
-+class JS_FRIEND_API(AutoLockGC)
-+{
-+  public:
-+    explicit AutoLockGC(JSRuntime *rt = NULL
-+                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
-+      : runtime(rt)
-+    {
-+        MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-+        if (rt)
-+            LockGC(rt);
-+    }
-+
-+    ~AutoLockGC()
-+    {
-+        if (runtime)
-+            UnlockGC(runtime);
-+    }
-+
-+    bool locked() const {
-+        return !!runtime;
-+    }
-+    void lock(JSRuntime *rt);
-+
-+  private:
-+    static void LockGC(JSRuntime *rt);
-+    static void UnlockGC(JSRuntime *rt);
-+
-+    JSRuntime *runtime;
-+    MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
-+};
-+
- } /* namespace js */
- 
- /*
-  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
-  * JSProto_Null, clasp must non-null.
-  */
- extern JS_FRIEND_API(JSBool)
- js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,

AutoLockJSGC

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part p: Remove AutoLockJSGC in favour of js::AutoLockGC; r=bholley
-
-diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp
---- a/js/xpconnect/src/XPCJSRuntime.cpp
-+++ b/js/xpconnect/src/XPCJSRuntime.cpp
-@@ -61,18 +61,16 @@
- #include "js/MemoryMetrics.h"
- 
- #ifdef MOZ_CRASHREPORTER
- #include "nsExceptionHandler.h"
- #endif
- 
- #include "jscntxt.h"
- #if 0
--JS_LOCK_GC, JS_UNLOCK_GC
--
- js_NextActiveContext, js::TriggerOperationCallback
-         mWatchdogWakeup = JS_NEW_CONDVAR(mJSRuntime->gcLock);
- #endif
- 
- using namespace mozilla;
- using namespace mozilla::xpconnect::memory;
- 
- /***************************************************************************/
-@@ -932,38 +930,24 @@ JSBool XPCJSRuntime::GCCallback(JSContex
-     for (PRUint32 i = 0; i < callbacks.Length(); ++i) {
-         if (!callbacks[i](cx, status))
-             return false;
-     }
- 
-     return true;
- }
- 
--// Auto JS GC lock helper.
--class AutoLockJSGC
--{
--public:
--    AutoLockJSGC(JSRuntime* rt) : mJSRuntime(rt) { JS_LOCK_GC(mJSRuntime); }
--    ~AutoLockJSGC() { JS_UNLOCK_GC(mJSRuntime); }
--private:
--    JSRuntime* mJSRuntime;
--
--    // Disable copy or assignment semantics.
--    AutoLockJSGC(const AutoLockJSGC&);
--    void operator=(const AutoLockJSGC&);
--};
--
- //static
- void
- XPCJSRuntime::WatchdogMain(void *arg)
- {
-     XPCJSRuntime* self = static_cast<XPCJSRuntime*>(arg);
- 
-     // Lock lasts until we return
--    AutoLockJSGC lock(self->mJSRuntime);
-+    js::AutoLockGC lock(self->mJSRuntime);
- 
-     PRIntervalTime sleepInterval;
-     while (self->mWatchdogThread) {
-         // Sleep only 1 second if recently (or currently) active; otherwise, hibernate
-         if (self->mLastActiveTime == -1 || PR_Now() - self->mLastActiveTime <= PRTime(2*PR_USEC_PER_SEC))
-             sleepInterval = PR_TicksPerSecond();
-         else {
-             sleepInterval = PR_INTERVAL_NO_TIMEOUT;
-@@ -1082,17 +1066,17 @@ XPCJSRuntime::GetJSCycleCollectionContex
- XPCJSRuntime::~XPCJSRuntime()
- {
-     if (mWatchdogWakeup) {
-         // If the watchdog thread is running, tell it to terminate waking it
-         // up if necessary and wait until it signals that it finished. As we
-         // must release the lock before calling PR_DestroyCondVar, we use an
-         // extra block here.
-         {
--            AutoLockJSGC lock(mJSRuntime);
-+            js::AutoLockGC lock(mJSRuntime);
-             if (mWatchdogThread) {
-                 mWatchdogThread = nsnull;
-                 PR_NotifyCondVar(mWatchdogWakeup);
-                 PR_WaitCondVar(mWatchdogWakeup, PR_INTERVAL_NO_TIMEOUT);
-             }
-         }
-         PR_DestroyCondVar(mWatchdogWakeup);
-         mWatchdogWakeup = nsnull;
-@@ -2015,17 +1999,17 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* 
- 
-     // Install a JavaScript 'debugger' keyword handler in debug builds only
- #ifdef DEBUG
-     if (mJSRuntime && !JS_GetGlobalDebugHooks(mJSRuntime)->debuggerHandler)
-         xpc_InstallJSDebuggerKeywordHandler(mJSRuntime);
- #endif
- 
-     if (mWatchdogWakeup) {
--        AutoLockJSGC lock(mJSRuntime);
-+        js::AutoLockGC lock(mJSRuntime);
- 
-         mWatchdogThread = PR_CreateThread(PR_USER_THREAD, WatchdogMain, this,
-                                           PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
-                                           PR_UNJOINABLE_THREAD, 0);
-         if (!mWatchdogThread)
-             NS_RUNTIMEABORT("PR_CreateThread failed!");
-     }
- }

AutoSkipConservativeScan

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part r: Provide AutoSkipConservativeScan in jsfriendapi.h; r=luke
-
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -534,16 +534,36 @@ GetContextOutstandingRequests(const JSCo
-     return cx->outstandingRequests;
- }
- 
- JS_FRIEND_API(PRLock *)
- GetRuntimeGCLock(const JSRuntime *rt)
- {
-     return rt->gcLock;
- }
-+
-+AutoSkipConservativeScan::AutoSkipConservativeScan(JSContext *cx
-+                                                   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
-+  : context(cx)
-+{
-+    MOZ_GUARD_OBJECT_NOTIFIER_INIT;
-+
-+    ThreadData &threadData = context->thread()->data;
-+    JS_ASSERT(threadData.requestDepth >= 1);
-+    JS_ASSERT(!threadData.conservativeGC.requestThreshold);
-+    if (threadData.requestDepth == 1)
-+        threadData.conservativeGC.requestThreshold = 1;
-+}
-+
-+AutoSkipConservativeScan::~AutoSkipConservativeScan()
-+{
-+    ThreadData &threadData = context->thread()->data;
-+    if (threadData.requestDepth == 1)
-+        threadData.conservativeGC.requestThreshold = 0;
-+}
- #endif
- 
- JS_FRIEND_API(JSCompartment *)
- GetContextCompartment(const JSContext *cx)
- {
-     return cx->compartment;
- }
- 
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -456,16 +456,27 @@ GetPCCountScriptContents(JSContext *cx, 
- JS_FRIEND_API(JSThread *)
- GetContextThread(const JSContext *cx);
- 
- JS_FRIEND_API(unsigned)
- GetContextOutstandingRequests(const JSContext *cx);
- 
- JS_FRIEND_API(PRLock *)
- GetRuntimeGCLock(const JSRuntime *rt);
-+
-+class JS_FRIEND_API(AutoSkipConservativeScan)
-+{
-+  public:
-+    AutoSkipConservativeScan(JSContext *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
-+    ~AutoSkipConservativeScan();
-+
-+  private:
-+    JSContext *context;
-+    MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
-+};
- #endif
- 
- JS_FRIEND_API(JSCompartment *)
- GetContextCompartment(const JSContext *cx);
- 
- JS_FRIEND_API(bool)
- HasUnrootedGlobal(const JSContext *cx);
- 
-diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp
---- a/js/xpconnect/src/nsXPConnect.cpp
-+++ b/js/xpconnect/src/nsXPConnect.cpp
-@@ -64,18 +64,17 @@
- #include "XPCQuickStubs.h"
- #include "dombindings.h"
- 
- #include "mozilla/Assertions.h"
- #include "mozilla/Base64.h"
- 
- #include "nsWrapperCacheInlines.h"
- 
--#include "jscntxt.h" // js::ThreadData, JS_TRACER_INIT, context->stackLimit,
--// sizeof(JSContext), js::CompartmentVector, cx->stack.empty()
-+#include "jscntxt.h" // JS_TRACER_INIT, context->stackLimit, sizeof(JSContext), js::CompartmentVector, cx->stack.empty()
- 
- NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
-                               nsIXPConnect,
-                               nsISupportsWeakReference,
-                               nsIThreadObserver,
-                               nsIJSRuntimeService,
-                               nsIJSContextStack,
-                               nsIThreadJSContextStack,
-@@ -399,27 +398,21 @@ nsXPConnect::Collect(bool shrinkingGC)
- 
-     JSContext *cx = ccx.GetJSContext();
- 
-     // We want to scan the current thread for GC roots only if it was in a
-     // request prior to the Collect call to avoid false positives during the
-     // cycle collection. So to compensate for JS_BeginRequest in
-     // XPCCallContext::Init we disable the conservative scanner if that call
-     // has started the request on this thread.
--    js::ThreadData &threadData = cx->thread()->data;
--    JS_ASSERT(threadData.requestDepth >= 1);
--    JS_ASSERT(!threadData.conservativeGC.requestThreshold);
--    if (threadData.requestDepth == 1)
--        threadData.conservativeGC.requestThreshold = 1;
-+    js::AutoSkipConservativeScan ascs(cx);
-     if (shrinkingGC)
-         JS_ShrinkingGC(cx);
-     else
-         JS_GC(cx);
--    if (threadData.requestDepth == 1)
--        threadData.conservativeGC.requestThreshold = 0;
- }
- 
- NS_IMETHODIMP
- nsXPConnect::GarbageCollect(bool shrinkingGC)
- {
-     Collect(shrinkingGC);
-     return NS_OK;
- }

AutoValueVector

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part x: Move AutoValueVector to jsapi.h; r=evilpie
-
-diff --git a/js/src/jsapi.h b/js/src/jsapi.h
---- a/js/src/jsapi.h
-+++ b/js/src/jsapi.h
-@@ -1118,16 +1118,29 @@ class AutoVectorRooter : protected AutoG
-             memset(t, 0, sizeof(T));
-     }
- 
-     typedef js::Vector<T, 8> VectorImpl;
-     VectorImpl vector;
-     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
- };
- 
-+class AutoValueVector : public AutoVectorRooter<Value>
-+{
-+  public:
-+    explicit AutoValueVector(JSContext *cx
-+                             JS_GUARD_OBJECT_NOTIFIER_PARAM)
-+        : AutoVectorRooter<Value>(cx, VALVECTOR)
-+    {
-+        JS_GUARD_OBJECT_NOTIFIER_INIT;
-+    }
-+
-+    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
-+};
-+
- }  /* namespace JS */
- 
- /************************************************************************/
- 
- /*
-  * JS::Value and jsval are the same type; jsval is the old name, kept around
-  * for backwards compatibility along with all the JSVAL_* operations below.
-  * jsval_layout is an implementation detail and should not be used externally.
-diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
---- a/js/src/jscntxt.h
-+++ b/js/src/jscntxt.h
-@@ -2084,35 +2084,16 @@ SetValueRangeToNull(Value *beg, Value *e
- }
- 
- static JS_ALWAYS_INLINE void
- SetValueRangeToNull(Value *vec, size_t len)
- {
-     SetValueRangeToNull(vec, vec + len);
- }
- 
--class AutoValueVector : public AutoVectorRooter<Value>
--{
--  public:
--    explicit AutoValueVector(JSContext *cx
--                             JS_GUARD_OBJECT_NOTIFIER_PARAM)
--        : AutoVectorRooter<Value>(cx, VALVECTOR)
--    {
--        JS_GUARD_OBJECT_NOTIFIER_INIT;
--    }
--
--    const jsval *jsval_begin() const { return begin(); }
--    jsval *jsval_begin() { return begin(); }
--
--    const jsval *jsval_end() const { return end(); }
--    jsval *jsval_end() { return end(); }
--
--    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
--};
--
- class AutoObjectVector : public AutoVectorRooter<JSObject *>
- {
-   public:
-     explicit AutoObjectVector(JSContext *cx
-                               JS_GUARD_OBJECT_NOTIFIER_PARAM)
-         : AutoVectorRooter<JSObject *>(cx, OBJVECTOR)
-     {
-         JS_GUARD_OBJECT_NOTIFIER_INIT;
-diff --git a/js/src/jsgc.h b/js/src/jsgc.h
---- a/js/src/jsgc.h
-+++ b/js/src/jsgc.h
-@@ -1305,17 +1305,16 @@ struct WrapperHasher
-         return uint32_t(bits) ^ uint32_t(bits >> 32);
-     }
- 
-     static bool match(const Value &l, const Value &k) { return l == k; }
- };
- 
- typedef HashMap<Value, Value, WrapperHasher, SystemAllocPolicy> WrapperMap;
- 
--class AutoValueVector;
- class AutoIdVector;
- 
- } /* namespace js */
- 
- #ifdef DEBUG
- extern bool
- CheckAllocation(JSContext *cx);
- #endif
-diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp
---- a/js/xpconnect/src/XPCWrappedJSClass.cpp
-+++ b/js/xpconnect/src/XPCWrappedJSClass.cpp
-@@ -44,17 +44,17 @@
- 
- #include "xpcprivate.h"
- #include "nsArrayEnumerator.h"
- #include "nsWrapperCache.h"
- #include "XPCWrapper.h"
- #include "AccessCheck.h"
- #include "nsJSUtils.h"
- 
--#include "jscntxt.h" // js::AutoValueVector
-+#include "jsapi.h"
- 
- NS_IMPL_THREADSAFE_ISUPPORTS1(nsXPCWrappedJSClass, nsIXPCWrappedJSClass)
- 
- // the value of this variable is never used - we use its address as a sentinel
- static uint32_t zero_methods_descriptor;
- 
- bool AutoScriptEvaluate::StartEvaluating(JSObject *scope, JSErrorReporter errorReporter)
- {
-@@ -1169,61 +1169,56 @@ class ContextPrincipalGuard
- NS_IMETHODIMP
- nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
-                                 const XPTMethodDescriptor* info,
-                                 nsXPTCMiniVariant* nativeParams)
- {
-     jsval* sp = nsnull;
-     jsval* argv = nsnull;
-     uint8_t i;
--    uint8_t argc=0;
--    uint8_t paramCount=0;
-     nsresult retval = NS_ERROR_FAILURE;
-     nsresult pending_result = NS_OK;
-     JSBool success;
-     JSBool readyToDoTheCall = false;
-     nsID  param_iid;
--    JSObject* obj;
-     const char* name = info->name;
-     jsval fval;
-     JSBool foundDependentParam;
--    XPCContext* xpcc;
--    JSContext* cx;
--    JSObject* thisObj;
- 
-     // Make sure not to set the callee on ccx until after we've gone through
-     // the whole nsIXPCFunctionThisTranslator bit.  That code uses ccx to
-     // convert natives to JSObjects, but we do NOT plan to pass those JSObjects
-     // to our real callee.
-     JSContext *context = GetContextFromObject(wrapper->GetJSObject());
-     XPCCallContext ccx(NATIVE_CALLER, context);
-     if (!ccx.IsValid())
-         return retval;
- 
--    xpcc = ccx.GetXPCContext();
--    cx = ccx.GetJSContext();
-+    XPCContext *xpcc = ccx.GetXPCContext();
-+    JSContext *cx = ccx.GetJSContext();
- 
-     if (!cx || !xpcc || !IsReflectable(methodIndex))
-         return NS_ERROR_FAILURE;
- 
--    obj = thisObj = wrapper->GetJSObject();
-+    JSObject *obj = wrapper->GetJSObject();
-+    JSObject *thisObj = obj;
- 
-     JSAutoEnterCompartment ac;
-     if (!ac.enter(cx, obj))
-         return NS_ERROR_FAILURE;
- 
-     ccx.SetScopeForNewJSObjects(obj);
- 
--    js::AutoValueVector args(cx);
-+    JS::AutoValueVector args(cx);
-     AutoScriptEvaluate scriptEval(cx);
-     ContextPrincipalGuard principalGuard(ccx);
- 
-     // XXX ASSUMES that retval is last arg. The xpidl compiler ensures this.
--    paramCount = info->num_args;
--    argc = paramCount -
-+    uint8_t paramCount = info->num_args;
-+    uint8_t argc = paramCount -
-         (paramCount && XPT_PD_IS_RETVAL(info->params[paramCount-1].flags) ? 1 : 0);
- 
-     if (!scriptEval.StartEvaluating(obj, xpcWrappedJSErrorReporter))
-         goto pre_call_clean_up;
- 
-     xpcc->SetPendingResult(pending_result);
-     xpcc->SetException(nsnull);
-     ccx.GetThreadData()->SetException(nsnull);
-@@ -1349,17 +1344,17 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWra
-         }
-     }
- 
-     if (!args.resize(argc)) {
-         retval = NS_ERROR_OUT_OF_MEMORY;
-         goto pre_call_clean_up;
-     }
- 
--    argv = args.jsval_begin();
-+    argv = args.begin();
-     sp = argv;
- 
-     // build the args
-     // NB: This assignment *looks* wrong because we haven't yet called our
-     // function. However, we *have* already entered the compartmen that we're
-     // about to call, and that's the global that we want here. In other words:
-     // we're trusting the JS engine to come up with a good global to use for
-     // our object (whatever it was).

AutoVectorRooter

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part w: Move AutoVectorRooter to jsapi.h; r=evilpie
-
-diff --git a/js/src/jsapi.h b/js/src/jsapi.h
---- a/js/src/jsapi.h
-+++ b/js/src/jsapi.h
-@@ -45,21 +45,23 @@
-  */
- 
- #include "mozilla/StdInt.h"
- 
- #include <stddef.h>
- #include <stdio.h>
- #include "js-config.h"
- #include "jspubtd.h"
-+#include "jsutil.h"
- #include "jsval.h"
- 
- #include "js/Utility.h"
- 
- #ifdef __cplusplus
-+#include "js/Vector.h"
- #include "mozilla/Attributes.h"
- #endif
- 
- /************************************************************************/
- 
- /* JS::Value can store a full int32_t. */
- #define JSVAL_INT_BITS          32
- #define JSVAL_INT_MIN           ((jsint)0x80000000)
-@@ -1109,16 +1111,88 @@ class AutoEnumStateRooter : private Auto
- 
-     JSObject * const obj;
- 
-   private:
-     Value stateValue;
-     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
- };
- 
-+template<class T>
-+class AutoVectorRooter : protected AutoGCRooter
-+{
-+  public:
-+    explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
-+                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
-+        : AutoGCRooter(cx, tag), vector(cx)
-+    {
-+        JS_GUARD_OBJECT_NOTIFIER_INIT;
-+    }
-+
-+    size_t length() const { return vector.length(); }
-+
-+    bool append(const T &v) { return vector.append(v); }
-+
-+    /* For use when space has already been reserved. */
-+    void infallibleAppend(const T &v) { vector.infallibleAppend(v); }
-+
-+    void popBack() { vector.popBack(); }
-+    T popCopy() { return vector.popCopy(); }
-+
-+    bool growBy(size_t inc) {
-+        size_t oldLength = vector.length();
-+        if (!vector.growByUninitialized(inc))
-+            return false;
-+        makeRangeGCSafe(oldLength);
-+        return true;
-+    }
-+
-+    bool resize(size_t newLength) {
-+        size_t oldLength = vector.length();
-+        if (newLength <= oldLength) {
-+            vector.shrinkBy(oldLength - newLength);
-+            return true;
-+        }
-+        if (!vector.growByUninitialized(newLength - oldLength))
-+            return false;
-+        makeRangeGCSafe(oldLength);
-+        return true;
-+    }
-+
-+    void clear() { vector.clear(); }
-+
-+    bool reserve(size_t newLength) {
-+        return vector.reserve(newLength);
-+    }
-+
-+    T &operator[](size_t i) { return vector[i]; }
-+    const T &operator[](size_t i) const { return vector[i]; }
-+
-+    const T *begin() const { return vector.begin(); }
-+    T *begin() { return vector.begin(); }
-+
-+    const T *end() const { return vector.end(); }
-+    T *end() { return vector.end(); }
-+
-+    const T &back() const { return vector.back(); }
-+
-+    friend void AutoGCRooter::trace(JSTracer *trc);
-+
-+  private:
-+    void makeRangeGCSafe(size_t oldLength) {
-+        T *t = vector.begin() + oldLength;
-+        for (size_t i = oldLength; i < vector.length(); ++i, ++t)
-+            memset(t, 0, sizeof(T));
-+    }
-+
-+    typedef js::Vector<T, 8> VectorImpl;
-+    VectorImpl vector;
-+    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
-+};
-+
- }  /* namespace JS */
- 
- /************************************************************************/
- 
- /*
-  * JS::Value and jsval are the same type; jsval is the old name, kept around
-  * for backwards compatibility along with all the JSVAL_* operations below.
-  * jsval_layout is an implementation detail and should not be used externally.
-diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
---- a/js/src/jscntxt.h
-+++ b/js/src/jscntxt.h
-@@ -2084,82 +2084,16 @@ SetValueRangeToNull(Value *beg, Value *e
- }
- 
- static JS_ALWAYS_INLINE void
- SetValueRangeToNull(Value *vec, size_t len)
- {
-     SetValueRangeToNull(vec, vec + len);
- }
- 
--template<class T>
--class AutoVectorRooter : protected AutoGCRooter
--{
--  public:
--    explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
--                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
--        : AutoGCRooter(cx, tag), vector(cx)
--    {
--        JS_GUARD_OBJECT_NOTIFIER_INIT;
--    }
--
--    size_t length() const { return vector.length(); }
--
--    bool append(const T &v) { return vector.append(v); }
--
--    /* For use when space has already been reserved. */
--    void infallibleAppend(const T &v) { vector.infallibleAppend(v); }
--
--    void popBack() { vector.popBack(); }
--    T popCopy() { return vector.popCopy(); }
--
--    bool growBy(size_t inc) {
--        size_t oldLength = vector.length();
--        if (!vector.growByUninitialized(inc))
--            return false;
--        MakeRangeGCSafe(vector.begin() + oldLength, vector.end());
--        return true;
--    }
--
--    bool resize(size_t newLength) {
--        size_t oldLength = vector.length();
--        if (newLength <= oldLength) {
--            vector.shrinkBy(oldLength - newLength);
--            return true;
--        }
--        if (!vector.growByUninitialized(newLength - oldLength))
--            return false;
--        MakeRangeGCSafe(vector.begin() + oldLength, vector.end());
--        return true;
--    }
--
--    void clear() { vector.clear(); }
--
--    bool reserve(size_t newLength) {
--        return vector.reserve(newLength);
--    }
--
--    T &operator[](size_t i) { return vector[i]; }
--    const T &operator[](size_t i) const { return vector[i]; }
--
--    const T *begin() const { return vector.begin(); }
--    T *begin() { return vector.begin(); }
--
--    const T *end() const { return vector.end(); }
--    T *end() { return vector.end(); }
--
--    const T &back() const { return vector.back(); }
--
--    friend void AutoGCRooter::trace(JSTracer *trc);
--
--  private:
--    typedef Vector<T, 8> VectorImpl;
--    VectorImpl vector;
--    JS_DECL_USE_GUARD_OBJECT_NOTIFIER
--};
--
- class AutoValueVector : public AutoVectorRooter<Value>
- {
-   public:
-     explicit AutoValueVector(JSContext *cx
-                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
-         : AutoVectorRooter<Value>(cx, VALVECTOR)
-     {
-         JS_GUARD_OBJECT_NOTIFIER_INIT;

CallContextDebugHandler

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part h: Expose debuggerHandler in jsfriendapi.h; r=igor
-
-diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp
---- a/dom/base/nsJSEnvironment.cpp
-+++ b/dom/base/nsJSEnvironment.cpp
-@@ -32,17 +32,17 @@
-  * use your version of this file under the terms of the MPL, indicate your
-  * decision by deleting the provisions above and replace them with the notice
-  * and other provisions required by the GPL or the LGPL. If you do not delete
-  * the provisions above, a recipient may use your version of this file under
-  * the terms of any one of the MPL, the GPL or the LGPL.
-  *
-  * ***** END LICENSE BLOCK ***** */
- 
--#include "jscntxt.h"
-+#include "jscntxt.h" // outstandingRequests
- #include "nsJSEnvironment.h"
- #include "nsIScriptGlobalObject.h"
- #include "nsIScriptObjectPrincipal.h"
- #include "nsIDOMChromeWindow.h"
- #include "nsPIDOMWindow.h"
- #include "nsIScriptSecurityManager.h"
- #include "nsDOMCID.h"
- #include "nsIServiceManager.h"
-@@ -707,18 +707,17 @@ nsJSContext::DOMOperationCallback(JSCont
-   // If we get here we're most likely executing an infinite loop in JS,
-   // we'll tell the user about this and we'll give the user the option
-   // of stopping the execution of the script.
-   nsCOMPtr<nsIPrompt> prompt = GetPromptFromContext(ctx);
-   NS_ENSURE_TRUE(prompt, JS_FALSE);
- 
-   // Check if we should offer the option to debug
-   JSStackFrame* fp = ::JS_GetScriptedCaller(cx, NULL);
--  bool debugPossible = (fp != nsnull && cx->debugHooks &&
--                          cx->debugHooks->debuggerHandler != nsnull);
-+  bool debugPossible = fp && js::CanCallContextDebugHandler(cx);
- #ifdef MOZ_JSDEBUGGER
-   // Get the debugger service if necessary.
-   if (debugPossible) {
-     bool jsds_IsOn = false;
-     const char jsdServiceCtrID[] = "@mozilla.org/js/jsd/debugger-service;1";
-     nsCOMPtr<jsdIExecutionHook> jsdHook;
-     nsCOMPtr<jsdIDebuggerService> jsds = do_GetService(jsdServiceCtrID, &rv);
- 
-@@ -837,20 +836,17 @@ nsJSContext::DOMOperationCallback(JSCont
-     }
- 
-     ctx->mOperationCallbackTime = PR_Now();
-     return JS_TRUE;
-   }
-   else if ((buttonPressed == 2) && debugPossible) {
-     // Debug the script
-     jsval rval;
--    switch(cx->debugHooks->debuggerHandler(cx, script, ::JS_GetFramePC(cx, fp),
--                                           &rval,
--                                           cx->debugHooks->
--                                           debuggerHandlerData)) {
-+    switch (js::CallContextDebugHandler(cx, script, JS_GetFramePC(cx, fp), &rval)) {
-       case JSTRAP_RETURN:
-         JS_SetFrameReturnValue(cx, fp, rval);
-         return JS_TRUE;
-       case JSTRAP_ERROR:
-         JS_ClearPendingException(cx);
-         return JS_FALSE;
-       case JSTRAP_THROW:
-         JS_SetPendingException(cx, rval);
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -500,16 +500,32 @@ GetContextStructuredCloneCallbacks(JSCon
- 
- JS_FRIEND_API(JSVersion)
- VersionSetXML(JSVersion version, bool enable)
- {
-     return enable ? JSVersion(uint32_t(version) | VersionFlags::HAS_XML)
-                   : JSVersion(uint32_t(version) & ~VersionFlags::HAS_XML);
- }
- 
-+JS_FRIEND_API(bool)
-+CanCallContextDebugHandler(JSContext *cx)
-+{
-+    return cx->debugHooks && cx->debugHooks->debuggerHandler;
-+}
-+
-+JS_FRIEND_API(JSTrapStatus)
-+CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval)
-+{
-+    if (!CanCallContextDebugHandler(cx))
-+        return JSTRAP_RETURN;
-+
-+    return cx->debugHooks->debuggerHandler(cx, script, bc, rval,
-+                                           cx->debugHooks->debuggerHandlerData);
-+}
-+
- #ifdef JS_THREADSAFE
- JSThread *
- GetContextThread(const JSContext *cx)
- {
-     return cx->thread();
- }
- #endif
- 
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -487,16 +487,22 @@ class JS_FRIEND_API(AutoLockGC)
- };
- 
- extern JS_FRIEND_API(const JSStructuredCloneCallbacks *)
- GetContextStructuredCloneCallbacks(JSContext *cx);
- 
- extern JS_FRIEND_API(JSVersion)
- VersionSetXML(JSVersion version, bool enable);
- 
-+extern JS_FRIEND_API(bool)
-+CanCallContextDebugHandler(JSContext *cx);
-+
-+extern JS_FRIEND_API(JSTrapStatus)
-+CallContextDebugHandler(JSContext *cx, JSScript *script, jsbytecode *bc, Value *rval);
-+
- } /* namespace js */
- 
- /*
-  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
-  * JSProto_Null, clasp must non-null.
-  */
- extern JS_FRIEND_API(JSBool)
- js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,

CompartmentVector

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part v: Expose rt->compartments in jsfriendapi.h; r=jorendorff
-
-diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
---- a/js/src/jscntxt.h
-+++ b/js/src/jscntxt.h
-@@ -334,17 +334,16 @@ typedef enum JSRuntimeState {
- 
- typedef struct JSPropertyTreeEntry {
-     JSDHashEntryHdr     hdr;
-     js::Shape           *child;
- } JSPropertyTreeEntry;
- 
- namespace js {
- 
--typedef Vector<JSCompartment *, 0, SystemAllocPolicy> CompartmentVector;
- typedef Vector<ScriptOpcodeCountsPair, 0, SystemAllocPolicy> ScriptOpcodeCountsVector;
- 
- }
- 
- struct JSRuntime
- {
-     /* Default compartment. */
-     JSCompartment       *atomsCompartment;
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -590,9 +590,15 @@ JS_FRIEND_API(void)
- TriggerOperationCallbacksForActiveContexts(JSRuntime *rt)
- {
-     JSContext* cx = NULL;
-     while ((cx = js_NextActiveContext(rt, cx))) {
-         TriggerOperationCallback(cx);
-     }
- }
- 
-+JS_FRIEND_API(const CompartmentVector&)
-+GetRuntimeCompartments(JSRuntime *rt)
-+{
-+    return rt->compartments;
-+}
-+
- } // namespace js
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -537,16 +537,21 @@ CallContextDebugHandler(JSContext *cx, J
- 
- extern JS_FRIEND_API(bool)
- IsContextRunningJS(JSContext *cx);
- 
- /* Must be called with GC lock taken. */
- extern JS_FRIEND_API(void)
- TriggerOperationCallbacksForActiveContexts(JSRuntime *rt);
- 
-+class SystemAllocPolicy;
-+typedef Vector<JSCompartment*, 0, SystemAllocPolicy> CompartmentVector;
-+extern JS_FRIEND_API(const CompartmentVector&)
-+GetRuntimeCompartments(JSRuntime *rt);
-+
- } /* namespace js */
- 
- /*
-  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
-  * JSProto_Null, clasp must non-null.
-  */
- extern JS_FRIEND_API(JSBool)
- js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,
-diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp
---- a/js/xpconnect/src/nsXPConnect.cpp
-+++ b/js/xpconnect/src/nsXPConnect.cpp
-@@ -64,17 +64,17 @@
- #include "XPCQuickStubs.h"
- #include "dombindings.h"
- 
- #include "mozilla/Assertions.h"
- #include "mozilla/Base64.h"
- 
- #include "nsWrapperCacheInlines.h"
- 
--#include "jscntxt.h" // context->stackLimit, sizeof(JSContext), js::CompartmentVector
-+#include "jscntxt.h" // context->stackLimit, sizeof(JSContext)
- 
- NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
-                               nsIXPConnect,
-                               nsISupportsWeakReference,
-                               nsIThreadObserver,
-                               nsIJSRuntimeService,
-                               nsIJSContextStack,
-                               nsIThreadJSContextStack,
-@@ -2520,18 +2520,18 @@ nsXPConnect::CheckForDebugMode(JSRuntime
-     {
-         struct AutoDestroyContext {
-             JSContext *cx;
-             AutoDestroyContext(JSContext *cx) : cx(cx) {}
-             ~AutoDestroyContext() { JS_DestroyContext(cx); }
-         } adc(cx);
-         JSAutoRequest ar(cx);
- 
--        js::CompartmentVector &vector = rt->compartments;
--        for (JSCompartment **p = vector.begin(); p != vector.end(); ++p) {
-+        const js::CompartmentVector &vector = js::GetRuntimeCompartments(rt);
-+        for (JSCompartment * const *p = vector.begin(); p != vector.end(); ++p) {
-             JSCompartment *comp = *p;
-             if (!JS_GetCompartmentPrincipals(comp)) {
-                 /* Ignore special compartments (atoms, JSD compartments) */
-                 continue;
-             }
- 
-             /* ParticipatesInCycleCollection means "on the main thread" */
-             if (xpc::CompartmentParticipatesInCycleCollection(cx, comp)) {

GetContextOutstandingRequests

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part k: Expose outstandingRequests in jsfriendapi.h; r=cdleary
-
-diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp
---- a/dom/base/nsJSEnvironment.cpp
-+++ b/dom/base/nsJSEnvironment.cpp
-@@ -32,17 +32,16 @@
-  * use your version of this file under the terms of the MPL, indicate your
-  * decision by deleting the provisions above and replace them with the notice
-  * and other provisions required by the GPL or the LGPL. If you do not delete
-  * the provisions above, a recipient may use your version of this file under
-  * the terms of any one of the MPL, the GPL or the LGPL.
-  *
-  * ***** END LICENSE BLOCK ***** */
- 
--#include "jscntxt.h" // outstandingRequests
- #include "nsJSEnvironment.h"
- #include "nsIScriptGlobalObject.h"
- #include "nsIScriptObjectPrincipal.h"
- #include "nsIDOMChromeWindow.h"
- #include "nsPIDOMWindow.h"
- #include "nsIScriptSecurityManager.h"
- #include "nsDOMCID.h"
- #include "nsIServiceManager.h"
-@@ -1122,17 +1121,17 @@ nsJSContext::DestroyJSContext()
-   mContext = nsnull;
- }
- 
- // QueryInterface implementation for nsJSContext
- NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSContext)
- NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSContext)
- NS_IMPL_CYCLE_COLLECTION_TRACE_END
- NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSContext)
--  NS_ASSERTION(!tmp->mContext || tmp->mContext->outstandingRequests == 0,
-+  NS_ASSERTION(!tmp->mContext || js::GetContextOutstandingRequests(tmp->mContext) == 0,
-                "Trying to unlink a context with outstanding requests.");
-   tmp->mIsInitialized = false;
-   tmp->mGCOnDestruction = false;
-   tmp->DestroyJSContext();
-   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGlobalObjectRef)
- NS_IMPL_CYCLE_COLLECTION_UNLINK_END
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsJSContext)
-   NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsJSContext, tmp->GetCCRefcnt())
-@@ -1152,17 +1151,17 @@ NS_INTERFACE_MAP_END
- NS_IMPL_CYCLE_COLLECTING_ADDREF(nsJSContext)
- NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSContext)
- 
- nsrefcnt
- nsJSContext::GetCCRefcnt()
- {
-   nsrefcnt refcnt = mRefCnt.get();
-   if (NS_LIKELY(mContext))
--    refcnt += mContext->outstandingRequests;
-+    refcnt += js::GetContextOutstandingRequests(mContext);
-   return refcnt;
- }
- 
- nsresult
- nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
-                                      JSObject* aScopeObject,
-                                      nsIPrincipal *aPrincipal,
-                                      const char *aURL,
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -522,11 +522,17 @@ CallContextDebugHandler(JSContext *cx, J
- }
- 
- #ifdef JS_THREADSAFE
- JSThread *
- GetContextThread(const JSContext *cx)
- {
-     return cx->thread();
- }
-+
-+JS_FRIEND_API(unsigned)
-+GetContextOutstandingRequests(const JSContext *cx)
-+{
-+    return cx->outstandingRequests;
-+}
- #endif
- 
- } // namespace js
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -448,16 +448,19 @@ JS_FRIEND_API(JSString *)
- GetPCCountScriptSummary(JSContext *cx, size_t script);
- 
- JS_FRIEND_API(JSString *)
- GetPCCountScriptContents(JSContext *cx, size_t script);
- 
- #ifdef JS_THREADSAFE
- JS_FRIEND_API(JSThread *)
- GetContextThread(const JSContext *cx);
-+
-+JS_FRIEND_API(unsigned)
-+GetContextOutstandingRequests(const JSContext *cx);
- #endif
- 
- class JS_FRIEND_API(AutoLockGC)
- {
-   public:
-     explicit AutoLockGC(JSRuntime *rt = NULL
-                         MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
-       : runtime(rt)
-diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp
---- a/js/xpconnect/src/nsXPConnect.cpp
-+++ b/js/xpconnect/src/nsXPConnect.cpp
-@@ -64,17 +64,17 @@
- #include "XPCQuickStubs.h"
- #include "dombindings.h"
- 
- #include "mozilla/Assertions.h"
- #include "mozilla/Base64.h"
- 
- #include "nsWrapperCacheInlines.h"
- 
--#include "jscntxt.h" // js::ThreadData, JS_TRACER_INIT, context->stackLimit, cx->outstandingRequests,
-+#include "jscntxt.h" // js::ThreadData, JS_TRACER_INIT, context->stackLimit,
- // cx->globalObject, sizeof(JSContext), js::CompartmentVector, cx->stack.empty()
- 
- NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
-                               nsIXPConnect,
-                               nsISupportsWeakReference,
-                               nsIThreadObserver,
-                               nsIJSRuntimeService,
-                               nsIJSContextStack,
-@@ -966,17 +966,17 @@ nsXPConnect::Traverse(void *p, nsCycleCo
-     }
- 
-     return NS_OK;
- }
- 
- unsigned
- nsXPConnect::GetOutstandingRequests(JSContext* cx)
- {
--    unsigned n = cx->outstandingRequests;
-+    unsigned n = js::GetContextOutstandingRequests(cx);
-     XPCCallContext* context = mCycleCollectionContext;
-     // Ignore the contribution from the XPCCallContext we created for cycle
-     // collection.
-     if (context && cx == context->GetJSContext()) {
-         JS_ASSERT(n);
-         --n;
-     }
-     return n;

GetContextStackLimit

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part z: Move JS_CHECK_RECURSION to jsfriendapi.h; r=mjrosenb
-
-diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h
---- a/js/src/jscntxt.h
-+++ b/js/src/jscntxt.h
-@@ -1872,33 +1872,19 @@ js_ExpandErrorArguments(JSContext *cx, J
-                         void *userRef, const uintN errorNumber,
-                         char **message, JSErrorReport *reportp,
-                         bool charArgs, va_list ap);
- #endif
- 
- extern void
- js_ReportOutOfMemory(JSContext *cx);
- 
--/* JS_CHECK_RECURSION is used outside JS, so JS_FRIEND_API. */
--JS_FRIEND_API(void)
--js_ReportOverRecursed(JSContext *maybecx);
--
- extern JS_FRIEND_API(void)
- js_ReportAllocationOverflow(JSContext *cx);
- 
--#define JS_CHECK_RECURSION(cx, onerror)                                       \
--    JS_BEGIN_MACRO                                                            \
--        int stackDummy_;                                                      \
--                                                                              \
--        if (!JS_CHECK_STACK_SIZE(cx->stackLimit, &stackDummy_)) {             \
--            js_ReportOverRecursed(cx);                                        \
--            onerror;                                                          \
--        }                                                                     \
--    JS_END_MACRO
--
- /*
-  * Report an exception using a previously composed JSErrorReport.
-  * XXXbe remove from "friend" API
-  */
- extern JS_FRIEND_API(void)
- js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
- 
- extern void
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -596,9 +596,15 @@ TriggerOperationCallbacksForActiveContex
- }
- 
- JS_FRIEND_API(const CompartmentVector&)
- GetRuntimeCompartments(JSRuntime *rt)
- {
-     return rt->compartments;
- }
- 
-+JS_FRIEND_API(uintptr_t)
-+GetContextStackLimit(const JSContext *cx)
-+{
-+    return cx->stackLimit;
-+}
-+
- } // namespace js
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -131,16 +131,19 @@ extern JS_FRIEND_API(JSObject *)
- JS_ObjectToOuterObject(JSContext *cx, JSObject *obj);
- 
- extern JS_FRIEND_API(JSObject *)
- JS_CloneObject(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent);
- 
- extern JS_FRIEND_API(JSBool)
- js_GetterOnlyPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
- 
-+JS_FRIEND_API(void)
-+js_ReportOverRecursed(JSContext *maybecx);
-+
- #ifdef __cplusplus
- 
- extern JS_FRIEND_API(bool)
- JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj);
- 
- extern JS_FRIEND_API(JSBool)
- JS_WrapPropertyDescriptor(JSContext *cx, js::PropertyDescriptor *desc);
- 
-@@ -429,16 +432,28 @@ IsObjectInContextCompartment(const JSObj
-  * JSXDR_BYTECODE_VERSION.
-  */
- #define JSITER_ENUMERATE  0x1   /* for-in compatible hidden default iterator */
- #define JSITER_FOREACH    0x2   /* return [key, value] pair rather than key */
- #define JSITER_KEYVALUE   0x4   /* destructuring for-in wants [key, value] */
- #define JSITER_OWNONLY    0x8   /* iterate over obj's own properties only */
- #define JSITER_HIDDEN     0x10  /* also enumerate non-enumerable properties */
- 
-+JS_FRIEND_API(uintptr_t)
-+GetContextStackLimit(const JSContext *cx);
-+
-+#define JS_CHECK_RECURSION(cx, onerror)                                         \
-+    JS_BEGIN_MACRO                                                              \
-+        int stackDummy_;                                                        \
-+        if (!JS_CHECK_STACK_SIZE(js::GetContextStackLimit(cx), &stackDummy_)) { \
-+            js_ReportOverRecursed(cx);                                          \
-+            onerror;                                                            \
-+        }                                                                       \
-+    JS_END_MACRO
-+
- JS_FRIEND_API(void)
- StartPCCountProfiling(JSContext *cx);
- 
- JS_FRIEND_API(void)
- StopPCCountProfiling(JSContext *cx);
- 
- JS_FRIEND_API(void)
- PurgePCCounts(JSContext *cx);
-diff --git a/js/xpconnect/src/XPCVariant.cpp b/js/xpconnect/src/XPCVariant.cpp
---- a/js/xpconnect/src/XPCVariant.cpp
-+++ b/js/xpconnect/src/XPCVariant.cpp
-@@ -38,17 +38,17 @@
-  *
-  * ***** END LICENSE BLOCK ***** */
- 
- /* nsIVariant implementation for xpconnect. */
- 
- #include "xpcprivate.h"
- #include "XPCWrapper.h"
- 
--#include "jscntxt.h" // JS_CHECK_RECURSION
-+#include "jsfriendapi.h"
- 
- NS_IMPL_CYCLE_COLLECTION_CLASS(XPCVariant)
- 
- NS_IMPL_CLASSINFO(XPCVariant, NULL, 0, XPCVARIANT_CID)
- NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XPCVariant)
-   NS_INTERFACE_MAP_ENTRY(XPCVariant)
-   NS_INTERFACE_MAP_ENTRY(nsIVariant)
-   NS_INTERFACE_MAP_ENTRY(nsISupports)
-diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp
---- a/js/xpconnect/src/nsXPConnect.cpp
-+++ b/js/xpconnect/src/nsXPConnect.cpp
-@@ -64,17 +64,17 @@
- #include "XPCQuickStubs.h"
- #include "dombindings.h"
- 
- #include "mozilla/Assertions.h"
- #include "mozilla/Base64.h"
- 
- #include "nsWrapperCacheInlines.h"
- 
--#include "jscntxt.h" // context->stackLimit, sizeof(JSContext)
-+#include "jscntxt.h" // sizeof(JSContext)
- 
- NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
-                               nsIXPConnect,
-                               nsISupportsWeakReference,
-                               nsIThreadObserver,
-                               nsIJSRuntimeService,
-                               nsIJSContextStack,
-                               nsIThreadJSContextStack,
-@@ -702,17 +702,17 @@ xpc_GCThingIsGrayCCThing(void *thing)
-  * black in step 2 above. This must be done on everything reachable from the
-  * object being returned. The following code takes care of the recursive
-  * re-coloring.
-  */
- static void
- UnmarkGrayChildren(JSTracer *trc, void *thing, JSGCTraceKind kind)
- {
-     int stackDummy;
--    if (!JS_CHECK_STACK_SIZE(trc->context->stackLimit, &stackDummy)) {
-+    if (!JS_CHECK_STACK_SIZE(js::GetContextStackLimit(trc->context), &stackDummy)) {
-         /*
-          * If we run out of stack, we take a more drastic measure: require that
-          * we GC again before the next CC.
-          */
-         nsXPConnect* xpc = nsXPConnect::GetXPConnect();
-         xpc->EnsureGCBeforeCC();
-         return;
-     }

GetContextStructuredCloneCallbacks

-From: Ms2ger <ms2ger@gmail.com>
-Bug 677079 - Part f: Expose structuredCloneCallbacks in jsfriendapi.h; r=jorendorff
-
-diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp
---- a/dom/base/nsGlobalWindow.cpp
-+++ b/dom/base/nsGlobalWindow.cpp
-@@ -252,18 +252,16 @@
- #include "mozilla/Telemetry.h"
- #include "nsLocation.h"
- #include "nsWrapperCacheInlines.h"
- 
- #ifdef ANDROID
- #include <android/log.h>
- #endif
- 
--#include "jscntxt.h" // cx->runtime->structuredCloneCallbacks
--
- #ifdef PR_LOGGING
- static PRLogModuleInfo* gDOMLeakPRLog;
- #endif
- 
- static const char kStorageEnabled[] = "dom.storage.enabled";
- 
- using namespace mozilla;
- using namespace mozilla::dom;
-@@ -6026,17 +6024,17 @@ PostMessageReadStructuredClone(JSContext
-                                                     getter_AddRefs(wrapper)))) {
-           return JSVAL_TO_OBJECT(val);
-         }
-       }
-     }
-   }
- 
-   const JSStructuredCloneCallbacks* runtimeCallbacks =
--    cx->runtime->structuredCloneCallbacks;
-+    js::GetContextStructuredCloneCallbacks(cx);
- 
-   if (runtimeCallbacks) {
-     return runtimeCallbacks->read(cx, reader, tag, data, nsnull);
-   }
- 
-   return JS_FALSE;
- }
- 
-@@ -6066,17 +6064,17 @@ PostMessageWriteStructuredClone(JSContex
- 
-     if (scTag)
-       return JS_WriteUint32Pair(writer, scTag, 0) &&
-              JS_WriteBytes(writer, &supports, sizeof(supports)) &&
-              scInfo->event->StoreISupports(supports);
-   }
- 
-   const JSStructuredCloneCallbacks* runtimeCallbacks =
--    cx->runtime->structuredCloneCallbacks;
-+    js::GetContextStructuredCloneCallbacks(cx);
- 
-   if (runtimeCallbacks) {
-     return runtimeCallbacks->write(cx, writer, obj, nsnull);
-   }
- 
-   return JS_FALSE;
- }
- 
-diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp
---- a/dom/indexedDB/IDBObjectStore.cpp
-+++ b/dom/indexedDB/IDBObjectStore.cpp
-@@ -36,17 +36,16 @@
-  * the terms of any one of the MPL, the GPL or the LGPL.
-  *
-  * ***** END LICENSE BLOCK ***** */
- 
- #include "IDBObjectStore.h"
- 
- #include "nsIJSContextStack.h"
- 
--#include "jscntxt.h" // structuredCloneCallbacks
- #include "jsfriendapi.h"
- #include "mozilla/dom/StructuredCloneTags.h"
- #include "mozilla/storage.h"
- #include "nsCharSeparatedTokenizer.h"
- #include "nsContentUtils.h"
- #include "nsDOMClassInfo.h"
- #include "nsDOMFile.h"
- #include "nsDOMLists.h"
-@@ -1019,17 +1018,17 @@ IDBObjectStore::StructuredCloneReadCallb
-       NS_WARNING("Failed to wrap native!");
-       return nsnull;
-     }
- 
-     return JSVAL_TO_OBJECT(wrappedFile);
-   }
- 
-   const JSStructuredCloneCallbacks* runtimeCallbacks =
--    aCx->runtime->structuredCloneCallbacks;
-+    js::GetContextStructuredCloneCallbacks(aCx);
- 
-   if (runtimeCallbacks) {
-     return runtimeCallbacks->read(aCx, aReader, aTag, aData, nsnull);
-   }
- 
-   return nsnull;
- }
- 
-@@ -1100,17 +1099,17 @@ IDBObjectStore::StructuredCloneWriteCall
-       cloneWriteInfo->mBlobs.AppendElement(blob);
- 
-       return true;
-     }
-   }
- 
-   // try using the runtime callbacks
-   const JSStructuredCloneCallbacks* runtimeCallbacks =
--    aCx->runtime->structuredCloneCallbacks;
-+    js::GetContextStructuredCloneCallbacks(aCx);
-   if (runtimeCallbacks) {
-     return runtimeCallbacks->write(aCx, aWriter, aObj, nsnull);
-   }
- 
-   return false;
- }
- 
- nsresult
-diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
---- a/js/src/jsfriendapi.cpp
-+++ b/js/src/jsfriendapi.cpp
-@@ -487,16 +487,22 @@ void
- AutoLockGC::lock(JSRuntime *rt)
- {
-     JS_ASSERT(rt);
-     JS_ASSERT(!runtime);
-     runtime = rt;
-     JS_LOCK_GC(rt);
- }
- 
-+JS_FRIEND_API(const JSStructuredCloneCallbacks *)
-+GetContextStructuredCloneCallbacks(JSContext *cx)
-+{
-+    return cx->runtime->structuredCloneCallbacks;
-+}
-+
- #ifdef JS_THREADSAFE
- JSThread *
- GetContextThread(const JSContext *cx)
- {
-     return cx->thread();
- }
- #endif
- 
-diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
---- a/js/src/jsfriendapi.h
-+++ b/js/src/jsfriendapi.h
-@@ -481,16 +481,19 @@ class JS_FRIEND_API(AutoLockGC)
-   private:
-     static void LockGC(JSRuntime *rt);
-     static void UnlockGC(JSRuntime *rt);
- 
-     JSRuntime *runtime;
-     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
- };
- 
-+extern JS_FRIEND_API(const JSStructuredCloneCallbacks *)
-+GetContextStructuredCloneCallbacks(JSContext *cx);
-+
- } /* namespace js */
- 
- /*
-  * If protoKey is not JSProto_Null, then clasp is ignored. If protoKey is
-  * JSProto_Null, clasp must non-null.
-  */
- extern JS_FRIEND_API(JSBool)
- js_GetClassPrototype(JSContext *cx, JSObject *scope, JSProtoKey protoKey,

GuardObjects

-From: Ms2ger <ms2ger@gmail.com>
-Bug 716236 - Fix indentation in GuardObjects.h and allow its inclusion into C files; r=Waldo
-
-diff --git a/mfbt/GuardObjects.h b/mfbt/GuardObjects.h
---- a/mfbt/GuardObjects.h
-+++ b/mfbt/GuardObjects.h
-@@ -33,130 +33,146 @@
-  * use your version of this file under the terms of the MPL, indicate your
-  * decision by deleting the provisions above and replace them with the notice
-  * and other provisions required by the GPL or the LGPL. If you do not delete
-  * the provisions above, a recipient may use your version of this file under
-  * the terms of any one of the MPL, the GPL or the LGPL.
-  *
-  * ***** END LICENSE BLOCK ***** */
- 
-+/* Implementation of macros to ensure correct use of RAII Auto* objects. */
-+
- #ifndef mozilla_GuardObjects_h
- #define mozilla_GuardObjects_h
- 
- #include "mozilla/Assertions.h"
- 
-+#ifdef __cplusplus
-+
-+#ifdef DEBUG
-+
- namespace mozilla {
--  /**
--   * The following classes are designed to cause assertions to detect
--   * inadvertent use of guard objects as temporaries.  In other words,
--   * when we have a guard object whose only purpose is its constructor and
--   * destructor (and is never otherwise referenced), the intended use
--   * might be:
--   *     AutoRestore savePainting(mIsPainting);
--   * but is is easy to accidentally write:
--   *     AutoRestore(mIsPainting);
--   * which compiles just fine, but runs the destructor well before the
--   * intended time.
--   *
--   * They work by adding (#ifdef DEBUG) an additional parameter to the
--   * guard object's constructor, with a default value, so that users of
--   * the guard object's API do not need to do anything.  The default value
--   * of this parameter is a temporary object.  C++ (ISO/IEC 14882:1998),
--   * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a
--   * guarantee that temporaries are destroyed in the reverse of their
--   * construction order, but I actually can't find a statement that that
--   * is true in the general case (beyond the two specific cases mentioned
--   * there).  However, it seems to be true.
--   *
--   * These classes are intended to be used only via the macros immediately
--   * below them:
--   *   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member
--   *     variable, and should be put where a declaration of a private
--   *     member variable would be placed.
--   *   MOZ_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the
--   *     parameters to each constructor of the guard object; it declares
--   *     (ifdef DEBUG) an additional parameter.  (But use the *_ONLY_PARAM
--   *     variant for constructors that take no other parameters.)
--   *   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in
--   *     the implementation of such constructors when they are not inline.
--   *   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in
--   *     the implementation of such constructors to pass the parameter to
--   *     a base class that also uses these macros
--   *   MOZ_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each
--   *     constructor.  It uses the parameter declared by
--   *     MOZ_GUARD_OBJECT_NOTIFIER_PARAM.
--   *
--   * For more details, and examples of using these macros, see
--   * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla
--   */
--#ifdef DEBUG
--  class GuardObjectNotifier
--  {
-+namespace detail {
-+/*
-+ * The following classes are designed to cause assertions to detect
-+ * inadvertent use of guard objects as temporaries. In other words,
-+ * when we have a guard object whose only purpose is its constructor and
-+ * destructor (and is never otherwise referenced), the intended use
-+ * might be:
-+ *
-+ *     AutoRestore savePainting(mIsPainting);
-+ *
-+ * but is is easy to accidentally write:
-+ *
-+ *     AutoRestore(mIsPainting);
-+ *
-+ * which compiles just fine, but runs the destructor well before the
-+ * intended time.
-+ *
-+ * They work by adding (#ifdef DEBUG) an additional parameter to the
-+ * guard object's constructor, with a default value, so that users of
-+ * the guard object's API do not need to do anything. The default value
-+ * of this parameter is a temporary object. C++ (ISO/IEC 14882:1998),
-+ * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a
-+ * guarantee that temporaries are destroyed in the reverse of their
-+ * construction order, but I actually can't find a statement that that
-+ * is true in the general case (beyond the two specific cases mentioned
-+ * there). However, it seems to be true.
-+ *
-+ * These classes are intended to be used only via the macros immediately
-+ * below them:
-+ *
-+ *   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member
-+ *     variable, and should be put where a declaration of a private
-+ *     member variable would be placed.
-+ *   MOZ_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the
-+ *     parameters to each constructor of the guard object; it declares
-+ *     (ifdef DEBUG) an additional parameter. (But use the *_ONLY_PARAM
-+ *     variant for constructors that take no other parameters.)
-+ *   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in
-+ *     the implementation of such constructors when they are not inline.
-+ *   MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in
-+ *     the implementation of such constructors to pass the parameter to
-+ *     a base class that also uses these macros
-+ *   MOZ_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each
-+ *     constructor. It uses the parameter declared by
-+ *     MOZ_GUARD_OBJECT_NOTIFIER_PARAM.
-+ *
-+ * For more details, and examples of using these macros, see
-+ * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla
-+ */
-+class GuardObjectNotifier
-+{
-   private:
--    bool* mStatementDone;
-+    bool* statementDone;
-+
-   public:
--    GuardObjectNotifier() : mStatementDone(NULL) {}
-+    GuardObjectNotifier() : statementDone(NULL) {}
- 
-     ~GuardObjectNotifier() {
--      *mStatementDone = true;
-+        *statementDone = true;
-     }
- 
--    void SetStatementDone(bool *aStatementDone) {
--      mStatementDone = aStatementDone;
-+    void setStatementDone(bool* statementIsDone) {
-+        statementDone = statementIsDone;
-     }
--  };
-+};
- 
--  class GuardObjectNotificationReceiver
--  {
-+class GuardObjectNotificationReceiver
-+{
-   private:
--    bool mStatementDone;
-+    bool statementDone;
-+
-   public:
--    GuardObjectNotificationReceiver() : mStatementDone(false) {}
-+    GuardObjectNotificationReceiver() : statementDone(false) {}
- 
-     ~GuardObjectNotificationReceiver() {
--      /*
--       * Assert that the guard object was not used as a temporary.
--       * (Note that this assert might also fire if Init is not called
--       * because the guard object's implementation is not using the
--       * above macros correctly.)
--       */
--      MOZ_ASSERT(mStatementDone);
-+        /*
-+         * Assert that the guard object was not used as a temporary.
-+         * (Note that this assert might also fire if init is not called
-+         * because the guard object's implementation is not using the
-+         * above macros correctly.)
-+         */
-+        MOZ_ASSERT(statementDone);
-     }
- 
--    void Init(const GuardObjectNotifier &aNotifier) {
--      /*
--       * aNotifier is passed as a const reference so that we can pass a
--       * temporary, but we really intend it as non-const
--       */
--      const_cast<GuardObjectNotifier&>(aNotifier).
--          SetStatementDone(&mStatementDone);
-+    void init(const GuardObjectNotifier& constNotifier) {
-+        /*
-+         * constNotifier is passed as a const reference so that we can pass a
-+         * temporary, but we really intend it as non-const.
-+         */
-+        GuardObjectNotifier& notifier = const_cast<GuardObjectNotifier&>(constNotifier);
-+        notifier.setStatementDone(&statementDone);
-     }
--  };
-+};
- 
--  #define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER \
--      mozilla::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary;
--  #define MOZ_GUARD_OBJECT_NOTIFIER_PARAM \
--      , const mozilla::GuardObjectNotifier& _notifier = \
--                mozilla::GuardObjectNotifier()
--  #define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \
--      const mozilla::GuardObjectNotifier& _notifier = \
--              mozilla::GuardObjectNotifier()
--  #define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \
--      , const mozilla::GuardObjectNotifier& _notifier
--  #define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \
--      , _notifier
--  #define MOZ_GUARD_OBJECT_NOTIFIER_INIT \
--      PR_BEGIN_MACRO _mCheckNotUsedAsTemporary.Init(_notifier); PR_END_MACRO
-+} /* namespace detail */
-+} /* namespace mozilla */
- 
--#else /* defined(DEBUG) */
-+#endif /* DEBUG */
- 
--  #define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
--  #define MOZ_GUARD_OBJECT_NOTIFIER_PARAM
--  #define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM
--  #define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL
--  #define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT
--  #define MOZ_GUARD_OBJECT_NOTIFIER_INIT PR_BEGIN_MACRO PR_END_MACRO
-+#ifdef DEBUG
-+#  define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER \
-+     mozilla::detail::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary;
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_PARAM \
-+     , const mozilla::detail::GuardObjectNotifier& _notifier = \
-+         mozilla::detail::GuardObjectNotifier()
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \
-+     const mozilla::detail::GuardObjectNotifier& _notifier = \
-+         mozilla::detail::GuardObjectNotifier()
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \
-+     , const mozilla::detail::GuardObjectNotifier& _notifier
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \
-+     , _notifier
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_INIT \
-+     do { _mCheckNotUsedAsTemporary.init(_notifier); } while (0)
-+#else
-+#  define MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_PARAM
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT
-+#  define MOZ_GUARD_OBJECT_NOTIFIER_INIT do { } while (0)
-+#endif
- 
--#endif /* !defined(DEBUG) */
--
--} // namespace mozilla
-+#endif /* __cplusplus */
- 
- #endif /* mozilla_GuardObjects_h */