2017-03-22 13:04:57 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
#include "AbortController.h"
|
|
|
|
#include "AbortSignal.h"
|
|
|
|
#include "mozilla/dom/AbortControllerBinding.h"
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
2017-03-22 13:04:57 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AbortController, mGlobal, mSignal)
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(AbortController)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(AbortController)
|
2017-03-22 13:04:57 +03:00
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AbortController)
|
2017-03-22 13:04:57 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
/* static */ already_AddRefed<AbortController>
|
|
|
|
AbortController::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
|
2017-03-22 13:04:57 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (!global) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
RefPtr<AbortController> abortController = new AbortController(global);
|
|
|
|
return abortController.forget();
|
2017-03-22 13:04:57 +03:00
|
|
|
}
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
AbortController::AbortController(nsIGlobalObject* aGlobal)
|
2017-03-22 13:04:57 +03:00
|
|
|
: mGlobal(aGlobal)
|
|
|
|
, mAborted(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
JSObject*
|
2017-08-29 12:31:06 +03:00
|
|
|
AbortController::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2017-03-22 13:04:57 +03:00
|
|
|
{
|
2017-08-29 12:31:06 +03:00
|
|
|
return AbortControllerBinding::Wrap(aCx, this, aGivenProto);
|
2017-03-22 13:04:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIGlobalObject*
|
2017-08-29 12:31:06 +03:00
|
|
|
AbortController::GetParentObject() const
|
2017-03-22 13:04:57 +03:00
|
|
|
{
|
|
|
|
return mGlobal;
|
|
|
|
}
|
|
|
|
|
2017-08-29 12:31:06 +03:00
|
|
|
AbortSignal*
|
|
|
|
AbortController::Signal()
|
2017-03-22 13:04:57 +03:00
|
|
|
{
|
|
|
|
if (!mSignal) {
|
2017-08-29 12:31:06 +03:00
|
|
|
mSignal = new AbortSignal(this, mAborted);
|
2017-03-22 13:04:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return mSignal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-29 12:31:06 +03:00
|
|
|
AbortController::Abort()
|
2017-03-22 13:04:57 +03:00
|
|
|
{
|
|
|
|
if (mAborted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAborted = true;
|
|
|
|
|
|
|
|
if (mSignal) {
|
|
|
|
mSignal->Abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|