@johnhenry/andbox 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/worker-source.mjs +4 -2
package/package.json
CHANGED
package/src/worker-source.mjs
CHANGED
|
@@ -167,10 +167,12 @@ self.onmessage = async ({ data: msg }) => {
|
|
|
167
167
|
case 'evaluate': {
|
|
168
168
|
const fwdConsole = makeForwardingConsole(msg.id);
|
|
169
169
|
try {
|
|
170
|
-
// Wrap in async function for top-level await
|
|
170
|
+
// Wrap in async function for top-level await. The newlines before and
|
|
171
|
+
// after the user code matter: without the trailing one, code ending in
|
|
172
|
+
// a // line comment swallows the closing brace (andbox#23).
|
|
171
173
|
const asyncFn = new Function(
|
|
172
174
|
'sandboxImport', 'host', 'console',
|
|
173
|
-
\`return (async () => {
|
|
175
|
+
\`return (async () => {\\n\${msg.code}\\n})();\`
|
|
174
176
|
);
|
|
175
177
|
const result = await asyncFn(sandboxImport, host, fwdConsole);
|
|
176
178
|
self.postMessage({ type: 'result', id: msg.id, success: true, value: serialize(result) });
|