Bug 1723715 part 16 - Move WindowProxy to GlobalObjectData. r=jonco

This is done last because it requires reordering the initialization code, and we
can finally do this now.

Differential Revision: https://phabricator.services.mozilla.com/D121996
This commit is contained in:
Jan de Mooij 2021-08-09 15:25:10 +00:00
Родитель 6bd69b8edd
Коммит 29d4bbfc82
3 изменённых файлов: 23 добавлений и 27 удалений

Просмотреть файл

@ -572,7 +572,7 @@ static const uint32_t JSCLASS_FOREGROUND_FINALIZE =
// application.
static const uint32_t JSCLASS_GLOBAL_APPLICATION_SLOTS = 5;
static const uint32_t JSCLASS_GLOBAL_SLOT_COUNT =
JSCLASS_GLOBAL_APPLICATION_SLOTS + 2;
JSCLASS_GLOBAL_APPLICATION_SLOTS + 1;
static constexpr uint32_t JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(uint32_t n) {
return JSCLASS_IS_GLOBAL |

Просмотреть файл

@ -661,26 +661,11 @@ GlobalObject* GlobalObject::createInternal(JSContext* cx,
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
MOZ_ASSERT(global->isUnqualifiedVarObj());
Rooted<GlobalLexicalEnvironmentObject*> lexical(
cx, GlobalLexicalEnvironmentObject::create(cx, global));
if (!lexical) {
return nullptr;
}
Rooted<GlobalScope*> emptyGlobalScope(
cx, GlobalScope::createEmpty(cx, ScopeKind::Global));
if (!emptyGlobalScope) {
return nullptr;
}
{
auto data = cx->make_unique<GlobalObjectData>();
if (!data) {
return nullptr;
}
data->emptyGlobalScope.init(emptyGlobalScope);
data->lexicalEnvironment.init(lexical);
// Note: it's important for the realm's global to be initialized at the
// same time as the global's GlobalObjectData, because we free the global's
// data when Realm::global_ is cleared.
@ -689,6 +674,20 @@ GlobalObject* GlobalObject::createInternal(JSContext* cx,
MemoryUse::GlobalObjectData);
}
Rooted<GlobalLexicalEnvironmentObject*> lexical(
cx, GlobalLexicalEnvironmentObject::create(cx, global));
if (!lexical) {
return nullptr;
}
global->data().lexicalEnvironment.init(lexical);
Rooted<GlobalScope*> emptyGlobalScope(
cx, GlobalScope::createEmpty(cx, ScopeKind::Global));
if (!emptyGlobalScope) {
return nullptr;
}
global->data().emptyGlobalScope.init(emptyGlobalScope);
if (!JSObject::setQualifiedVarObj(cx, global)) {
return nullptr;
}
@ -1162,9 +1161,10 @@ void GlobalObjectData::trace(JSTracer* trc) {
TraceNullableEdge(trc, &proto, "global-builtin-proto");
}
TraceEdge(trc, &emptyGlobalScope, "global-empty-scope");
TraceNullableEdge(trc, &emptyGlobalScope, "global-empty-scope");
TraceNullableEdge(trc, &lexicalEnvironment, "global-lexical-env");
TraceNullableEdge(trc, &windowProxy, "global-window-proxy");
TraceNullableEdge(trc, &regExpStatics, "global-regexp-statics");
TraceNullableEdge(trc, &intrinsicsHolder, "global-intrinsics-holder");
TraceNullableEdge(trc, &forOfPICChain, "global-for-of-pic");

Просмотреть файл

@ -116,6 +116,9 @@ class GlobalObjectData {
// The lexical environment for global let/const/class bindings.
HeapPtr<GlobalLexicalEnvironmentObject*> lexicalEnvironment;
// The WindowProxy associated with this global.
HeapPtr<JSObject*> windowProxy;
// Global state for regular expressions.
HeapPtr<RegExpStaticsObject*> regExpStatics;
@ -155,7 +158,6 @@ class GlobalObjectData {
class GlobalObject : public NativeObject {
enum : unsigned {
GLOBAL_DATA_SLOT = JSCLASS_GLOBAL_APPLICATION_SLOTS,
WINDOW_PROXY,
// Total reserved-slot count for global objects.
RESERVED_SLOTS
@ -922,16 +924,10 @@ class GlobalObject : public NativeObject {
static NativeObject* getOrCreateForOfPICObject(JSContext* cx,
Handle<GlobalObject*> global);
JSObject* windowProxy() const {
return &getReservedSlot(WINDOW_PROXY).toObject();
}
JSObject* maybeWindowProxy() const {
Value v = getReservedSlot(WINDOW_PROXY);
MOZ_ASSERT(v.isObject() || v.isUndefined());
return v.isObject() ? &v.toObject() : nullptr;
}
JSObject* maybeWindowProxy() const { return data().windowProxy; }
void setWindowProxy(JSObject* windowProxy) {
setReservedSlot(WINDOW_PROXY, ObjectValue(*windowProxy));
data().windowProxy = windowProxy;
}
ArrayObject* getSourceURLsHolder() const { return data().sourceURLsHolder; }