Bug 883450 - Assert that we're in a request whenever we create a Rooted<T>. r=terrence

This commit is contained in:
Bobby Holley 2013-06-20 11:05:34 -07:00
parent 2fa8b1cfb0
commit 68f0e73503
2 changed files with 19 additions and 0 deletions

View File

@ -497,6 +497,12 @@ struct GCMethods<T *>
#endif
};
#if defined(DEBUG) && defined(JS_THREADSAFE)
/* This helper allows us to assert that Rooted<T> is scoped within a request. */
extern JS_PUBLIC_API(bool)
IsInRequest(JSContext *cx);
#endif
} /* namespace js */
namespace JS {
@ -513,6 +519,10 @@ template <typename T>
class MOZ_STACK_CLASS Rooted : public js::RootedBase<T>
{
void init(JSContext *cxArg) {
MOZ_ASSERT(cxArg);
#ifdef JS_THREADSAFE
MOZ_ASSERT(js::IsInRequest(cxArg));
#endif
#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
js::ContextFriendFields *cx = js::ContextFriendFields::get(cxArg);
commonInit(cx->thingGCRooters);
@ -520,6 +530,7 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase<T>
}
void init(js::PerThreadDataFriendFields *pt) {
MOZ_ASSERT(pt);
#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
commonInit(pt->thingGCRooters);
#endif

View File

@ -1108,3 +1108,11 @@ js_ReportIsNotFunction(JSContext *cx, const JS::Value& v)
{
return ReportIsNotFunction(cx, v);
}
#if defined(DEBUG) && defined(JS_THREADSAFE)
JS_PUBLIC_API(bool)
js::IsInRequest(JSContext *cx)
{
return !!cx->runtime()->requestDepth;
}
#endif