Morph supports a subset of the standard JavaScript global functions under their browser names: isNaN, isFinite, encodeURI, encodeURIComponent, decodeURI, decodeURIComponent, atob, btoa, structuredClone, and queueMicrotask, plus crypto.randomUUID() and the console.debug / console.assert methods.
These are native globals: no import is required, and they are available at module scope, in components, and in event handlers.
const id = crypto.randomUUID()
const copy = structuredClone({ name: "Ada", tags: ["math"] })
queueMicrotask(() => console.log("cloned", copy.name))Morph reuses the JavaScript names under Name Follows Behavior because every input Morph accepts produces the JavaScript result. Inputs Morph cannot reproduce — extra arguments, spread arguments, first-class helper values, and callback shapes the runtime cannot schedule safely — fail morph check with mx-js-syntax or mx-js-member instead of compiling to something different.
isNaN(value): boolean
isFinite(value): booleanisNaN and isFinite coerce their argument with JavaScript Number() first, so they are the coercing globals, not the strict Number.isNaN / Number.isFinite predicates:
| Call | Result |
|---|---|
isNaN("abc") |
true |
isNaN("") |
false (Number("") is 0) |
isNaN(undefined) |
true |
isNaN(null) |
false |
isFinite("10") |
true |
isFinite(undefined) |
false |
isFinite(Infinity) |
false |
Both functions take zero or one argument. Zero arguments coerce undefined, matching JavaScript. Extra arguments and spread calls are rejected.
encodeURI(value): string
encodeURIComponent(value): string
decodeURI(value): string
decodeURIComponent(value): stringEach helper coerces its argument with JavaScript String(), encodes UTF-8 as uppercase %XX escapes, and preserves the same unreserved and reserved sets as JavaScript:
encodeURI leaves the reserved characters ;/?:@&=+$,# unescaped.encodeURIComponent escapes those reserved characters but leaves -_.!~*'() unescaped.decodeURI decodes escapes except for escapes of reserved characters, which stay spelled as written.decodeURIComponent decodes every valid escape.Malformed input — a truncated escape, a non-hex escape, or an invalid UTF-8 sequence (overlong, surrogate, or above U+10FFFF) — throws a catchable URIError object:
try {
decodeURIComponent("%C3")
} catch (error) {
console.log(error.name) // "URIError"
}btoa(value): string
atob(value): stringbtoa coerces its argument with String() and encodes the text's Latin-1 code points. Characters above U+00FF throw an InvalidCharacterError object.
atob implements the forgiving-base64 algorithm: ASCII whitespace is ignored, padding is optional, and invalid characters or an impossible length throw InvalidCharacterError. Morph stores strings as UTF-8, so atob emits the UTF-8 encoding of each decoded code point. The text-level contract matches JavaScript: atob(btoa("é")) is "é", and btoa(atob("w6k=")) is "w6k=".
console.log(btoa("hello")) // "aGVsbG8="
console.log(atob("aGVsbG8=")) // "hello"structuredClone(value): valuestructuredClone performs a deep clone of primitives, arrays, and plain objects. It preserves cycles and shared references: a cloned graph points at the cloned objects, never back at the source graph.
const original = { name: "Ada", nested: { count: 1 } }
original.nested.owner = original
const copy = structuredClone(original)
copy.name = "Grace"
console.log(original.name) // "Ada"
console.log(copy.nested.owner.name) // "Grace"The function value itself is not cloneable. Source-level function values, class instances, and native value types (Date, URL, URLSearchParams, RegExp, Map, Set) throw a catchable DataCloneError object. morph check rejects direct new expressions for unsupported native/class instances, zero or multiple arguments, spreads, and a transfer-options second argument; those shapes never reach codegen.
structuredClone takes exactly one argument.
queueMicrotask(callback: () => void): undefinedqueueMicrotask appends a synchronous zero-parameter callback to a FIFO queue and returns undefined. The queue drains until empty at the end of the current task, so a microtask that queues another microtask runs it in the same checkpoint.
The callback may be an inline zero-parameter arrow/function or a module-scope zero-parameter named callable:
function refresh() {
console.log("refresh")
}
queueMicrotask(() => console.log("first"))
queueMicrotask(refresh)Async callbacks, callbacks with parameters, spreads, first-class uses of queueMicrotask, and zero or multiple arguments are rejected by morph check.
Microtask checkpoints run at every callback boundary:
crypto.randomUUID(): stringcrypto.randomUUID() returns a random version-4 UUID in the canonical lowercase form, for example "6f1c2a3d-4b5e-4c7d-8a9b-0c1d2e3f4a5b". typeof crypto is "object".
crypto is method-only: storing it as a value, reading crypto.randomUUID as a property, bracket access, and unknown members fail morph check. crypto.getRandomValues is not supported because Morph's JS subset does not have typed arrays; use randomUUID() or write a C++ helper when you need raw random bytes.
| Call | Behavior |
|---|---|
console.debug(...values) |
Prints to the log sink, like console.log |
console.assert(condition, ...data) |
Prints only when the condition is falsy; returns undefined |
console.assert(false) prints Assertion failed to standard error. With data values it prints Assertion failed: <data>, separated by spaces. A truthy condition prints nothing, but arguments are still evaluated left-to-right before the condition is tested, matching a JavaScript call. console.table, console.dir, console.group, console.trace, console.count, and the timing methods remain rejected.
The throwing helpers raise ordinary JavaScript-style error objects with name and message properties, so existing try / catch code keeps working:
| Helper failure | error.name |
|---|---|
| Malformed URI or invalid UTF-8 in a decoder | URIError |
Invalid base64 or a character above U+00FF in btoa |
InvalidCharacterError |
A function value or native/class instance in structuredClone |
DataCloneError |
Generated apps that use these helpers are built with C++ exceptions enabled, so catch (error) works as written. When the runtime itself is compiled with exceptions disabled, the same misuse aborts instead; the helper test suite exercises that build without triggering the throwing paths.
All global helpers are direct-call only. The linter rejects:
const parse = isNaN), property access, or bracket access — mx-js-member;mx-js-syntax;structuredClone() without an argument or with more than one — mx-js-syntax;structuredClone(new Date()) and other native/class new instances — mx-js-syntax;queueMicrotask with a non-callable, async, or parameter-taking callback — mx-js-syntax;crypto members other than randomUUID and non-call uses of crypto — mx-js-member;mx-js-member.typeof is the one value-position use that is allowed: typeof isNaN is "function", and typeof crypto is "object".