detect proxy
This commit is contained in:
parent
a161689cc0
commit
c119065678
3 changed files with 25 additions and 14 deletions
|
@ -58,6 +58,16 @@ export interface WorkletOptions {
|
|||
}
|
||||
export type WorkletMessage = number;
|
||||
|
||||
const proxies = new WeakSet();
|
||||
|
||||
globalThis.Proxy = new Proxy(Proxy, {
|
||||
construct(target, args) {
|
||||
var newProxy = new target(...args);
|
||||
proxies.add(newProxy);
|
||||
return newProxy;
|
||||
},
|
||||
})
|
||||
|
||||
// process method isn't needed for this weird use case
|
||||
// @ts-expect-error
|
||||
class BytebeatProcessor extends AudioWorkletProcessor {
|
||||
|
@ -101,23 +111,28 @@ class BytebeatProcessor extends AudioWorkletProcessor {
|
|||
out = NaN;
|
||||
}
|
||||
|
||||
if (Array.isArray(out)) {
|
||||
// replace array for safety, arrays could have modified functions
|
||||
// TODO can the index operator be overridden? is this safe?
|
||||
if (Array.isArray(out) && !proxies.has(out)) {
|
||||
out = [out[0], out[1]];
|
||||
} else {
|
||||
out = [out, out];
|
||||
}
|
||||
|
||||
out.forEach((v, i) => {
|
||||
out = out.map(v => {
|
||||
try {
|
||||
this.lastOut[i] = Number(v);
|
||||
if (proxies.has(out)) {
|
||||
new TypeError("can't convert proxy to number")
|
||||
} else {
|
||||
return +v;
|
||||
}
|
||||
} catch (err) {
|
||||
// TODO error message
|
||||
this.lastOut[i] = v;
|
||||
return NaN;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO show NaN but hold last sample for audio
|
||||
this.lastOut = out;
|
||||
|
||||
left[sample] = this.lastOut[0];
|
||||
right[sample] = this.lastOut[1];
|
||||
}
|
||||
|
|
|
@ -72,6 +72,9 @@ function initAudioContext() {
|
|||
return { audioCtx, audioGain };
|
||||
}
|
||||
|
||||
// TODO bug, this gets called twice every time,
|
||||
// because setting codemirror programmatically also calls this
|
||||
// the code text input might also have this issue?
|
||||
async function refresh() {
|
||||
// TODO
|
||||
const code = codeEditor.getCode().trim();
|
||||
|
@ -121,13 +124,6 @@ export function getSong(): Song {
|
|||
/*
|
||||
function handleMessage(e: MessageEvent<any>) {
|
||||
if (isPlainObject(e.data)) {
|
||||
const data = e.data;
|
||||
if (data.clearCanvas) {
|
||||
osc.clear();
|
||||
} else if (data.clearDrawBuffer) {
|
||||
osc.clearBuffer();
|
||||
}
|
||||
|
||||
if (data.errorMessage !== undefined) {
|
||||
if (isPlainObject(data.errorMessage)) {
|
||||
if (
|
||||
|
|
|
@ -20,7 +20,7 @@ export class CodeEditor {
|
|||
this.setCode = v =>
|
||||
// codemirror type is wrong
|
||||
// TODO pull request fix
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
codemirror.dispatch({
|
||||
changes: { from: 0, to: codemirror.state.doc.length, insert: v },
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue