event target

This commit is contained in:
velzie 2024-08-31 11:29:09 -04:00
parent 5f7a9d4bd4
commit 08ccb4f56e
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
6 changed files with 48 additions and 5 deletions

View file

@ -8,6 +8,7 @@ import { createLocationProxy } from "./location";
import { nativeGetOwnPropertyDescriptor } from "./natives";
import { CookieStore, config, decodeUrl, encodeUrl } from "../shared";
import { createWrapFn } from "./shared/wrap";
import { NavigateEvent } from "./events";
declare global {
interface Window {
@ -26,6 +27,7 @@ export type ProxyCtx = {
args: any[];
newTarget: AnyFunction;
return: (r: any) => void;
call: () => any;
};
export type Proxy = {
construct?(ctx: ProxyCtx): any;
@ -140,9 +142,15 @@ export class ScramjetClient {
}
set url(url: URL | string) {
if (typeof url === "string") url = new URL(url);
if (url instanceof URL) url = url.toString();
self.location.href = encodeUrl(url.href);
const ev = new NavigateEvent(url);
if (this.frame) {
this.frame.dispatchEvent(ev);
}
if (ev.defaultPrevented) return;
self.location.href = encodeUrl(ev.url);
}
// below are the utilities for proxying and trapping dom APIs
@ -192,6 +200,7 @@ export class ScramjetClient {
return: (r: any) => {
returnValue = r;
},
call: () => alert("todo"),
};
handler.construct(ctx);
@ -218,6 +227,10 @@ export class ScramjetClient {
earlyreturn = true;
returnValue = r;
},
call: () => {
earlyreturn = true;
returnValue = Reflect.apply(ctx.fn, ctx.this, ctx.args);
},
};
const pst = Error.prepareStackTrace;