Skip to content

Commit 7e3a456

Browse files
committed
Merge branch 'main' into fix/worker-terminate-isolate-race
2 parents 44f3c8c + 560b3bf commit 7e3a456

207 files changed

Lines changed: 13837 additions & 8909 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.coderabbit.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
reviews:
2+
pre_merge_checks:
3+
docstrings:
4+
mode: "off"

‎.github/workflows/npm_release.yml‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ jobs:
3333
npm_tag: ${{ steps.npm_version_output.outputs.NPM_TAG }}
3434
steps:
3535
- name: Harden the runner (Audit all outbound calls)
36-
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
36+
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
3737
with:
3838
egress-policy: audit
3939

4040
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4141
with:
4242
fetch-depth: 0
4343
submodules: true
44-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
44+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
4545
with:
4646
node-version: 22
4747
registry-url: "https://registry.npmjs.org"
48-
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
48+
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
4949
with:
5050
distribution: "temurin"
5151
java-version: "21"
@@ -133,18 +133,18 @@ jobs:
133133
runs-on: ubuntu-latest
134134
steps:
135135
- name: Harden the runner (Audit all outbound calls)
136-
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
136+
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
137137
with:
138138
egress-policy: audit
139139

140140
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
141141
with:
142142
submodules: true
143-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
143+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
144144
with:
145145
node-version: 22
146146
registry-url: "https://registry.npmjs.org"
147-
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
147+
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
148148
with:
149149
distribution: "temurin"
150150
java-version: "21"
@@ -212,7 +212,7 @@ jobs:
212212
path: test-app/dist/android_unit_test_results.xml
213213
- name: Test report summary
214214
if: ${{ !cancelled() }}
215-
uses: mikepenz/action-junit-report@a9170d5795813c01ab4901ffb045b52bab4ab09d # v6.5.0
215+
uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1
216216
with:
217217
report_paths: test-app/dist/android_unit_test_results.xml
218218
annotate_only: true
@@ -231,11 +231,11 @@ jobs:
231231
NPM_TAG: ${{needs.build.outputs.npm_tag}}
232232
steps:
233233
- name: Harden the runner (Audit all outbound calls)
234-
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
234+
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
235235
with:
236236
egress-policy: audit
237237

238-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
238+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
239239
with:
240240
node-version: 22
241241
registry-url: "https://registry.npmjs.org"
@@ -282,14 +282,14 @@ jobs:
282282
NPM_VERSION: ${{needs.build.outputs.npm_version}}
283283
steps:
284284
- name: Harden the runner (Audit all outbound calls)
285-
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
285+
uses: step-security/harden-runner@46b06cea07f9e64621fdf066ba77ac6915163d43 # v2.22.3
286286
with:
287287
egress-policy: audit
288288

289289
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
290290
with:
291291
fetch-depth: 0
292-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
292+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
293293
with:
294294
node-version: 22
295295
- name: Setup

‎.github/workflows/pull_request.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ jobs:
3030
with:
3131
fetch-depth: 0
3232
submodules: true
33-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
33+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
3434
with:
3535
node-version: 22
3636
registry-url: "https://registry.npmjs.org"
37-
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
37+
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
3838
with:
3939
distribution: "temurin"
4040
java-version: "21"
@@ -112,11 +112,11 @@ jobs:
112112
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
113113
with:
114114
submodules: true
115-
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
115+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
116116
with:
117117
node-version: 22
118118
registry-url: "https://registry.npmjs.org"
119-
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
119+
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
120120
with:
121121
distribution: "temurin"
122122
java-version: "21"
@@ -186,7 +186,7 @@ jobs:
186186
if: ${{ !cancelled() }}
187187
# annotate_only keeps this usable from fork PRs: it reports via workflow
188188
# commands and the step summary, so no checks:write token is needed
189-
uses: mikepenz/action-junit-report@a9170d5795813c01ab4901ffb045b52bab4ab09d # v6.5.0
189+
uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1
190190
with:
191191
report_paths: test-app/dist/android_unit_test_results.xml
192192
annotate_only: true

