feat: improve natives store and proxy element.hasattribute

This commit is contained in:
Percs 2024-12-09 10:56:45 -06:00
parent f43637fed7
commit f022024291
3 changed files with 59 additions and 10 deletions

View file

@ -66,7 +66,7 @@ export class ScramjetClient {
bare: BareClientType;
descriptors: Record<string, PropertyDescriptor> = {};
natives: Record<string, any> = {};
natives: Record<string, any>;
wrapfn: (i: any, ...args: any) => any;
cookieStore = new CookieStore();
@ -120,7 +120,51 @@ export class ScramjetClient {
})
);
}
this.natives = new Proxy(
{},
{
get: (target, prop: string) => {
if (prop in target) {
return target[prop];
} else {
const split = prop.split(".");
const realProp = split.pop();
const realTarget = split.reduce((a, b) => a?.[b], this.global);
if (!realTarget) return;
const original = Reflect.get(realTarget, realProp);
target[prop] = original;
return target[prop];
}
},
}
);
this.descriptors = new Proxy(
{},
{
get: (target, prop: string) => {
if (prop in target) {
return target[prop];
} else {
const split = prop.split(".");
const realProp = split.pop();
const realTarget = split.reduce((a, b) => a?.[b], this.global);
if (!realTarget) return;
const original = nativeGetOwnPropertyDescriptor(
realTarget,
realProp
);
target[prop] = original;
return target[prop];
}
},
}
);
// eslint-disable-next-line @typescript-eslint/no-this-alias
const client = this;
this.meta = {