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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AudioParamTimeline.cpp

Issue 2656993002: Throw TypeError instead of InvalidAccessError for invalid times (Closed)
Patch Set: Address review comments and clang-format it Created 3 years, 6 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
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // be larger than least positive normalized single precision 54 // be larger than least positive normalized single precision
55 // value (1.1754944e-38) because we normally operate with flush-to-zero enabled. 55 // value (1.1754944e-38) because we normally operate with flush-to-zero enabled.
56 const float kSetTargetZeroThreshold = 1e-20; 56 const float kSetTargetZeroThreshold = 1e-20;
57 57
58 static bool IsNonNegativeAudioParamTime(double time, 58 static bool IsNonNegativeAudioParamTime(double time,
59 ExceptionState& exception_state, 59 ExceptionState& exception_state,
60 String message = "Time") { 60 String message = "Time") {
61 if (time >= 0) 61 if (time >= 0)
62 return true; 62 return true;
63 63
64 exception_state.ThrowDOMException( 64 exception_state.ThrowRangeError(
65 kInvalidAccessError, message + " must be a finite non-negative number: " + 65 message +
66 String::Number(time)); 66 " must be a finite non-negative number: " + String::Number(time));
67 return false; 67 return false;
68 } 68 }
69 69
70 static bool IsPositiveAudioParamTime(double time, 70 static bool IsPositiveAudioParamTime(double time,
71 ExceptionState& exception_state, 71 ExceptionState& exception_state,
72 String message) { 72 String message) {
73 if (time > 0) 73 if (time > 0)
74 return true; 74 return true;
75 75
76 exception_state.ThrowDOMException( 76 exception_state.ThrowRangeError(
77 kInvalidAccessError,
78 message + " must be a finite positive number: " + String::Number(time)); 77 message + " must be a finite positive number: " + String::Number(time));
79 return false; 78 return false;
80 } 79 }
81 80
82 String AudioParamTimeline::EventToString(const ParamEvent& event) { 81 String AudioParamTimeline::EventToString(const ParamEvent& event) {
83 // The default arguments for most automation methods is the value and the 82 // The default arguments for most automation methods is the value and the
84 // time. 83 // time.
85 String args = 84 String args =
86 String::Number(event.Value()) + ", " + String::Number(event.Time(), 16); 85 String::Number(event.Value()) + ", " + String::Number(event.Time(), 16);
87 86
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 double time, 436 double time,
438 float initial_value, 437 float initial_value,
439 double call_time, 438 double call_time,
440 ExceptionState& exception_state) { 439 ExceptionState& exception_state) {
441 DCHECK(IsMainThread()); 440 DCHECK(IsMainThread());
442 441
443 if (!IsNonNegativeAudioParamTime(time, exception_state)) 442 if (!IsNonNegativeAudioParamTime(time, exception_state))
444 return; 443 return;
445 444
446 if (!value) { 445 if (!value) {
447 exception_state.ThrowDOMException( 446 exception_state.ThrowRangeError(
448 kInvalidAccessError,
449 "The float target value provided (" + String::Number(value) + 447 "The float target value provided (" + String::Number(value) +
450 ") should not be in the range (" + 448 ") should not be in the range (" +
451 String::Number(-std::numeric_limits<float>::denorm_min()) + ", " + 449 String::Number(-std::numeric_limits<float>::denorm_min()) + ", " +
452 String::Number(std::numeric_limits<float>::denorm_min()) + ")."); 450 String::Number(std::numeric_limits<float>::denorm_min()) + ").");
453 return; 451 return;
454 } 452 }
455 453
456 MutexLocker locker(events_lock_); 454 MutexLocker locker(events_lock_);
457 InsertEvent(ParamEvent::CreateExponentialRampEvent(value, time, initial_value, 455 InsertEvent(ParamEvent::CreateExponentialRampEvent(value, time, initial_value,
458 call_time), 456 call_time),
459 exception_state); 457 exception_state);
460 } 458 }
461 459
462 void AudioParamTimeline::SetTargetAtTime(float target, 460 void AudioParamTimeline::SetTargetAtTime(float target,
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 unsigned write_index) { 1773 unsigned write_index) {
1776 size_t index = write_index; 1774 size_t index = write_index;
1777 1775
1778 for (; index < end_frame; ++index) 1776 for (; index < end_frame; ++index)
1779 values[index] = default_value; 1777 values[index] = default_value;
1780 1778
1781 return index; 1779 return index;
1782 } 1780 }
1783 1781
1784 } // namespace blink 1782 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/dom-exceptions-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698