properly? handle getOwnPropertyDescriptor

This commit is contained in:
velzie 2024-08-25 20:17:45 -04:00
parent e8b9e04d46
commit 8d2ab5ac8b
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
6 changed files with 35 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import { createDocumentProxy } from "./document";
import { createGlobalProxy } from "./global";
import { getOwnPropertyDescriptorHandler } from "./helpers";
import { createLocationProxy } from "./location";
import { CookieStore, decodeUrl } from "./shared";
@ -191,6 +192,7 @@ export class ScramjetClient {
};
}
h.getOwnPropertyDescriptor = getOwnPropertyDescriptorHandler;
target[prop] = new Proxy(value, h);
}
Trap<T>(name: string | string[], descriptor: Trap<T>): PropertyDescriptor {

View file

@ -1,5 +1,6 @@
import { encodeUrl } from "../shared/rewriters/url";
import { ScramjetClient } from "./client";
import { getOwnPropertyDescriptorHandler } from "./helpers";
export function createDocumentProxy(
client: ScramjetClient,
@ -26,5 +27,6 @@ export function createDocumentProxy(
return Reflect.set(target, prop, newValue);
},
getOwnPropertyDescriptor: getOwnPropertyDescriptorHandler,
});
}

View file

@ -2,6 +2,7 @@ import { encodeUrl } from "./shared";
import { ScramjetClient } from "./client";
import { indirectEval } from "./shared/eval";
import { config } from "./shared";
import { getOwnPropertyDescriptorHandler } from "./helpers";
export function createGlobalProxy(
client: ScramjetClient,
@ -51,5 +52,6 @@ export function createGlobalProxy(
return Reflect.defineProperty(target, property, attributes);
},
getOwnPropertyDescriptor: getOwnPropertyDescriptorHandler,
});
}

26
src/client/helpers.ts Normal file
View file

@ -0,0 +1,26 @@
export function getOwnPropertyDescriptorHandler(target, prop) {
let realDescriptor = Reflect.getOwnPropertyDescriptor(target, prop);
if (!realDescriptor) return realDescriptor;
let d: PropertyDescriptor = {};
if (realDescriptor.enumerable !== undefined)
d.enumerable = realDescriptor.enumerable;
if (realDescriptor.configurable !== undefined)
d.configurable = realDescriptor.configurable;
if (realDescriptor.writable !== undefined)
d.writable = realDescriptor.writable;
if (realDescriptor.get) {
d.get = () => this.get(target, prop);
}
if (realDescriptor.set) {
d.set = (value) => this.set(target, prop, value);
}
if (realDescriptor.value) {
d.value = this.get(target, prop);
}
return d;
}

View file

@ -1,5 +1,6 @@
import { iswindow } from "..";
import { ScramjetClient } from "../client";
import { getOwnPropertyDescriptorHandler } from "../helpers";
import { unproxy } from "./unproxy";
const realOnEvent = Symbol.for("scramjet original onevent function");
@ -66,12 +67,14 @@ export default function (client: ScramjetClient, self: Self) {
return Reflect.get(target, prop, reciever);
},
getOwnPropertyDescriptor: getOwnPropertyDescriptorHandler,
});
}
}
return Reflect.apply(target, thisArg, argArray);
},
getOwnPropertyDescriptor: getOwnPropertyDescriptorHandler,
});
}

View file

@ -103,7 +103,6 @@ export const htmlRules: {
fn: (value: string, origin: URL) => {
if (["_parent", "_top", "_unfencedTop"].includes(value)) return "_self";
console.log(value, origin);
return encodeUrl(value, origin);
},