Skip to content

fix: audioworklet registerProcessor should expect a constructor not a function #1296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion baselines/audioworklet.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ declare var AudioWorkletProcessor: {
new(): AudioWorkletProcessor;
};

interface AudioWorkletProcessorImpl extends AudioWorkletProcessor {
process(inputs: Float32Array[][], outputs: Float32Array[][], parameters: Record<string, Float32Array>): boolean;
}

/** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */
interface ByteLengthQueuingStrategy extends QueuingStrategy<ArrayBufferView> {
readonly highWaterMark: number;
Expand Down Expand Up @@ -890,7 +894,7 @@ declare namespace WebAssembly {
}

interface AudioWorkletProcessorConstructor {
(options: any): AudioWorkletProcessor;
new (options: any): AudioWorkletProcessorImpl;
}

interface PerformanceObserverCallback {
Expand Down
16 changes: 16 additions & 0 deletions inputfiles/addedTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,22 @@
},
"interfaces": {
"interface": {
"AudioWorkletProcessorImpl": {
"name": "AudioWorkletProcessorImpl",
"extends": "AudioWorkletProcessor",
"methods": {
"method": {
"process": {
"name": "process",
"overrideSignatures": [
"process(inputs: Float32Array[][], outputs: Float32Array[][], parameters: Record<string, Float32Array>): boolean"
]
}
}
},
"exposed": "AudioWorklet",
"noInterfaceObject": true
},
"BroadcastChannel": {
"events": {
"event": [
Expand Down
5 changes: 5 additions & 0 deletions inputfiles/overridingTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@
"overrideSignatures": [
"new (...params: any[]): HTMLElement"
]
},
"AudioWorkletProcessorConstructor": {
"overrideSignatures": [
"new (options: any): AudioWorkletProcessorImpl"
]
}
}
},
Expand Down
17 changes: 17 additions & 0 deletions unittests/files/audioworklet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2020"],
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": [
"../../../baselines/audioworklet*",
"**/*"
]
}
8 changes: 8 additions & 0 deletions unittests/files/audioworklet/usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
registerProcessor(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test in extra folder as other files has to be included. If other setup is needed say how to change it.

"test",
class extends AudioWorkletProcessor {
process(input: Float32Array[][], output: Float32Array[][], params: { [key: string]: Float32Array }) {
return true;
}
}
);
8 changes: 8 additions & 0 deletions unittests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ for (const filename of await readdir(new URL("files/", import.meta.url))) {
});
}
}

for (const filename of await readdir(new URL("files/audioworklet", import.meta.url))) {
if (filename.endsWith(".ts")) {
execSync(`npx tsc generated/audioworklet.generated.d.ts unittests/files/audioworklet/${filename} --target es2020 --lib es2020 --types --noEmit`, {
stdio: "inherit"
});
}
}