Skip to content

Commit

Permalink
Bugfix (unmangle onmessageerror) & improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Jun 15, 2024
1 parent 13db455 commit 6e5a38e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@exact-realty/lot",
"version": "0.0.25",
"version": "0.0.26",
"description": "Sandbox for isolating ECMAScript code",
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
Expand Down
2 changes: 1 addition & 1 deletion src/untrusted/impl/worker/workerSandboxManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const workerSandboxManager = async (
if (EMessageTypes.REQUEST !== data[0]) return;

Logger.debug(
'Forwarding REQUEST from worker to parent for executing task' +
'Forwarding REQUEST from worker to parent for executing task ' +
data[2],
);

Expand Down
15 changes: 10 additions & 5 deletions src/untrusted/lib/performTaskFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const performTaskFactory = <T>(
unresolved.splice(idx, 1);
}
};
incomingPort.onmessage = (ev) => {
// The following const definitions prevent Google Closure Compiler
// from mangling the event handler names
const onmessage = 'onmessage';
const onmessageerror = 'onmessageerror';
incomingPort[onmessage] = (ev) => {
const data = ev['data'];
if (
!aIsArray(data) ||
Expand All @@ -73,7 +77,8 @@ const performTaskFactory = <T>(
(data[0] === EMessageTypes.RESULT
? 'RESULT'
: 'ERROR') +
' from executing task',
' from executing task ' +
op,
);

if (data[0] === EMessageTypes.RESULT) {
Expand All @@ -83,12 +88,12 @@ const performTaskFactory = <T>(
}
markAsResolved();
};
incomingPort.onmessageerror = (ev) => {
incomingPort[onmessageerror] = () => {
Logger.debug(
'Error receiving task result after executing task',
'Error decoding task result after executing task ' + op,
);

reject(ev['data']);
reject(new E('Error decoding task result'));
markAsResolved();
};
incomingPort.start();
Expand Down

0 comments on commit 6e5a38e

Please sign in to comment.