Skip to content

Commit 144d048

Browse files
committed
[core] NUKE GLOBALPROXY
1 parent 787265b commit 144d048

File tree

8 files changed

+11
-381
lines changed

8 files changed

+11
-381
lines changed

src/client/document.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/client/dom/element.ts

Lines changed: 7 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,13 @@ export default function (client: ScramjetClient, self: typeof window) {
410410
const realwin = ctx.get() as Window;
411411
if (!realwin) return realwin;
412412

413-
if (SCRAMJETCLIENT in realwin) {
414-
return realwin[SCRAMJETCLIENT].globalProxy;
415-
} else {
416-
// hook the iframe
413+
if (!(SCRAMJETCLIENT in realwin)) {
414+
// hook the iframe before the client can start to steal globals out of it
417415
const newclient = new ScramjetClient(realwin);
418416
newclient.hook();
419-
420-
return newclient.globalProxy;
421417
}
418+
419+
return realwin;
422420
},
423421
}
424422
);
@@ -438,14 +436,12 @@ export default function (client: ScramjetClient, self: typeof window) {
438436
);
439437
if (!realwin) return realwin;
440438

441-
if (SCRAMJETCLIENT in realwin) {
442-
return realwin[SCRAMJETCLIENT].documentProxy;
443-
} else {
439+
if (!(SCRAMJETCLIENT in realwin)) {
444440
const newclient = new ScramjetClient(realwin);
445441
newclient.hook();
446-
447-
return newclient.documentProxy;
448442
}
443+
444+
return realwin.document;
449445
},
450446
}
451447
);
@@ -467,76 +463,6 @@ export default function (client: ScramjetClient, self: typeof window) {
467463
}
468464
);
469465

470-
client.Trap("TreeWalker.prototype.currentNode", {
471-
get(ctx) {
472-
return ctx.get();
473-
},
474-
set(ctx, value) {
475-
if (value === client.documentProxy) {
476-
return ctx.set(self.document);
477-
}
478-
479-
return ctx.set(value);
480-
},
481-
});
482-
483-
client.Proxy("Document.prototype.open", {
484-
apply(ctx) {
485-
const doc = ctx.call() as Document;
486-
487-
const scram: ScramjetClient = doc[SCRAMJETCLIENT];
488-
if (!scram) return ctx.return(doc); // ??
489-
490-
return ctx.return(scram.documentProxy);
491-
},
492-
});
493-
494-
client.Trap("Node.prototype.ownerDocument", {
495-
get(ctx) {
496-
const doc = ctx.get() as Document | null;
497-
if (!doc) return null;
498-
499-
const scram: ScramjetClient = doc[SCRAMJETCLIENT];
500-
if (!scram) return doc; // ??
501-
502-
return scram.documentProxy;
503-
},
504-
});
505-
506-
client.Trap(
507-
[
508-
"Node.prototype.parentNode",
509-
"Node.prototype.parentElement",
510-
"Node.prototype.previousSibling",
511-
"Node.prototype.nextSibling",
512-
"Range.prototype.commonAncestorContainer",
513-
"AbstractRange.prototype.endContainer",
514-
"AbstractRange.prototype.startContainer",
515-
],
516-
{
517-
get(ctx) {
518-
const n = ctx.get() as Node;
519-
if (!(n instanceof Document)) return n;
520-
521-
const scram: ScramjetClient = n[SCRAMJETCLIENT];
522-
if (!scram) return n; // ??
523-
524-
return scram.documentProxy;
525-
},
526-
}
527-
);
528-
client.Proxy("Node.prototype.getRootNode", {
529-
apply(ctx) {
530-
const n = ctx.call() as Node;
531-
if (!(n instanceof Document)) return ctx.return(n);
532-
533-
const scram: ScramjetClient = n[SCRAMJETCLIENT];
534-
if (!scram) return ctx.return(n); // ??
535-
536-
return ctx.return(scram.documentProxy);
537-
},
538-
});
539-
540466
client.Proxy("DOMParser.prototype.parseFromString", {
541467
apply(ctx) {
542468
if (ctx.args[1] === "text/html") {

src/client/dom/open.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,7 @@ export default function (client: ScramjetClient) {
1313

1414
const realwin = ctx.call();
1515

16-
if (!realwin) return ctx.return(realwin);
17-
18-
if (SCRAMJETCLIENT in realwin) {
19-
return ctx.return(realwin[SCRAMJETCLIENT].globalProxy);
20-
} else {
21-
const newclient = new ScramjetClient(realwin);
22-
// hook the opened window
23-
newclient.hook();
24-
25-
return ctx.return(newclient.globalProxy);
26-
}
27-
},
28-
});
29-
30-
// opener will refer to the real window if it was opened by window.open
31-
client.Trap("opener", {
32-
get(ctx) {
33-
const realwin = ctx.get() as Window;
34-
35-
if (realwin && SCRAMJETCLIENT in realwin) {
36-
return realwin[SCRAMJETCLIENT].globalProxy;
37-
} else {
38-
// the opener has to have been already hooked, so if we reach here then it's a real window
39-
return undefined;
40-
}
16+
return ctx.return(realwin);
4117
},
4218
});
4319

src/client/global.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/client/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { ScramjetFrame } from "@/controller/frame";
22
import { SCRAMJETCLIENT, SCRAMJETFRAME } from "@/symbols";
3-
import { createDocumentProxy } from "@client/document";
4-
import { createGlobalProxy } from "@client/global";
53
import { getOwnPropertyDescriptorHandler } from "@client/helpers";
64
import { createLocationProxy } from "@client/location";
75
import { nativeGetOwnPropertyDescriptor } from "@client/natives";
@@ -68,8 +66,6 @@ export type Trap<T> = {
6866
};
6967

7068
export class ScramjetClient {
71-
documentProxy: any;
72-
globalProxy: any;
7369
locationProxy: any;
7470
serviceWorker: ServiceWorkerContainer;
7571
bare: BareClientType;
@@ -123,13 +119,10 @@ export class ScramjetClient {
123119
this.serviceWorker = this.global.navigator.serviceWorker;
124120

125121
if (iswindow) {
126-
this.documentProxy = createDocumentProxy(this, global);
127-
128122
global.document[SCRAMJETCLIENT] = this;
129123
}
130124

131125
this.locationProxy = createLocationProxy(this, global);
132-
this.globalProxy = createGlobalProxy(this, global);
133126
this.wrapfn = createWrapFn(this, global);
134127
this.sourcemaps = {};
135128
this.natives = {

src/client/shared/event.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { SCRAMJETCLIENT } from "@/symbols";
44
import { ScramjetClient } from "@client/index";
55
import { getOwnPropertyDescriptorHandler } from "@client/helpers";
66
import { nativeGetOwnPropertyDescriptor } from "@client/natives";
7-
import { unproxy } from "@client/shared/unproxy";
87

98
const realOnEvent = Symbol.for("scramjet original onevent function");
109

@@ -26,9 +25,9 @@ export default function (client: ScramjetClient, self: Self) {
2625
source() {
2726
if (this.source === null) return null;
2827

29-
const scram: ScramjetClient = this.source[SCRAMJETCLIENT];
28+
// const scram: ScramjetClient = this.source[SCRAMJETCLIENT];
3029

31-
if (scram) return scram.globalProxy;
30+
// if (scram) return scram.globalProxy;
3231

3332
return this.source;
3433
},
@@ -127,7 +126,6 @@ export default function (client: ScramjetClient, self: Self) {
127126

128127
client.Proxy("EventTarget.prototype.addEventListener", {
129128
apply(ctx) {
130-
unproxy(ctx, client);
131129
if (typeof ctx.args[1] !== "function") return;
132130

133131
const origlistener = ctx.args[1];
@@ -148,7 +146,6 @@ export default function (client: ScramjetClient, self: Self) {
148146

149147
client.Proxy("EventTarget.prototype.removeEventListener", {
150148
apply(ctx) {
151-
unproxy(ctx, client);
152149
if (typeof ctx.args[1] !== "function") return;
153150

154151
const arr = client.eventcallbacks.get(ctx.this);
@@ -166,12 +163,6 @@ export default function (client: ScramjetClient, self: Self) {
166163
},
167164
});
168165

169-
client.Proxy("EventTarget.prototype.dispatchEvent", {
170-
apply(ctx) {
171-
unproxy(ctx, client);
172-
},
173-
});
174-
175166
const targets = [self.self, self.MessagePort.prototype] as Array<any>;
176167
if (iswindow) targets.push(self.HTMLElement.prototype);
177168
if (self.Worker) targets.push(self.Worker.prototype);

0 commit comments

Comments
 (0)