Bug 1848771 part 1 - Stop eagerly initializing JS standard classes for non-Window globals. r=peterv

For non-Window globals we pass `true` for `aInitStandardClasses` which results in
`CreateGlobal` calling `JS::InitRealmStandardClasses`.

This affects performance and memory usage and likely isn't necessary. It's also
nicer to not have this difference in behavior.

Differential Revision: https://phabricator.services.mozilla.com/D186216
This commit is contained in:
Jan de Mooij 2024-01-23 15:06:32 +00:00
parent cf4b5c9ad2
commit 5656ba3a2d
7 changed files with 9 additions and 16 deletions

View File

@ -2053,7 +2053,7 @@ static nsresult CreateNativeGlobalForInner(
flags |= xpc::DONT_FIRE_ONNEWGLOBALHOOK;
if (!Window_Binding::Wrap(aCx, aNewInner, aNewInner, options,
nsJSPrincipals::get(principal), false, aGlobal) ||
nsJSPrincipals::get(principal), aGlobal) ||
!xpc::InitGlobalObject(aCx, aGlobal, flags)) {
return NS_ERROR_FAILURE;
}

View File

@ -2911,7 +2911,7 @@ uint64_t GetWindowID(DedicatedWorkerGlobalScope* aGlobal);
template <class T, ProtoHandleGetter GetProto>
bool CreateGlobal(JSContext* aCx, T* aNative, nsWrapperCache* aCache,
const JSClass* aClass, JS::RealmOptions& aOptions,
JSPrincipals* aPrincipal, bool aInitStandardClasses,
JSPrincipals* aPrincipal,
JS::MutableHandle<JSObject*> aGlobal) {
aOptions.creationOptions()
.setTrace(CreateGlobalOptions<T>::TraceGlobal)
@ -2950,11 +2950,6 @@ bool CreateGlobal(JSContext* aCx, T* aNative, nsWrapperCache* aCache,
}
}
if (aInitStandardClasses && !JS::InitRealmStandardClasses(aCx)) {
NS_WARNING("Failed to init standard classes");
return false;
}
JS::Handle<JSObject*> proto = GetProto(aCx);
if (!proto || !JS_SetPrototype(aCx, aGlobal, proto)) {
NS_WARNING("Failed to set proto");

View File

@ -4788,7 +4788,6 @@ class CGWrapGlobalMethod(CGAbstractMethod):
Argument("nsWrapperCache*", "aCache"),
Argument("JS::RealmOptions&", "aOptions"),
Argument("JSPrincipals*", "aPrincipal"),
Argument("bool", "aInitStandardClasses"),
Argument("JS::MutableHandle<JSObject*>", "aReflector"),
]
CGAbstractMethod.__init__(self, descriptor, "Wrap", "bool", args)
@ -4836,7 +4835,6 @@ class CGWrapGlobalMethod(CGAbstractMethod):
sClass.ToJSClass(),
aOptions,
aPrincipal,
aInitStandardClasses,
aReflector)) {
$*{failureCode}
}

View File

@ -49,7 +49,7 @@ bool AudioWorkletGlobalScope::WrapGlobalObject(
JS::RealmOptions options = CreateRealmOptions();
return AudioWorkletGlobalScope_Binding::Wrap(
aCx, this, this, options, BasePrincipal::Cast(mImpl->Principal()), true,
aCx, this, this, options, BasePrincipal::Cast(mImpl->Principal()),
aReflector);
}

View File

@ -48,7 +48,7 @@ JSObject* NewShadowRealmGlobal(JSContext* aCx, JS::RealmOptions& aOptions,
scope = new ShadowRealmGlobalScope(nsGlobal);
ShadowRealmGlobalScope_Binding::Wrap(aCx, scope, scope, aOptions,
aPrincipals, true, &reflector);
aPrincipals, &reflector);
}
return reflector;

View File

@ -912,7 +912,7 @@ bool DedicatedWorkerGlobalScope::WrapGlobalObject(
return DedicatedWorkerGlobalScope_Binding::Wrap(
aCx, this, this, options,
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), true, aReflector);
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), aReflector);
}
void DedicatedWorkerGlobalScope::PostMessage(
@ -1073,7 +1073,7 @@ bool SharedWorkerGlobalScope::WrapGlobalObject(
return SharedWorkerGlobalScope_Binding::Wrap(
aCx, this, this, options,
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), true, aReflector);
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), aReflector);
}
void SharedWorkerGlobalScope::Close() {
@ -1114,7 +1114,7 @@ bool ServiceWorkerGlobalScope::WrapGlobalObject(
return ServiceWorkerGlobalScope_Binding::Wrap(
aCx, this, this, options,
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), true, aReflector);
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), aReflector);
}
already_AddRefed<Clients> ServiceWorkerGlobalScope::GetClients() {
@ -1239,7 +1239,7 @@ bool WorkerDebuggerGlobalScope::WrapGlobalObject(
return WorkerDebuggerGlobalScope_Binding::Wrap(
aCx, this, this, options,
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), true, aReflector);
nsJSPrincipals::get(mWorkerPrivate->GetPrincipal()), aReflector);
}
void WorkerDebuggerGlobalScope::GetGlobal(JSContext* aCx,

View File

@ -23,7 +23,7 @@ bool PaintWorkletGlobalScope::WrapGlobalObject(
JSContext* aCx, JS::MutableHandle<JSObject*> aReflector) {
JS::RealmOptions options = CreateRealmOptions();
return PaintWorkletGlobalScope_Binding::Wrap(
aCx, this, this, options, nsJSPrincipals::get(mImpl->Principal()), true,
aCx, this, this, options, nsJSPrincipals::get(mImpl->Principal()),
aReflector);
}