Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / events / CustomEvent.cpp
blobc4f1b30044298d02d94a0700408b9afecbc7bc4b
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 "CustomEvent.h"
8 #include "mozilla/dom/CustomEventBinding.h"
10 #include "mozilla/dom/BindingUtils.h"
11 #include "mozilla/HoldDropJSObjects.h"
12 #include "nsContentUtils.h"
14 using namespace mozilla;
15 using namespace mozilla::dom;
17 CustomEvent::CustomEvent(mozilla::dom::EventTarget* aOwner,
18 nsPresContext* aPresContext,
19 mozilla::WidgetEvent* aEvent)
20 : Event(aOwner, aPresContext, aEvent), mDetail(JS::NullValue()) {
21 mozilla::HoldJSObjects(this);
24 CustomEvent::~CustomEvent() { mozilla::DropJSObjects(this); }
26 NS_IMPL_CYCLE_COLLECTION_CLASS(CustomEvent)
27 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CustomEvent, Event)
28 mozilla::DropJSObjects(tmp);
29 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
31 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CustomEvent, Event)
32 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
34 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CustomEvent, Event)
35 NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mDetail)
36 NS_IMPL_CYCLE_COLLECTION_TRACE_END
38 NS_IMPL_ADDREF_INHERITED(CustomEvent, Event)
39 NS_IMPL_RELEASE_INHERITED(CustomEvent, Event)
41 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CustomEvent)
42 NS_INTERFACE_MAP_END_INHERITING(Event)
44 already_AddRefed<CustomEvent> CustomEvent::Constructor(
45 const GlobalObject& aGlobal, const nsAString& aType,
46 const CustomEventInit& aParam) {
47 nsCOMPtr<mozilla::dom::EventTarget> t =
48 do_QueryInterface(aGlobal.GetAsSupports());
49 RefPtr<CustomEvent> e = new CustomEvent(t, nullptr, nullptr);
50 bool trusted = e->Init(t);
51 JS::Rooted<JS::Value> detail(aGlobal.Context(), aParam.mDetail);
52 e->InitCustomEvent(aGlobal.Context(), aType, aParam.mBubbles,
53 aParam.mCancelable, detail);
54 e->SetTrusted(trusted);
55 e->SetComposed(aParam.mComposed);
56 return e.forget();
59 JSObject* CustomEvent::WrapObjectInternal(JSContext* aCx,
60 JS::Handle<JSObject*> aGivenProto) {
61 return mozilla::dom::CustomEvent_Binding::Wrap(aCx, this, aGivenProto);
64 void CustomEvent::InitCustomEvent(JSContext* aCx, const nsAString& aType,
65 bool aCanBubble, bool aCancelable,
66 JS::Handle<JS::Value> aDetail) {
67 NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
69 Event::InitEvent(aType, aCanBubble, aCancelable);
70 mDetail = aDetail;
73 void CustomEvent::GetDetail(JSContext* aCx,
74 JS::MutableHandle<JS::Value> aRetval) {
75 aRetval.set(mDetail);
78 already_AddRefed<CustomEvent> NS_NewDOMCustomEvent(
79 EventTarget* aOwner, nsPresContext* aPresContext,
80 mozilla::WidgetEvent* aEvent) {
81 RefPtr<CustomEvent> it = new CustomEvent(aOwner, aPresContext, aEvent);
82 return it.forget();