Skip to content

Commit 956c43d

Browse files
committed
fix: handle OscillatorNode custom type special cases
1 parent 04e7979 commit 956c43d

File tree

3 files changed

+57
-34
lines changed

3 files changed

+57
-34
lines changed

generator/js/AudioNodes.tmpl.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ module.exports = (jsExport, nativeBinding) => {
197197
return checkMember;
198198
}).join('');
199199

200+
// handle spacial cases
201+
if (d.name(d.node) === 'OscillatorNode') {
202+
// https://webaudio.github.io/web-audio-api/#dom-oscillatoroptions-type
203+
checkOptions += `
204+
if (parsedOptions.type === 'custom' && parsedOptions.periodicWave === null) {
205+
throw new DOMException("Failed to construct 'OscillatorNode': A PeriodicWave must be specified if the type is set to 'custom'", 'InvalidStateError');
206+
}
207+
208+
if (parsedOptions.periodicWave !== null) {
209+
parsedOptions.type = 'custom';
210+
}
211+
212+
`;
213+
}
214+
200215
return checkOptions;
201216
}())}
202217

js/OscillatorNode.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ module.exports = (jsExport, nativeBinding) => {
101101
parsedOptions.periodicWave = null;
102102
}
103103

104+
if (parsedOptions.type === 'custom' && parsedOptions.periodicWave === null) {
105+
throw new DOMException('Failed to construct \'OscillatorNode\': A PeriodicWave must be specified if the type is set to \'custom\'', 'InvalidStateError');
106+
}
107+
108+
if (parsedOptions.periodicWave !== null) {
109+
parsedOptions.type = 'custom';
110+
}
111+
104112
let napiObj;
105113

106114
try {

js/lib/errors.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@ const internalRe = new RegExp(internalPath);
66

77
// from wpt/resources/tesharness.js (line 2226)
88
const nameCodeMap = {
9-
IndexSizeError: 1,
10-
HierarchyRequestError: 3,
11-
WrongDocumentError: 4,
12-
InvalidCharacterError: 5,
13-
NoModificationAllowedError: 7,
14-
NotFoundError: 8,
15-
NotSupportedError: 9,
16-
InUseAttributeError: 10,
17-
InvalidStateError: 11,
18-
SyntaxError: 12,
19-
InvalidModificationError: 13,
20-
NamespaceError: 14,
21-
InvalidAccessError: 15,
22-
TypeMismatchError: 17,
23-
SecurityError: 18,
24-
NetworkError: 19,
25-
AbortError: 20,
26-
URLMismatchError: 21,
27-
QuotaExceededError: 22,
28-
TimeoutError: 23,
29-
InvalidNodeTypeError: 24,
30-
DataCloneError: 25,
31-
32-
EncodingError: 0,
33-
NotReadableError: 0,
34-
UnknownError: 0,
35-
ConstraintError: 0,
36-
DataError: 0,
37-
TransactionInactiveError: 0,
38-
ReadOnlyError: 0,
39-
VersionError: 0,
40-
OperationError: 0,
41-
NotAllowedError: 0,
42-
OptOutError: 0
9+
IndexSizeError: 1,
10+
HierarchyRequestError: 3,
11+
WrongDocumentError: 4,
12+
InvalidCharacterError: 5,
13+
NoModificationAllowedError: 7,
14+
NotFoundError: 8,
15+
NotSupportedError: 9,
16+
InUseAttributeError: 10,
17+
InvalidStateError: 11,
18+
SyntaxError: 12,
19+
InvalidModificationError: 13,
20+
NamespaceError: 14,
21+
InvalidAccessError: 15,
22+
TypeMismatchError: 17,
23+
SecurityError: 18,
24+
NetworkError: 19,
25+
AbortError: 20,
26+
URLMismatchError: 21,
27+
QuotaExceededError: 22,
28+
TimeoutError: 23,
29+
InvalidNodeTypeError: 24,
30+
DataCloneError: 25,
31+
32+
EncodingError: 0,
33+
NotReadableError: 0,
34+
UnknownError: 0,
35+
ConstraintError: 0,
36+
DataError: 0,
37+
TransactionInactiveError: 0,
38+
ReadOnlyError: 0,
39+
VersionError: 0,
40+
OperationError: 0,
41+
NotAllowedError: 0,
42+
OptOutError: 0,
4343
};
4444

4545
exports.nameCodeMap = nameCodeMap;

0 commit comments

Comments
 (0)