proxy Object.getOwnPropertyDescriptor

This commit is contained in:
velzie 2024-08-29 15:39:49 -04:00
parent ac5b03736a
commit 52a5e49150
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
7 changed files with 45 additions and 9 deletions

View file

@ -1,6 +1,7 @@
import { iswindow } from "..";
import { ScramjetClient } from "../client";
import { getOwnPropertyDescriptorHandler } from "../helpers";
import { nativeGetOwnPropertyDescriptor } from "../natives";
import { unproxy } from "./unproxy";
const realOnEvent = Symbol.for("scramjet original onevent function");
@ -138,7 +139,7 @@ export default function (client: ScramjetClient, self: Self) {
key.startsWith("on") &&
handlers[key.slice(2)]
) {
const descriptor = Object.getOwnPropertyDescriptor(target, key);
const descriptor = nativeGetOwnPropertyDescriptor(target, key);
if (!descriptor.get || !descriptor.set || !descriptor.configurable)
continue;

View file

@ -19,8 +19,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
return this;
},
writable: false,
configurable: false,
writable: true,
configurable: true,
enumerable: false,
});
}

View file

@ -41,6 +41,35 @@ export default function (client: ScramjetClient, self: typeof window) {
} catch (e) {}
}
}
client.Proxy("Object.getOwnPropertyDescriptor", {
apply(ctx) {
const desc = ctx.fn.apply(ctx.this, ctx.args);
if (!desc) return;
if (desc.get) {
client.RawProxy(desc, "get", {
apply(ctx) {
// value of this in the getter needs to be corrected
unproxy(ctx, client);
},
});
}
if (desc.set) {
client.RawProxy(desc, "set", {
apply(ctx) {
unproxy(ctx, client);
},
});
}
// i don't think we have to care about value but it's worth looking into
ctx.return(desc);
},
});
}
export function unproxy(ctx: ProxyCtx, client: ScramjetClient) {