commontoolsinc / system

A constellation of Common tools
2 stars 0 forks source link

Ensure uniform environment between JS VMs #70

Open jsantell opened 1 month ago

jsantell commented 1 month ago

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

[
  "AggregateError",
  "Array",
  "ArrayBuffer",
  "BigInt",
  "BigInt64Array",
  "BigUint64Array",
  "Boolean",
  "ByteLengthQueuingStrategy",
  "CompressionStream",
  "CountQueuingStrategy",
  "Crypto",
  "CryptoKey",
  "DOMException",
  "DataView",
  "Date",
  "DecompressionStream",
  "Error",
  "EvalError",
  "FinalizationRegistry",
  "Float32Array",
  "Float64Array",
  "Function",
  "Headers",
  "Infinity",
  "Int16Array",
  "Int32Array",
  "Int8Array",
  "InternalError",
  "JSON",
  "Map",
  "Math",
  "NaN",
  "Number",
  "Object",
  "Performance",
  "Promise",
  "Proxy",
  "RangeError",
  "ReadableByteStreamController",
  "ReadableStream",
  "ReadableStreamBYOBReader",
  "ReadableStreamBYOBRequest",
  "ReadableStreamDefaultController",
  "ReadableStreamDefaultReader",
  "ReferenceError",
  "Reflect",
  "RegExp",
  "Request",
  "Response",
  "Set",
  "String",
  "SubtleCrypto",
  "Symbol",
  "SyntaxError",
  "TextDecoder",
  "TextEncoder",
  "TransformStream",
  "TypeError",
  "URIError",
  "URL",
  "URLSearchParams",
  "Uint16Array",
  "Uint32Array",
  "Uint8Array",
  "Uint8ClampedArray",
  "WeakMap",
  "WeakRef",
  "WeakSet",
  "WorkerLocation",
  "WritableStream",
  "addEventListener",
  "atob",
  "btoa",
  "clearInterval",
  "clearTimeout",
  "console",
  "crypto",
  "decodeURI",
  "decodeURIComponent",
  "encodeURI",
  "encodeURIComponent",
  "escape",
  "eval",
  "fetch",
  "globalThis",
  "isFinite",
  "isNaN",
  "location",
  "parseFloat",
  "parseInt",
  "performance",
  "queueMicrotask",
  "self",
  "setInterval",
  "setTimeout",
  "structuredClone",
  "undefined",
  "unescape"
]

Common Script

[
  "AggregateError",
  "Array",
  "ArrayBuffer",
  "Atomics",
  "BigInt",
  "BigInt64Array",
  "BigUint64Array",
  "Boolean",
  "DataView",
  "Date",
  "Error",
  "EvalError",
  "Float32Array",
  "Float64Array",
  "Function",
  "Infinity",
  "Int16Array",
  "Int32Array",
  "Int8Array",
  "JSON",
  "Map",
  "Math",
  "NaN",
  "Number",
  "Object",
  "Promise",
  "Proxy",
  "RangeError",
  "Reference",
  "ReferenceError",
  "Reflect",
  "RegExp",
  "Set",
  "SharedArrayBuffer",
  "String",
  "Symbol",
  "SyntaxError",
  "TypeError",
  "TypedArray",
  "URIError",
  "Uint16Array",
  "Uint32Array",
  "Uint8Array",
  "Uint8ClampedArray",
  "WeakMap",
  "WeakRef",
  "WeakSet",
  "console",
  "decodeURI",
  "decodeURIComponent",
  "encodeURI",
  "encodeURIComponent",
  "eval",
  "globalThis",
  "isFinite",
  "isNaN",
  "parseFloat",
  "parseInt",
  "undefined"
]

Shared Globals

[
  "AggregateError",
  "Array",
  "ArrayBuffer",
  "BigInt",
  "BigInt64Array",
  "BigUint64Array",
  "Boolean",
  "DataView",
  "Date",
  "Error",
  "EvalError",
  "Float32Array",
  "Float64Array",
  "Function",
  "Infinity",
  "Int16Array",
  "Int32Array",
  "Int8Array",
  "JSON",
  "Map",
  "Math",
  "NaN",
  "Number",
  "Object",
  "Promise",
  "Proxy",
  "RangeError",
  "ReferenceError",
  "Reflect",
  "RegExp",
  "Set",
  "String",
  "Symbol",
  "SyntaxError",
  "TypeError",
  "URIError",
  "Uint16Array",
  "Uint32Array",
  "Uint8Array",
  "Uint8ClampedArray",
  "WeakMap",
  "WeakRef",
  "WeakSet",
  "console",
  "decodeURI",
  "decodeURIComponent",
  "encodeURI",
  "encodeURIComponent",
  "eval",
  "globalThis",
  "isFinite",
  "isNaN",
  "parseFloat",
  "parseInt",
  "undefined"
]

Unique Module Globals

[
  "ByteLengthQueuingStrategy",
  "CompressionStream",
  "CountQueuingStrategy",
  "Crypto",
  "CryptoKey",
  "DOMException",
  "DecompressionStream",
  "FinalizationRegistry",
  "Headers",
  "InternalError",
  "Performance",
  "ReadableByteStreamController",
  "ReadableStream",
  "ReadableStreamBYOBReader",
  "ReadableStreamBYOBRequest",
  "ReadableStreamDefaultController",
  "ReadableStreamDefaultReader",
  "Request",
  "Response",
  "SubtleCrypto",
  "TextDecoder",
  "TextEncoder",
  "TransformStream",
  "URL",
  "URLSearchParams",
  "WorkerLocation",
  "WritableStream",
  "addEventListener",
  "atob",
  "btoa",
  "clearInterval",
  "clearTimeout",
  "crypto",
  "escape",
  "fetch",
  "location",
  "performance",
  "queueMicrotask",
  "self",
  "setInterval",
  "setTimeout",
  "structuredClone",
  "unescape"
]

Unique Script Globals

[
  "Atomics",
  "Reference",
  "SharedArrayBuffer",
  "TypedArray"
]
cdata commented 1 month ago

We may be able to homogenize a lot of this by dropping Starling Monkey entirely https://github.com/commontoolsinc/system/issues/71