@nativescript/windows 0.1.0-alpha.52 → 0.1.0-alpha.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/framework/dotnet-bridge/BinaryProtocol.cs +15 -0
- package/framework/dotnet-bridge/Bridge.BinaryDispatch.cs +7 -0
- package/framework/dotnet-bridge/Bridge.Dispatch.cs +0 -13
- package/framework/dotnet-bridge/Bridge.JsDelegate.cs +0 -4
- package/framework/dotnet-bridge/Bridge.cs +0 -1
- package/framework/dotnet-bridge/DispatchTypes.cs +0 -14
- package/framework/libs/arm64/nativescript.dll +0 -0
- package/framework/libs/devtools/arm64/nativescript.dll +0 -0
- package/framework/libs/devtools/x64/nativescript.dll +0 -0
- package/framework/libs/x64/nativescript.dll +0 -0
- package/package.json +1 -1
|
@@ -10,6 +10,13 @@ internal readonly struct HandleRef(int id)
|
|
|
10
10
|
public readonly int Id = id;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// Carries a raw IUnknown/IInspectable pointer from a WinRT proxy (tag 0x0A).
|
|
14
|
+
// CoerceBin calls Marshal.GetObjectForIUnknown to create a managed RCW.
|
|
15
|
+
internal readonly struct WinRtRef(long ptr)
|
|
16
|
+
{
|
|
17
|
+
public readonly long Ptr = ptr;
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
internal ref struct BinReader(ReadOnlySpan<byte> buf)
|
|
14
21
|
{
|
|
15
22
|
private readonly ReadOnlySpan<byte> _buf = buf;
|
|
@@ -24,6 +31,13 @@ internal ref struct BinReader(ReadOnlySpan<byte> buf)
|
|
|
24
31
|
return v;
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
public long ReadI64()
|
|
35
|
+
{
|
|
36
|
+
var v = BinaryPrimitives.ReadInt64LittleEndian(_buf[_pos..]);
|
|
37
|
+
_pos += 8;
|
|
38
|
+
return v;
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
public ushort ReadU16()
|
|
28
42
|
{
|
|
29
43
|
var v = BinaryPrimitives.ReadUInt16LittleEndian(_buf[_pos..]);
|
|
@@ -65,6 +79,7 @@ internal ref struct BinReader(ReadOnlySpan<byte> buf)
|
|
|
65
79
|
0x04 => (object)ReadF64(),
|
|
66
80
|
0x05 => (object)ReadString16(),
|
|
67
81
|
0x06 => (object)new HandleRef(ReadI32()),
|
|
82
|
+
0x0A => (object)new WinRtRef(ReadI64()),
|
|
68
83
|
_ => null,
|
|
69
84
|
};
|
|
70
85
|
}
|
|
@@ -158,6 +158,13 @@ public static partial class Bridge
|
|
|
158
158
|
s_handles.TryGetValue(hr.Id, out var obj);
|
|
159
159
|
return obj;
|
|
160
160
|
}
|
|
161
|
+
if (value is WinRtRef wr && wr.Ptr != 0)
|
|
162
|
+
{
|
|
163
|
+
// Marshal.GetObjectForIUnknown calls AddRef internally; the RCW will
|
|
164
|
+
// Release when GC'd.
|
|
165
|
+
try { return Marshal.GetObjectForIUnknown(new IntPtr(wr.Ptr)); }
|
|
166
|
+
catch { return null; }
|
|
167
|
+
}
|
|
161
168
|
if (value.GetType() == targetType) return value;
|
|
162
169
|
try { return Convert.ChangeType(value, targetType); }
|
|
163
170
|
catch { return value; }
|
|
@@ -86,8 +86,6 @@ public static partial class Bridge
|
|
|
86
86
|
finally { if (builtArgs.Length > 0) ReturnArgs(builtArgs); }
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
// ── compiled dispatch cache ───────────────────────────────────────────────
|
|
90
|
-
|
|
91
89
|
private static DispatchEntry GetCachedMethod(Type type, string name, int argCount, BindingFlags flags)
|
|
92
90
|
=> s_methodCache.GetOrAdd(
|
|
93
91
|
new MethodKey(type, name, argCount, flags),
|
|
@@ -148,8 +146,6 @@ public static partial class Bridge
|
|
|
148
146
|
new PropKey(type, method[prefixLen..], flags),
|
|
149
147
|
static k => k.Type.GetProperty(k.Name, k.Flags));
|
|
150
148
|
|
|
151
|
-
// ── argument coercion ─────────────────────────────────────────────────────
|
|
152
|
-
|
|
153
149
|
// Pooled: rented array passed to the compiled delegate (which accesses by index,
|
|
154
150
|
// not by Length). Caller must return via ReturnArgs immediately after invoke.
|
|
155
151
|
private static object?[] BuildArgs(JsonElement[] elements, ParameterInfo[] parameters)
|
|
@@ -186,8 +182,6 @@ public static partial class Bridge
|
|
|
186
182
|
return el.Deserialize(targetType, s_coerceOpts);
|
|
187
183
|
}
|
|
188
184
|
|
|
189
|
-
// ── async unwrapping ──────────────────────────────────────────────────────
|
|
190
|
-
|
|
191
185
|
private static object? AwaitIfTask(object? value)
|
|
192
186
|
{
|
|
193
187
|
if (value is null) return null;
|
|
@@ -216,8 +210,6 @@ public static partial class Bridge
|
|
|
216
210
|
return value;
|
|
217
211
|
}
|
|
218
212
|
|
|
219
|
-
// ── result boxing ─────────────────────────────────────────────────────────
|
|
220
|
-
|
|
221
213
|
private static DispatchResult Box(object? value)
|
|
222
214
|
{
|
|
223
215
|
if (value is null) return DispatchResult.Void;
|
|
@@ -239,8 +231,6 @@ public static partial class Bridge
|
|
|
239
231
|
return DispatchResult.Handle(id, t.FullName ?? t.Name);
|
|
240
232
|
}
|
|
241
233
|
|
|
242
|
-
// ── type/member resolution ────────────────────────────────────────────────
|
|
243
|
-
|
|
244
234
|
internal static DispatchResult BuildMembersResult(Type t)
|
|
245
235
|
{
|
|
246
236
|
const BindingFlags inst = BindingFlags.Public | BindingFlags.Instance;
|
|
@@ -351,7 +341,6 @@ public static partial class Bridge
|
|
|
351
341
|
internal static Exception Unwrap(Exception ex) =>
|
|
352
342
|
ex is TargetInvocationException { InnerException: { } inner } ? Unwrap(inner) : ex;
|
|
353
343
|
|
|
354
|
-
// ── full-pipeline helpers (parse + dispatch + serialise) ──────────────────
|
|
355
344
|
// Used by benchmarks to give a fair end-to-end comparison of protocols.
|
|
356
345
|
|
|
357
346
|
internal static byte[] PipelineJson(ReadOnlySpan<byte> jsonRequest)
|
|
@@ -377,8 +366,6 @@ public static partial class Bridge
|
|
|
377
366
|
return buf.WrittenSpan.ToArray();
|
|
378
367
|
}
|
|
379
368
|
|
|
380
|
-
// ── JSON response writers ─────────────────────────────────────────────────
|
|
381
|
-
|
|
382
369
|
private static unsafe void WriteResult(DispatchResult res, byte** outPtr, int* outLen)
|
|
383
370
|
{
|
|
384
371
|
var buf = new ArrayBufferWriter<byte>(256);
|
|
@@ -10,8 +10,6 @@ namespace NativeScriptBridge;
|
|
|
10
10
|
|
|
11
11
|
public static partial class Bridge
|
|
12
12
|
{
|
|
13
|
-
// ── JS delegate creation ──────────────────────────────────────────────────
|
|
14
|
-
//
|
|
15
13
|
// opcode 0x09: given a delegate type name (or "" for System.Action) and a
|
|
16
14
|
// JS callback id, compile a .NET delegate that serialises its parameters as
|
|
17
15
|
// binary and calls back into V8 via the s_jsInvoker function pointer.
|
|
@@ -51,8 +49,6 @@ public static partial class Bridge
|
|
|
51
49
|
return Box(del);
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
// ── Callback invocation helper ────────────────────────────────────────────
|
|
55
|
-
|
|
56
52
|
internal static unsafe void CallJsCallback(int id, object?[] args)
|
|
57
53
|
{
|
|
58
54
|
if (s_jsInvoker == null) return;
|
|
@@ -12,14 +12,10 @@ using System.Threading.Tasks;
|
|
|
12
12
|
|
|
13
13
|
namespace NativeScriptBridge;
|
|
14
14
|
|
|
15
|
-
// ── JSON source-gen context ───────────────────────────────────────────────────
|
|
16
|
-
|
|
17
15
|
[JsonSerializable(typeof(InvokeRequest))]
|
|
18
16
|
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
|
|
19
17
|
internal partial class BridgeJsonContext : JsonSerializerContext { }
|
|
20
18
|
|
|
21
|
-
// ── JSON wire type ────────────────────────────────────────────────────────────
|
|
22
|
-
|
|
23
19
|
internal sealed record InvokeRequest(
|
|
24
20
|
string? Assembly,
|
|
25
21
|
string? TypeName,
|
|
@@ -28,7 +24,6 @@ internal sealed record InvokeRequest(
|
|
|
28
24
|
JsonElement[]? Args
|
|
29
25
|
);
|
|
30
26
|
|
|
31
|
-
// ── cache key structs ─────────────────────────────────────────────────────────
|
|
32
27
|
//
|
|
33
28
|
// Using Type as the key field (rather than Type.FullName) is correct and faster:
|
|
34
29
|
// Type instances are singletons within an AssemblyLoadContext, so reference
|
|
@@ -38,8 +33,6 @@ internal readonly record struct MethodKey(Type Type, string Name, int ArgCount,
|
|
|
38
33
|
internal readonly record struct PropKey(Type Type, string Name, BindingFlags Flags);
|
|
39
34
|
internal readonly record struct CtorKey(Type Type, int ArgCount);
|
|
40
35
|
|
|
41
|
-
// ── cache value types ─────────────────────────────────────────────────────────
|
|
42
|
-
|
|
43
36
|
internal readonly struct DispatchEntry(Func<object?, object?[], object?>? invoke, ParameterInfo[] parameters)
|
|
44
37
|
{
|
|
45
38
|
public readonly Func<object?, object?[], object?>? Invoke = invoke;
|
|
@@ -53,8 +46,6 @@ internal readonly struct CtorEntry(ConstructorInfo? ctor, ParameterInfo[] parame
|
|
|
53
46
|
public readonly ParameterInfo[] Parameters = parameters;
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
// ── dispatch result ───────────────────────────────────────────────────────────
|
|
57
|
-
|
|
58
49
|
internal enum DispatchKind : byte { Void, Primitive, Handle, Collection, Members }
|
|
59
50
|
|
|
60
51
|
internal readonly struct DispatchResult
|
|
@@ -108,8 +99,6 @@ internal readonly struct DispatchResult
|
|
|
108
99
|
|
|
109
100
|
internal int HandleId() => _handle;
|
|
110
101
|
|
|
111
|
-
// ── JSON serialisation ────────────────────────────────────────────────────
|
|
112
|
-
|
|
113
102
|
public void WriteTo(Utf8JsonWriter w, JsonSerializerOptions opts)
|
|
114
103
|
{
|
|
115
104
|
switch (_kind)
|
|
@@ -158,7 +147,6 @@ internal readonly struct DispatchResult
|
|
|
158
147
|
w.WriteEndArray();
|
|
159
148
|
}
|
|
160
149
|
|
|
161
|
-
// ── binary serialisation ──────────────────────────────────────────────────
|
|
162
150
|
//
|
|
163
151
|
// Response tags:
|
|
164
152
|
// 0x00 = null 0x01 = false 0x02 = true
|
|
@@ -262,8 +250,6 @@ internal readonly struct DispatchResult
|
|
|
262
250
|
}
|
|
263
251
|
}
|
|
264
252
|
|
|
265
|
-
// ── async result helpers ──────────────────────────────────────────────────────
|
|
266
|
-
|
|
267
253
|
internal static class TaskResultCache
|
|
268
254
|
{
|
|
269
255
|
private static readonly ConcurrentDictionary<Type, Func<Task, object?>> s_cache = new();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|