/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
nsPIDOMWindowInner* innerWindow = globalObject->GetAsInnerWindow(); if (innerWindow && !innerWindow->IsCurrentInnerWindow()) {
aRv.ThrowInvalidStateError( "Cannot create worker for a going to be discarded document"); return nullptr;
}
// The spec only mentions Window and WorkerGlobalScope global objects, but // Gecko can actually call the constructor with other ones, so we just skip // trusted types handling in that case. // https://html.spec.whatwg.org/multipage/workers.html#dedicated-workers-and-the-worker-interface const nsAString* compliantString = nullptr; bool performTrustedTypeConversion = innerWindow; if (!performTrustedTypeConversion) { if (JSObject* globalJSObject = globalObject->GetGlobalJSObject()) {
performTrustedTypeConversion = IsWorkerGlobal(globalJSObject);
}
}
Maybe<nsAutoString> compliantStringHolder; if (performTrustedTypeConversion) {
constexpr nsLiteralString sink = u"Worker constructor"_ns;
compliantString = TrustedTypeUtils::GetTrustedTypesCompliantString(
aScriptURL, sink, kTrustedTypesOnlySinkGroup, *globalObject,
compliantStringHolder, aRv); if (aRv.Failed()) { return nullptr;
}
} else {
compliantString = aScriptURL.IsUSVString()
? &aScriptURL.GetAsUSVString()
: &aScriptURL.GetAsTrustedScriptURL().mData;
}
MOZ_ASSERT(compliantString);
JSObject* Worker::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
JS::Rooted<JSObject*> wrapper(aCx,
Worker_Binding::Wrap(aCx, this, aGivenProto)); if (wrapper) { // Most DOM objects don't assume they have a reflector. If they don't have // one and need one, they create it. But in workers code, we assume that the // reflector is always present. In order to guarantee that it's always // present, we have to preserve it. Otherwise the GC will happily collect it // as needed.
MOZ_ALWAYS_TRUE(TryPreserveWrapper(wrapper));
}
if (!mWorkerPrivate || mWorkerPrivate->ParentStatusProtected() > Running) { return;
}
if (NS_WARN_IF(aRv.Failed())) { return;
}
// The worker could have closed between the time we entered this function and // checked ParentStatusProtected and now, which could cause the dispatch to // fail.
Unused << NS_WARN_IF(!runnable->Dispatch(mWorkerPrivate));
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.