@@ -89,14 +89,12 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
8989 aPort->GetId (id);
9090 ErrorResult rv;
9191 if (aPort->State () == MIDIPortDeviceState::Disconnected) {
92- if (aPort->Type () == MIDIPortType::Input && mInputMap ->Has (id)) {
93- MIDIInputMap_Binding::MaplikeHelpers::Delete (mInputMap , aPort->StableId (),
94- rv);
95- mInputMap ->Remove (id);
96- } else if (aPort->Type () == MIDIPortType::Output && mOutputMap ->Has (id)) {
97- MIDIOutputMap_Binding::MaplikeHelpers::Delete (mOutputMap ,
98- aPort->StableId (), rv);
99- mOutputMap ->Remove (id);
92+ if (aPort->Type () == MIDIPortType::Input &&
93+ MIDIInputMap_Binding::MaplikeHelpers::Has (mInputMap , id, rv)) {
94+ MIDIInputMap_Binding::MaplikeHelpers::Delete (mInputMap , id, rv);
95+ } else if (aPort->Type () == MIDIPortType::Output &&
96+ MIDIOutputMap_Binding::MaplikeHelpers::Has (mOutputMap , id, rv)) {
97+ MIDIOutputMap_Binding::MaplikeHelpers::Delete (mOutputMap , id, rv);
10098 }
10199 // Check to make sure Has()/Delete() calls haven't failed.
102100 if (NS_WARN_IF(rv.Failed ())) {
@@ -108,31 +106,31 @@ void MIDIAccess::FireConnectionEvent(MIDIPort* aPort) {
108106 // this means a port that was disconnected has been reconnected, with the
109107 // port owner holding the object during that time, and we should add that
110108 // port object to our maps again.
111- if (aPort->Type () == MIDIPortType::Input && !mInputMap ->Has (id)) {
109+ if (aPort->Type () == MIDIPortType::Input &&
110+ !MIDIInputMap_Binding::MaplikeHelpers::Has (mInputMap , id, rv)) {
112111 if (NS_WARN_IF(rv.Failed ())) {
113112 LOG (" Input port not found" );
114113 return ;
115114 }
116115 MIDIInputMap_Binding::MaplikeHelpers::Set (
117- mInputMap , aPort-> StableId () , *(static_cast <MIDIInput*>(aPort)), rv);
116+ mInputMap , id , *(static_cast <MIDIInput*>(aPort)), rv);
118117 if (NS_WARN_IF(rv.Failed ())) {
119118 LOG (" Map Set failed for input port" );
120119 return ;
121120 }
122- mInputMap ->Insert (id, aPort);
123- } else if (aPort->Type () == MIDIPortType::Output && mOutputMap ->Has (id)) {
121+ } else if (aPort->Type () == MIDIPortType::Output &&
122+ !MIDIOutputMap_Binding::MaplikeHelpers::Has (mOutputMap , id,
123+ rv)) {
124124 if (NS_WARN_IF(rv.Failed ())) {
125125 LOG (" Output port not found" );
126126 return ;
127127 }
128128 MIDIOutputMap_Binding::MaplikeHelpers::Set (
129- mOutputMap , aPort->StableId (), *(static_cast <MIDIOutput*>(aPort)),
130- rv);
129+ mOutputMap , id, *(static_cast <MIDIOutput*>(aPort)), rv);
131130 if (NS_WARN_IF(rv.Failed ())) {
132131 LOG (" Map set failed for output port" );
133132 return ;
134133 }
135- mOutputMap ->Insert (id, aPort);
136134 }
137135 }
138136 RefPtr<MIDIConnectionEvent> event =
@@ -146,7 +144,9 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
146144 MIDIPortType type = static_cast <MIDIPortType>(aInfo.type ());
147145 RefPtr<MIDIPort> port;
148146 if (type == MIDIPortType::Input) {
149- if (mInputMap ->Has (id) || NS_WARN_IF(aRv.Failed ())) {
147+ bool hasPort =
148+ MIDIInputMap_Binding::MaplikeHelpers::Has (mInputMap , id, aRv);
149+ if (hasPort || NS_WARN_IF(aRv.Failed ())) {
150150 // We already have the port in our map.
151151 return ;
152152 }
@@ -157,15 +157,15 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
157157 return ;
158158 }
159159 MIDIInputMap_Binding::MaplikeHelpers::Set (
160- mInputMap , port->StableId (), *(static_cast <MIDIInput*>(port.get ())),
161- aRv);
160+ mInputMap , id, *(static_cast <MIDIInput*>(port.get ())), aRv);
162161 if (NS_WARN_IF(aRv.Failed ())) {
163162 LOG (" Coudld't set input port in map" );
164163 return ;
165164 }
166- mInputMap ->Insert (id, port);
167165 } else if (type == MIDIPortType::Output) {
168- if (mOutputMap ->Has (id) || NS_WARN_IF(aRv.Failed ())) {
166+ bool hasPort =
167+ MIDIOutputMap_Binding::MaplikeHelpers::Has (mOutputMap , id, aRv);
168+ if (hasPort || NS_WARN_IF(aRv.Failed ())) {
169169 // We already have the port in our map.
170170 return ;
171171 }
@@ -176,13 +176,11 @@ void MIDIAccess::MaybeCreateMIDIPort(const MIDIPortInfo& aInfo,
176176 return ;
177177 }
178178 MIDIOutputMap_Binding::MaplikeHelpers::Set (
179- mOutputMap , port->StableId (), *(static_cast <MIDIOutput*>(port.get ())),
180- aRv);
179+ mOutputMap , id, *(static_cast <MIDIOutput*>(port.get ())), aRv);
181180 if (NS_WARN_IF(aRv.Failed ())) {
182181 LOG (" Coudld't set output port in map" );
183182 return ;
184183 }
185- mOutputMap ->Insert (id, port);
186184 } else {
187185 // If we hit this, then we have some port that is neither input nor output.
188186 // That is bad.
0 commit comments