1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "AbortController.h"
8 #include "AbortSignal.h"
10 #include "mozilla/dom/AbortControllerBinding.h"
11 #include "mozilla/dom/BindingUtils.h"
12 #include "mozilla/dom/DOMException.h"
13 #include "mozilla/dom/WorkerPrivate.h"
14 #include "mozilla/HoldDropJSObjects.h"
16 namespace mozilla::dom
{
18 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(AbortController
,
22 NS_IMPL_CYCLE_COLLECTING_ADDREF(AbortController
)
23 NS_IMPL_CYCLE_COLLECTING_RELEASE(AbortController
)
25 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AbortController
)
26 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
27 NS_INTERFACE_MAP_ENTRY(nsISupports
)
31 already_AddRefed
<AbortController
> AbortController::Constructor(
32 const GlobalObject
& aGlobal
, ErrorResult
& aRv
) {
33 nsCOMPtr
<nsIGlobalObject
> global
= do_QueryInterface(aGlobal
.GetAsSupports());
35 aRv
.Throw(NS_ERROR_FAILURE
);
39 RefPtr
<AbortController
> abortController
= new AbortController(global
);
40 return abortController
.forget();
43 AbortController::AbortController(nsIGlobalObject
* aGlobal
)
44 : mGlobal(aGlobal
), mAborted(false), mReason(JS::UndefinedHandleValue
) {
45 mozilla::HoldJSObjects(this);
48 JSObject
* AbortController::WrapObject(JSContext
* aCx
,
49 JS::Handle
<JSObject
*> aGivenProto
) {
50 return AbortController_Binding::Wrap(aCx
, this, aGivenProto
);
53 nsIGlobalObject
* AbortController::GetParentObject() const { return mGlobal
; }
55 AbortSignal
* AbortController::Signal() {
57 JS::Rooted
<JS::Value
> reason(RootingCx(), mReason
);
58 mSignal
= new AbortSignal(mGlobal
, mAborted
, reason
);
64 void AbortController::Abort(JSContext
* aCx
, JS::Handle
<JS::Value
> aReason
) {
72 mSignal
->SignalAbort(aReason
);
78 AbortController::~AbortController() { mozilla::DropJSObjects(this); }
80 } // namespace mozilla::dom