diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index f9b697729d03..8aafde9af320 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -6855,3 +6855,22 @@ JS_CallOnce(JSCallOnceType *once, JSInitCallback func) } #endif } + +namespace JS { + +AutoGCRooter::AutoGCRooter(JSContext *cx, ptrdiff_t tag) + : down(cx->autoGCRooters), tag(tag), context(cx) +{ + JS_ASSERT(this != cx->autoGCRooters); + CHECK_REQUEST(cx); + cx->autoGCRooters = this; +} + +AutoGCRooter::~AutoGCRooter() +{ + JS_ASSERT(this == context->autoGCRooters); + CHECK_REQUEST(context); + context->autoGCRooters = down; +} + +} // namespace JS diff --git a/js/src/jsapi.h b/js/src/jsapi.h index f6afedf41efd..846ac60ca34a 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -54,6 +54,10 @@ #include "js/Utility.h" +#ifdef __cplusplus +#include "mozilla/Attributes.h" +#endif + /************************************************************************/ /* JS::Value can store a full int32_t. */ @@ -786,6 +790,74 @@ inline Anchor::~Anchor() #endif +#if defined JS_THREADSAFE && defined DEBUG + +class JS_PUBLIC_API(AutoCheckRequestDepth) +{ + JSContext *cx; + public: + AutoCheckRequestDepth(JSContext *cx); + ~AutoCheckRequestDepth(); +}; + +# define CHECK_REQUEST(cx) \ + JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx) + +#else + +# define CHECK_REQUEST(cx) \ + ((void) 0) + +#endif + +class JS_PUBLIC_API(AutoGCRooter) { + public: + AutoGCRooter(JSContext *cx, ptrdiff_t tag); + ~AutoGCRooter(); + + /* Implemented in jsgc.cpp. */ + inline void trace(JSTracer *trc); + void traceAll(JSTracer *trc); + + protected: + AutoGCRooter * const down; + + /* + * Discriminates actual subclass of this being used. If non-negative, the + * subclass roots an array of values of the length stored in this field. + * If negative, meaning is indicated by the corresponding value in the enum + * below. Any other negative value indicates some deeper problem such as + * memory corruption. + */ + ptrdiff_t tag; + + JSContext * const context; + + enum { + JSVAL = -1, /* js::AutoValueRooter */ + VALARRAY = -2, /* js::AutoValueArrayRooter */ + PARSER = -3, /* js::Parser */ + SHAPEVECTOR = -4, /* js::AutoShapeVector */ + ENUMERATOR = -5, /* js::AutoEnumStateRooter */ + IDARRAY = -6, /* js::AutoIdArray */ + DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ + NAMESPACES = -8, /* js::AutoNamespaceArray */ + XML = -9, /* js::AutoXMLRooter */ + OBJECT = -10, /* js::AutoObjectRooter */ + ID = -11, /* js::AutoIdRooter */ + VALVECTOR = -12, /* js::AutoValueVector */ + DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */ + STRING = -14, /* js::AutoStringRooter */ + IDVECTOR = -15, /* js::AutoIdVector */ + OBJVECTOR = -16 /* js::AutoObjectVector */ + }; + + private: + /* No copy or assignment semantics. */ + AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; + void operator=(AutoGCRooter &ida) MOZ_DELETE; +}; + } /* namespace JS */ /************************************************************************/ diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index ca652413c12b..73cfd61f54a4 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -1712,3 +1712,26 @@ AutoEnumStateRooter::~AutoEnumStateRooter() } } /* namespace js */ + +namespace JS { + +#if defined JS_THREADSAFE && defined DEBUG + +AutoCheckRequestDepth::AutoCheckRequestDepth(JSContext *cx) + : cx(cx) +{ + JS_ASSERT(cx->thread()); + JS_ASSERT(cx->thread()->data.requestDepth || cx->thread() == cx->runtime->gcThread); + JS_ASSERT(cx->runtime->onOwnerThread()); + cx->thread()->checkRequestDepth++; +} + +AutoCheckRequestDepth::~AutoCheckRequestDepth() +{ + JS_ASSERT(cx->thread()->checkRequestDepth != 0); + cx->thread()->checkRequestDepth--; +} + +#endif + +} // namespace JS diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index 774da801c9c0..97936cbc1e57 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -47,6 +47,7 @@ #include +#include "jsapi.h" #include "jsfriendapi.h" #include "jsprvtd.h" #include "jsatom.h" @@ -794,7 +795,6 @@ extern const JSDebugHooks js_NullDebugHooks; /* defined in jsdbgapi.cpp */ namespace js { -class AutoGCRooter; template class Root; class CheckRoot; @@ -1310,29 +1310,6 @@ struct JSContext namespace js { -#if defined JS_THREADSAFE && defined DEBUG - -class AutoCheckRequestDepth { - JSContext *cx; - public: - AutoCheckRequestDepth(JSContext *cx) : cx(cx) { cx->thread()->checkRequestDepth++; } - - ~AutoCheckRequestDepth() { - JS_ASSERT(cx->thread()->checkRequestDepth != 0); - cx->thread()->checkRequestDepth--; - } -}; - -# define CHECK_REQUEST(cx) \ - JS_ASSERT((cx)->thread()); \ - JS_ASSERT((cx)->thread()->data.requestDepth || (cx)->thread() == (cx)->runtime->gcThread); \ - JS_ASSERT(cx->runtime->onOwnerThread()); \ - AutoCheckRequestDepth _autoCheckRequestDepth(cx); - -#else -# define CHECK_REQUEST(cx) ((void) 0) -#endif - struct AutoResolving { public: enum Kind { @@ -1369,64 +1346,6 @@ struct AutoResolving { JS_DECL_USE_GUARD_OBJECT_NOTIFIER }; -class AutoGCRooter { - public: - AutoGCRooter(JSContext *cx, ptrdiff_t tag) - : down(cx->autoGCRooters), tag(tag), context(cx) - { - JS_ASSERT(this != cx->autoGCRooters); - CHECK_REQUEST(cx); - cx->autoGCRooters = this; - } - - ~AutoGCRooter() { - JS_ASSERT(this == context->autoGCRooters); - CHECK_REQUEST(context); - context->autoGCRooters = down; - } - - /* Implemented in jsgc.cpp. */ - inline void trace(JSTracer *trc); - void traceAll(JSTracer *trc); - - protected: - AutoGCRooter * const down; - - /* - * Discriminates actual subclass of this being used. If non-negative, the - * subclass roots an array of values of the length stored in this field. - * If negative, meaning is indicated by the corresponding value in the enum - * below. Any other negative value indicates some deeper problem such as - * memory corruption. - */ - ptrdiff_t tag; - - JSContext * const context; - - enum { - JSVAL = -1, /* js::AutoValueRooter */ - VALARRAY = -2, /* js::AutoValueArrayRooter */ - PARSER = -3, /* js::Parser */ - SHAPEVECTOR = -4, /* js::AutoShapeVector */ - ENUMERATOR = -5, /* js::AutoEnumStateRooter */ - IDARRAY = -6, /* js::AutoIdArray */ - DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */ - NAMESPACES = -8, /* js::AutoNamespaceArray */ - XML = -9, /* js::AutoXMLRooter */ - OBJECT = -10, /* js::AutoObjectRooter */ - ID = -11, /* js::AutoIdRooter */ - VALVECTOR = -12, /* js::AutoValueVector */ - DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */ - STRING = -14, /* js::AutoStringRooter */ - IDVECTOR = -15, /* js::AutoIdVector */ - OBJVECTOR = -16 /* js::AutoObjectVector */ - }; - - private: - AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE; - void operator=(AutoGCRooter &ida) MOZ_DELETE; -}; - /* * Moving GC Stack Rooting * diff --git a/js/src/jsobjinlines.h b/js/src/jsobjinlines.h index 95c49ec86c0c..ee9a39c639f7 100644 --- a/js/src/jsobjinlines.h +++ b/js/src/jsobjinlines.h @@ -43,6 +43,7 @@ #include +#include "jsapi.h" #include "jsarray.h" #include "jsbool.h" #include "jscntxt.h"