|
import { iswindow } from "..";
|
|
import { SCRAMJETCLIENT } from "../../symbols";
|
|
import { ScramjetClient } from "../client";
|
|
import { config } from "../../shared";
|
|
|
|
import { indirectEval } from "./eval";
|
|
|
|
export function createWrapFn(client: ScramjetClient, self: typeof globalThis) {
|
|
return function (identifier: any, strict: boolean) {
|
|
if (identifier === self) return client.globalProxy;
|
|
if (identifier === self.location) return client.locationProxy;
|
|
if (identifier === eval) return indirectEval.bind(client, strict);
|
|
|
|
if (iswindow) {
|
|
if (identifier === self.parent) {
|
|
if (SCRAMJETCLIENT in self.parent) {
|
|
|
|
return self.parent[SCRAMJETCLIENT].globalProxy;
|
|
} else {
|
|
|
|
return client.globalProxy;
|
|
}
|
|
} else if (identifier === self.document) {
|
|
return client.documentProxy;
|
|
} else if (identifier === self.top) {
|
|
|
|
let current = self;
|
|
|
|
for (;;) {
|
|
const test = current.parent.self;
|
|
if (test === current) break;
|
|
|
|
|
|
if (!(SCRAMJETCLIENT in test)) break;
|
|
|
|
|
|
current = test;
|
|
}
|
|
|
|
return current[SCRAMJETCLIENT].globalProxy;
|
|
}
|
|
}
|
|
|
|
return identifier;
|
|
};
|
|
}
|
|
|
|
export const order = 4;
|
|
export default function (client: ScramjetClient, self: typeof globalThis) {
|
|
|
|
|
|
|
|
Object.defineProperty(self, config.globals.wrapfn, {
|
|
value: client.wrapfn,
|
|
writable: false,
|
|
configurable: false,
|
|
});
|
|
Object.defineProperty(self, config.globals.wrapthisfn, {
|
|
value: function (i) {
|
|
if (i === self) return client.globalProxy;
|
|
|
|
return i;
|
|
},
|
|
writable: false,
|
|
configurable: false,
|
|
});
|
|
|
|
self.$scramitize = function (v) {
|
|
if (v === self) debugger;
|
|
if (v === location) debugger;
|
|
if (iswindow) {
|
|
if (v === self.parent) debugger;
|
|
if (v === self.document) debugger;
|
|
if (v === self.top) debugger;
|
|
}
|
|
|
|
if (typeof v === "string" && v.includes("scramjet")) debugger;
|
|
if (typeof v === "string" && v.includes(location.origin)) debugger;
|
|
|
|
return v;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(self, config.globals.trysetfn, {
|
|
value: function (lhs: any, op: string, rhs: any) {
|
|
if (lhs instanceof Location) {
|
|
|
|
locationProxy.href = rhs;
|
|
|
|
return true;
|
|
}
|
|
},
|
|
writable: false,
|
|
configurable: false,
|
|
});
|
|
}
|
|
|