Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: Source/modules/webaudio/AudioNode.cpp

Issue 24877002: Add more informative messages for DOM exceptions. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Upload again Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 26
27 #if ENABLE(WEB_AUDIO) 27 #if ENABLE(WEB_AUDIO)
28 28
29 #include "modules/webaudio/AudioNode.h" 29 #include "modules/webaudio/AudioNode.h"
30 30
31 #include "bindings/v8/ExceptionMessages.h"
31 #include "bindings/v8/ExceptionState.h" 32 #include "bindings/v8/ExceptionState.h"
32 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
33 #include "modules/webaudio/AudioContext.h" 34 #include "modules/webaudio/AudioContext.h"
34 #include "modules/webaudio/AudioNodeInput.h" 35 #include "modules/webaudio/AudioNodeInput.h"
35 #include "modules/webaudio/AudioNodeOutput.h" 36 #include "modules/webaudio/AudioNodeOutput.h"
36 #include "modules/webaudio/AudioParam.h" 37 #include "modules/webaudio/AudioParam.h"
37 #include "wtf/Atomics.h" 38 #include "wtf/Atomics.h"
38 #include "wtf/MainThread.h" 39 #include "wtf/MainThread.h"
39 40
40 #if DEBUG_AUDIONODE_REFERENCES 41 #if DEBUG_AUDIONODE_REFERENCES
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 return m_outputs[i].get(); 124 return m_outputs[i].get();
124 return 0; 125 return 0;
125 } 126 }
126 127
127 void AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsigned i nputIndex, ExceptionState& es) 128 void AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsigned i nputIndex, ExceptionState& es)
128 { 129 {
129 ASSERT(isMainThread()); 130 ASSERT(isMainThread());
130 AudioContext::AutoLocker locker(context()); 131 AudioContext::AutoLocker locker(context());
131 132
132 if (!destination) { 133 if (!destination) {
133 es.throwUninformativeAndGenericDOMException(SyntaxError); 134 es.throwDOMException(
135 SyntaxError,
136 ExceptionMessages::failedToExecute(
137 "connect",
138 "AudioNode",
139 "invalid destination node."));
134 return; 140 return;
135 } 141 }
136 142
137 // Sanity check input and output indices. 143 // Sanity check input and output indices.
138 if (outputIndex >= numberOfOutputs()) { 144 if (outputIndex >= numberOfOutputs()) {
139 es.throwUninformativeAndGenericDOMException(IndexSizeError); 145 es.throwDOMException(
146 IndexSizeError,
147 ExceptionMessages::failedToExecute(
148 "connect",
149 "AudioNode",
150 "output index (" + String::number(outputIndex) + ") exceeds numb er of outputs (" + String::number(numberOfOutputs()) + ")."));
140 return; 151 return;
141 } 152 }
142 153
143 if (destination && inputIndex >= destination->numberOfInputs()) { 154 if (destination && inputIndex >= destination->numberOfInputs()) {
144 es.throwUninformativeAndGenericDOMException(IndexSizeError); 155 es.throwDOMException(
156 IndexSizeError,
157 ExceptionMessages::failedToExecute(
158 "connect",
159 "AudioNode",
160 "input index (" + String::number(inputIndex) + ") exceeds number of inputs (" + String::number(destination->numberOfInputs()) + ")."));
145 return; 161 return;
146 } 162 }
147 163
148 if (context() != destination->context()) { 164 if (context() != destination->context()) {
149 es.throwUninformativeAndGenericDOMException(SyntaxError); 165 es.throwDOMException(
166 SyntaxError,
167 ExceptionMessages::failedToExecute(
168 "connect",
169 "AudioNode",
170 "cannot connect to a destination belonging to a different audio context."));
150 return; 171 return;
151 } 172 }
152 173
153 AudioNodeInput* input = destination->input(inputIndex); 174 AudioNodeInput* input = destination->input(inputIndex);
154 AudioNodeOutput* output = this->output(outputIndex); 175 AudioNodeOutput* output = this->output(outputIndex);
155 input->connect(output); 176 input->connect(output);
156 177
157 // Let context know that a connection has been made. 178 // Let context know that a connection has been made.
158 context()->incrementConnectionCount(); 179 context()->incrementConnectionCount();
159 } 180 }
160 181
161 void AudioNode::connect(AudioParam* param, unsigned outputIndex, ExceptionState& es) 182 void AudioNode::connect(AudioParam* param, unsigned outputIndex, ExceptionState& es)
162 { 183 {
163 ASSERT(isMainThread()); 184 ASSERT(isMainThread());
164 AudioContext::AutoLocker locker(context()); 185 AudioContext::AutoLocker locker(context());
165 186
166 if (!param) { 187 if (!param) {
167 es.throwUninformativeAndGenericDOMException(SyntaxError); 188 es.throwDOMException(
189 SyntaxError,
190 ExceptionMessages::failedToExecute(
191 "connect",
192 "AudioNode",
193 "invalid AudioParam."));
168 return; 194 return;
169 } 195 }
170 196
171 if (outputIndex >= numberOfOutputs()) { 197 if (outputIndex >= numberOfOutputs()) {
172 es.throwUninformativeAndGenericDOMException(IndexSizeError); 198 es.throwDOMException(
199 IndexSizeError,
200 ExceptionMessages::failedToExecute(
201 "connect",
202 "AudioNode",
203 "output index (" + String::number(outputIndex) + ") exceeds numb er of outputs (" + String::number(numberOfOutputs()) + ")."));
173 return; 204 return;
174 } 205 }
175 206
176 if (context() != param->context()) { 207 if (context() != param->context()) {
177 es.throwUninformativeAndGenericDOMException(SyntaxError); 208 es.throwDOMException(
209 SyntaxError,
210 ExceptionMessages::failedToExecute(
211 "connect",
212 "AudioNode",
213 "cannot connect to an AudioParam belonging to a different audio context."));
178 return; 214 return;
179 } 215 }
180 216
181 AudioNodeOutput* output = this->output(outputIndex); 217 AudioNodeOutput* output = this->output(outputIndex);
182 param->connect(output); 218 param->connect(output);
183 } 219 }
184 220
185 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& es) 221 void AudioNode::disconnect(unsigned outputIndex, ExceptionState& es)
186 { 222 {
187 ASSERT(isMainThread()); 223 ASSERT(isMainThread());
188 AudioContext::AutoLocker locker(context()); 224 AudioContext::AutoLocker locker(context());
189 225
190 // Sanity check input and output indices. 226 // Sanity check input and output indices.
191 if (outputIndex >= numberOfOutputs()) { 227 if (outputIndex >= numberOfOutputs()) {
192 es.throwUninformativeAndGenericDOMException(IndexSizeError); 228 es.throwDOMException(
229 IndexSizeError,
230 ExceptionMessages::failedToExecute(
231 "disconnect",
232 "AudioNode",
233 "output index (" + String::number(outputIndex) + ") exceeds numb er of outputs (" + String::number(numberOfOutputs()) + ")."));
193 return; 234 return;
194 } 235 }
195 236
196 AudioNodeOutput* output = this->output(outputIndex); 237 AudioNodeOutput* output = this->output(outputIndex);
197 output->disconnectAll(); 238 output->disconnectAll();
198 } 239 }
199 240
200 unsigned long AudioNode::channelCount() 241 unsigned long AudioNode::channelCount()
201 { 242 {
202 return m_channelCount; 243 return m_channelCount;
203 } 244 }
204 245
205 void AudioNode::setChannelCount(unsigned long channelCount, ExceptionState& es) 246 void AudioNode::setChannelCount(unsigned long channelCount, ExceptionState& es)
206 { 247 {
207 ASSERT(isMainThread()); 248 ASSERT(isMainThread());
208 AudioContext::AutoLocker locker(context()); 249 AudioContext::AutoLocker locker(context());
209 250
210 if (channelCount > 0 && channelCount <= AudioContext::maxNumberOfChannels()) { 251 if (channelCount > 0 && channelCount <= AudioContext::maxNumberOfChannels()) {
211 if (m_channelCount != channelCount) { 252 if (m_channelCount != channelCount) {
212 m_channelCount = channelCount; 253 m_channelCount = channelCount;
213 if (m_channelCountMode != Max) 254 if (m_channelCountMode != Max)
214 updateChannelsForInputs(); 255 updateChannelsForInputs();
215 } 256 }
216 } else { 257 } else {
217 es.throwUninformativeAndGenericDOMException(InvalidStateError); 258 es.throwDOMException(
259 InvalidStateError,
260 ExceptionMessages::failedToSet(
261 "channelCount",
262 "AudioNode",
263 "channel count (" + String::number(channelCount)
264 + ") must be between 1 and "
265 + String::number(AudioContext::maxNumberOfChannels()) + "."));
218 } 266 }
219 } 267 }
220 268
221 String AudioNode::channelCountMode() 269 String AudioNode::channelCountMode()
222 { 270 {
223 switch (m_channelCountMode) { 271 switch (m_channelCountMode) {
224 case Max: 272 case Max:
225 return "max"; 273 return "max";
226 case ClampedMax: 274 case ClampedMax:
227 return "clamped-max"; 275 return "clamped-max";
228 case Explicit: 276 case Explicit:
229 return "explicit"; 277 return "explicit";
230 } 278 }
231 ASSERT_NOT_REACHED(); 279 ASSERT_NOT_REACHED();
232 return ""; 280 return "";
233 } 281 }
234 282
235 void AudioNode::setChannelCountMode(const String& mode, ExceptionState& es) 283 void AudioNode::setChannelCountMode(const String& mode, ExceptionState& es)
236 { 284 {
237 ASSERT(isMainThread()); 285 ASSERT(isMainThread());
238 AudioContext::AutoLocker locker(context()); 286 AudioContext::AutoLocker locker(context());
239 287
240 ChannelCountMode oldMode = m_channelCountMode; 288 ChannelCountMode oldMode = m_channelCountMode;
241 289
242 if (mode == "max") 290 if (mode == "max") {
243 m_channelCountMode = Max; 291 m_channelCountMode = Max;
244 else if (mode == "clamped-max") 292 } else if (mode == "clamped-max") {
245 m_channelCountMode = ClampedMax; 293 m_channelCountMode = ClampedMax;
246 else if (mode == "explicit") 294 } else if (mode == "explicit") {
247 m_channelCountMode = Explicit; 295 m_channelCountMode = Explicit;
248 else 296 } else {
249 es.throwUninformativeAndGenericDOMException(InvalidStateError); 297 es.throwDOMException(
298 InvalidStateError,
299 ExceptionMessages::failedToSet(
300 "channelCountMode",
301 "AudioNode",
302 "invalid mode '" + mode + "'; must be 'max', 'clamped-max', or ' explicit'."));
303 }
250 304
251 if (m_channelCountMode != oldMode) 305 if (m_channelCountMode != oldMode)
252 updateChannelsForInputs(); 306 updateChannelsForInputs();
253 } 307 }
254 308
255 String AudioNode::channelInterpretation() 309 String AudioNode::channelInterpretation()
256 { 310 {
257 switch (m_channelInterpretation) { 311 switch (m_channelInterpretation) {
258 case AudioBus::Speakers: 312 case AudioBus::Speakers:
259 return "speakers"; 313 return "speakers";
260 case AudioBus::Discrete: 314 case AudioBus::Discrete:
261 return "discrete"; 315 return "discrete";
262 } 316 }
263 ASSERT_NOT_REACHED(); 317 ASSERT_NOT_REACHED();
264 return ""; 318 return "";
265 } 319 }
266 320
267 void AudioNode::setChannelInterpretation(const String& interpretation, Exception State& es) 321 void AudioNode::setChannelInterpretation(const String& interpretation, Exception State& es)
268 { 322 {
269 ASSERT(isMainThread()); 323 ASSERT(isMainThread());
270 AudioContext::AutoLocker locker(context()); 324 AudioContext::AutoLocker locker(context());
271 325
272 if (interpretation == "speakers") 326 if (interpretation == "speakers") {
273 m_channelInterpretation = AudioBus::Speakers; 327 m_channelInterpretation = AudioBus::Speakers;
274 else if (interpretation == "discrete") 328 } else if (interpretation == "discrete") {
275 m_channelInterpretation = AudioBus::Discrete; 329 m_channelInterpretation = AudioBus::Discrete;
276 else 330 } else {
277 es.throwUninformativeAndGenericDOMException(InvalidStateError); 331 es.throwDOMException(
332 InvalidStateError,
333 ExceptionMessages::failedToSet(
334 "channelInterpretation",
335 "AudioNode",
336 "invalid interpretation '" + interpretation + "'; must be 'speak ers' or 'discrete'."));
337 }
278 } 338 }
279 339
280 void AudioNode::updateChannelsForInputs() 340 void AudioNode::updateChannelsForInputs()
281 { 341 {
282 for (unsigned i = 0; i < m_inputs.size(); ++i) 342 for (unsigned i = 0; i < m_inputs.size(); ++i)
283 input(i)->changedOutputs(); 343 input(i)->changedOutputs();
284 } 344 }
285 345
286 const AtomicString& AudioNode::interfaceName() const 346 const AtomicString& AudioNode::interfaceName() const
287 { 347 {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 fprintf(stderr, "%d: %d\n", i, s_nodeCount[i]); 579 fprintf(stderr, "%d: %d\n", i, s_nodeCount[i]);
520 580
521 fprintf(stderr, "===========================\n\n\n"); 581 fprintf(stderr, "===========================\n\n\n");
522 } 582 }
523 583
524 #endif // DEBUG_AUDIONODE_REFERENCES 584 #endif // DEBUG_AUDIONODE_REFERENCES
525 585
526 } // namespace WebCore 586 } // namespace WebCore
527 587
528 #endif // ENABLE(WEB_AUDIO) 588 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioContext.cpp ('k') | Source/modules/webaudio/DefaultAudioDestinationNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698