Skip to content

Instantly share code, notes, and snippets.

@syg
Created December 8, 2012 00:35
Show Gist options
  • Save syg/4237838 to your computer and use it in GitHub Desktop.
Save syg/4237838 to your computer and use it in GitHub Desktop.
diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp
index f20a2f2..0009b47 100644
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -23,7 +23,7 @@ using namespace js;
using namespace JS;
// Required by PerThreadDataFriendFields::getMainThread()
-JS_STATIC_ASSERT(offsetof(JSRuntime, mainThread) == JS_PERTHREADDATAOFFSET);
+JS_STATIC_ASSERT(offsetof(JSRuntime, mainThread) == PerThreadDataFriendFields::PerThreadDataOffset);
PerThreadDataFriendFields::PerThreadDataFriendFields()
{
diff --git a/js/src/jspubtd.h b/js/src/jspubtd.h
index f914697d2..cf76af0 100644
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -318,6 +318,14 @@ class PerThreadData;
struct PerThreadDataFriendFields
{
+ private:
+ struct RuntimeDummy : RuntimeFriendFields
+ {
+ void *perThread;
+ };
+
+ public:
+
PerThreadDataFriendFields();
#if defined(JSGC_ROOT_ANALYSIS) || defined(JSGC_USE_EXACT_ROOTING)
@@ -331,42 +339,28 @@ struct PerThreadDataFriendFields
/* Limit pointer for checking native stack consumption. */
uintptr_t nativeStackLimit;
- static inline PerThreadDataFriendFields *get(js::PerThreadData *pt);
- static inline PerThreadDataFriendFields *getMainThread(JSRuntime *rt);
- static inline const PerThreadDataFriendFields *getMainThread(const JSRuntime *rt);};
+ static const size_t PerThreadDataOffset = offsetof(RuntimeDummy, perThread);
-// Note: this type only exists to permit us to derive the offset of
-// the perThread data within the real JSRuntime* type in a portable
-// way.
-struct __RuntimeDummy : RuntimeFriendFields
-{
- PerThreadDataFriendFields perThread;
-};
+ static inline PerThreadDataFriendFields *get(js::PerThreadData *pt) {
+ return reinterpret_cast<PerThreadDataFriendFields *>(pt);
+ }
-#define JS_PERTHREADDATAOFFSET offsetof(__RuntimeDummy, perThread)
+ static inline PerThreadDataFriendFields *getMainThread(JSRuntime *rt) {
+ // mainThread must always appear directly after |RuntimeFriendFields|.
+ // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp|
+ return reinterpret_cast<PerThreadDataFriendFields *>(
+ reinterpret_cast<char*>(rt) + PerThreadDataOffset);
+ }
-} /* namespace js */
+ static inline const PerThreadDataFriendFields *getMainThread(const JSRuntime *rt) {
+ // mainThread must always appear directly after |RuntimeFriendFields|.
+ // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp|
+ return reinterpret_cast<const PerThreadDataFriendFields *>(
+ reinterpret_cast<const char*>(rt) + PerThreadDataOffset);
+ }
+};
-js::PerThreadDataFriendFields *
-js::PerThreadDataFriendFields::get(js::PerThreadData *pt) {
- return reinterpret_cast<PerThreadDataFriendFields *>(pt);
-}
-
-js::PerThreadDataFriendFields *
-js::PerThreadDataFriendFields::getMainThread(JSRuntime *rt) {
- // mainThread must always appear directly after |RuntimeFriendFields|.
- // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp|
- return reinterpret_cast<PerThreadDataFriendFields *>(
- reinterpret_cast<char*>(rt) + JS_PERTHREADDATAOFFSET);
-}
-
-const js::PerThreadDataFriendFields *
-js::PerThreadDataFriendFields::getMainThread(const JSRuntime *rt) {
- // mainThread must always appear directly after |RuntimeFriendFields|.
- // Tested by a JS_STATIC_ASSERT in |jsfriendapi.cpp|
- return reinterpret_cast<const PerThreadDataFriendFields *>(
- reinterpret_cast<const char*>(rt) + JS_PERTHREADDATAOFFSET);
-}
+} /* namespace js */
#endif /* __cplusplus */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment