Bug 1469006 - Replace some script->compartment() calls with script->realm(). r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 22 Jun 2018 09:54:22 +0200
changeset 480103 f1b6b50a1b9a4cab76e2bd51b8f1fa01a8c06d70
parent 480102 2fa69e8f19b92e2bc11de7cbea3300cdab6a56c4
child 480104 21a438d7881dff06ad8afa3f24d118cb5206de15
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1469006
milestone62.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 1469006 - Replace some script->compartment() calls with script->realm(). r=luke
js/src/builtin/Eval.cpp
js/src/jit/BaselineDebugModeOSR.cpp
js/src/jsapi.cpp
js/src/shell/js.cpp
js/src/vm/BytecodeUtil.cpp
js/src/vm/BytecodeUtil.h
js/src/vm/Debugger.cpp
js/src/vm/HelperThreads.cpp
js/src/vm/JSFunction-inl.h
js/src/vm/JSFunction.cpp
js/src/vm/JSFunction.h
js/src/vm/SelfHosting.cpp
js/src/vm/Stack.cpp
--- a/js/src/builtin/Eval.cpp
+++ b/js/src/builtin/Eval.cpp
@@ -437,17 +437,17 @@ static bool
 ExecuteInExtensibleLexicalEnvironment(JSContext* cx, HandleScript scriptArg, HandleObject env)
 {
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, env);
     MOZ_ASSERT(IsExtensibleLexicalEnvironment(env));
     MOZ_RELEASE_ASSERT(scriptArg->hasNonSyntacticScope());
 
     RootedScript script(cx, scriptArg);
