Bug 677079 - Part z: Move JS_CHECK_RECURSION to jsfriendapi.h; r=mjrosenb
authorMs2ger <ms2ger@gmail.com>
Sun, 15 Jan 2012 09:13:11 +0100
changeset 85703 cf1294a14a4c97a3ed2dd1da1ceca715a0d926df
parent 85702 9ee7f65718423e5a684602699295933a08624fdf
child 85704 9f706102086fbbc7b622d1a562d28d107b6ee269
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmjrosenb
bugs677079
milestone12.0a1
Bug 677079 - Part z: Move JS_CHECK_RECURSION to jsfriendapi.h; r=mjrosenb
js/src/jscntxt.h
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/xpconnect/src/XPCVariant.cpp
js/xpconnect/src/nsXPConnect.cpp
--- 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
--- 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
--- 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);
--- 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)
--- 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;
     }