mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1568245 - Move JSScript::global to BaseScript. r=jandem
Combine the LazyScript::function_ and JSScript::global_ fields into the BaseScript type. This provides a common definition of script realm and compartment. Currently a non-lazy function script will set this to point this to the global, but in future it should be made to point to canonical function for both the lazy and non-lazy cases. Differential Revision: https://phabricator.services.mozilla.com/D40520 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
19a1cfc52a
commit
f7e78abd00
@ -965,6 +965,7 @@ bool js::GCMarker::mark(T* thing) {
|
||||
// traversing equivalent subgraphs.
|
||||
|
||||
void BaseScript::traceChildren(JSTracer* trc) {
|
||||
TraceEdge(trc, &functionOrGlobal_, "function");
|
||||
TraceNullableEdge(trc, &sourceObject_, "sourceObject");
|
||||
}
|
||||
|
||||
@ -976,8 +977,6 @@ void LazyScript::traceChildren(JSTracer* trc) {
|
||||
TraceNullableEdge(trc, &script_, "script");
|
||||
}
|
||||
|
||||
TraceEdge(trc, &function_, "function");
|
||||
|
||||
if (enclosingLazyScriptOrScope_) {
|
||||
TraceGenericPointerRoot(
|
||||
trc,
|
||||
@ -1004,14 +1003,14 @@ void LazyScript::traceChildren(JSTracer* trc) {
|
||||
}
|
||||
}
|
||||
inline void js::GCMarker::eagerlyMarkChildren(LazyScript* thing) {
|
||||
traverseEdge(thing, static_cast<JSObject*>(thing->functionOrGlobal_));
|
||||
|
||||
if (thing->sourceObject_) {
|
||||
traverseEdge(thing, static_cast<JSObject*>(thing->sourceObject_));
|
||||
}
|
||||
|
||||
// script_ is weak so is not traced here.
|
||||
|
||||
traverseEdge(thing, static_cast<JSObject*>(thing->function_));
|
||||
|
||||
if (thing->enclosingLazyScriptOrScope_) {
|
||||
TraceManuallyBarrieredGenericPointerEdge(
|
||||
this,
|
||||
|
@ -60,11 +60,11 @@ void SetFrameArgumentsObject(JSContext* cx, AbstractFramePtr frame,
|
||||
|
||||
/* static */ inline JSFunction* LazyScript::functionDelazifying(
|
||||
JSContext* cx, Handle<LazyScript*> script) {
|
||||
RootedFunction fun(cx, script->function_);
|
||||
if (script->function_ && !JSFunction::getOrCreateScript(cx, fun)) {
|
||||
RootedFunction fun(cx, script->functionNonDelazifying());
|
||||
if (fun && !JSFunction::getOrCreateScript(cx, fun)) {
|
||||
return nullptr;
|
||||
}
|
||||
return script->function_;
|
||||
return fun;
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
@ -3805,11 +3805,8 @@ JSScript::JSScript(HandleObject global, uint8_t* stubEntry,
|
||||
HandleScriptSourceObject sourceObject, uint32_t sourceStart,
|
||||
uint32_t sourceEnd, uint32_t toStringStart,
|
||||
uint32_t toStringEnd)
|
||||
: js::BaseScript(stubEntry, sourceObject, sourceStart, sourceEnd,
|
||||
toStringStart, toStringEnd),
|
||||
global_(global) {
|
||||
MOZ_ASSERT(global->compartment() == sourceObject->compartment());
|
||||
}
|
||||
: js::BaseScript(stubEntry, global, sourceObject, sourceStart, sourceEnd,
|
||||
toStringStart, toStringEnd) {}
|
||||
|
||||
/* static */
|
||||
JSScript* JSScript::New(JSContext* cx, HandleScriptSourceObject sourceObject,
|
||||
@ -4918,8 +4915,6 @@ void JSScript::traceChildren(JSTracer* trc) {
|
||||
TraceManuallyBarrieredEdge(trc, &lazyScript, "lazyScript");
|
||||
}
|
||||
|
||||
TraceEdge(trc, &global_, "global");
|
||||
|
||||
jit::TraceJitScripts(trc, this);
|
||||
|
||||
if (trc->isMarkingTracer()) {
|
||||
@ -5245,15 +5240,10 @@ LazyScript::LazyScript(JSFunction* fun, uint8_t* stubEntry,
|
||||
uint32_t immutableFlags, uint32_t sourceStart,
|
||||
uint32_t sourceEnd, uint32_t toStringStart,
|
||||
uint32_t toStringEnd, uint32_t lineno, uint32_t column)
|
||||
: BaseScript(stubEntry, &sourceObject, sourceStart, sourceEnd,
|
||||
: BaseScript(stubEntry, fun, &sourceObject, sourceStart, sourceEnd,
|
||||
toStringStart, toStringEnd),
|
||||
script_(nullptr),
|
||||
function_(fun),
|
||||
lazyData_(data) {
|
||||
MOZ_ASSERT(function_);
|
||||
MOZ_ASSERT(sourceObject_);
|
||||
MOZ_ASSERT(function_->compartment() == sourceObject_->compartment());
|
||||
|
||||
lineno_ = lineno;
|
||||
column_ = column;
|
||||
|
||||
@ -5270,12 +5260,6 @@ void LazyScript::initScript(JSScript* script) {
|
||||
script_.set(script);
|
||||
}
|
||||
|
||||
JS::Compartment* LazyScript::compartment() const {
|
||||
return function_->compartment();
|
||||
}
|
||||
|
||||
Realm* LazyScript::realm() const { return function_->realm(); }
|
||||
|
||||
void LazyScript::setEnclosingLazyScript(LazyScript* enclosingLazyScript) {
|
||||
MOZ_ASSERT(enclosingLazyScript);
|
||||
|
||||
|
@ -1348,6 +1348,11 @@ class BaseScript : public gc::TenuredCell {
|
||||
// non-null (except on no-jit builds).
|
||||
uint8_t* jitCodeRaw_ = nullptr;
|
||||
|
||||
// Object that determines what Realm this script is compiled for. In general
|
||||
// this refers to the realm's GlobalObject, but for a lazy-script we instead
|
||||
// refer to the associated function.
|
||||
GCPtrObject functionOrGlobal_;
|
||||
|
||||
// The ScriptSourceObject for this script.
|
||||
GCPtr<ScriptSourceObject*> sourceObject_ = {};
|
||||
|
||||
@ -1389,15 +1394,17 @@ class BaseScript : public gc::TenuredCell {
|
||||
uint32_t immutableFlags_ = 0;
|
||||
uint32_t mutableFlags_ = 0;
|
||||
|
||||
BaseScript(uint8_t* stubEntry, ScriptSourceObject* sourceObject,
|
||||
uint32_t sourceStart, uint32_t sourceEnd, uint32_t toStringStart,
|
||||
uint32_t toStringEnd)
|
||||
BaseScript(uint8_t* stubEntry, JSObject* functionOrGlobal,
|
||||
ScriptSourceObject* sourceObject, uint32_t sourceStart,
|
||||
uint32_t sourceEnd, uint32_t toStringStart, uint32_t toStringEnd)
|
||||
: jitCodeRaw_(stubEntry),
|
||||
functionOrGlobal_(functionOrGlobal),
|
||||
sourceObject_(sourceObject),
|
||||
sourceStart_(sourceStart),
|
||||
sourceEnd_(sourceEnd),
|
||||
toStringStart_(toStringStart),
|
||||
toStringEnd_(toStringEnd) {
|
||||
MOZ_ASSERT(functionOrGlobal->compartment() == sourceObject->compartment());
|
||||
MOZ_ASSERT(toStringStart <= sourceStart);
|
||||
MOZ_ASSERT(sourceStart <= sourceEnd);
|
||||
MOZ_ASSERT(sourceEnd <= toStringEnd);
|
||||
@ -1557,6 +1564,12 @@ class BaseScript : public gc::TenuredCell {
|
||||
|
||||
uint8_t* jitCodeRaw() const { return jitCodeRaw_; }
|
||||
|
||||
JS::Realm* realm() const { return functionOrGlobal_->nonCCWRealm(); }
|
||||
JS::Compartment* compartment() const {
|
||||
return functionOrGlobal_->compartment();
|
||||
}
|
||||
JS::Compartment* maybeCompartment() const { return compartment(); }
|
||||
|
||||
ScriptSourceObject* sourceObject() const { return sourceObject_; }
|
||||
ScriptSource* scriptSource() const { return sourceObject()->source(); }
|
||||
ScriptSource* maybeForwardedScriptSource() const;
|
||||
@ -2145,9 +2158,6 @@ class JSScript : public js::BaseScript {
|
||||
// Unshared variable-length data
|
||||
js::PrivateScriptData* data_ = nullptr;
|
||||
|
||||
public:
|
||||
js::GCPtrObject global_ = {};
|
||||
|
||||
private:
|
||||
// JIT and type inference data for this script. May be purged on GC.
|
||||
js::jit::JitScript* jitScript_ = nullptr;
|
||||
@ -2273,10 +2283,6 @@ class JSScript : public js::BaseScript {
|
||||
public:
|
||||
inline JSPrincipals* principals();
|
||||
|
||||
JS::Realm* realm() const { return global_->nonCCWRealm(); }
|
||||
JS::Compartment* compartment() const { return global_->compartment(); }
|
||||
JS::Compartment* maybeCompartment() const { return compartment(); }
|
||||
|
||||
js::RuntimeScriptData* scriptData() { return scriptData_; }
|
||||
js::ImmutableScriptData* immutableScriptData() const {
|
||||
return scriptData_->isd_.get();
|
||||
@ -3153,9 +3159,6 @@ class LazyScript : public BaseScript {
|
||||
WeakHeapPtrScript script_;
|
||||
friend void js::gc::SweepLazyScripts(GCParallelTask* task);
|
||||
|
||||
// Original function with which the lazy script is associated.
|
||||
GCPtrFunction function_;
|
||||
|
||||
// This field holds one of:
|
||||
// * LazyScript in which the script is nested. This case happens if the
|
||||
// enclosing script is lazily parsed and have never been compiled.
|
||||
@ -3290,11 +3293,9 @@ class LazyScript : public BaseScript {
|
||||
|
||||
static inline JSFunction* functionDelazifying(JSContext* cx,
|
||||
Handle<LazyScript*>);
|
||||
JSFunction* functionNonDelazifying() const { return function_; }
|
||||
|
||||
JS::Compartment* compartment() const;
|
||||
JS::Compartment* maybeCompartment() const { return compartment(); }
|
||||
Realm* realm() const;
|
||||
JSFunction* functionNonDelazifying() const {
|
||||
return &functionOrGlobal_->as<JSFunction>();
|
||||
}
|
||||
|
||||
void initScript(JSScript* script);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user