diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/midi/MIDIMessageEvent.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/midi/MIDIMessageEvent.cpp')
-rw-r--r-- | dom/midi/MIDIMessageEvent.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/dom/midi/MIDIMessageEvent.cpp b/dom/midi/MIDIMessageEvent.cpp new file mode 100644 index 0000000000..f539bf7c89 --- /dev/null +++ b/dom/midi/MIDIMessageEvent.cpp @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#include "mozilla/dom/EventBinding.h" +#include "mozilla/dom/MIDIMessageEvent.h" +#include "mozilla/dom/MIDIMessageEventBinding.h" +#include "js/GCAPI.h" +#include "jsfriendapi.h" +#include "mozilla/FloatingPoint.h" +#include "mozilla/HoldDropJSObjects.h" +#include "mozilla/dom/Nullable.h" +#include "mozilla/dom/PrimitiveConversions.h" +#include "mozilla/dom/TypedArray.h" +#include "mozilla/dom/Performance.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_INHERITED_WITH_JS_MEMBERS(MIDIMessageEvent, Event, (), + (mData)) + +NS_IMPL_ADDREF_INHERITED(MIDIMessageEvent, Event) +NS_IMPL_RELEASE_INHERITED(MIDIMessageEvent, Event) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MIDIMessageEvent) +NS_INTERFACE_MAP_END_INHERITING(Event) + +MIDIMessageEvent::MIDIMessageEvent(mozilla::dom::EventTarget* aOwner) + : Event(aOwner, nullptr, nullptr) { + mozilla::HoldJSObjects(this); +} + +MIDIMessageEvent::~MIDIMessageEvent() { mozilla::DropJSObjects(this); } + +JSObject* MIDIMessageEvent::WrapObjectInternal( + JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { + return MIDIMessageEvent_Binding::Wrap(aCx, this, aGivenProto); +} + +MIDIMessageEvent* MIDIMessageEvent::AsMIDIMessageEvent() { return this; } + +already_AddRefed<MIDIMessageEvent> MIDIMessageEvent::Constructor( + EventTarget* aOwner, const class TimeStamp& aReceivedTime, + const nsTArray<uint8_t>& aData) { + MOZ_ASSERT(aOwner); + RefPtr<MIDIMessageEvent> e = new MIDIMessageEvent(aOwner); + e->InitEvent(u"midimessage"_ns, false, false); + e->mEvent->mTimeStamp = aReceivedTime; + e->mRawData = aData.Clone(); + e->SetTrusted(true); + return e.forget(); +} + +already_AddRefed<MIDIMessageEvent> MIDIMessageEvent::Constructor( + const GlobalObject& aGlobal, const nsAString& aType, + const MIDIMessageEventInit& aEventInitDict, ErrorResult& aRv) { + nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports()); + RefPtr<MIDIMessageEvent> e = new MIDIMessageEvent(owner); + bool trusted = e->Init(owner); + e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable); + // Set data for event. Timestamp will always be set to Now() (default for + // event) using this constructor. + if (aEventInitDict.mData.WasPassed()) { + const auto& a = aEventInitDict.mData.Value(); + a.ComputeState(); + e->mData = + Uint8Array::Create(aGlobal.Context(), owner, a.Length(), a.Data()); + if (NS_WARN_IF(!e->mData)) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + return nullptr; + } + } + + e->SetTrusted(trusted); + mozilla::HoldJSObjects(e.get()); + return e.forget(); +} + +void MIDIMessageEvent::GetData(JSContext* cx, + JS::MutableHandle<JSObject*> aData, + ErrorResult& aRv) { + if (!mData) { + mData = + Uint8Array::Create(cx, this, mRawData.Length(), mRawData.Elements()); + if (!mData) { + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); + return; + } + mRawData.Clear(); + } + aData.set(mData); +} + +} // namespace mozilla::dom |