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 da341c0
Browse filesBrowse the repository at this point in the historyBrowse files
feat(runtime): ns:interop builtin modules, interop globals as compat
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.
Copy file name to clipboardExpand all lines: docs/ns-builtin-modules.md
+77-12Lines changed: 77 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,13 +95,22 @@ Node's single-quoted style.
95
95
96
96
### `ns:runtime`
97
97
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.
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. |
0 commit comments