1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
|
// Define several classes.
class EmptyWorkletProcessor extends AudioWorkletProcessor {}
class NoProcessWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
}
class BadDescriptorsWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return "A string";
}
}
class GoodDescriptorsWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "myParam",
defaultValue: 0.707,
},
];
}
}
class DummyProcessWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
}
class DescriptorsNoNameWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
defaultValue: 0.707,
},
];
}
}
class DescriptorsDefaultValueNotNumberWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
defaultValue: "test",
},
];
}
}
class DescriptorsMinValueNotNumberWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
minValue: "test",
},
];
}
}
class DescriptorsMaxValueNotNumberWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
maxValue: "test",
},
];
}
}
class DescriptorsDuplicatedNameWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
},
{
name: "test",
},
];
}
}
class DescriptorsNotDictWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [42];
}
}
class DescriptorsOutOfRangeMinWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
defaultValue: 0,
minValue: 1,
maxValue: 2,
},
];
}
}
class DescriptorsOutOfRangeMaxWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
defaultValue: 3,
minValue: 1,
maxValue: 2,
},
];
}
}
class DescriptorsBadRangeMaxWorkletProcessor extends AudioWorkletProcessor {
constructor() {
super();
}
process() {
// Do nothing, output silence
}
static get parameterDescriptors() {
return [
{
name: "test",
defaultValue: 1.5,
minValue: 2,
maxValue: 1,
},
];
}
}
// Test not a constructor
// "TypeError: Argument 2 of AudioWorkletGlobalScope.registerProcessor is not a constructor."
try {
registerProcessor("sure!", () => {});
} catch (e) {
console.log(e);
}
// Test empty name
// "NotSupportedError: Argument 1 of AudioWorkletGlobalScope.registerProcessor should not be an empty string."
try {
registerProcessor("", EmptyWorkletProcessor);
} catch (e) {
console.log(e);
}
// Test not an object
// "TypeError: Argument 2 of AudioWorkletGlobalScope.registerProcessor is not an object."
try {
registerProcessor("my-worklet-processor", "");
} catch (e) {
console.log(e);
}
// Test Empty class definition
registerProcessor("empty-worklet-processor", EmptyWorkletProcessor);
// Test class with constructor but not process function
registerProcessor("no-worklet-processor", NoProcessWorkletProcessor);
// Test class with parameterDescriptors being iterable, but the elements are not
// dictionaries.
// "TypeError: AudioWorkletGlobalScope.registerProcessor: Element 0 in parameterDescriptors can't be converted to a dictionary.",
try {
registerProcessor(
"bad-descriptors-worklet-processor",
BadDescriptorsWorkletProcessor
);
} catch (e) {
console.log(e);
}
// Test class with good parameterDescriptors
// No error expected here
registerProcessor(
"good-descriptors-worklet-processor",
GoodDescriptorsWorkletProcessor
);
// Test class with constructor and process function
// No error expected here
registerProcessor("dummy-worklet-processor", DummyProcessWorkletProcessor);
// Test class adding class with the same name twice
// "NotSupportedError: Operation is not supported: Argument 1 of AudioWorkletGlobalScope.registerProcessor is invalid: a class with the same name is already registered."
try {
registerProcessor("dummy-worklet-processor", DummyProcessWorkletProcessor);
} catch (e) {
console.log(e);
}
// "name" is a mandatory field in descriptors
// "TypeError: Missing required 'name' member of AudioParamDescriptor."
try {
registerProcessor(
"descriptors-no-name-worklet-processor",
DescriptorsNoNameWorkletProcessor
);
} catch (e) {
console.log(e);
}
// "defaultValue" should be a number
// "TypeError: 'defaultValue' member of AudioParamDescriptor is not a finite floating-point value."
try {
registerProcessor(
"descriptors-default-value-not-number-worklet-processor",
DescriptorsDefaultValueNotNumberWorkletProcessor
);
} catch (e) {
console.log(e);
}
// "min" should be a number
// "TypeError: 'minValue' member of AudioParamDescriptor is not a finite floating-point value."
try {
registerProcessor(
"descriptors-min-value-not-number-worklet-processor",
DescriptorsMinValueNotNumberWorkletProcessor
);
} catch (e) {
console.log(e);
}
// "max" should be a number
// "TypeError: 'maxValue' member of AudioParamDescriptor is not a finite floating-point value."
try {
registerProcessor(
"descriptors-max-value-not-number-worklet-processor",
DescriptorsMaxValueNotNumberWorkletProcessor
);
} catch (e) {
console.log(e);
}
// Duplicated values are not allowed for "name"
// "NotSupportedError: Duplicated name \"test\" in parameterDescriptors"
try {
registerProcessor(
"descriptors-duplicated-name-worklet-processor",
DescriptorsDuplicatedNameWorkletProcessor
);
} catch (e) {
console.log(e);
}
// Descriptors' elements should be dictionnary
// "TypeError: Element 0 in parameterDescriptors can't be converted to a dictionary.",
try {
registerProcessor(
"descriptors-not-dict-worklet-processor",
DescriptorsNotDictWorkletProcessor
);
} catch (e) {
console.log(e);
}
// defaultValue value should be in range [minValue, maxValue]. defaultValue < minValue is not allowed
// "NotSupportedError: In parameterDescriptors, test defaultValue is out of the range defined by minValue and maxValue.",
try {
registerProcessor(
"descriptors-out-of-range-min-worklet-processor",
DescriptorsOutOfRangeMinWorkletProcessor
);
} catch (e) {
console.log(e);
}
// defaultValue value should be in range [minValue, maxValue]. defaultValue > maxValue is not allowed
// "NotSupportedError: In parameterDescriptors, test defaultValue is out of the range defined by minValue and maxValue.",
try {
registerProcessor(
"descriptors-out-of-range-max-worklet-processor",
DescriptorsOutOfRangeMaxWorkletProcessor
);
} catch (e) {
console.log(e);
}
// We should have minValue < maxValue to define a valid range
// "NotSupportedError: In parameterDescriptors, test minValue should be smaller than maxValue.",
try {
registerProcessor(
"descriptors-bad-range-max-worklet-processor",
DescriptorsBadRangeMaxWorkletProcessor
);
} catch (e) {
console.log(e);
}
|