OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 if (MessageValidator::validate(array, exceptionState, midiAccess()->sysexEna
bled())) | 209 if (MessageValidator::validate(array, exceptionState, midiAccess()->sysexEna
bled())) |
210 midiAccess()->sendMIDIData(m_portIndex, array->data(), array->length(),
timestamp); | 210 midiAccess()->sendMIDIData(m_portIndex, array->data(), array->length(),
timestamp); |
211 } | 211 } |
212 | 212 |
213 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception
State& exceptionState) | 213 void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, Exception
State& exceptionState) |
214 { | 214 { |
215 if (timestamp == 0.0) | 215 if (timestamp == 0.0) |
216 timestamp = now(executionContext()); | 216 timestamp = now(executionContext()); |
217 | 217 |
218 RefPtr<DOMUint8Array> array = DOMUint8Array::create(unsignedData.size()); | 218 // TODO(junov): crbug.com/536816 |
| 219 // Use createOrNull instead of deprecatedCreateOrCrash. Requires determining |
| 220 // the appropriate course of action for dealing with allocation failures, wh
ich |
| 221 // is currently not specified in the spec. Throwing a RangeError may be |
| 222 // appropriate considering the ECMAScript spec: |
| 223 // http://ecma-international.org/ecma-262/6.0/#sec-createbytedatablock |
| 224 // However the spec for MIDIOutput.send does not state that such exceptions |
| 225 // should be re-thrown, so for now we just crash the process when out of mem
ory. |
| 226 RefPtr<DOMUint8Array> array = DOMUint8Array::deprecatedCreateOrCrash(unsigne
dData.size()); |
219 DOMUint8Array::ValueType* const arrayData = array->data(); | 227 DOMUint8Array::ValueType* const arrayData = array->data(); |
220 const uint32_t arrayLength = array->length(); | 228 const uint32_t arrayLength = array->length(); |
221 | 229 |
222 for (size_t i = 0; i < unsignedData.size(); ++i) { | 230 for (size_t i = 0; i < unsignedData.size(); ++i) { |
223 if (unsignedData[i] > 0xff) { | 231 if (unsignedData[i] > 0xff) { |
224 exceptionState.throwTypeError("The value at index " + String::number
(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF."); | 232 exceptionState.throwTypeError("The value at index " + String::number
(i) + " (" + String::number(unsignedData[i]) + ") is greater than 0xFF."); |
225 return; | 233 return; |
226 } | 234 } |
227 if (i < arrayLength) | 235 if (i < arrayLength) |
228 arrayData[i] = unsignedData[i] & 0xff; | 236 arrayData[i] = unsignedData[i] & 0xff; |
(...skipping 11 matching lines...) Expand all Loading... |
240 { | 248 { |
241 send(unsignedData, 0.0, exceptionState); | 249 send(unsignedData, 0.0, exceptionState); |
242 } | 250 } |
243 | 251 |
244 DEFINE_TRACE(MIDIOutput) | 252 DEFINE_TRACE(MIDIOutput) |
245 { | 253 { |
246 MIDIPort::trace(visitor); | 254 MIDIPort::trace(visitor); |
247 } | 255 } |
248 | 256 |
249 } // namespace blink | 257 } // namespace blink |
OLD | NEW |