From a1542bcec5c5f92fe3432c6f517a31c5695e3a1c Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Mon, 27 May 2024 23:21:51 -0300 Subject: [PATCH 1/3] okay codium agent --- scripts/generateReport.ts | 12 ++++++++---- src/webpack/webpack.ts | 8 +++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/generateReport.ts b/scripts/generateReport.ts index 89632addf..cd3767404 100644 --- a/scripts/generateReport.ts +++ b/scripts/generateReport.ts @@ -42,8 +42,8 @@ const page = await browser.newPage(); await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"); async function maybeGetError(handle: JSHandle) { - return (handle as JSHandle)?.getProperty("message") - .then(m => m.jsonValue()); + return (handle as JSHandle).getProperty("message") + .then(m => m?.jsonValue() ?? "Unknown Error"); } const report = { @@ -356,7 +356,9 @@ async function runtime(token: string) { // setImmediate to avoid blocking the factory patching execution while checking for lazy chunks setTimeout(() => { let isResolved = false; - searchAndLoadLazyChunks(String(factory)).then(() => isResolved = true); + searchAndLoadLazyChunks(String(factory)) + .then(() => isResolved = true) + .catch(() => isResolved = true); chunksSearchPromises.push(() => isResolved); }, 0); @@ -364,7 +366,9 @@ async function runtime(token: string) { for (const factoryId in wreq.m) { let isResolved = false; - searchAndLoadLazyChunks(String(wreq.m[factoryId])).then(() => isResolved = true); + searchAndLoadLazyChunks(String(wreq.m[factoryId])) + .then(() => isResolved = true) + .catch(() => isResolved = true); chunksSearchPromises.push(() => isResolved); } diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index a46a7de45..d9301508d 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -76,6 +76,8 @@ export const factoryListeners = new Set<(factory: ModuleFactory) => void>(); export function _initWebpack(webpackRequire: WebpackRequire) { wreq = webpackRequire; + + if (webpackRequire.c == null) return; cache = webpackRequire.c; Reflect.defineProperty(webpackRequire.c, Symbol.toStringTag, { @@ -507,10 +509,10 @@ export function search(...filters: Array) { outer: for (const id in factories) { const factory = factories[id]; - const str = String(factory); + const factoryStr = String(factory); for (const filter of filters) { - if (typeof filter === "string" && !str.includes(filter)) continue outer; - if (filter instanceof RegExp && !filter.test(str)) continue outer; + if (typeof filter === "string" && !factoryStr.includes(factoryStr)) continue outer; + if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer; } results[id] = factory; } From e96458fafa4d1a3587b7299932b91b8ad6a48608 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Mon, 27 May 2024 23:31:08 -0300 Subject: [PATCH 2/3] fixes for if we use prototype proxy in the future --- src/webpack/patchWebpack.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 570e41097..968a2ea0c 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -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 Reflect.setPrototypeOf(moduleFactories, new Proxy(moduleFactories, moduleFactoriesHandler)); */ - } Reflect.defineProperty(this, "m", { @@ -146,13 +145,23 @@ const moduleFactoriesHandler: ProxyHandler = { get: (target, p, receiver) => { 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 set: (target, p, newValue, receiver) => { // If the property is not a number, we are not dealing with a module factory 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); From 539b70cd52016276c599e9c03c26817b9b921fb6 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Mon, 27 May 2024 23:32:40 -0300 Subject: [PATCH 3/3] lmao oops --- src/webpack/webpack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index d9301508d..bde269776 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -511,7 +511,7 @@ export function search(...filters: Array) { const factory = factories[id]; const factoryStr = String(factory); for (const filter of filters) { - if (typeof filter === "string" && !factoryStr.includes(factoryStr)) continue outer; + if (typeof filter === "string" && !factoryStr.includes(filter)) continue outer; if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer; } results[id] = factory;