Skip to content

feat(runtime): ns:interop builtin modules, interop globals as compat - #2074

Draft
edusperoni wants to merge 1 commit into
mainfrom
feat/ns-interop
Draft

edusperoni wants to merge 1 commit into
mainfrom
feat/ns-interop

Conversation

@edusperoni

Copy link
Copy Markdown
Collaborator

Description

Adoption step 0 of rfcs#58 ("interop and runtime helpers"). The interop helpers move into builtin modules, and today's globals become a compat layer built from them.

Module Exports
ns:interop nothing yet, frozen and empty. Android has none of the native-memory members iOS exports here; rfcs#56's initializer will land here.
ns:interop/android long, byte, short, char, float, double, newArray (the function Array.create has always been)
ns:runtime (new member) escapeException

Compat. js/interop-globals.js is an internal builtin that requires ns:runtime and ns:interop/android and installs:

  • globalThis.interop = { escapeException };
  • the six cast globals;
  • Array.create.

Each global holds the module's own function object, with the same writable, enumerable and configurable attributes as before. It runs eagerly, at the point where interop used to be installed, for both the main isolate and workers, because @nativescript/core reads these at module top level. The ns: files never refer to it.

Native changes:

  • The casts, Array.create and escapeException are now built by binding factories in NsBuiltinModules.cpp, rather than set on the global template or the global itself.
  • ArrayHelper's JNI class/method lookup runs once per process (std::call_once). It used to be redone per isolate, with unsynchronized writes to static fields.

Typings. This repo doesn't ship .d.ts for its ns: modules yet, so none are added here. The iOS runtime ships them in types/, and Android doing the same is a follow-up.

Does your commit message include the wording below to reference a specific issue in this repo?

No issue; this implements part of rfcs#58.

Related Pull Requests

Does your pull request have unit tests?

Yes. tests/testNsInterop.js (16 specs) and tests/nsInteropWorker.js cover:

  • export lists and frozen exports;
  • that every global is the module's export, and that the globals' property attributes are unchanged;
  • Java overload resolution through the module casts;
  • newArray by type name and by class;
  • bad arguments;
  • static and dynamic ESM import;
  • a worker getting its own instances.

testNsRuntime.js now expects escapeException.

Full suite: 1281 passed, 0 failed (baseline 1265 plus the 16 new specs), on an API 35 arm64 emulator.

Add the ns:interop and ns:interop/android builtin modules and move
escapeException onto ns:runtime, per rfcs#58 ("interop and runtime
helpers", adoption step 0).

- ns:interop: frozen and empty on Android (none of the cross-platform
  native-memory members exist here).
- ns:interop/android: long, byte, short, char, float, double and
  newArray (the function Array.create has always been).
- ns:runtime: gains escapeException.

The natives move from being set on the global (template casts,
Interop::Init, ArrayHelper::Init) to binding factories in
NsBuiltinModules.cpp. The legacy globals are now assembled by
interop-globals.js, an internal-tier builtin run eagerly at the point
the interop global was installed: it requires ns:runtime and
ns:interop/android and assigns their functions, so interop.escapeException,
the cast globals and Array.create are the module exports themselves,
with the same writable/enumerable/configurable attributes as before.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant