This might be an ever-moving goal post to get the compiled and interpreter environments identical, but doing some tests to illuminate what's available in the globals in the different environments.
Using Object.getOwnPropertyNames(globalThis).sort() to test, below are globals available in each environment, followed by the shared globals (55), and unique globals (43 for module, 4 for script).
Module VM has many DOM APIs (timers, fetch, crypto), not available to script VM, whereas script VM has atomic-related globals. A reasonable approach may be a bootstrap.js script executed on startup to normalize/remove many of these APIs, or provide JS implementations (e.g. TextEncoder) consistently across VMs.
This might be an ever-moving goal post to get the compiled and interpreter environments identical, but doing some tests to illuminate what's available in the globals in the different environments.
Using
Object.getOwnPropertyNames(globalThis).sort()
to test, below are globals available in each environment, followed by the shared globals (55), and unique globals (43 for module, 4 for script).Module VM has many DOM APIs (timers, fetch, crypto), not available to script VM, whereas script VM has atomic-related globals. A reasonable approach may be a
bootstrap.js
script executed on startup to normalize/remove many of these APIs, or provide JS implementations (e.g.TextEncoder
) consistently across VMs.Common Module
Common Script
Shared Globals
Unique Module Globals
Unique Script Globals