mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 07:30:02 -04:00
proxy Object.getOwnPropertyDescriptor
This commit is contained in:
parent
ac5b03736a
commit
52a5e49150
7 changed files with 45 additions and 9 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
|
||||
return this;
|
||||
},
|
||||
writable: false,
|
||||
configurable: false,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue