detect proxy in audio worklet
cherrypicked fromc119065
(detect proxy, 2024-06-29) anddf1f9bf
(detect Proxy properly, 2024-06-30)
This commit is contained in:
parent
5ec0219691
commit
6273ac4bdd
1 changed files with 18 additions and 4 deletions
|
@ -53,6 +53,18 @@ function getErrorMessage(err: any, time: number) {
|
|||
}
|
||||
}
|
||||
|
||||
// replace Proxy so that they can be detected from the bytebeat code
|
||||
// this is completely undetectable by the bytebeat code
|
||||
const proxies = new WeakSet();
|
||||
Proxy = Object.getPrototypeOf(Proxy).contructor = new Proxy(Proxy, {
|
||||
construct(target, args) {
|
||||
// @ts-expect-error
|
||||
const newProxy = new target(...args);
|
||||
proxies.add(newProxy);
|
||||
return newProxy;
|
||||
},
|
||||
})
|
||||
|
||||
class BytebeatProcessor extends AudioWorkletProcessor {
|
||||
audioSample = 0; // TODO: is this needed? might be better to use currentTime global
|
||||
lastFlooredTime = -1;
|
||||
|
@ -250,9 +262,7 @@ class BytebeatProcessor extends AudioWorkletProcessor {
|
|||
funcValue = NaN;
|
||||
}
|
||||
|
||||
if (Array.isArray(funcValue)) {
|
||||
// replace array for safety, arrays could have modified functions
|
||||
// TODO can the index operator be overridden? is this safe?
|
||||
if (Array.isArray(funcValue) && !proxies.has(funcValue)) {
|
||||
funcValue = [funcValue[0], funcValue[1]];
|
||||
} else {
|
||||
funcValue = [funcValue, funcValue];
|
||||
|
@ -261,7 +271,11 @@ class BytebeatProcessor extends AudioWorkletProcessor {
|
|||
let changedSample = false;
|
||||
for (const c in funcValue) {
|
||||
try {
|
||||
funcValue[c] = Number(funcValue[c]);
|
||||
if (proxies.has(funcValue[c])) {
|
||||
throw new TypeError("can't convert proxy to number");
|
||||
} else {
|
||||
funcValue[c] = +funcValue[c];
|
||||
}
|
||||
} catch (err) {
|
||||
funcValue[c] = NaN;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue