mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
chore: more code cleanup
This commit is contained in:
parent
f022024291
commit
a5a99ea188
3 changed files with 38 additions and 27 deletions
|
@ -125,19 +125,19 @@ export class ScramjetClient {
|
||||||
{
|
{
|
||||||
get: (target, prop: string) => {
|
get: (target, prop: string) => {
|
||||||
if (prop in target) {
|
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];
|
return target[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -146,22 +146,19 @@ export class ScramjetClient {
|
||||||
{
|
{
|
||||||
get: (target, prop: string) => {
|
get: (target, prop: string) => {
|
||||||
if (prop in target) {
|
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];
|
return target[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -65,10 +65,18 @@ export default function (client: ScramjetClient, _self: typeof window) {
|
||||||
|
|
||||||
client.Trap("Attr.prototype.value", {
|
client.Trap("Attr.prototype.value", {
|
||||||
get(ctx) {
|
get(ctx) {
|
||||||
return ctx.this.ownerElement?.getAttribute(ctx.this.name);
|
if (ctx.this?.ownerElement) {
|
||||||
|
return ctx.this.ownerElement.getAttribute(ctx.this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.get();
|
||||||
},
|
},
|
||||||
set(ctx, value) {
|
set(ctx, value) {
|
||||||
return ctx.this.ownerElement?.setAttribute(ctx.this.name, value);
|
if (ctx.this?.ownerElement) {
|
||||||
|
return ctx.this.ownerElement.setAttribute(ctx.this.name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.set(value);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,12 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.Proxy("Element.prototype.getAttributeNode", {
|
||||||
|
apply(ctx) {
|
||||||
|
if (ctx.args[0].startsWith("scramjet-attr")) return ctx.return(null);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
client.Proxy("Element.prototype.hasAttribute", {
|
client.Proxy("Element.prototype.hasAttribute", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[0].startsWith("scramjet-attr")) return ctx.return(false);
|
if (ctx.args[0].startsWith("scramjet-attr")) return ctx.return(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue