mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
proxy Object.getOwnPropertyDescriptor
This commit is contained in:
parent
ac5b03736a
commit
52a5e49150
7 changed files with 45 additions and 9 deletions
|
@ -2,6 +2,7 @@ import { createDocumentProxy } from "./document";
|
||||||
import { createGlobalProxy } from "./global";
|
import { createGlobalProxy } from "./global";
|
||||||
import { getOwnPropertyDescriptorHandler } from "./helpers";
|
import { getOwnPropertyDescriptorHandler } from "./helpers";
|
||||||
import { createLocationProxy } from "./location";
|
import { createLocationProxy } from "./location";
|
||||||
|
import { nativeGetOwnPropertyDescriptor } from "./natives";
|
||||||
import { CookieStore, config, decodeUrl } from "./shared";
|
import { CookieStore, config, decodeUrl } from "./shared";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -236,7 +237,7 @@ export class ScramjetClient {
|
||||||
const prop = split.pop();
|
const prop = split.pop();
|
||||||
const target = split.reduce((a, b) => a?.[b], this.global);
|
const target = split.reduce((a, b) => a?.[b], this.global);
|
||||||
|
|
||||||
const original = Object.getOwnPropertyDescriptor(target, prop);
|
const original = nativeGetOwnPropertyDescriptor(target, prop);
|
||||||
this.descriptors[name] = original;
|
this.descriptors[name] = original;
|
||||||
|
|
||||||
return this.RawTrap(target, prop, descriptor);
|
return this.RawTrap(target, prop, descriptor);
|
||||||
|
@ -250,7 +251,7 @@ export class ScramjetClient {
|
||||||
if (!prop) return;
|
if (!prop) return;
|
||||||
if (!Reflect.has(target, prop)) return;
|
if (!Reflect.has(target, prop)) return;
|
||||||
|
|
||||||
const oldDescriptor = Object.getOwnPropertyDescriptor(target, prop);
|
const oldDescriptor = nativeGetOwnPropertyDescriptor(target, prop);
|
||||||
|
|
||||||
const ctx: TrapCtx<T> = {
|
const ctx: TrapCtx<T> = {
|
||||||
this: null,
|
this: null,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { ScramjetClient } from "../client";
|
import { ScramjetClient } from "../client";
|
||||||
|
import { nativeGetOwnPropertyDescriptor } from "../natives";
|
||||||
import { config, decodeUrl, htmlRules, unrewriteHtml } from "../shared";
|
import { config, decodeUrl, htmlRules, unrewriteHtml } from "../shared";
|
||||||
import {
|
import {
|
||||||
encodeUrl,
|
encodeUrl,
|
||||||
|
@ -33,7 +34,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
|
|
||||||
for (const attr of attrs) {
|
for (const attr of attrs) {
|
||||||
for (const element of attrObject[attr]) {
|
for (const element of attrObject[attr]) {
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(
|
const descriptor = nativeGetOwnPropertyDescriptor(
|
||||||
element.prototype,
|
element.prototype,
|
||||||
attr
|
attr
|
||||||
);
|
);
|
||||||
|
@ -167,6 +168,7 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
|
|
||||||
client.Trap("Node.prototype.ownerDocument", {
|
client.Trap("Node.prototype.ownerDocument", {
|
||||||
get(ctx) {
|
get(ctx) {
|
||||||
|
return client.documentProxy;
|
||||||
let doc = ctx.get() as Document | null;
|
let doc = ctx.get() as Document | null;
|
||||||
if (!doc) return null;
|
if (!doc) return null;
|
||||||
|
|
||||||
|
|
3
src/client/natives.ts
Normal file
3
src/client/natives.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const nativeFunction = self.Function;
|
||||||
|
export const nativeGetOwnPropertyDescriptor =
|
||||||
|
self.Object.getOwnPropertyDescriptor;
|
|
@ -1,6 +1,7 @@
|
||||||
import { iswindow } from "..";
|
import { iswindow } from "..";
|
||||||
import { ScramjetClient } from "../client";
|
import { ScramjetClient } from "../client";
|
||||||
import { getOwnPropertyDescriptorHandler } from "../helpers";
|
import { getOwnPropertyDescriptorHandler } from "../helpers";
|
||||||
|
import { nativeGetOwnPropertyDescriptor } from "../natives";
|
||||||
import { unproxy } from "./unproxy";
|
import { unproxy } from "./unproxy";
|
||||||
|
|
||||||
const realOnEvent = Symbol.for("scramjet original onevent function");
|
const realOnEvent = Symbol.for("scramjet original onevent function");
|
||||||
|
@ -138,7 +139,7 @@ export default function (client: ScramjetClient, self: Self) {
|
||||||
key.startsWith("on") &&
|
key.startsWith("on") &&
|
||||||
handlers[key.slice(2)]
|
handlers[key.slice(2)]
|
||||||
) {
|
) {
|
||||||
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
const descriptor = nativeGetOwnPropertyDescriptor(target, key);
|
||||||
if (!descriptor.get || !descriptor.set || !descriptor.configurable)
|
if (!descriptor.get || !descriptor.set || !descriptor.configurable)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
writable: false,
|
writable: true,
|
||||||
configurable: false,
|
configurable: true,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,35 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
} catch (e) {}
|
} 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) {
|
export function unproxy(ctx: ProxyCtx, client: ScramjetClient) {
|
||||||
|
|
|
@ -95,9 +95,9 @@ export async function swfetch(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this is wrong somehow
|
// TODO this is wrong somehow
|
||||||
// headers.set("Sec-Fetch-Mode", "cors");
|
headers.set("Sec-Fetch-Mode", "cors");
|
||||||
// headers.set("Sec-Fetch-Site", "same-origin");
|
headers.set("Sec-Fetch-Site", "same-origin");
|
||||||
// headers.set("Sec-Fetch-Dest", "empty");
|
headers.set("Sec-Fetch-Dest", "empty");
|
||||||
|
|
||||||
const response: BareResponseFetch = await this.client.fetch(url, {
|
const response: BareResponseFetch = await this.client.fetch(url, {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue