-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpreload.js
More file actions
30 lines (26 loc) · 1.01 KB
/
Copy pathpreload.js
File metadata and controls
30 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Everything here is evaluated at build time and serialized into the snapshot.
// jsvm starts with it already on the heap: no parse, no compile, no allocation.
//
// Good candidates: polyfills, validation helpers, parsers, any pure-JS library
// your scripts always need.
//
// Will NOT survive snapshotting:
// - anything holding a host object or external pointer not listed in
// kExternalReferences
// - open handles, timers, pending network state (none of which exist here)
// - Date.now() / Math.random() results you expect to be fresh, since they
// are frozen at build time
globalThis.jsvm = Object.freeze({
version: '0.1.0',
// Structured output for callers that parse stdout.
emit(value) {
print(JSON.stringify(value));
},
assert(condition, message) {
if (!condition) throw new Error(message || 'assertion failed');
},
});
// Deterministic deep clone that predates structuredClone in some builds.
globalThis.clone = function clone(value) {
return JSON.parse(JSON.stringify(value));
};