Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Dec 14, 2024
1 parent 8fe0d89 commit 530439b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/client/dom/serviceworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function (client: ScramjetClient, _self: Self) {
> = new WeakMap();
client.Proxy("EventTarget.prototype.addEventListener", {
apply(ctx) {
if (registration === ctx.this) {
if (registrationmap.get(ctx.this)) {
// do nothing
ctx.return(undefined);
}
Expand All @@ -34,7 +34,7 @@ export default function (client: ScramjetClient, _self: Self) {

client.Proxy("EventTarget.prototype.removeEventListener", {
apply(ctx) {
if (registration === ctx.this) {
if (registrationmap.get(ctx.this)) {
// do nothing
ctx.return(undefined);
}
Expand Down
62 changes: 2 additions & 60 deletions src/client/shared/requests/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ type FakeWebSocketState = {
url: string;
binaryType: string;
barews: BareWebSocket;
/*
captureListeners: Record<string, EventListener[]>;
listeners: Record<string, EventListener[]>;
*/

onclose?: (ev: CloseEvent) => any;
onerror?: (ev: Event) => any;
onmessage?: (ev: MessageEvent) => any;
Expand Down Expand Up @@ -49,10 +46,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
url: ctx.args[0],
binaryType: "blob",
barews,
/*
captureListeners: {},
listeners: {},
*/

onclose: null,
onerror: null,
onmessage: null,
Expand Down Expand Up @@ -107,58 +101,6 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
ctx.return(fakeWebSocket);
},
});
// i have no clue why this is here but it prevents the real event listener from ever happening so im commenting it out for now
/*
client.Proxy("EventTarget.prototype.addEventListener", {
apply(ctx) {
const ws = socketmap.get(ctx.this);
if (!ws) return; // it's not a websocket ignore it
const [type, listener, opts] = ctx.args;
if (
(typeof opts === "object" && opts.capture) ||
(typeof opts === "boolean" && opts)
) {
const listeners = (ws.captureListeners[type] ??= []);
listeners.push(listener);
ws.captureListeners[type] = listeners;
} else {
const listeners = (ws.listeners[type] ??= []);
listeners.push(listener);
ws.listeners[type] = listeners;
}
ctx.return(undefined);
},
});
client.Proxy("EventTarget.prototype.removeEventListener", {
apply(ctx) {
const ws = socketmap.get(ctx.this);
if (!ws) return;
const [type, listener, opts] = ctx.args;
if (
(typeof opts === "object" && opts.capture) ||
(typeof opts === "boolean" && opts)
) {
const listeners = (ws.captureListeners[type] ??= []);
const idx = listeners.indexOf(listener);
if (idx !== -1) listeners.splice(idx, 1);
ws.captureListeners[type] = listeners;
} else {
const listeners = (ws.listeners[type] ??= []);
const idx = listeners.indexOf(listener);
if (idx !== -1) listeners.splice(idx, 1);
ws.listeners[type] = listeners;
}
ctx.return(undefined);
},
});
*/
client.Trap("WebSocket.prototype.binaryType", {
get(ctx) {
const ws = socketmap.get(ctx.this);
Expand Down
4 changes: 4 additions & 0 deletions src/client/shared/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
debugger;
}

if (v === self && v.$scramjet) {
debugger;
}

if (iswindow && v instanceof Document && v.defaultView.$scramjet) {
debugger;
}
Expand Down
1 change: 1 addition & 0 deletions static/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const scramjet = new ScramjetController({
flags: {
serviceworkers: true,
syncxhr: true,
scramitize: true,
},
});

Expand Down

0 comments on commit 530439b

Please sign in to comment.