diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 0b2a4ce3520..f9b697729d0 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -6587,6 +6587,12 @@ JS_ThrowStopIteration(JSContext *cx) return js_ThrowStopIteration(cx); } +JS_PUBLIC_API(intptr_t) +JS_GetCurrentThread() +{ + return reinterpret_cast(js_CurrentThreadId()); +} + /* * Get the owning thread id of a context. Returns 0 if the context is not * owned by any thread. @@ -6595,7 +6601,7 @@ JS_PUBLIC_API(intptr_t) JS_GetContextThread(JSContext *cx) { #ifdef JS_THREADSAFE - return reinterpret_cast(JS_THREAD_ID(cx)); + return cx->thread() ? reinterpret_cast(cx->thread()->id) : 0; #else return 0; #endif diff --git a/js/src/jsapi.h b/js/src/jsapi.h index a982ae6f8ef..f6afedf41ef 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -4929,6 +4929,9 @@ JS_ThrowReportedError(JSContext *cx, const char *message, extern JS_PUBLIC_API(JSBool) JS_ThrowStopIteration(JSContext *cx); +extern JS_PUBLIC_API(intptr_t) +JS_GetCurrentThread(); + /* * Associate the current thread with the given context. This is done * implicitly by JS_NewContext. diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index ac7ae79a454..774da801c9c 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -1310,10 +1310,6 @@ struct JSContext namespace js { -#ifdef JS_THREADSAFE -# define JS_THREAD_ID(cx) ((cx)->thread() ? (cx)->thread()->id : 0) -#endif - #if defined JS_THREADSAFE && defined DEBUG class AutoCheckRequestDepth { diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index d643ee71deb..a6e4fa81290 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -458,3 +458,15 @@ js::DumpHeapComplete(JSContext *cx, FILE *fp) } #endif + +namespace js { + +#ifdef JS_THREADSAFE +JSThread * +GetContextThread(const JSContext *cx) +{ + return cx->thread(); +} +#endif + +} // namespace js diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 3b6c06fa3ca..292a4988c62 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -445,6 +445,11 @@ 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); +#endif + } /* namespace js */ /* diff --git a/js/xpconnect/src/XPCThreadContext.cpp b/js/xpconnect/src/XPCThreadContext.cpp index c85539817d6..c96385616f1 100644 --- a/js/xpconnect/src/XPCThreadContext.cpp +++ b/js/xpconnect/src/XPCThreadContext.cpp @@ -423,7 +423,7 @@ XPCPerThreadData::GetDataImpl(JSContext *cx) } if (cx && !sMainJSThread && NS_IsMainThread()) { - sMainJSThread = cx->thread(); + sMainJSThread = js::GetContextThread(cx); sMainThreadData = data; diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 10725a1e0a1..973ff5d7fce 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -552,7 +552,7 @@ GetContextFromObject(JSObject *obj) if (xpcc) { JSContext *cx = xpcc->GetJSContext(); - if (cx->thread()->id == js_CurrentThreadId()) + if (JS_GetContextThread(cx) == JS_GetCurrentThread()) return cx; } diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 2542fec62fc..4fec388fdf1 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -3646,9 +3646,9 @@ public: static inline XPCPerThreadData* GetData(JSContext *cx) { if (cx) { - NS_ASSERTION(cx->thread(), "Uh, JS context w/o a thread?"); + NS_ASSERTION(js::GetContextThread(cx), "Uh, JS context w/o a thread?"); - if (cx->thread() == sMainJSThread) + if (js::GetContextThread(cx) == sMainJSThread) return sMainThreadData; } else if (sMainThreadData && sMainThreadData->mThread == PR_GetCurrentThread()) { return sMainThreadData; @@ -3751,7 +3751,7 @@ public: {sMainJSThread = nsnull; sMainThreadData = nsnull;} static bool IsMainThread(JSContext *cx) - { return cx->thread() == sMainJSThread; } + { return js::GetContextThread(cx) == sMainJSThread; } private: XPCPerThreadData();