本文整理汇总了C++中GlobalObject::GetContext方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalObject::GetContext方法的具体用法?C++ GlobalObject::GetContext怎么用?C++ GlobalObject::GetContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalObject
的用法示例。
在下文中一共展示了GlobalObject::GetContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateURLRunnable
// 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);
}
}
示例2: Promise
/* 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();
}
示例3: WorkerDataStore
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();
}
示例4: RevokeURLRunnable
// 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);
}
}
示例5: WebSocket
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();
}