chore: more code cleanup

This commit is contained in:
Percs 2024-12-09 13:21:17 -06:00
parent f022024291
commit a5a99ea188
3 changed files with 38 additions and 27 deletions

View file

@ -126,7 +126,8 @@ export class ScramjetClient {
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);
@ -137,7 +138,6 @@ export class ScramjetClient {
target[prop] = original;
return target[prop];
}
},
}
);
@ -147,21 +147,18 @@ export class ScramjetClient {
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
);
const original = nativeGetOwnPropertyDescriptor(realTarget, realProp);
target[prop] = original;
return target[prop];
}
},
}
);

View file

@ -65,10 +65,18 @@ export default function (client: ScramjetClient, _self: typeof window) {
client.Trap("Attr.prototype.value", {
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) {
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);
},
});
}

View file

@ -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", {
apply(ctx) {
if (ctx.args[0].startsWith("scramjet-attr")) return ctx.return(false);