Skip to content

Commit 1127341

Browse files
committed
AudioNode.connect(): First parameter should not be nullable
https://bugs.webkit.org/show_bug.cgi?id=163773 Reviewed by Darin Adler. Source/WebCore: AudioNode.connect()'s first parameter should not be nullable: - https://webaudio.github.io/web-audio-api/#idl-def-AudioNode. We were throwing a SYNTAX_ERR when passing null, we now throw a TypeError instead. No new tests, updated existing test. * Modules/webaudio/AudioBasicInspectorNode.cpp: (WebCore::AudioBasicInspectorNode::connect): * Modules/webaudio/AudioBasicInspectorNode.h: * Modules/webaudio/AudioNode.cpp: (WebCore::AudioNode::connect): * Modules/webaudio/AudioNode.h: * Modules/webaudio/AudioNode.idl: LayoutTests: Improve test coverage. * webaudio/audionode-expected.txt: * webaudio/audionode.html: Canonical link: https://commits.webkit.org/181552@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@207672 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 77bbf5f commit 1127341

9 files changed

Lines changed: 52 additions & 26 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2016-10-21 Chris Dumez <cdumez@apple.com>
2+
3+
AudioNode.connect(): First parameter should not be nullable
4+
https://bugs.webkit.org/show_bug.cgi?id=163773
5+
6+
Reviewed by Darin Adler.
7+
8+
Improve test coverage.
9+
10+
* webaudio/audionode-expected.txt:
11+
* webaudio/audionode.html:
12+
113
2016-10-21 Wenson Hsieh <wenson_hsieh@apple.com>
214

315
Implement InputEvent.getTargetRanges() for the input events spec

LayoutTests/webaudio/audionode-expected.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ PASS Source AudioNode has no inputs.
66
PASS Source AudioNode has one output.
77
PASS Destination AudioNode has one input.
88
PASS Destination AudioNode has no outputs.
9-
PASS connect() exception thrown for illegal destination AudioNode.
9+
PASS audioNode.connect(0, 0, 0) threw exception TypeError: Argument 1 ('destination') to AudioNode.connect must be an instance of AudioNode.
10+
PASS audioNode.connect(null, 0, 0) threw exception TypeError: Argument 1 ('destination') to AudioNode.connect must be an instance of AudioNode.
1011
PASS connect() exception thrown for illegal output index.
1112
PASS connect() exception thrown for illegal input index.
1213
PASS audioNode.connect(context.destination) succeeded.

LayoutTests/webaudio/audionode.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@
5151

5252
// Try calling connect() method with illegal values.
5353

54-
try {
55-
audioNode.connect(0, 0, 0);
56-
testFailed("connect() exception should be thrown for illegal destination AudioNode.");
57-
} catch(e) {
58-
testPassed("connect() exception thrown for illegal destination AudioNode.");
59-
}
54+
shouldThrowErrorName("audioNode.connect(0, 0, 0)", "TypeError");
55+
shouldThrowErrorName("audioNode.connect(null, 0, 0)", "TypeError");
6056

6157
try {
6258
audioNode.connect(context.destination, 5, 0);

Source/WebCore/ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2016-10-21 Chris Dumez <cdumez@apple.com>
2+
3+
AudioNode.connect(): First parameter should not be nullable
4+
https://bugs.webkit.org/show_bug.cgi?id=163773
5+
6+
Reviewed by Darin Adler.
7+
8+
AudioNode.connect()'s first parameter should not be nullable:
9+
- https://webaudio.github.io/web-audio-api/#idl-def-AudioNode.
10+
11+
We were throwing a SYNTAX_ERR when passing null, we now throw
12+
a TypeError instead.
13+
14+
No new tests, updated existing test.
15+
16+
* Modules/webaudio/AudioBasicInspectorNode.cpp:
17+
(WebCore::AudioBasicInspectorNode::connect):
18+
* Modules/webaudio/AudioBasicInspectorNode.h:
19+
* Modules/webaudio/AudioNode.cpp:
20+
(WebCore::AudioNode::connect):
21+
* Modules/webaudio/AudioNode.h:
22+
* Modules/webaudio/AudioNode.idl:
23+
124
2016-10-21 Wenson Hsieh <wenson_hsieh@apple.com>
225

326
Implement InputEvent.getTargetRanges() for the input events spec

Source/WebCore/Modules/webaudio/AudioBasicInspectorNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void AudioBasicInspectorNode::pullInputs(size_t framesToProcess)
4949
input(0)->pull(output(0)->bus(), framesToProcess);
5050
}
5151

52-
ExceptionOr<void> AudioBasicInspectorNode::connect(AudioNode* destination, unsigned outputIndex, unsigned inputIndex)
52+
ExceptionOr<void> AudioBasicInspectorNode::connect(AudioNode& destination, unsigned outputIndex, unsigned inputIndex)
5353
{
5454
ASSERT(isMainThread());
5555

Source/WebCore/Modules/webaudio/AudioBasicInspectorNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AudioBasicInspectorNode : public AudioNode {
3737

3838
private:
3939
void pullInputs(size_t framesToProcess) override;
40-
ExceptionOr<void> connect(AudioNode*, unsigned outputIndex, unsigned inputIndex) override;
40+
ExceptionOr<void> connect(AudioNode&, unsigned outputIndex, unsigned inputIndex) override;
4141
ExceptionOr<void> disconnect(unsigned outputIndex) override;
4242
void checkNumberOfChannelsForInput(AudioNodeInput*) override;
4343

Source/WebCore/Modules/webaudio/AudioNode.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,22 @@ AudioNodeOutput* AudioNode::output(unsigned i)
123123
return nullptr;
124124
}
125125

126-
ExceptionOr<void> AudioNode::connect(AudioNode* destination, unsigned outputIndex, unsigned inputIndex)
126+
ExceptionOr<void> AudioNode::connect(AudioNode& destination, unsigned outputIndex, unsigned inputIndex)
127127
{
128128
ASSERT(isMainThread());
129129
AudioContext::AutoLocker locker(context());
130130

131-
if (!destination)
132-
return Exception { SYNTAX_ERR };
133-
134131
// Sanity check input and output indices.
135132
if (outputIndex >= numberOfOutputs())
136133
return Exception { INDEX_SIZE_ERR };
137134

138-
if (destination && inputIndex >= destination->numberOfInputs())
135+
if (inputIndex >= destination.numberOfInputs())
139136
return Exception { INDEX_SIZE_ERR };
140137

141-
if (context() != destination->context())
138+
if (context() != destination.context())
142139
return Exception { SYNTAX_ERR };
143140

144-
auto* input = destination->input(inputIndex);
141+
auto* input = destination.input(inputIndex);
145142
auto* output = this->output(outputIndex);
146143
input->connect(output);
147144

@@ -151,22 +148,19 @@ ExceptionOr<void> AudioNode::connect(AudioNode* destination, unsigned outputInde
151148
return { };
152149
}
153150

154-
ExceptionOr<void> AudioNode::connect(AudioParam* param, unsigned outputIndex)
151+
ExceptionOr<void> AudioNode::connect(AudioParam& param, unsigned outputIndex)
155152
{
156153
ASSERT(isMainThread());
157154
AudioContext::AutoLocker locker(context());
158155

159-
if (!param)
160-
return Exception { SYNTAX_ERR };
161-
162156
if (outputIndex >= numberOfOutputs())
163157
return Exception { INDEX_SIZE_ERR };
164158

165-
if (context() != param->context())
159+
if (context() != param.context())
166160
return Exception { SYNTAX_ERR };
167161

168162
auto* output = this->output(outputIndex);
169-
param->connect(output);
163+
param.connect(output);
170164

171165
return { };
172166
}

Source/WebCore/Modules/webaudio/AudioNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class AudioNode : public EventTargetWithInlineData {
121121
AudioNodeOutput* output(unsigned);
122122

123123
// Called from main thread by corresponding JavaScript methods.
124-
virtual ExceptionOr<void> connect(AudioNode*, unsigned outputIndex, unsigned inputIndex);
125-
ExceptionOr<void> connect(AudioParam*, unsigned outputIndex);
124+
virtual ExceptionOr<void> connect(AudioNode&, unsigned outputIndex, unsigned inputIndex);
125+
ExceptionOr<void> connect(AudioParam&, unsigned outputIndex);
126126
virtual ExceptionOr<void> disconnect(unsigned outputIndex);
127127

128128
virtual float sampleRate() const { return m_sampleRate; }

Source/WebCore/Modules/webaudio/AudioNode.idl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
[SetterMayThrowException] attribute DOMString channelCountMode;
3535
[SetterMayThrowException] attribute DOMString channelInterpretation;
3636

37-
[MayThrowException] void connect(AudioNode? destination, optional unsigned long output = 0, optional unsigned long input = 0);
38-
[MayThrowException] void connect(AudioParam? destination, optional unsigned long output = 0);
37+
[MayThrowException] void connect(AudioNode destination, optional unsigned long output = 0, optional unsigned long input = 0);
38+
[MayThrowException] void connect(AudioParam destination, optional unsigned long output = 0);
3939
[MayThrowException] void disconnect(optional unsigned long output = 0);
4040
};

0 commit comments

Comments
 (0)