Bug 1281529 part 2 - Make cx->runtime() return |this|. r=jorendorff
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 27 Jun 2016 08:51:46 +0200
changeset 381507 51d28e336d478a2b35bae1668cce76594f732665
parent 381506 cb97f090f9d42cabffef9812f33da36b316ff88d
child 381508 f35504e8fc9de135eb1a697828dcec202d082ffb
push id21504
push userbmo:npang@mozilla.com
push dateMon, 27 Jun 2016 18:10:09 +0000
reviewersjorendorff
bugs1281529
milestone50.0a1
Bug 1281529 part 2 - Make cx->runtime() return |this|. r=jorendorff
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jscntxtinlines.h
js/src/vm/Runtime.h
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -931,22 +931,17 @@ JSContext::isThrowingDebuggeeWouldRun()
            unwrappedException_.isObject() &&
            unwrappedException_.toObject().is<ErrorObject>() &&
            unwrappedException_.toObject().as<ErrorObject>().type() == JSEXN_DEBUGGEEWOULDRUN;
 }
 
 bool
 JSContext::currentlyRunning() const
 {
-    for (ActivationIterator iter(runtime()); !iter.done(); ++iter) {
-        if (iter->cx() == this)
-            return true;
-    }
-
-    return false;
+    return !!activation();
 }
 
 static bool
 ComputeIsJITBroken()
 {
 #if !defined(ANDROID)
     return false;
 #else  // ANDROID
@@ -1056,17 +1051,17 @@ JSVersion
 JSContext::findVersion() const
 {
     if (JSScript* script = currentScript(nullptr, ALLOW_CROSS_COMPARTMENT))
         return script->getVersion();
 
     if (compartment() && compartment()->behaviors().version() != JSVERSION_UNKNOWN)
         return compartment()->behaviors().version();
 
-    return runtime()->defaultVersion();
+    return defaultVersion();
 }
 
 #ifdef DEBUG
 
 JS::AutoCheckRequestDepth::AutoCheckRequestDepth(JSContext* cx)
     : cx(cx)
 {
     MOZ_ASSERT(cx->runtime()->requestDepth || cx->runtime()->isHeapBusy());
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -313,18 +313,18 @@ struct JSContext : public js::ExclusiveC
     using ExclusiveContext::make_unique;
     using ExclusiveContext::new_;
     using ExclusiveContext::permanentAtoms;
     using ExclusiveContext::pod_calloc;
     using ExclusiveContext::pod_malloc;
     using ExclusiveContext::staticStrings;
     using ExclusiveContext::wellKnownSymbols;
 
-    JSRuntime* runtime() const { return runtime_; }
-    js::PerThreadData& mainThread() const { return runtime()->mainThread; }
+    JSRuntime* runtime() { return this; }
+    js::PerThreadData& mainThread() { return this->JSRuntime::mainThread; }
 
     static size_t offsetOfRuntime() {
         return offsetof(JSContext, runtime_);
     }
     static size_t offsetOfCompartment() {
         return offsetof(JSContext, compartment_);
     }
 
--- a/js/src/jscntxtinlines.h
+++ b/js/src/jscntxtinlines.h
@@ -366,17 +366,17 @@ JSContext::setPendingException(js::Value
     // We don't use assertSameCompartment here to allow
     // js::SetPendingExceptionCrossContext to work.
     MOZ_ASSERT_IF(v.isObject(), v.toObject().compartment() == compartment());
 }
 
 inline bool
 JSContext::runningWithTrustedPrincipals() const
 {
-    return !compartment() || compartment()->principals() == runtime()->trustedPrincipals();
+    return !compartment() || compartment()->principals() == trustedPrincipals();
 }
 
 inline void
 js::ExclusiveContext::enterCompartment(JSCompartment* c)
 {
     enterCompartmentDepth_++;
     c->enter();
     setCompartment(c);
@@ -434,17 +434,17 @@ js::ExclusiveContext::setCompartment(JSC
 
 inline JSScript*
 JSContext::currentScript(jsbytecode** ppc,
                          MaybeAllowCrossCompartment allowCrossCompartment) const
 {
     if (ppc)
         *ppc = nullptr;
 
-    js::Activation* act = runtime()->activation();
+    js::Activation* act = activation();
     while (act && (act->cx() != this || (act->isJit() && !act->asJit()->isActive())))
         act = act->prev();
 
     if (!act)
         return nullptr;
 
     MOZ_ASSERT(act->cx() == this);
 
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -1104,17 +1104,17 @@ struct JSRuntime : public JS::shadow::Ru
     bool setDefaultLocale(const char* locale);
 
     /* Reset the default locale to OS defaults. */
     void resetDefaultLocale();
 
     /* Gets current default locale. String remains owned by context. */
     const char* getDefaultLocale();
 
-    JSVersion defaultVersion() { return defaultVersion_; }
+    JSVersion defaultVersion() const { return defaultVersion_; }
     void setDefaultVersion(JSVersion v) { defaultVersion_ = v; }
 
     /* Base address of the native stack for the current thread. */
     const uintptr_t     nativeStackBase;
 
     /* The native stack size limit that runtime should not exceed. */
     size_t              nativeStackQuota[js::StackKindCount];