Bug 1461938 part 40 - Use private inheritance. r=evilpie

This commit is contained in:
Jan de Mooij 2018-05-25 11:12:04 +02:00
parent 194d004c4d
commit 8c3f199bdd
9 changed files with 38 additions and 20 deletions

View File

@ -4253,8 +4253,9 @@ GCRuntime::prepareZonesForCollection(JS::gcreason::Reason reason, bool* isFullOu
for (RealmsIter r(rt, WithAtoms); !r.done(); r.next()) {
r->unmark();
r->scheduledForDestruction = false;
r->maybeAlive = r->shouldTraceGlobal() || !r->zone()->isGCScheduled();
JSCompartment* comp = JS::GetCompartmentForRealm(r);
comp->scheduledForDestruction = false;
comp->maybeAlive = r->shouldTraceGlobal() || !r->zone()->isGCScheduled();
if (shouldPreserveJITCode(r, currentTime, reason, canAllocateMoreCode))
r->zone()->setPreservingCode(true);
}
@ -7953,16 +7954,16 @@ js::NewCompartment(JSContext* cx, JSPrincipals* principals,
}
}
ScopedJSDeletePtr<Realm> compartment(cx->new_<Realm>(zone, options));
if (!compartment || !compartment->init(cx))
ScopedJSDeletePtr<Realm> realm(cx->new_<Realm>(zone, options));
if (!realm || !realm->init(cx))
return nullptr;
// Set up the principals.
JS_SetCompartmentPrincipals(compartment, principals);
JS_SetCompartmentPrincipals(JS::GetCompartmentForRealm(realm), principals);
AutoLockGC lock(rt);
if (!zone->compartments().append(compartment.get())) {
if (!zone->compartments().append(JS::GetCompartmentForRealm(realm.get()))) {
ReportOutOfMemory(cx);
return nullptr;
}
@ -7982,7 +7983,7 @@ js::NewCompartment(JSContext* cx, JSPrincipals* principals,
}
zoneHolder.forget();
return compartment.forget();
return JS::GetCompartmentForRealm(realm.forget());
}
void

View File

@ -682,7 +682,7 @@ JS::EnterRealm(JSContext* cx, JSObject* target)
Realm* oldRealm = cx->realm();
cx->enterRealmOf(target);
return JS::GetRealmForCompartment(oldRealm);
return JS::GetCompartmentForRealm(oldRealm);
}
JS_PUBLIC_API(void)

View File

@ -447,7 +447,7 @@ ErrorCopier::~ErrorCopier()
// The provenance of Debugger.DebuggeeWouldRun is the topmost locking
// debugger compartment; it should not be copied around.
if (ar->origin() != cx->compartment() &&
if (JS::GetCompartmentForRealm(ar->origin()) != cx->compartment() &&
cx->isExceptionPending() &&
!cx->isThrowingDebuggeeWouldRun())
{

View File

@ -2742,9 +2742,8 @@ Debugger::ensureExecutionObservabilityOfFrame(JSContext* cx, AbstractFramePtr fr
}
/* static */ bool
Debugger::ensureExecutionObservabilityOfCompartment(JSContext* cx, JSCompartment* comp)
Debugger::ensureExecutionObservabilityOfRealm(JSContext* cx, Realm* realm)
{
Realm* realm = JS::GetRealmForCompartment(comp);
if (realm->debuggerObservesAllExecution())
return true;
ExecutionObservableRealms obs(cx);
@ -3746,7 +3745,7 @@ Debugger::addAllGlobalsAsDebuggees(JSContext* cx, unsigned argc, Value* vp)
for (RealmsInZoneIter r(zone); !r.done(); r.next()) {
if (r == dbg->object->realm() || r->creationOptions().invisibleToDebugger())
continue;
r->scheduledForDestruction = false;
JS::GetCompartmentForRealm(r)->scheduledForDestruction = false;
GlobalObject* global = r->maybeGlobal();
if (global) {
Rooted<GlobalObject*> rg(cx, global);
@ -4078,7 +4077,7 @@ Debugger::addDebuggeeGlobal(JSContext* cx, Handle<GlobalObject*> global)
debuggeeRealm->updateDebuggerObservesAsmJS();
debuggeeRealm->updateDebuggerObservesBinarySource();
debuggeeRealm->updateDebuggerObservesCoverage();
if (observesAllExecution() && !ensureExecutionObservabilityOfCompartment(cx, debuggeeRealm))
if (observesAllExecution() && !ensureExecutionObservabilityOfRealm(cx, debuggeeRealm))
return false;
globalDebuggersGuard.release();
@ -4963,7 +4962,7 @@ Debugger::findAllGlobals(JSContext* cx, unsigned argc, Value* vp)
if (r->creationOptions().invisibleToDebugger())
continue;
r->scheduledForDestruction = false;
JS::GetCompartmentForRealm(r)->scheduledForDestruction = false;
GlobalObject* global = r->maybeGlobal();

View File

@ -754,8 +754,8 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
private:
static MOZ_MUST_USE bool ensureExecutionObservabilityOfFrame(JSContext* cx,
AbstractFramePtr frame);
static MOZ_MUST_USE bool ensureExecutionObservabilityOfCompartment(JSContext* cx,
JSCompartment* comp);
static MOZ_MUST_USE bool ensureExecutionObservabilityOfRealm(JSContext* cx,
JS::Realm* realm);
static bool hookObservesAllExecution(Hook which);

View File

@ -1088,7 +1088,7 @@ void
Realm::setNewObjectMetadata(JSContext* cx, HandleObject obj)
{
MOZ_ASSERT(obj->realm() == this);
assertSameCompartment(cx, this, obj);
assertSameCompartment(cx, JS::GetCompartmentForRealm(this), obj);
AutoEnterOOMUnsafeRegion oomUnsafe;
if (JSObject* metadata = allocationMetadataBuilder_->build(cx, obj, oomUnsafe)) {

View File

@ -746,7 +746,7 @@ class ObjectRealm
} // namespace js
class JS::Realm : public JSCompartment
class JS::Realm : private JSCompartment
{
const JS::RealmCreationOptions creationOptions_;
JS::RealmBehaviors behaviors_;
@ -904,6 +904,24 @@ class JS::Realm : public JSCompartment
size_t* privateData,
size_t* scriptCountsMapArg);
JS::Zone* zone() {
return zone_;
}
const JS::Zone* zone() const {
return zone_;
}
JSRuntime* runtimeFromMainThread() const {
MOZ_ASSERT(js::CurrentThreadCanAccessRuntime(runtime_));
return runtime_;
}
// Note: Unrestricted access to the runtime from an arbitrary thread
// can easily lead to races. Use this method very carefully.
JSRuntime* runtimeFromAnyThread() const {
return runtime_;
}
const JS::RealmCreationOptions& creationOptions() const { return creationOptions_; }
JS::RealmBehaviors& behaviors() { return behaviors_; }
const JS::RealmBehaviors& behaviors() const { return behaviors_; }

View File

@ -225,7 +225,7 @@ JSRuntime::init(JSContext* cx, uint32_t maxbytes, uint32_t maxNurseryBytes)
return false;
gc.atomsZone = atomsZone.get();
if (!atomsZone->compartments().append(atomsRealm.get()))
if (!atomsZone->compartments().append(JS::GetCompartmentForRealm(atomsRealm.get())))
return false;
atomsRealm->setIsSystem(true);

View File

@ -2809,7 +2809,7 @@ JSRuntime::createSelfHostingGlobal(JSContext* cx)
&shgClassOps
};
AutoRealmUnchecked ar(cx, realm);
AutoRealmUnchecked ar(cx, compartment);
Rooted<GlobalObject*> shg(cx, GlobalObject::createInternal(cx, &shgClass));
if (!shg)
return nullptr;