Bug 773911 part 1. Inline js::GetContextCompartment. r=waldo
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 15 Dec 2012 11:53:15 -0500
changeset 125255 79c26e82dfebe302c23867f46df11926d92aece4
parent 125254 82077de3f9bc573f09268bfcc01f7dcc7f63ac5d
child 125256 ea066846993ce8d78286deb51ce74333e1dba538
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs773911
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 773911 part 1. Inline js::GetContextCompartment. r=waldo
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
js/src/jspubtd.h
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1094,17 +1094,16 @@ JSContext::JSContext(JSRuntime *rt)
     hasVersionOverride(false),
     throwing(false),
     exception(UndefinedValue()),
     runOptions(0),
     reportGranularity(JS_DEFAULT_JITREPORT_GRANULARITY),
     localeCallbacks(NULL),
     resolvingList(NULL),
     generatingError(false),
-    compartment(NULL),
     enterCompartmentDepth_(0),
     savedFrameChains_(),
     defaultCompartmentObject_(NULL),
     stack(thisDuringConstruction()),
     parseMapPool_(NULL),
     cycleDetectorSet(thisDuringConstruction()),
     errorReporter(NULL),
     operationCallback(NULL),
@@ -1124,16 +1123,19 @@ JSContext::JSContext(JSRuntime *rt)
 #endif
     enumerators(NULL),
     innermostGenerator_(NULL),
 #ifdef DEBUG
     stackIterAssertionEnabled(true),
 #endif
     activeCompilations(0)
 {
+    JS_ASSERT(static_cast<ContextFriendFields*>(this) ==
+              ContextFriendFields::get(this));
+
 #ifdef JSGC_ROOT_ANALYSIS
     PodArrayZero(thingGCRooters);
 #if defined(JS_GC_ZEAL) && defined(DEBUG) && !defined(JS_THREADSAFE)
     skipGCRooters = NULL;
 #endif
 #endif
 }
 
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -1370,19 +1370,16 @@ struct JSContext : js::ContextFriendFiel
     /* Locale specific callbacks for string conversion. */
     JSLocaleCallbacks   *localeCallbacks;
 
     js::AutoResolving   *resolvingList;
 
     /* True if generating an error, to prevent runaway recursion. */
     bool                generatingError;
 
-    /* The current compartment. */
-    JSCompartment       *compartment;
-
     inline void setCompartment(JSCompartment *c) { compartment = c; }
 
     /*
      * "Entering" a compartment changes cx->compartment (which changes
      * cx->global). Note that this does not push any StackFrame which means
      * that it is possible for cx->fp()->compartment() != cx->compartment.
      * This is not a problem since, in general, most places in the VM cannot
      * know that they were called from script (e.g., they may have been called
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -759,22 +759,16 @@ js::GetOwnerThread(const JSContext *cx)
 
 JS_FRIEND_API(bool)
 js::ContextHasOutstandingRequests(const JSContext *cx)
 {
     return cx->outstandingRequests > 0;
 }
 #endif
 
-JS_FRIEND_API(JSCompartment *)
-js::GetContextCompartment(const JSContext *cx)
-{
-    return cx->compartment;
-}
-
 JS_FRIEND_API(bool)
 js::HasUnrootedGlobal(const JSContext *cx)
 {
     return cx->hasRunOption(JSOPTION_UNROOTED_GLOBAL);
 }
 
 JS_FRIEND_API(void)
 js::SetActivityCallback(JSRuntime *rt, ActivityCallback cb, void *arg)
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -193,16 +193,22 @@ namespace js {
 extern mozilla::ThreadLocal<PerThreadData *> TlsPerThreadData;
 
 inline JSRuntime *
 GetRuntime(const JSContext *cx)
 {
     return ContextFriendFields::get(cx)->runtime;
 }
 
+inline JSCompartment *
+GetContextCompartment(const JSContext *cx)
+{
+    return ContextFriendFields::get(cx)->compartment;
+}
+
 typedef bool
 (* PreserveWrapperCallback)(JSContext *cx, JSObject *obj);
 
  /*
   * Dump the complete object graph of heap-allocated things.
   * fp is the file for the dump output.
   */
 extern JS_FRIEND_API(void)
@@ -677,19 +683,16 @@ ProfilingGetPC(JSRuntime *rt, JSScript *
 #ifdef JS_THREADSAFE
 JS_FRIEND_API(void *)
 GetOwnerThread(const JSContext *cx);
 
 JS_FRIEND_API(bool)
 ContextHasOutstandingRequests(const JSContext *cx);
 #endif
 
-JS_FRIEND_API(JSCompartment *)
-GetContextCompartment(const JSContext *cx);
-
 JS_FRIEND_API(bool)
 HasUnrootedGlobal(const JSContext *cx);
 
 typedef void
 (* ActivityCallback)(void *arg, JSBool active);
 
 /*
  * Sets a callback that is run whenever the runtime goes idle - the
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -260,18 +260,22 @@ template <> struct RootKind<JSFunction *
 template <> struct RootKind<JSString *> : SpecificRootKind<JSString *, THING_ROOT_STRING> {};
 template <> struct RootKind<JSScript *> : SpecificRootKind<JSScript *, THING_ROOT_SCRIPT> {};
 template <> struct RootKind<jsid> : SpecificRootKind<jsid, THING_ROOT_ID> {};
 template <> struct RootKind<JS::Value> : SpecificRootKind<JS::Value, THING_ROOT_VALUE> {};
 
 struct ContextFriendFields {
     JSRuntime *const    runtime;
 
-    ContextFriendFields(JSRuntime *rt)
-      : runtime(rt) { }
+    /* The current compartment. */
+    JSCompartment       *compartment;
+
+    explicit ContextFriendFields(JSRuntime *rt)
+      : runtime(rt), compartment(NULL)
+    { }
 
     static const ContextFriendFields *get(const JSContext *cx) {
         return reinterpret_cast<const ContextFriendFields *>(cx);
     }
 
     static ContextFriendFields *get(JSContext *cx) {
         return reinterpret_cast<ContextFriendFields *>(cx);
     }