-    if (script->compartment() != cx->compartment()) {
+    if (script->realm() != cx->realm()) {
         script = CloneGlobalScript(cx, ScopeKind::NonSyntactic, script);
         if (!script)
             return false;
 
         Debugger::onNewScript(cx, script);
     }
 
     RootedValue rval(cx);
--- a/js/src/jit/BaselineDebugModeOSR.cpp
+++ b/js/src/jit/BaselineDebugModeOSR.cpp
@@ -794,17 +794,17 @@ CloneOldBaselineStub(JSContext* cx, Debu
 }
 
 static bool
 InvalidateScriptsInZone(JSContext* cx, Zone* zone, const Vector<DebugModeOSREntry>& entries)
 {
     RecompileInfoVector invalid;
     for (UniqueScriptOSREntryIter iter(entries); !iter.done(); ++iter) {
         JSScript* script = iter.entry().script;
-        if (script->compartment()->zone() != zone)
+        if (script->zone() != zone)
             continue;
 
         if (script->hasIonScript()) {
             if (!invalid.emplaceBack(script, script->ionScript()->compilationId())) {
                 ReportOutOfMemory(cx);
                 return false;
             }
         }
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3594,17 +3594,17 @@ CloneFunctionObject(JSContext* cx, Handl
         return nullptr;
     }
 
     if (!IsFunctionCloneable(fun)) {
         JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_CLONE_FUNOBJ_SCOPE);
         return nullptr;
     }
 
-    if (CanReuseScriptForClone(cx->compartment(), fun, env)) {
+    if (CanReuseScriptForClone(cx->realm(), fun, env)) {
         // If the script is to be reused, either the script can already handle
         // non-syntactic scopes, or there is only the standard global lexical
         // scope.
 #ifdef DEBUG
         // Fail here if we OOM during debug asserting.
         // CloneFunctionReuseScript will delazify the script anyways, so we
         // are not creating an extra failure condition for DEBUG builds.
         if (!JSFunction::getOrCreateScript(cx, fun))
@@ -4704,34 +4704,34 @@ JS_ExecuteScript(JSContext* cx, AutoObje
 
 JS_PUBLIC_API(bool)
 JS::CloneAndExecuteScript(JSContext* cx, HandleScript scriptArg,
                           JS::MutableHandleValue rval)
 {
     CHECK_REQUEST(cx);
     RootedScript script(cx, scriptArg);
     RootedObject globalLexical(cx, &cx->global()->lexicalEnvironment());
-    if (script->compartment() != cx->compartment()) {
+    if (script->realm() != cx->realm()) {
         script = CloneGlobalScript(cx, ScopeKind::Global, script);
         if (!script)
             return false;
 
         js::Debugger::onNewScript(cx, script);
     }
     return ExecuteScript(cx, globalLexical, script, rval.address());
 }
 
 JS_PUBLIC_API(bool)
 JS::CloneAndExecuteScript(JSContext* cx, JS::AutoObjectVector& envChain,
                           HandleScript scriptArg,
                           JS::MutableHandleValue rval)
 {
     CHECK_REQUEST(cx);
     RootedScript script(cx, scriptArg);
-    if (script->compartment() != cx->compartment()) {
+    if (script->realm() != cx->realm()) {
         script = CloneGlobalScript(cx, ScopeKind::NonSyntactic, script);
         if (!script)
             return false;
 
         js::Debugger::onNewScript(cx, script);
     }
     return ExecuteScript(cx, envChain, script, rval.address());
 }
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -8900,17 +8900,17 @@ Shell(JSContext* cx, OptionParser* op, c
     if (!GetShellContext(cx)->quitting)
         js::RunJobs(cx);
 
     if (sc->exitCode)
         result = sc->exitCode;
 
     if (enableDisassemblyDumps) {
         AutoReportException are(cx);
-        if (!js::DumpCompartmentPCCounts(cx))
+        if (!js::DumpRealmPCCounts(cx))
             result = EXITCODE_OUT_OF_MEMORY;
     }
 
     if (!op->getBoolOption("no-js-cache-per-process")) {
         if (jsCacheAsmJSPath) {
             unlink(jsCacheAsmJSPath);
             JS_free(cx, const_cast<char*>(jsCacheAsmJSPath));
         }
--- a/js/src/vm/BytecodeUtil.cpp
+++ b/js/src/vm/BytecodeUtil.cpp
@@ -186,22 +186,22 @@ DumpPCCounts(JSContext* cx, HandleScript
 
         ionCounts = ionCounts->previous();
     }
 
     return true;
 }
 
 bool
-js::DumpCompartmentPCCounts(JSContext* cx)
+js::DumpRealmPCCounts(JSContext* cx)
 {
     Rooted<GCVector<JSScript*>> scripts(cx, GCVector<JSScript*>(cx));
     for (auto iter = cx->zone()->cellIter<JSScript>(); !iter.done(); iter.next()) {
         JSScript* script = iter;
-        if (script->compartment() != cx->compartment())
+        if (script->realm() != cx->realm())
             continue;
         if (script->hasScriptCounts()) {
             if (!scripts.append(script))
                 return false;
         }
     }
 
     for (uint32_t i = 0; i < scripts.length(); i++) {
--- a/js/src/vm/BytecodeUtil.h
+++ b/js/src/vm/BytecodeUtil.h
@@ -921,13 +921,13 @@ Disassemble(JSContext* cx, JS::Handle<JS
 
 unsigned
 Disassemble1(JSContext* cx, JS::Handle<JSScript*> script, jsbytecode* pc, unsigned loc,
              bool lines, Sprinter* sp);
 
 #endif
 
 extern MOZ_MUST_USE bool
-DumpCompartmentPCCounts(JSContext* cx);
+DumpRealmPCCounts(JSContext* cx);
 
 } // namespace js
 
 #endif /* vm_BytecodeUtil_h */
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -2406,19 +2406,19 @@ class MOZ_RAII ExecutionObservableFrame 
     explicit ExecutionObservableFrame(AbstractFramePtr frame
                                       MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
       : frame_(frame)
     {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     }
 
     Zone* singleZone() const override {
-        // We never inline across compartments, let alone across zones, so
+        // We never inline across realms, let alone across zones, so
         // frames_'s script's zone is the only one of interest.
-        return frame_.script()->compartment()->zone();
+        return frame_.script()->zone();
     }
 
     JSScript* singleScriptForZoneInvalidation() const override {
         MOZ_CRASH("ExecutionObservableFrame shouldn't need zone-wide invalidation.");
         return nullptr;
     }
 
     bool shouldRecompileOrInvalidate(JSScript* script) const override {
@@ -2467,17 +2467,17 @@ class MOZ_RAII ExecutionObservableScript
   public:
     ExecutionObservableScript(JSContext* cx, JSScript* script
                               MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
       : script_(cx, script)
     {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
     }
 
-    Zone* singleZone() const override { return script_->compartment()->zone(); }
+    Zone* singleZone() const override { return script_->zone(); }
     JSScript* singleScriptForZoneInvalidation() const override { return script_; }
     bool shouldRecompileOrInvalidate(JSScript* script) const override {
         return script->hasBaselineScript() && script == script_;
     }
     bool shouldMarkAsDebuggee(FrameIter& iter) const override {
         // AbstractFramePtr can't refer to non-remateralized Ion frames, and
         // while a non-rematerialized Ion frame may indeed be running script_,
         // we cannot mark them as debuggees until they bail out.
@@ -2550,20 +2550,20 @@ MarkBaselineScriptActiveIfObservable(JSS
 {
     if (obs.shouldRecompileOrInvalidate(script))
         script->baselineScript()->setActive();
 }
 
 static bool
 AppendAndInvalidateScript(JSContext* cx, Zone* zone, JSScript* script, Vector<JSScript*>& scripts)
 {
-    // Enter the script's compartment as addPendingRecompile attempts to
+    // Enter the script's realm as addPendingRecompile attempts to
     // cancel off-thread compilations, whose books are kept on the
-    // script's compartment.
-    MOZ_ASSERT(script->compartment()->zone() == zone);
+    // script's realm.
+    MOZ_ASSERT(script->zone() == zone);
     AutoRealm ar(cx, script);
     zone->types.addPendingRecompile(cx, script);
     return scripts.append(script);
 }
 
 static bool
 UpdateExecutionObservabilityOfScriptsInZone(JSContext* cx, Zone* zone,
                                             const Debugger::ExecutionObservableSet& obs,
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -2002,17 +2002,17 @@ HelperThread::handleIonWorkload(AutoLock
     jit::IonBuilder* builder = HelperThreadState().highestPriorityPendingIonCompile(locked);
 
     // The build is taken by this thread. Unfreeze the LifoAlloc to allow
     // mutations.
     builder->alloc().lifoAlloc()->setReadWrite();
 
     currentTask.emplace(builder);
 
-    JSRuntime* rt = builder->script()->compartment()->runtimeFromAnyThread();
+    JSRuntime* rt = builder->script()->runtimeFromAnyThread();
 
     {
         AutoUnlockHelperThreadState unlock(locked);
 
         TraceLoggerThread* logger = TraceLoggerForCurrentThread();
         TraceLoggerEvent event(TraceLogger_AnnotateScripts, builder->script());
         AutoTraceLog logScript(logger, event);
         AutoTraceLog logCompile(logger, TraceLogger_IonCompilation);
--- a/js/src/vm/JSFunction-inl.h
+++ b/js/src/vm/JSFunction-inl.h
@@ -73,17 +73,17 @@ CloneFunctionObjectIfNotSingleton(JSCont
     // These intermediate variables are needed to avoid link errors on some
     // platforms.  Sigh.
     gc::AllocKind finalizeKind = gc::AllocKind::FUNCTION;
     gc::AllocKind extendedFinalizeKind = gc::AllocKind::FUNCTION_EXTENDED;
     gc::AllocKind kind = fun->isExtended()
                          ? extendedFinalizeKind
                          : finalizeKind;
 
-    if (CanReuseScriptForClone(cx->compartment(), fun, parent))
+    if (CanReuseScriptForClone(cx->realm(), fun, parent))
         return CloneFunctionReuseScript(cx, fun, parent, kind, newKind, proto);
 
     RootedScript script(cx, JSFunction::getOrCreateScript(cx, fun));
     if (!script)
         return nullptr;
     RootedScope enclosingScope(cx, script->enclosingScope());
     return CloneFunctionAndScript(cx, fun, parent, enclosingScope, kind, proto);
 }
--- a/js/src/vm/JSFunction.cpp
+++ b/js/src/vm/JSFunction.cpp
@@ -2094,22 +2094,22 @@ js::NewFunctionWithProto(JSContext* cx, 
     if (allocKind == AllocKind::FUNCTION_EXTENDED)
         fun->initializeExtended();
     fun->initAtom(atom);
 
     return fun;
 }
 
 bool
-js::CanReuseScriptForClone(JS::Compartment* compartment, HandleFunction fun,
+js::CanReuseScriptForClone(JS::Realm* realm, HandleFunction fun,
                            HandleObject newParent)
 {
     MOZ_ASSERT(fun->isInterpreted());
 
-    if (compartment != fun->compartment() ||
+    if (realm != fun->realm() ||
         fun->isSingleton() ||
         ObjectGroup::useSingletonForClone(fun))
     {
         return false;
     }
 
     if (newParent->is<GlobalObject>())
         return true;
@@ -2183,17 +2183,17 @@ JSFunction*
 js::CloneFunctionReuseScript(JSContext* cx, HandleFunction fun, HandleObject enclosingEnv,
                              gc::AllocKind allocKind /* = FUNCTION */ ,
                              NewObjectKind newKind /* = GenericObject */,
                              HandleObject proto /* = nullptr */)
 {
     MOZ_ASSERT(NewFunctionEnvironmentIsWellFormed(cx, enclosingEnv));
     MOZ_ASSERT(fun->isInterpreted());
     MOZ_ASSERT(!fun->isBoundFunction());
-    MOZ_ASSERT(CanReuseScriptForClone(cx->compartment(), fun, enclosingEnv));
+    MOZ_ASSERT(CanReuseScriptForClone(cx->realm(), fun, enclosingEnv));
 
     RootedFunction clone(cx, NewFunctionClone(cx, fun, newKind, allocKind, proto));
     if (!clone)
         return nullptr;
 
     if (fun->hasScript()) {
         clone->initScript(fun->nonLazyScript());
         clone->initEnvironment(enclosingEnv);
@@ -2245,17 +2245,17 @@ js::CloneFunctionAndScript(JSContext* cx
     RootedObject terminatingEnv(cx, enclosingEnv);
     while (IsSyntacticEnvironment(terminatingEnv))
         terminatingEnv = terminatingEnv->enclosingEnvironment();
     MOZ_ASSERT_IF(!terminatingEnv->is<GlobalObject>(),
                   newScope->hasOnChain(ScopeKind::NonSyntactic));
 #endif
 
     RootedScript script(cx, fun->nonLazyScript());
-    MOZ_ASSERT(script->compartment() == fun->compartment());
+    MOZ_ASSERT(script->realm() == fun->realm());
     MOZ_ASSERT(cx->compartment() == clone->compartment(),
                "Otherwise we could relazify clone below!");
 
     RootedScript clonedScript(cx, CloneScriptIntoFunction(cx, newScope, clone, script));
     if (!clonedScript)
         return nullptr;
     Debugger::onNewScript(cx, clonedScript);
 
--- a/js/src/vm/JSFunction.h
+++ b/js/src/vm/JSFunction.h
@@ -926,17 +926,17 @@ class FunctionExtended : public JSFuncti
   private:
     friend class JSFunction;
 
     /* Reserved slots available for storage by particular native functions. */
     GCPtrValue extendedSlots[NUM_EXTENDED_SLOTS];
 };
 
 extern bool
-CanReuseScriptForClone(JS::Compartment* compartment, HandleFunction fun, HandleObject newParent);
+CanReuseScriptForClone(JS::Realm* realm, HandleFunction fun, HandleObject newParent);
 
 extern JSFunction*
 CloneFunctionReuseScript(JSContext* cx, HandleFunction fun, HandleObject parent,
                          gc::AllocKind kind = gc::AllocKind::FUNCTION,
                          NewObjectKind newKindArg = GenericObject,
                          HandleObject proto = nullptr);
 
 // Functions whose scripts are cloned are always given singleton types.
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -3127,17 +3127,17 @@ CloneObject(JSContext* cx, HandleNativeO
             MOZ_ASSERT(!selfHostedFunction->isArrow());
             js::gc::AllocKind kind = hasName
                 ? gc::AllocKind::FUNCTION_EXTENDED
                 : selfHostedFunction->getAllocKind();
 
             Handle<GlobalObject*> global = cx->global();
             Rooted<LexicalEnvironmentObject*> globalLexical(cx, &global->lexicalEnvironment());
             RootedScope emptyGlobalScope(cx, &global->emptyGlobalScope());
-            MOZ_ASSERT(!CanReuseScriptForClone(cx->compartment(), selfHostedFunction, global));
+            MOZ_ASSERT(!CanReuseScriptForClone(cx->realm(), selfHostedFunction, global));
             clone = CloneFunctionAndScript(cx, selfHostedFunction, globalLexical, emptyGlobalScope,
                                            kind);
             // To be able to re-lazify the cloned function, its name in the
             // self-hosting compartment has to be stored on the clone.
             if (clone && hasName) {
                 Value nameVal = StringValue(selfHostedFunction->explicitName());
                 clone->as<JSFunction>().setExtendedSlot(LAZY_FUNCTION_NAME_SLOT, nameVal);
             }
--- a/js/src/vm/Stack.cpp
+++ b/js/src/vm/Stack.cpp
@@ -1283,17 +1283,17 @@ FrameIter::matchCallee(JSContext* cx, Ha
     {
         return false;
     }
 
     // Use the same condition as |js::CloneFunctionObject|, to know if we should
     // expect both functions to have the same JSScript. If so, and if they are
     // different, then they cannot be equal.
     RootedObject global(cx, &fun->global());
-    bool useSameScript = CanReuseScriptForClone(fun->compartment(), currentCallee, global);
+    bool useSameScript = CanReuseScriptForClone(fun->realm(), currentCallee, global);
     if (useSameScript &&
         (currentCallee->hasScript() != fun->hasScript() ||
          currentCallee->nonLazyScript() != fun->nonLazyScript()))
     {
         return false;
     }
 
     // If none of the previous filters worked, then take the risk of