You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7e3a456
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/README.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,11 @@
19
19
and the lazy-global tier that runs their builtins only on first use.
20
20
-[Error handling](error-handling.md) — global `error`/`unhandledrejection` events, `reportError`, catching Java exceptions in JS (`error.nativeException`), forwarding JS throws to Java callers (`interop.escapeException`), JS stacks on Java exceptions (`com.tns.JavaScriptStackTrace`), configuration flags, and crash-reporter integration.
21
21
-[structuredClone](structured-clone.md) — the WHATWG `structuredClone(value, { transfer })` global: what clones, how graph identity and cycles are preserved, `ArrayBuffer` transfer, and the `DataCloneError``DOMException` on failure.
22
+
-[Messaging and `node:worker_threads`](worker-threads.md) — `MessagePort`,
23
+
`MessageChannel`, `BroadcastChannel` and `MessageEvent`, the
24
+
`node:worker_threads` real-vs-shim table and its documented deviations,
25
+
the strong-until-closed port lifetime, HTML port enabling, and the
26
+
transfer support matrix with its `DataCloneError` messages.
Runtime-level configuration. Keys, value domains, and scope are defined and
99
-
validated natively; the module surface is a thin frozen wrapper.
98
+
Runtime-level configuration and runtime plumbing. Keys, value domains, and
99
+
scope are defined and validated natively; the module surface is a thin frozen
100
+
wrapper.
100
101
101
102
| export | description |
102
103
|---|---|
103
104
|`setConfig(key, value)`| Sets a runtime config key. Throws `TypeError` on an unknown key, an invalid value, or (for process-wide keys) when called from a worker isolate. |
104
105
|`getConfig(key)`| Returns the current value of a config key. Throws `TypeError` on an unknown key. Readable from any isolate. |
106
+
|`escapeException(x)`| Returns an `Error` branded so that, when it is thrown back across a native callback boundary, the native caller receives the original native exception `x` carries rather than the runtime's wrapper exception. Idempotent: a branded error is returned unchanged. Throws `TypeError` when called with no argument. The global `interop.escapeException` is this same function (see [Legacy globals](#legacy-globals)). |
107
+
108
+
*Platform note (Android):* the original exception is the Java throwable `x`
109
+
wraps, or its `nativeException`; a Java `catch` of the concrete type then
110
+
matches instead of receiving a `com.tns.NativeScriptException`. A branded error
111
+
with no underlying throwable escapes as a `com.tns.NativeScriptException`
112
+
carrying the JS message and stack, as an unbranded one does, but bypasses
113
+
`discardUncaughtJsExceptions`.
105
114
106
115
Config keys:
107
116
@@ -170,6 +179,53 @@ a release build that cannot be diagnosed.
170
179
`TNS.esm`, `TNS.fetch`, `TNS.registry` — so `adb logcat -s TNS.esm` can filter
171
180
them without matching message text.
172
181
182
+
### `ns:interop`
183
+
184
+
The cross-platform interop surface: working with native values, as opposed to
185
+
finding native symbols. It exists on every platform with whatever members that
186
+
platform supports, so a feature check (`"Pointer" in interop`) is how portable
187
+
code asks; a member a platform lacks is absent, never present-but-throwing.
188
+
189
+
On Android the namespace is **empty**: Android has none of the native-memory
190
+
members iOS exports here (`Pointer`, `Reference`, `sizeof`, …). It is still a
191
+
frozen module, so `import * as interop from "ns:interop"` resolves everywhere.
192
+
193
+
### `ns:interop/android`
194
+
195
+
Java-specific interop helpers. Android only: on other platforms the specifier
196
+
is not registered and fails like any unknown builtin.
197
+
198
+
| export | description |
199
+
|---|---|
200
+
|`long(x)`, `byte(x)`, `short(x)`, `char(x)`, `float(x)`, `double(x)`| Mark a JS value as the named Java primitive, for overload resolution and argument conversion: `method(long("123456789012"))` picks the `long` overload and passes the full 64-bit value. Each takes exactly one argument. |
201
+
|`newArray(type, length)`| Creates a Java array of `length` elements. `type` is a primitive type name (`"int"`, `"char"`, `"boolean"`, …), a fully qualified Java class name (`"java.lang.String"`), or a Java class constructor (`java.lang.String`). Throws on any other arity, a non-integer or negative length, or a class name that does not resolve. |
correctly); they are never present-but-throwing. The one exception is a
442
+
member whose silent absence would read as a delivery bug rather than as a
443
+
missing feature — it may be present and throw, and the table below names
444
+
every such member.
386
445
- **One source file per specifier.** A shim is its own module that consumes
387
-
the `ns:`module it adapts through the internal require, and it owns *all*
388
-
the adaptation — argument shapes, option names, aliases, anything that has
389
-
to track Node. A standard `ns:` module never contains compatibility code
390
-
and never knows a shim exists.
446
+
the module it adapts through the internal require, and it owns *all* the
447
+
adaptation — argument shapes, option names, aliases, anything that has to
448
+
track Node. A standard `ns:` module never contains compatibility code and
449
+
never knows a shim exists.
391
450
- Shims are **lazy**: a shim's source is only evaluated when its specifier is
392
451
first resolved, so an app that never touches the `node:` scheme never pays
393
452
for one.
@@ -411,6 +470,7 @@ unmodified where a shim exists:
411
470
| `node:util` | `inspect`, `format`, `TextEncoder`, `TextDecoder` | Re-exports `ns:util`'s members unchanged (`nodeUtil.inspect===nsUtil.inspect`) from a **distinct, separately frozen module object**. `TextEncoder`/`TextDecoder` are the globals of those names, as they are in Node. Documented as partial. |
412
471
| `node:url` | `fileURLToPath`, `pathToFileURL` | Node-strict converters between `file:` URLs and paths. Documented as partial — no `URL`/`URLSearchParams` re-exports (both are globals), no legacy `url.parse`/`format`/`resolve`. |
413
472
| `node:module` | `createRequire` | Re-exports `ns:module`'s `createRequire` unchanged from a **distinct, separately frozen module object**. `createPumpingRequire` is deliberately absent: it has no Node counterpart, so code written against this shim keeps running on Node. `require.resolve`/`.cache`/`.main` are not implemented, and neither is any other `node:module` member (`Module`, `builtinModules`, `isBuiltin`, `register`, `syncBuiltinESMExports`). Documented as partial. |
473
+
| `node:worker_threads` | the messaging and thread surface — see [worker-threads.md](worker-threads.md) | The channel half (`MessagePort`, `MessageChannel`, `BroadcastChannel`, `receiveMessageOnPort`) is the real implementation, the same objects the globals of those names hold; the thread half is a bridge over the runtime's own `Worker`. It has no `ns:` counterpart — the surface tracks Node's, so there is nothing for a standard module to own. The one place it breaks the absent-not-throwing rule below is deliberate: `postMessageToThread` and `moveMessagePortToContext` are present and throw an `Error` naming themselves, because silently missing thread-addressed messaging reads as a delivery bug rather than as an unsupported call. Documented as partial. |
414
474
415
475
`node:url`'s parsing goes through the URL intrinsic, so `file://localhost/x` is
416
476
accepted (the URL spec folds a `localhost` authority to none) while any other
@@ -719,21 +779,32 @@ shims are built on, so it is normative: both runtimes provide it.
719
779
Android-only) note in between.
720
780
- Internal runtime machinery must never be reachable through the scheme.
721
781
722
-
That last rule holds because public modules and internal builtins are **two
723
-
separate loading paths**, not one registry with a per-entry flag:
724
-
725
-
- The **public registry** is a table mapping specifier → builtin, and it is the
726
-
only thing the `ns:`/`node:` resolver consults. A specifier absent from it
727
-
does not resolve, full stop. Today it holds six entries: `ns:module`,
0 commit comments