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 { ScramjetClient } from "./client";
|
||||||
import { nativeGetOwnPropertyDescriptor } from "./natives";
|
import { nativeGetOwnPropertyDescriptor } from "./natives";
|
||||||
import { encodeUrl, decodeUrl } from "../shared";
|
import { encodeUrl, decodeUrl } from "../shared";
|
||||||
|
import { iswindow } from ".";
|
||||||
|
|
||||||
export function createLocationProxy(
|
export function createLocationProxy(
|
||||||
client: ScramjetClient,
|
client: ScramjetClient,
|
||||||
self: typeof globalThis
|
self: typeof globalThis
|
||||||
) {
|
) {
|
||||||
|
const Location = iswindow ? self.Location : self.WorkerLocation;
|
||||||
// location cannot be Proxy()d
|
// location cannot be Proxy()d
|
||||||
const fakeLocation = {};
|
const fakeLocation = {};
|
||||||
Object.setPrototypeOf(fakeLocation, self.Location.prototype);
|
Object.setPrototypeOf(fakeLocation, Location.prototype);
|
||||||
fakeLocation.constructor = self.Location;
|
fakeLocation.constructor = Location;
|
||||||
|
|
||||||
const urlprops = [
|
const urlprops = [
|
||||||
"protocol",
|
"protocol",
|
||||||
|
@ -25,15 +27,19 @@ export function createLocationProxy(
|
||||||
];
|
];
|
||||||
for (const prop of urlprops) {
|
for (const prop of urlprops) {
|
||||||
const native = nativeGetOwnPropertyDescriptor(self.location, prop);
|
const native = nativeGetOwnPropertyDescriptor(self.location, prop);
|
||||||
|
if (!native) continue;
|
||||||
|
|
||||||
const desc = {
|
const desc = {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: new Proxy(native.get, {
|
};
|
||||||
|
if (native.get) {
|
||||||
|
desc.get = new Proxy(native.get, {
|
||||||
apply() {
|
apply() {
|
||||||
return client.url[prop];
|
return client.url[prop];
|
||||||
},
|
},
|
||||||
}),
|
});
|
||||||
};
|
}
|
||||||
if (native.set) {
|
if (native.set) {
|
||||||
desc.set = new Proxy(native.set, {
|
desc.set = new Proxy(native.set, {
|
||||||
apply(target, thisArg, args) {
|
apply(target, thisArg, args) {
|
||||||
|
@ -52,28 +58,33 @@ export function createLocationProxy(
|
||||||
return client.url.href;
|
return client.url.href;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
fakeLocation.valueOf = new Proxy(self.location.valueOf, {
|
|
||||||
apply() {
|
if (self.location.valueOf)
|
||||||
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]);
|
if (self.location.assign)
|
||||||
Reflect.apply(target, thisArg, args);
|
fakeLocation.assign = new Proxy(self.location.assign, {
|
||||||
},
|
apply(target, thisArg, args) {
|
||||||
});
|
args[0] = encodeUrl(args[0]);
|
||||||
fakeLocation.reload = new Proxy(self.location.reload, {
|
Reflect.apply(target, thisArg, args);
|
||||||
apply(target, thisArg, args) {
|
},
|
||||||
Reflect.apply(target, thisArg, args);
|
});
|
||||||
},
|
if (self.location.reload)
|
||||||
});
|
fakeLocation.reload = new Proxy(self.location.reload, {
|
||||||
fakeLocation.replace = new Proxy(self.location.replace, {
|
apply(target, thisArg, args) {
|
||||||
apply(target, thisArg, args) {
|
Reflect.apply(target, thisArg, args);
|
||||||
args[0] = encodeUrl(args[0]);
|
},
|
||||||
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;
|
return fakeLocation;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,14 +103,14 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
|
|
||||||
client.Proxy("Promise.prototype.catch", {
|
// client.Proxy("Promise.prototype.catch", {
|
||||||
apply(ctx) {
|
// apply(ctx) {
|
||||||
ctx.args[0] = new Proxy(ctx.args[0], {
|
// ctx.args[0] = new Proxy(ctx.args[0], {
|
||||||
apply(target, thisArg, argArray) {
|
// apply(target, thisArg, argArray) {
|
||||||
// console.warn("CAUGHT PROMISE REJECTION", argArray);
|
// // console.warn("CAUGHT PROMISE REJECTION", argArray);
|
||||||
Reflect.apply(target, thisArg, argArray);
|
// Reflect.apply(target, thisArg, argArray);
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue