Skip to content

Commit e4f0b5d

Browse files
committed
Fix formatting
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 28be8e6 commit e4f0b5d

3 files changed

Lines changed: 169 additions & 83 deletions

File tree

src/js-host-api/examples/user-modules.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,47 @@ async function main() {
2727
console.log('2. Registering user modules...');
2828

2929
// A constants module — other modules can import from it
30-
sandbox.addModule('constants', `
30+
sandbox.addModule(
31+
'constants',
32+
`
3133
export const PI = 3.14159;
3234
export const E = 2.71828;
33-
`);
35+
`
36+
);
3437

3538
// A geometry module that depends on the constants module
36-
sandbox.addModule('geometry', `
39+
sandbox.addModule(
40+
'geometry',
41+
`
3742
import { PI } from 'user:constants';
3843
export function circleArea(radius) { return PI * radius * radius; }
3944
export function circleCircumference(radius) { return 2 * PI * radius; }
40-
`);
45+
`
46+
);
4147

4248
// A string utils module with a custom namespace
43-
sandbox.addModule('strings', `
49+
sandbox.addModule(
50+
'strings',
51+
`
4452
export function capitalize(s) {
4553
return s.charAt(0).toUpperCase() + s.slice(1);
4654
}
4755
export function reverse(s) {
4856
return s.split('').reverse().join('');
4957
}
50-
`, 'mylib'); // custom namespace → import from 'mylib:strings'
58+
`,
59+
'mylib'
60+
); // custom namespace → import from 'mylib:strings'
5161

5262
console.log(' ✓ 3 modules registered (2 default namespace, 1 custom)\n');
5363

5464
// ── Add handlers that import the modules ─────────────────────────
5565
console.log('3. Adding handlers...');
5666

5767
// Handler 1: uses geometry module (which transitively imports constants)
58-
sandbox.addHandler('circle', `
68+
sandbox.addHandler(
69+
'circle',
70+
`
5971
import { circleArea, circleCircumference } from 'user:geometry';
6072
6173
function handler(event) {
@@ -65,10 +77,13 @@ async function main() {
6577
circumference: circleCircumference(event.radius),
6678
};
6779
}
68-
`);
80+
`
81+
);
6982

7083
// Handler 2: uses the custom-namespace strings module
71-
sandbox.addHandler('strings', `
84+
sandbox.addHandler(
85+
'strings',
86+
`
7287
import { capitalize, reverse } from 'mylib:strings';
7388
7489
function handler(event) {
@@ -78,7 +93,8 @@ async function main() {
7893
reversed: reverse(event.text),
7994
};
8095
}
81-
`);
96+
`
97+
);
8298

8399
const loaded = await sandbox.getLoadedSandbox();
84100
console.log(' ✓ Handlers loaded\n');

src/js-host-api/lib.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,14 @@ for (const method of ['callHandler', 'unload', 'snapshot', 'restore']) {
155155
// JSSandbox — async + sync methods + getters
156156
JSSandbox.prototype.getLoadedSandbox = wrapAsync(JSSandbox.prototype.getLoadedSandbox);
157157

158-
for (const method of ['addHandler', 'removeHandler', 'clearHandlers', 'addModule', 'removeModule', 'clearModules']) {
158+
for (const method of [
159+
'addHandler',
160+
'removeHandler',
161+
'clearHandlers',
162+
'addModule',
163+
'removeModule',
164+
'clearModules',
165+
]) {
159166
const orig = JSSandbox.prototype[method];
160167
if (!orig) throw new Error(`Cannot wrap missing method: JSSandbox.${method}`);
161168
JSSandbox.prototype[method] = wrapSync(orig);

0 commit comments

Comments
 (0)