зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1766469 - Handle empty data fields when creating MIDIMessageEvent objects r=padenot
This change matches Chrome's behavior of not throwing in cases when the data field is null. However contrary to Chrome we populate the object with an empty array instead of a null reference. Differential Revision: https://phabricator.services.mozilla.com/D146672
This commit is contained in:
Родитель
db27cb2f8b
Коммит
ff14b28782
|
@ -72,12 +72,15 @@ already_AddRefed<MIDIMessageEvent> MIDIMessageEvent::Constructor(
|
|||
e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
|
||||
// Set data for event. Timestamp will always be set to Now() (default for
|
||||
// event) using this constructor.
|
||||
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;
|
||||
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);
|
||||
|
|
|
@ -21,3 +21,4 @@ disabled = Bug 1437204
|
|||
[test_midi_device_pending.html]
|
||||
disabled = Bug 1437204
|
||||
[test_midi_send_messages.html]
|
||||
[test_midi_message_event.html]
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>WebMIDI MIDIMessageEvent Test</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script class="testbody" type="application/javascript">
|
||||
add_task(() => {
|
||||
is(new MIDIMessageEvent('eventType').bubbles, false, "bubbles field is false by default");
|
||||
is(new MIDIMessageEvent('eventType').cancelable, false, "cancelable field is false by default");
|
||||
isDeeply(new MIDIMessageEvent('eventType').data, [], "The default message is empty");
|
||||
|
||||
is(new MIDIMessageEvent('eventType', { bubbles: false }).bubbles, false, "bubbles is passed");
|
||||
is(new MIDIMessageEvent('eventType', { bubbles: true }).bubbles, true, "bubbles is passed");
|
||||
|
||||
is(new MIDIMessageEvent('eventType', { cancelable: false }).cancelable, false, "cancelable is passed");
|
||||
is(new MIDIMessageEvent('eventType', { cancelable: true }).cancelable, true, "cancelable is passed");
|
||||
|
||||
var data = new Uint8Array(16);
|
||||
isDeeply(new MIDIMessageEvent('eventType', { data }).data, data, "data is passed");
|
||||
|
||||
// All initializers are passed.
|
||||
data = new Uint8Array(3);
|
||||
is(new MIDIMessageEvent('eventType', { bubbles: true, cancelable: true, data }).bubbles, true, "all initializers are passed");
|
||||
is(new MIDIMessageEvent('eventType', { bubbles: true, cancelable: true, data }).cancelable, true, "all initializers are passed");
|
||||
isDeeply(new MIDIMessageEvent('eventType', { bubbles: true, cancelable: true, data }).data, data, "all initializers are passed");
|
||||
|
||||
if (window.SharedArrayBuffer) {
|
||||
data = new Uint8Array(new SharedArrayBuffer(3));
|
||||
doesThrow(() => { new MIDIMessageEvent('eventType', { data }); }, "shared array buffers are rejected");
|
||||
} else {
|
||||
todo(false, 'SharedArrayBuffer is unavailable.');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче