location proxy still buggy

This commit is contained in:
velzie 2024-08-31 18:47:20 -04:00
parent 077302aada
commit 8217897d1e
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -14,6 +14,8 @@ export function createLocationProxy(
Object.setPrototypeOf(fakeLocation, Location.prototype); Object.setPrototypeOf(fakeLocation, Location.prototype);
fakeLocation.constructor = Location; fakeLocation.constructor = Location;
// for some reason it's on the object for Location and on the prototype for WorkerLocation??
const descriptorSource = iswindow ? self.location : Location.prototype;
const urlprops = [ const urlprops = [
"protocol", "protocol",
"hash", "hash",
@ -26,7 +28,7 @@ export function createLocationProxy(
"search", "search",
]; ];
for (const prop of urlprops) { for (const prop of urlprops) {
const native = nativeGetOwnPropertyDescriptor(self.location, prop); const native = nativeGetOwnPropertyDescriptor(descriptorSource, prop);
if (!native) continue; if (!native) continue;
const desc = { const desc = {
@ -75,20 +77,20 @@ export function createLocationProxy(
fakeLocation.assign = new Proxy(self.location.assign, { fakeLocation.assign = new Proxy(self.location.assign, {
apply(target, thisArg, args) { apply(target, thisArg, args) {
args[0] = encodeUrl(args[0]); args[0] = encodeUrl(args[0]);
Reflect.apply(target, thisArg, args); Reflect.apply(target, self.location, args);
}, },
}); });
if (self.location.reload) if (self.location.reload)
fakeLocation.reload = new Proxy(self.location.reload, { fakeLocation.reload = new Proxy(self.location.reload, {
apply(target, thisArg, args) { apply(target, thisArg, args) {
Reflect.apply(target, thisArg, args); Reflect.apply(target, self.location, args);
}, },
}); });
if (self.location.replace) if (self.location.replace)
fakeLocation.replace = new Proxy(self.location.replace, { fakeLocation.replace = new Proxy(self.location.replace, {
apply(target, thisArg, args) { apply(target, thisArg, args) {
args[0] = encodeUrl(args[0]); args[0] = encodeUrl(args[0]);
Reflect.apply(target, thisArg, args); Reflect.apply(target, self.location, args);
}, },
}); });