fixes for if we use prototype proxy in the future

This commit is contained in:
Nuckyz 2024-05-27 23:31:08 -03:00
parent a1542bcec5
commit e96458fafa
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -88,7 +88,6 @@ Reflect.defineProperty(Function.prototype, "m", {
If Discord ever decides to set module factories using the variable of the modules object directly, instead of wreq.m, switch the proxy to the prototype If Discord ever decides to set module factories using the variable of the modules object directly, instead of wreq.m, switch the proxy to the prototype
Reflect.setPrototypeOf(moduleFactories, new Proxy(moduleFactories, moduleFactoriesHandler)); Reflect.setPrototypeOf(moduleFactories, new Proxy(moduleFactories, moduleFactoriesHandler));
*/ */
} }
Reflect.defineProperty(this, "m", { Reflect.defineProperty(this, "m", {
@ -146,13 +145,23 @@ const moduleFactoriesHandler: ProxyHandler<PatchedModuleFactories> = {
get: (target, p, receiver) => { get: (target, p, receiver) => {
return undefined; return undefined;
}, },
// Same thing as get
has: (target, p) => {
return false;
}
*/ */
// The set trap for patching or defining getters for the module factories when new module factories are loaded // The set trap for patching or defining getters for the module factories when new module factories are loaded
set: (target, p, newValue, receiver) => { set: (target, p, newValue, receiver) => {
// If the property is not a number, we are not dealing with a module factory // If the property is not a number, we are not dealing with a module factory
if (Number.isNaN(Number(p))) { if (Number.isNaN(Number(p))) {
return Reflect.set(target, p, newValue, receiver); Reflect.defineProperty(target, p, {
value: newValue,
configurable: true,
enumerable: true,
writable: true
});
return true;
} }
const existingFactory = Reflect.get(target, p, receiver); const existingFactory = Reflect.get(target, p, receiver);