mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
properly? handle getOwnPropertyDescriptor
This commit is contained in:
parent
e8b9e04d46
commit
8d2ab5ac8b
6 changed files with 35 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
26
src/client/helpers.ts
Normal 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;
|
||||
}
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue