mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 11:26:09 +00:00
Bug 1461938 part 21 - Move isSelfHosting and selfHostingScriptSource from JSCompartment to JS::Realm. r=evilpie
This commit is contained in:
parent
e8626c8f07
commit
b0a1778c10
@ -638,10 +638,10 @@ js::ErrorToException(JSContext* cx, JSErrorReport* reportp,
|
||||
MOZ_ASSERT(reportp);
|
||||
MOZ_ASSERT(!JSREPORT_IS_WARNING(reportp->flags));
|
||||
|
||||
// We cannot throw a proper object inside the self-hosting compartment, as
|
||||
// we cannot construct the Error constructor without self-hosted code. Just
|
||||
// We cannot throw a proper object inside the self-hosting realm, as we
|
||||
// cannot construct the Error constructor without self-hosted code. Just
|
||||
// print the error to stderr to help debugging.
|
||||
if (cx->runtime()->isSelfHostingCompartment(cx->compartment())) {
|
||||
if (cx->realm()->isSelfHostingRealm()) {
|
||||
PrintError(cx, stderr, JS::ConstUTF8CharsZ(), reportp, true);
|
||||
return;
|
||||
}
|
||||
|
@ -44,13 +44,11 @@ using mozilla::PodArrayZero;
|
||||
JSCompartment::JSCompartment(Zone* zone)
|
||||
: zone_(zone),
|
||||
runtime_(zone->runtimeFromAnyThread()),
|
||||
isSelfHosting(false),
|
||||
performanceMonitoring(runtime_),
|
||||
data(nullptr),
|
||||
regExps(),
|
||||
globalWriteBarriered(0),
|
||||
detachedTypedObjects(0),
|
||||
selfHostingScriptSource(nullptr),
|
||||
objectMetadataTable(nullptr),
|
||||
innerViews(zone),
|
||||
lazyArrayBuffers(nullptr),
|
||||
@ -765,7 +763,7 @@ Realm::sweepGlobalObject()
|
||||
}
|
||||
|
||||
void
|
||||
JSCompartment::sweepSelfHostingScriptSource()
|
||||
Realm::sweepSelfHostingScriptSource()
|
||||
{
|
||||
if (selfHostingScriptSource.unbarrieredGet() &&
|
||||
IsAboutToBeFinalized(&selfHostingScriptSource))
|
||||
|
@ -555,9 +555,6 @@ struct JSCompartment
|
||||
JS::Zone* zone_;
|
||||
JSRuntime* runtime_;
|
||||
|
||||
public:
|
||||
bool isSelfHosting;
|
||||
|
||||
private:
|
||||
friend struct JSRuntime;
|
||||
friend struct JSContext;
|
||||
@ -631,13 +628,6 @@ struct JSCompartment
|
||||
#ifdef JSGC_HASH_TABLE_CHECKS
|
||||
void checkWrapperMapAfterMovingGC();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Lazily initialized script source object to use for scripts cloned
|
||||
* from the self-hosting global.
|
||||
*/
|
||||
js::ReadBarrieredScriptSourceObject selfHostingScriptSource;
|
||||
|
||||
// Keep track of the metadata objects which can be associated with each JS
|
||||
// object. Both keys and values are in this compartment.
|
||||
js::ObjectWeakMap* objectMetadataTable;
|
||||
@ -768,7 +758,6 @@ struct JSCompartment
|
||||
|
||||
void sweepCrossCompartmentWrappers();
|
||||
void sweepSavedStacks();
|
||||
void sweepSelfHostingScriptSource();
|
||||
void sweepJitCompartment();
|
||||
void sweepRegExps();
|
||||
void sweepDebugEnvironments();
|
||||
@ -988,6 +977,7 @@ class JS::Realm : public JSCompartment
|
||||
unsigned enterRealmDepth_ = 0;
|
||||
|
||||
bool isAtomsRealm_ = false;
|
||||
bool isSelfHostingRealm_ = false;
|
||||
bool marked_ = true;
|
||||
bool isSystem_ = false;
|
||||
|
||||
@ -1003,6 +993,12 @@ class JS::Realm : public JSCompartment
|
||||
js::UniquePtr<js::ScriptNameMap> scriptNameMap;
|
||||
js::UniquePtr<js::DebugScriptMap> debugScriptMap;
|
||||
|
||||
/*
|
||||
* Lazily initialized script source object to use for scripts cloned
|
||||
* from the self-hosting global.
|
||||
*/
|
||||
js::ReadBarrieredScriptSourceObject selfHostingScriptSource { nullptr };
|
||||
|
||||
// Last time at which an animation was played for this realm.
|
||||
int64_t lastAnimationTime = 0;
|
||||
|
||||
@ -1049,6 +1045,13 @@ class JS::Realm : public JSCompartment
|
||||
isAtomsRealm_ = true;
|
||||
}
|
||||
|
||||
bool isSelfHostingRealm() const {
|
||||
return isSelfHostingRealm_;
|
||||
}
|
||||
void setIsSelfHostingRealm() {
|
||||
isSelfHostingRealm_ = true;
|
||||
}
|
||||
|
||||
/* The global object for this realm.
|
||||
*
|
||||
* This returns nullptr if this is the atoms realm. (The global_ field is
|
||||
@ -1087,6 +1090,8 @@ class JS::Realm : public JSCompartment
|
||||
*/
|
||||
void finishRoots();
|
||||
|
||||
void sweepSelfHostingScriptSource();
|
||||
|
||||
void clearScriptCounts();
|
||||
void clearScriptNames();
|
||||
|
||||
|
@ -1688,7 +1688,7 @@ JSFunction::maybeRelazify(JSRuntime* rt)
|
||||
|
||||
// The caller should have checked we're not in the self-hosting zone (it's
|
||||
// shared with worker runtimes so relazifying functions in it will race).
|
||||
MOZ_ASSERT(!realm->isSelfHosting);
|
||||
MOZ_ASSERT(!realm->isSelfHostingRealm());
|
||||
|
||||
// Don't relazify if the realm is being debugged.
|
||||
if (realm->isDebuggee())
|
||||
@ -2288,7 +2288,7 @@ JSFunction*
|
||||
js::CloneSelfHostingIntrinsic(JSContext* cx, HandleFunction fun)
|
||||
{
|
||||
MOZ_ASSERT(fun->isNative());
|
||||
MOZ_ASSERT(fun->compartment()->isSelfHosting);
|
||||
MOZ_ASSERT(fun->realm()->isSelfHostingRealm());
|
||||
MOZ_ASSERT(!fun->isExtended());
|
||||
MOZ_ASSERT(cx->compartment() != fun->compartment());
|
||||
|
||||
|
@ -3599,17 +3599,17 @@ CreateEmptyScriptForClone(JSContext* cx, HandleScript src)
|
||||
* use for them.
|
||||
*/
|
||||
RootedObject sourceObject(cx);
|
||||
if (cx->runtime()->isSelfHostingCompartment(src->compartment())) {
|
||||
if (!cx->compartment()->selfHostingScriptSource) {
|
||||
if (src->realm()->isSelfHostingRealm()) {
|
||||
if (!cx->realm()->selfHostingScriptSource) {
|
||||
CompileOptions options(cx);
|
||||
FillSelfHostingCompileOptions(options);
|
||||
|
||||
ScriptSourceObject* obj = frontend::CreateScriptSourceObject(cx, options);
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
cx->compartment()->selfHostingScriptSource.set(obj);
|
||||
cx->realm()->selfHostingScriptSource.set(obj);
|
||||
}
|
||||
sourceObject = cx->compartment()->selfHostingScriptSource;
|
||||
sourceObject = cx->realm()->selfHostingScriptSource;
|
||||
} else {
|
||||
sourceObject = src->sourceObject();
|
||||
if (!cx->compartment()->wrap(cx, &sourceObject))
|
||||
@ -4435,11 +4435,11 @@ void
|
||||
JSScript::AutoDelazify::holdScript(JS::HandleFunction fun)
|
||||
{
|
||||
if (fun) {
|
||||
if (fun->compartment()->isSelfHosting) {
|
||||
// The self-hosting compartment is shared across runtimes, so we
|
||||
// can't use JSAutoRealm: it could cause races. Functions in the
|
||||
// self-hosting compartment will never be lazy, so we can safely
|
||||
// assume we don't have to delazify.
|
||||
if (fun->realm()->isSelfHostingRealm()) {
|
||||
// The self-hosting realm is shared across runtimes, so we can't use
|
||||
// JSAutoRealm: it could cause races. Functions in the self-hosting
|
||||
// realm will never be lazy, so we can safely assume we don't have
|
||||
// to delazify.
|
||||
script_ = fun->nonLazyScript();
|
||||
} else {
|
||||
JSAutoRealm ar(cx_, fun);
|
||||
@ -4455,9 +4455,9 @@ JSScript::AutoDelazify::holdScript(JS::HandleFunction fun)
|
||||
void
|
||||
JSScript::AutoDelazify::dropScript()
|
||||
{
|
||||
// Don't touch script_ if it's in the self-hosting compartment, see the
|
||||
// comment in holdScript.
|
||||
if (script_ && !script_->compartment()->isSelfHosting)
|
||||
// Don't touch script_ if it's in the self-hosting realm, see the comment
|
||||
// in holdScript.
|
||||
if (script_ && !script_->realm()->isSelfHostingRealm())
|
||||
script_->setDoNotRelazify(oldDoNotRelazify_);
|
||||
script_ = nullptr;
|
||||
}
|
||||
|
@ -586,7 +586,6 @@ struct JSRuntime : public js::MallocProvider<JSRuntime>
|
||||
bool isSelfHostingGlobal(JSObject* global) {
|
||||
return global == selfHostingGlobal_;
|
||||
}
|
||||
bool isSelfHostingCompartment(JSCompartment* comp) const;
|
||||
bool isSelfHostingZone(const JS::Zone* zone) const;
|
||||
bool createLazySelfHostedFunctionClone(JSContext* cx, js::HandlePropertyName selfHostedName,
|
||||
js::HandleAtom name, unsigned nargs,
|
||||
|
@ -2815,7 +2815,7 @@ JSRuntime::createSelfHostingGlobal(JSContext* cx)
|
||||
return nullptr;
|
||||
|
||||
cx->runtime()->selfHostingGlobal_ = shg;
|
||||
realm->isSelfHosting = true;
|
||||
realm->setIsSelfHostingRealm();
|
||||
realm->setIsSystem(true);
|
||||
|
||||
if (!GlobalObject::initSelfHostingBuiltins(cx, shg, intrinsic_functions))
|
||||
@ -2986,12 +2986,6 @@ JSRuntime::traceSelfHostingGlobal(JSTracer* trc)
|
||||
TraceRoot(trc, const_cast<NativeObject**>(&selfHostingGlobal_.ref()), "self-hosting global");
|
||||
}
|
||||
|
||||
bool
|
||||
JSRuntime::isSelfHostingCompartment(JSCompartment* comp) const
|
||||
{
|
||||
return selfHostingGlobal_->compartment() == comp;
|
||||
}
|
||||
|
||||
bool
|
||||
JSRuntime::isSelfHostingZone(const JS::Zone* zone) const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user