/src/mozilla-central/dom/midi/MIDIMessageEvent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
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/. */ |
6 | | |
7 | | #include "mozilla/dom/EventBinding.h" |
8 | | #include "mozilla/dom/MIDIMessageEvent.h" |
9 | | #include "mozilla/dom/MIDIMessageEventBinding.h" |
10 | | #include "js/GCAPI.h" |
11 | | #include "jsfriendapi.h" |
12 | | #include "mozilla/FloatingPoint.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/PrimitiveConversions.h" |
15 | | #include "mozilla/dom/TypedArray.h" |
16 | | #include "mozilla/dom/Performance.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | |
22 | | NS_IMPL_CYCLE_COLLECTION_CLASS(MIDIMessageEvent) |
23 | | |
24 | | NS_IMPL_ADDREF_INHERITED(MIDIMessageEvent, Event) |
25 | | NS_IMPL_RELEASE_INHERITED(MIDIMessageEvent, Event) |
26 | | |
27 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MIDIMessageEvent, Event) |
28 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
29 | | |
30 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(MIDIMessageEvent, Event) |
31 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mData) |
32 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
33 | | |
34 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MIDIMessageEvent, Event) |
35 | 0 | tmp->mData = nullptr; |
36 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
37 | | |
38 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MIDIMessageEvent) |
39 | 0 | NS_INTERFACE_MAP_END_INHERITING(Event) |
40 | | |
41 | | MIDIMessageEvent::MIDIMessageEvent(mozilla::dom::EventTarget* aOwner) |
42 | | : Event(aOwner, nullptr, nullptr) |
43 | 0 | { |
44 | 0 | mozilla::HoldJSObjects(this); |
45 | 0 | } |
46 | | |
47 | | MIDIMessageEvent::~MIDIMessageEvent() |
48 | 0 | { |
49 | 0 | mData = nullptr; |
50 | 0 | mozilla::DropJSObjects(this); |
51 | 0 | } |
52 | | |
53 | | JSObject* |
54 | | MIDIMessageEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
55 | 0 | { |
56 | 0 | return MIDIMessageEvent_Binding::Wrap(aCx, this, aGivenProto); |
57 | 0 | } |
58 | | |
59 | | MIDIMessageEvent* |
60 | | MIDIMessageEvent::AsMIDIMessageEvent() |
61 | 0 | { |
62 | 0 | return this; |
63 | 0 | } |
64 | | |
65 | | already_AddRefed<MIDIMessageEvent> |
66 | | MIDIMessageEvent::Constructor(EventTarget* aOwner, |
67 | | const class TimeStamp& aReceivedTime, |
68 | | const nsTArray<uint8_t>& aData) |
69 | 0 | { |
70 | 0 | MOZ_ASSERT(aOwner); |
71 | 0 | RefPtr<MIDIMessageEvent> e = new MIDIMessageEvent(aOwner); |
72 | 0 | e->InitEvent(NS_LITERAL_STRING("midimessage"), false, false); |
73 | 0 | e->mEvent->mTimeStamp = aReceivedTime; |
74 | 0 | e->mRawData = aData; |
75 | 0 | e->SetTrusted(true); |
76 | 0 | return e.forget(); |
77 | 0 | } |
78 | | |
79 | | already_AddRefed<MIDIMessageEvent> |
80 | | MIDIMessageEvent::Constructor(const GlobalObject& aGlobal, |
81 | | const nsAString& aType, |
82 | | const MIDIMessageEventInit& aEventInitDict, |
83 | | ErrorResult& aRv) |
84 | 0 | { |
85 | 0 | nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports()); |
86 | 0 | RefPtr<MIDIMessageEvent> e = new MIDIMessageEvent(owner); |
87 | 0 | bool trusted = e->Init(owner); |
88 | 0 | e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable); |
89 | 0 | // Set data for event. Timestamp will always be set to Now() (default for |
90 | 0 | // event) using this constructor. |
91 | 0 | const auto& a = aEventInitDict.mData.Value(); |
92 | 0 | a.ComputeLengthAndData(); |
93 | 0 | e->mData = Uint8Array::Create(aGlobal.Context(), owner, a.Length(), a.Data()); |
94 | 0 | if (NS_WARN_IF(!e->mData)) { |
95 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
96 | 0 | return nullptr; |
97 | 0 | } |
98 | 0 | |
99 | 0 | e->SetTrusted(trusted); |
100 | 0 | mozilla::HoldJSObjects(e.get()); |
101 | 0 | return e.forget(); |
102 | 0 | } |
103 | | |
104 | | void |
105 | | MIDIMessageEvent::GetData(JSContext* cx, |
106 | | JS::MutableHandle<JSObject*> aData, |
107 | | ErrorResult& aRv) |
108 | 0 | { |
109 | 0 | if (!mData) { |
110 | 0 | mData = Uint8Array::Create(cx, |
111 | 0 | this, |
112 | 0 | mRawData.Length(), |
113 | 0 | mRawData.Elements()); |
114 | 0 | if (!mData) { |
115 | 0 | aRv.Throw(NS_ERROR_OUT_OF_MEMORY); |
116 | 0 | return; |
117 | 0 | } |
118 | 0 | mRawData.Clear(); |
119 | 0 | JS::ExposeObjectToActiveJS(mData); |
120 | 0 | } |
121 | 0 | aData.set(mData); |
122 | 0 | } |
123 | | |
124 | | |
125 | | } // namespace dom |
126 | | } // namespace mozilla |