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

Unified Diff: third_party/WebKit/Source/modules/webaudio/OscillatorNode.cpp

Issue 2102133002: Add constructors for WebAudio nodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and prefix use counter names with WebAudio Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/OscillatorNode.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/OscillatorNode.cpp b/third_party/WebKit/Source/modules/webaudio/OscillatorNode.cpp
index 4e0ec6a716d5fe19ac0c3d765c3dda4942182e3a..a6d37e1a7636017962010c58c5898f9dd836fd1c 100644
--- a/third_party/WebKit/Source/modules/webaudio/OscillatorNode.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/OscillatorNode.cpp
@@ -354,6 +354,48 @@ OscillatorNode* OscillatorNode::create(BaseAudioContext& context, ExceptionState
return new OscillatorNode(context);
}
+OscillatorNode* OscillatorNode::create(BaseAudioContext* context, const OscillatorOptions& options, ExceptionState& exceptionState)
+{
+ OscillatorNode* node = create(*context, exceptionState);
+
+ if (!node)
+ return nullptr;
+
+ node->handleChannelOptions(options, exceptionState);
+
+ if (options.hasType()) {
+ if (options.type() == "custom" && !options.hasPeriodicWave()) {
+ exceptionState.throwDOMException(
+ InvalidStateError,
+ "'type' cannot be set to 'custom' without also specifying 'periodicWave'");
+ return nullptr;
+ }
+ if (options.type() != "custom" && options.hasPeriodicWave()) {
+ exceptionState.throwDOMException(
+ InvalidStateError,
+ "'type' MUST be 'custom' instead of '"
+ + options.type()
+ + "' if 'periodicWave' is also given");
+ return nullptr;
+ }
+
+ // At this both type and periodicWave are consistently defined. In that
+ // case, don't set the type if periodicWave is specified because that
+ // will cause an (incorrect) error to be signaled.
+ if (options.type() != "custom")
+ node->setType(options.type(), exceptionState);
+ }
+ if (options.hasDetune())
+ node->detune()->setValue(options.detune());
+ if (options.hasFrequency())
+ node->frequency()->setValue(options.frequency());
+
+ if (options.hasPeriodicWave())
+ node->setPeriodicWave(options.periodicWave());
+
+ return node;
+}
+
DEFINE_TRACE(OscillatorNode)
{
visitor->trace(m_frequency);

Powered by Google App Engine
This is Rietveld 408576698