mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
fix ggf
This commit is contained in:
parent
08ccb4f56e
commit
7adf76d37f
2 changed files with 48 additions and 37 deletions
|
@ -2,15 +2,17 @@
|
|||
import { ScramjetClient } from "./client";
|
||||
import { nativeGetOwnPropertyDescriptor } from "./natives";
|
||||
import { encodeUrl, decodeUrl } from "../shared";
|
||||
import { iswindow } from ".";
|
||||
|
||||
export function createLocationProxy(
|
||||
client: ScramjetClient,
|
||||
self: typeof globalThis
|
||||
) {
|
||||
const Location = iswindow ? self.Location : self.WorkerLocation;
|
||||
// location cannot be Proxy()d
|
||||
const fakeLocation = {};
|
||||
Object.setPrototypeOf(fakeLocation, self.Location.prototype);
|
||||
fakeLocation.constructor = self.Location;
|
||||
Object.setPrototypeOf(fakeLocation, Location.prototype);
|
||||
fakeLocation.constructor = Location;
|
||||
|
||||
const urlprops = [
|
||||
"protocol",
|
||||
|
@ -25,15 +27,19 @@ export function createLocationProxy(
|
|||
];
|
||||
for (const prop of urlprops) {
|
||||
const native = nativeGetOwnPropertyDescriptor(self.location, prop);
|
||||
if (!native) continue;
|
||||
|
||||
const desc = {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: new Proxy(native.get, {
|
||||
};
|
||||
if (native.get) {
|
||||
desc.get = new Proxy(native.get, {
|
||||
apply() {
|
||||
return client.url[prop];
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
}
|
||||
if (native.set) {
|
||||
desc.set = new Proxy(native.set, {
|
||||
apply(target, thisArg, args) {
|
||||
|
@ -52,28 +58,33 @@ export function createLocationProxy(
|
|||
return client.url.href;
|
||||
},
|
||||
});
|
||||
fakeLocation.valueOf = new Proxy(self.location.valueOf, {
|
||||
apply() {
|
||||
return client.url.href;
|
||||
},
|
||||
});
|
||||
fakeLocation.assign = new Proxy(self.location.assign, {
|
||||
apply(target, thisArg, args) {
|
||||
args[0] = encodeUrl(args[0]);
|
||||
Reflect.apply(target, thisArg, args);
|
||||
},
|
||||
});
|
||||
fakeLocation.reload = new Proxy(self.location.reload, {
|
||||
apply(target, thisArg, args) {
|
||||
Reflect.apply(target, thisArg, args);
|
||||
},
|
||||
});
|
||||
fakeLocation.replace = new Proxy(self.location.replace, {
|
||||
apply(target, thisArg, args) {
|
||||
args[0] = encodeUrl(args[0]);
|
||||
Reflect.apply(target, thisArg, args);
|
||||
},
|
||||
});
|
||||
|
||||
if (self.location.valueOf)
|
||||
fakeLocation.valueOf = new Proxy(self.location.valueOf, {
|
||||
apply() {
|
||||
return client.url.href;
|
||||
},
|
||||
});
|
||||
if (self.location.assign)
|
||||
fakeLocation.assign = new Proxy(self.location.assign, {
|
||||
apply(target, thisArg, args) {
|
||||
args[0] = encodeUrl(args[0]);
|
||||
Reflect.apply(target, thisArg, args);
|
||||
},
|
||||
});
|
||||
if (self.location.reload)
|
||||
fakeLocation.reload = new Proxy(self.location.reload, {
|
||||
apply(target, thisArg, args) {
|
||||
Reflect.apply(target, thisArg, args);
|
||||
},
|
||||
});
|
||||
if (self.location.replace)
|
||||
fakeLocation.replace = new Proxy(self.location.replace, {
|
||||
apply(target, thisArg, args) {
|
||||
args[0] = encodeUrl(args[0]);
|
||||
Reflect.apply(target, thisArg, args);
|
||||
},
|
||||
});
|
||||
|
||||
return fakeLocation;
|
||||
}
|
||||
|
|
|
@ -103,14 +103,14 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
return t;
|
||||
};
|
||||
|
||||
client.Proxy("Promise.prototype.catch", {
|
||||
apply(ctx) {
|
||||
ctx.args[0] = new Proxy(ctx.args[0], {
|
||||
apply(target, thisArg, argArray) {
|
||||
// console.warn("CAUGHT PROMISE REJECTION", argArray);
|
||||
Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
// client.Proxy("Promise.prototype.catch", {
|
||||
// apply(ctx) {
|
||||
// ctx.args[0] = new Proxy(ctx.args[0], {
|
||||
// apply(target, thisArg, argArray) {
|
||||
// // console.warn("CAUGHT PROMISE REJECTION", argArray);
|
||||
// Reflect.apply(target, thisArg, argArray);
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue