mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-23 08:06:11 +00:00
This is a simple getter and setter of the OscillatorType enum, with error checking to not allow 'custom', as that should only be changed through 'setPeriodicWave()'.
37 lines
1.1 KiB
HTML
37 lines
1.1 KiB
HTML
<script src="../include.js"></script>
|
|
<script>
|
|
test(() => {
|
|
const audioContext = new OfflineAudioContext(1, 5000, 44100);
|
|
|
|
const oscillator = audioContext.createOscillator();
|
|
|
|
// Check prototype
|
|
let prototype = Object.getPrototypeOf(oscillator);
|
|
|
|
while (prototype) {
|
|
println(prototype.constructor.name);
|
|
prototype = Object.getPrototypeOf(prototype);
|
|
}
|
|
|
|
// Context getter
|
|
println(`context: '${oscillator.context}, is same as original: ${audioContext === oscillator.context}`);
|
|
|
|
// Invalid type in constructor
|
|
try {
|
|
new OscillatorNode(audioContext, { type: 'custom' });
|
|
} catch (e) {
|
|
println(`Error creating node: '${e}'`);
|
|
}
|
|
|
|
// Type attribute
|
|
println(`oscillator node type: '${oscillator.type}'`);
|
|
try {
|
|
oscillator.type = 'custom';
|
|
} catch (e) {
|
|
println(`Error: '${e}', type is: ${oscillator.type}`);
|
|
}
|
|
oscillator.type = 'triangle';
|
|
println(`oscillator node type: '${oscillator.type}'`);
|
|
});
|
|
</script>
|