// static void URL::CreateObjectURL(const GlobalObject& aGlobal, JSObject* aBlob, const mozilla::dom::objectURLOptions& aOptions, nsString& aResult, mozilla::ErrorResult& aRv) { JSContext* cx = aGlobal.GetContext(); WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx); nsCOMPtr<nsIDOMBlob> blob = file::GetDOMBlobFromJSObject(aBlob); if (!blob) { SetDOMStringToNull(aResult); NS_NAMED_LITERAL_STRING(argStr, "Argument 1 of URL.createObjectURL"); NS_NAMED_LITERAL_STRING(blobStr, "Blob"); aRv.ThrowTypeError(MSG_DOES_NOT_IMPLEMENT_INTERFACE, &argStr, &blobStr); return; } nsRefPtr<CreateURLRunnable> runnable = new CreateURLRunnable(workerPrivate, blob, aOptions, aResult); if (!runnable->Dispatch(cx)) { JS_ReportPendingException(cx); } }
/* static */ already_AddRefed<Promise> Promise::Constructor(const GlobalObject& aGlobal, PromiseInit& aInit, ErrorResult& aRv) { JSContext* cx = aGlobal.GetContext(); nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports()); if (!window) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } nsRefPtr<Promise> promise = new Promise(window); aInit.Call(promise, *promise->mResolver, aRv, CallbackObject::eRethrowExceptions); aRv.WouldReportJSException(); if (aRv.IsJSException()) { Optional<JS::Handle<JS::Value> > value(cx); aRv.StealJSException(cx, &value.Value()); Maybe<JSAutoCompartment> ac; EnterCompartment(ac, cx, value); promise->mResolver->Reject(cx, value); } return promise.forget(); }
already_AddRefed<WorkerDataStore> WorkerDataStore::Constructor(GlobalObject& aGlobal, ErrorResult& aRv) { JSContext* cx = aGlobal.GetContext(); WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx); MOZ_ASSERT(workerPrivate); workerPrivate->AssertIsOnWorkerThread(); nsRefPtr<WorkerDataStore> store = new WorkerDataStore(workerPrivate->GlobalScope()); return store.forget(); }
// static void URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl) { JSContext* cx = aGlobal.GetContext(); WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx); nsRefPtr<RevokeURLRunnable> runnable = new RevokeURLRunnable(workerPrivate, aUrl); if (!runnable->Dispatch(cx)) { JS_ReportPendingException(cx); } }
already_AddRefed<WebSocket> WebSocket::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl, const Sequence<nsString>& aProtocols, ErrorResult& aRv) { if (!PrefEnabled()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); return nullptr; } nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal = do_QueryInterface(aGlobal.GetAsSupports()); if (!scriptPrincipal) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal(); if (!principal) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aGlobal.GetAsSupports()); if (!sgo) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsCOMPtr<nsPIDOMWindow> ownerWindow = do_QueryInterface(aGlobal.GetAsSupports()); if (!ownerWindow) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; } nsTArray<nsString> protocolArray; for (uint32_t index = 0, len = aProtocols.Length(); index < len; ++index) { const nsString& protocolElement = aProtocols[index]; if (protocolElement.IsEmpty()) { aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); return nullptr; } if (protocolArray.Contains(protocolElement)) { aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); return nullptr; } if (protocolElement.FindChar(',') != -1) /* interferes w/list */ { aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); return nullptr; } protocolArray.AppendElement(protocolElement); } nsRefPtr<WebSocket> webSocket = new WebSocket(); nsresult rv = webSocket->Init(aGlobal.GetContext(), principal, ownerWindow, aUrl, protocolArray); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } return webSocket.forget(); }