Skip to content

Commit

Permalink
adding marshalling for ushort, uint and ulong #245
Browse files Browse the repository at this point in the history
  • Loading branch information
agracio committed Feb 26, 2025
1 parent a9074ea commit db876ea
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 639 deletions.
825 changes: 197 additions & 628 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "http://tomasz.janczuk.org",
"twitter": "tjanczuk"
},
"version": "23.1.4",
"version": "23.1.5",
"description": "Edge.js: run .NET and Node.js in-process on Windows, Mac OS, and Linux",
"tags": [
"owin",
Expand Down Expand Up @@ -40,16 +40,16 @@
"license": "MIT",
"dependencies": {
"edge-cs": "npm:@agracio/edge-cs@^1.3.7",
"nan": "^2.22.0"
"nan": "^2.22.2"
},
"devDependencies": {
"follow-redirects": "^1.15.9",
"junit-report-merger": "7.0.0",
"mocha": "11.0.1",
"junit-report-merger": "7.0.1",
"mocha": "11.1.0",
"mocha-junit-reporter": "^2.2.1",
"mocha-multi-reporters": "^1.5.1",
"mochawesome": "^7.1.3",
"mochawesome-merge": "^4.3.0",
"mochawesome-merge": "^5.0.0",
"mochawesome-report-generator": "^6.2.0"
},
"homepage": "https://github.com/agracio/edge-js",
Expand Down
23 changes: 22 additions & 1 deletion src/double/Edge.js/dotnetcore/coreclrembedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using System.Collections;
using System.Threading.Tasks;
using System.IO;
using System.Numerics;
using System.Security.Policy;
using Microsoft.Extensions.DependencyModel;

// ReSharper disable InconsistentNaming
Expand Down Expand Up @@ -1005,6 +1007,7 @@ public static void FreeMarshalData(IntPtr marshalData, int v8Type)
{
case V8Type.String:
case V8Type.Int32:
case V8Type.UInt32:
case V8Type.Boolean:
case V8Type.Number:
case V8Type.Date:
Expand Down Expand Up @@ -1138,7 +1141,7 @@ public static IntPtr MarshalCLRToV8(object clrObject, out V8Type v8Type)
return Marshal.StringToCoTaskMemUTF8(clrObject.ToString());
}

else if (clrObject is short)
else if (clrObject is short || clrObject is ushort)
{
v8Type = V8Type.Int32;
IntPtr memoryLocation = Marshal.AllocCoTaskMem(sizeof (int));
Expand All @@ -1155,6 +1158,15 @@ public static IntPtr MarshalCLRToV8(object clrObject, out V8Type v8Type)
Marshal.WriteInt32(memoryLocation, (int) clrObject);
return memoryLocation;
}

else if (clrObject is uint)
{
v8Type = V8Type.Number;
IntPtr memoryLocation = Marshal.AllocCoTaskMem(sizeof (uint));

WriteDouble(memoryLocation, Convert.ToDouble(BigInteger.Parse(clrObject.ToString()).ToString()));
return memoryLocation;
}

else if (clrObject is long)
{
Expand All @@ -1164,7 +1176,16 @@ public static IntPtr MarshalCLRToV8(object clrObject, out V8Type v8Type)
WriteDouble(memoryLocation, Convert.ToDouble((long) clrObject));
return memoryLocation;
}

else if (clrObject is ulong)
{
v8Type = V8Type.Number;
IntPtr memoryLocation = Marshal.AllocCoTaskMem(sizeof (double));

WriteDouble(memoryLocation, Convert.ToDouble((ulong) clrObject));
return memoryLocation;
}

else if (clrObject is double)
{
v8Type = V8Type.Number;
Expand Down
9 changes: 8 additions & 1 deletion test/102_node2net.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ describe('async call from node.js to .net', function () {
g: [ 1, 'fooåäö' ],
h: { a: 'fooåäö', b: 12 },
i: function (payload, callback) { },
j: new Date(Date.UTC(2013, 07, 30))
j: new Date(Date.UTC(2013, 07, 30)),
k: 65535,
l: 4294967295,
m: 18446744073709551615,

};
func(payload, function (error, result) {
assert.ifError(error);
Expand Down Expand Up @@ -71,6 +75,9 @@ describe('async call from node.js to .net', function () {
assert.equal(typeof result.i, 'function');
assert.equal(typeof result.j, 'object');
assert.ok(result.j.valueOf() === Date.UTC(2013, 07, 30));
assert.equal(result.k, 65535);
assert.equal(result.l, 4294967295);
assert.equal(result.m, 18446744073709551615);
done();
});
});
Expand Down
10 changes: 9 additions & 1 deletion test/103_net2node.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ describe('async call from .net to node.js', function () {
assert.equal(typeof result.i, 'function');
assert.equal(typeof result.j, 'object');
assert.ok(result.j.valueOf() === Date.UTC(2013, 07, 30));
assert.equal(result.k, 65535);
assert.equal(result.l, 4294967295);
assert.equal(result.m, 18446744073709551615);


callback(null, 'yes');
}
Expand Down Expand Up @@ -111,7 +115,11 @@ describe('async call from .net to node.js', function () {
f: Buffer.alloc(10),
g: [ 1, 'fooåäö' ],
h: { a: 'fooåäö', b: 12 },
j: new Date(Date.UTC(2013, 07, 30))
j: new Date(Date.UTC(2013, 07, 30)),
k: 65535,
l: 4294967295,
m: 18446744073709551615,

};
callback(null, payload);
}
Expand Down
5 changes: 4 additions & 1 deletion test/105_node2net_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe('sync call from node.js to .net', function () {
g: [ 1, 'fooåäö' ],
h: { a: 'fooåäö', b: 12 },
i: function (payload, callback) { },
j: new Date(Date.UTC(2013,07,30))
j: new Date(Date.UTC(2013,07,30)),
k: 65535,
l: 4294967295,
m: 18446744073709551615,
};
var result = func(payload, true);
assert.equal(result, 'yes');
Expand Down
8 changes: 7 additions & 1 deletion test/106_node2net_symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ describe('node.js to .net dll from path with asian chracters', function () {
g: [ 1, 'fooåäö' ],
h: { a: 'fooåäö', b: 12 },
i: function (payload, callback) { },
j: new Date(Date.UTC(2013, 07, 30))
j: new Date(Date.UTC(2013, 07, 30)),
k: 65535,
l: 4294967295,
m: 18446744073709551615,
};
func(payload, function (error, result) {
assert.ifError(error);
Expand Down Expand Up @@ -80,6 +83,9 @@ describe('node.js to .net dll from path with asian chracters', function () {
assert.equal(typeof result.i, 'function');
assert.equal(typeof result.j, 'object');
assert.ok(result.j.valueOf() === Date.UTC(2013, 07, 30));
assert.equal(result.k, 65535);
assert.equal(result.l, 4294967295);
assert.equal(result.m, 18446744073709551615);
done();
});
});
Expand Down
25 changes: 24 additions & 1 deletion test/tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.Xml;
#if NET6_0
#if NETCOREAPP
using Newtonsoft.Json;
using System.Reflection;
using Microsoft.Extensions.DependencyModel;
using System.Linq;
using System.Net;
// ReSharper disable UnusedMember.Global
// ReSharper disable CheckNamespace
#endif

#pragma warning disable 1998
Expand Down Expand Up @@ -73,6 +74,13 @@ string ValidateMarshalNodeJsToNet(dynamic input, bool expectFunction)
if (i == null) throw new Exception("i is not a Func<object,Task<object>>");
}
if ((DateTime)data["j"] != new DateTime(2013, 08, 30)) throw new Exception("j is not DateTime(2013,08,30)");

int k = (int)data["k"];
if (k != 65535) throw new Exception("k is not 65535");
UInt32 l = (UInt32)data["l"];
if (l != 4294967295) throw new Exception("l is not 4294967295");
double m = (double)data["m"];
if (m != 18446744073709551615) throw new Exception("m is not 18446744073709551615");
}
catch (Exception e)
{
Expand Down Expand Up @@ -106,6 +114,14 @@ string ValidateMarshalNodeJsToNet(dynamic input, bool expectFunction)
if (i == null) throw new Exception("dynamic i is not a Func<object,Task<object>>");
}
if ((DateTime)input.j != new DateTime(2013, 08, 30)) throw new Exception("dynamic j is not DateTime(2013,08,30)");

int k = input.k;
if (k != 65535) throw new Exception("k is not 65535");
UInt32 l = input.l;
if (l != 4294967295) throw new Exception("l is not 4294967295");
double m = input.m;
if (m != 18446744073709551615) throw new Exception("m is not 18446744073709551615");

}
catch (Exception e)
{
Expand Down Expand Up @@ -139,6 +155,9 @@ public Task<object> MarshalBack(dynamic input)
result.h = new { a = "fooåäö", b = 12 };
result.i = (Func<object,Task<object>>)(async (i) => { return i; });
result.j = new DateTime(2013, 08, 30);
result.k = ushort.MaxValue;
result.l = uint.MaxValue;;
result.m = ulong.MaxValue;;

return Task.FromResult<object>(result);
}
Expand Down Expand Up @@ -188,6 +207,10 @@ public async Task<object> MarshalInFromNet(dynamic input)
payload.h = new { a = "fooåäö", b = 12 };
payload.i = (Func<object,Task<object>>)(async (i) => { return i; });
payload.j = new DateTime(2013, 08, 30);
payload.k = ushort.MaxValue;
payload.l = uint.MaxValue;;
payload.m = ulong.MaxValue;;


var result = await input.hello(payload);
return result;
Expand Down

0 comments on commit db876ea

Please sign in to comment.