‎.github/workflows/scorecards.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ jobs:
6868

6969
# Upload the results to GitHub's code scanning dashboard.
7070
- name: "Upload to code-scanning"
71-
uses: github/codeql-action/upload-sarif@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
71+
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
7272
with:
7373
sarif_file: results.sarif

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Note: You might need to run the Android Studio from the command line in order to
9494

9595
## How to Run Tests
9696

97+
* Run `npm install` in the repository root. The test app's Jasmine (`jasmine-core`) comes from there and is copied into the APK at build time.
9798
* Go to subfolder test-app after you built the runtime.
9899
* Start an emulator or connect a device.
99100

‎docs/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
and the lazy-global tier that runs their builtins only on first use.
2020
- [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.
2121
- [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.
2227
- [Implementing additional Chrome DevTools protocol Domains](extending-inspector.md)
2328

2429
## Knowledge

‎docs/knowledge/v8-14-migration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ new, and why:
3434
**`v8_array_buffer_view_internal_field_count=2`** — both default to `0` in
3535
14.9 and defaulted to `2` in 10.3. When an `ArrayBuffer`/`SharedArrayBuffer`/
3636
typed array is marshalled to a Java NIO buffer,
37-
`JSToJavaObjectsConverter` calls `ObjectManager::Link` on the buffer object
37+
`JsArgConverter` calls `ObjectManager::Link` on the buffer object
3838
itself, and `Link` stores its `JSInstanceInfo` in internal field 0. With zero
3939
internal fields every such conversion throws *"Trying to link invalid 'this'
4040
to a Java object"*. `v8-array-buffer.h` still falls back to `2` when the macro

‎docs/ns-builtin-modules.md‎

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,22 @@ Node's single-quoted style.
9595

9696
### `ns:runtime`
9797

98-
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.
100101

101102
| export | description |
102103
|---|---|
103104
| `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. |
104105
| `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`.
105114

106115
Config keys:
107116

@@ -170,6 +179,53 @@ a release build that cannot be diagnosed.
170179
`TNS.esm`, `TNS.fetch`, `TNS.registry` — so `adb logcat -s TNS.esm` can filter
171180
them without matching message text.
172181

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. |
202+
203+
```js
204+
import { long, newArray } from "ns:interop/android";
205+
206+
const bytes = newArray("byte", 1024); // byte[1024]
207+
const names = newArray(java.lang.String, 3); // String[3]
208+
someJavaObject.setTimestamp(long(Date.now()));
209+
```
210+
211+
### Legacy globals
212+
213+
Before these modules existed the same functions were reachable only as
214+
globals, and app code and `@nativescript/core` read them at module top level.
215+
They remain, installed before any app code runs, as **aliases of the module
216+
exports** — the very same function objects, per realm:
217+
218+
| global | module export |
219+
|---|---|
220+
| `interop.escapeException` | `ns:runtime`'s `escapeException` |
221+
| `long`, `byte`, `short`, `char`, `float`, `double` (Android) | `ns:interop/android`'s members of those names |
222+
| `Array.create` (Android) | `ns:interop/android`'s `newArray` |
223+
224+
The global `interop` object, the cast globals and `Array.create` are ordinary
225+
writable, enumerable, configurable data properties. On Android the global
226+
`interop` has exactly one member, `escapeException`; it is a plain object, not
227+
the `ns:interop` namespace. New code should import from the modules.
228+
173229
### `ns:module`
174230

175231
The module-loader control surface: import-map vocabulary, registry
@@ -380,14 +436,17 @@ npm packages that require Node builtins by their prefixed names can run
380436
unmodified where a shim exists:
381437
382438
- A shim implements a documented **subset** of the corresponding Node module's
383-
API, backed by `ns:` modules. Unimplemented members are simply absent
439+
API, backed by the runtime's own modules. Unimplemented members are simply absent
384440
(so `typeof util.promisify === "function"` feature-checks behave
385-
correctly); they are never present-but-throwing.
441+
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.
386445
- **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.
391450
- Shims are **lazy**: a shim's source is only evaluated when its specifier is
392451
first resolved, so an app that never touches the `node:` scheme never pays
393452
for one.
@@ -411,6 +470,7 @@ unmodified where a shim exists:
411470
| `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. |
412471
| `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`. |
413472
| `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. |
414474
415475
`node:url`'s parsing goes through the URL intrinsic, so `file://localhost/x` is
416476
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.
719779
Android-only) note in between.
720780
- Internal runtime machinery must never be reachable through the scheme.
721781
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`,
728-
`ns:runtime`, `ns:util`, `node:module`, `node:url`, `node:util`.
729-
- **Internal builtins** (the intrinsics snapshot, the require factory, the
730-
console formatter, and so on) are invoked directly from their own native call
731-
sites. They are never named in the public registry, so there is no specifier
732-
that could reach them and nothing to mark private.
733-
734-
Adding an internal builtin therefore cannot accidentally expose it; exposing
735-
one is an explicit registry entry, which is also the change this document has
736-
to describe.
782+
That last rule holds because every registry row carries its tier, and the two
783+
resolvers read the same table differently:
784+
785+
- The **`ns:`/`node:` resolver** — the app-facing one, behind `require()`,
786+
`import` and `import()` — serves only rows *not* marked internal-only. An
787+
internal-only specifier fails exactly as a name absent from the table does.
788+
Nine rows are public today: `ns:interop`, `ns:interop/android`, `ns:module`,
789+
`ns:runtime`, `ns:util`, `node:module`, `node:url`, `node:util`,
790+
`node:worker_threads`.
791+
- The **internal require** builtins receive (previous section) is the only
792+
thing that can name an internal-only row. Seven rows are marked that way:
793+
`internal/broadcast-channel`, `internal/dom-exception`, `internal/events`,
794+
`internal/interop-globals`, `internal/message-channel`,
795+
`internal/message-event`, `internal/worker-events`. Their exports carry
796+
capabilities app code must not hold — listener-accounting hook keys, the
797+
error-reporter setter, the key a worker's rebuilt error travels under, base
798+
classes that must be the runtime's own rather than whatever a global
799+
currently names — or, for `internal/interop-globals`, install the legacy
800+
globals.
801+
- Builtins with **no row at all** (the intrinsics snapshot, the require
802+
factory, the console formatter) are invoked straight from their native call
803+
sites. There is no specifier that could reach them and nothing to mark.
804+
805+
So a builtin is unreachable from app code unless a registry row says
806+
otherwise, and exposing one means editing that row's tier — which is also the
807+
change this document has to describe.
737808

738809
## Source-text modules: deliberately not supported
739810

@@ -765,8 +836,14 @@ internal require is a fixed parameter of the builtin function wrapper
765836
The files under `js/` that are *not* in the public registry — `primordials.js`,
766837
`require-factory.js`, `inspect.js`, `json-helper.js`, `events.js`,
767838
`error-events.js`, `structured-clone.js`, `blob-url.js`, `performance.js`,
768-
`weak-ref.js` — are the internal builtins: each is run from its own native call
769-
site and none is named in the registry table.
839+
`weak-ref.js`, `interop-globals.js` — are the internal builtins: each is run
840+
from its own native call site and none is named in the public registry.
841+
842+
`interop-globals.js` is the [legacy globals](#legacy-globals) layer. It runs
843+
eagerly from `Runtime::PrepareV8Runtime` in every isolate, requires
844+
`ns:runtime` and `ns:interop/android` through the internal require and assigns
845+
their functions to the globals, so the compat knowledge lives only in that
846+
consumer and neither module refers to it.
770847
771848
Per-realm builtin state — the exports objects, the synthetic modules, the
772849
in-progress set that produces the circular-require error, the cached `format`,

0 commit comments

Comments
 (0)