Merge branch 'modules-proxy-patches' into immediate-finds-modules-proxy
This commit is contained in:
commit
fa45beb8ca
|
@ -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");
|
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) {
|
async function maybeGetError(handle: JSHandle) {
|
||||||
return (handle as JSHandle<Error>)?.getProperty("message")
|
return (handle as JSHandle<Error>).getProperty("message")
|
||||||
.then(m => m.jsonValue());
|
.then(m => m?.jsonValue() ?? "Unknown Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
const report = {
|
const report = {
|
||||||
|
@ -354,7 +354,9 @@ async function runtime(token: string) {
|
||||||
// setImmediate to avoid blocking the factory patching execution while checking for lazy chunks
|
// setImmediate to avoid blocking the factory patching execution while checking for lazy chunks
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let isResolved = false;
|
let isResolved = false;
|
||||||
searchAndLoadLazyChunks(String(factory)).then(() => isResolved = true);
|
searchAndLoadLazyChunks(String(factory))
|
||||||
|
.then(() => isResolved = true)
|
||||||
|
.catch(() => isResolved = true);
|
||||||
|
|
||||||
chunksSearchPromises.push(() => isResolved);
|
chunksSearchPromises.push(() => isResolved);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -362,7 +364,9 @@ async function runtime(token: string) {
|
||||||
|
|
||||||
for (const factoryId in wreq.m) {
|
for (const factoryId in wreq.m) {
|
||||||
let isResolved = false;
|
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);
|
chunksSearchPromises.push(() => isResolved);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -94,6 +94,8 @@ export const factoryListeners = new Set<(factory: ModuleFactory) => void>();
|
||||||
|
|
||||||
export function _initWebpack(webpackRequire: WebpackRequire) {
|
export function _initWebpack(webpackRequire: WebpackRequire) {
|
||||||
wreq = webpackRequire;
|
wreq = webpackRequire;
|
||||||
|
|
||||||
|
if (webpackRequire.c == null) return;
|
||||||
cache = webpackRequire.c;
|
cache = webpackRequire.c;
|
||||||
|
|
||||||
Reflect.defineProperty(webpackRequire.c, Symbol.toStringTag, {
|
Reflect.defineProperty(webpackRequire.c, Symbol.toStringTag, {
|
||||||
|
@ -740,10 +742,10 @@ export function search(...filters: Array<string | RegExp>) {
|
||||||
outer:
|
outer:
|
||||||
for (const id in factories) {
|
for (const id in factories) {
|
||||||
const factory = factories[id];
|
const factory = factories[id];
|
||||||
const str = String(factory);
|
const factoryStr = String(factory);
|
||||||
for (const filter of filters) {
|
for (const filter of filters) {
|
||||||
if (typeof filter === "string" && !str.includes(filter)) continue outer;
|
if (typeof filter === "string" && !factoryStr.includes(filter)) continue outer;
|
||||||
if (filter instanceof RegExp && !filter.test(str)) continue outer;
|
if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer;
|
||||||
}
|
}
|
||||||
results[id] = factory;
|
results[id] = factory;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue