@crossbind/core-embind-jsi 2.0.0-beta.63 → 2.0.0-beta.64
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/js/embind.js +24 -6
- package/package.json +1 -1
package/js/embind.js
CHANGED
|
@@ -2434,7 +2434,13 @@ var MIN_INT53 = -9007199254740992;
|
|
|
2434
2434
|
function bigintToI53Checked(num) {
|
|
2435
2435
|
return (num < MIN_INT53 || num > MAX_INT53) ? NaN : Number(num);
|
|
2436
2436
|
}
|
|
2437
|
+
// A value C++ returns by copy crosses through the converter `isReference` marks, though the handle it makes is
|
|
2438
|
+
// typed as a pointer to the object's own class: JavaScript owns that copy (ownHandle).
|
|
2437
2439
|
function RegisteredPointer_fromWireType(ptr) {
|
|
2440
|
+
var handle = handleFromWire.call(this, ptr);
|
|
2441
|
+
return this.isReference && handle ? ownHandle(handle) : handle;
|
|
2442
|
+
}
|
|
2443
|
+
function handleFromWire(ptr) {
|
|
2438
2444
|
//console.log('RegisteredPointer_fromWireType', ptr);
|
|
2439
2445
|
// ptr is a raw pointer (or a raw smartpointer)
|
|
2440
2446
|
// ptr = bigintToI53Checked(ptr);
|
|
@@ -2531,16 +2537,17 @@ function attachFinalizer(handle) {
|
|
|
2531
2537
|
// https://github.com/tc39/proposal-weakrefs), then attach finalizers
|
|
2532
2538
|
// for class handles. We check for the presence of FinalizationRegistry
|
|
2533
2539
|
// at run-time, not build-time.
|
|
2534
|
-
// A collected handle is released without the warning upstream prints under ASSERTIONS
|
|
2535
|
-
// does: JavaScript never has to call .delete() on what crossbind hands it.
|
|
2540
|
+
// A collected handle is released without the warning upstream prints under ASSERTIONS: it is freed by design.
|
|
2536
2541
|
finalizationRegistry = new FinalizationRegistry((info) => {
|
|
2537
2542
|
releaseClassHandle(info.$$);
|
|
2538
2543
|
});
|
|
2539
2544
|
attachFinalizer = (handle) => {
|
|
2540
2545
|
var $$ = handle.$$;
|
|
2541
2546
|
var hasSmartPtr = !!$$.smartPtr;
|
|
2542
|
-
|
|
2543
|
-
|
|
2547
|
+
// JavaScript owns an object behind a smart pointer, and one ownHandle marked on the count a handle shares with
|
|
2548
|
+
// its clones, as the wasm glue does after utils/embindObjectLifetime.js. A raw pointer stays its library's:
|
|
2549
|
+
// other code may expect the pointee to live.
|
|
2550
|
+
if (hasSmartPtr || $$.count.owned) {
|
|
2544
2551
|
finalizationRegistry.register(handle, { $$: $$ }, handle);
|
|
2545
2552
|
}
|
|
2546
2553
|
return handle;
|
|
@@ -2548,6 +2555,16 @@ function attachFinalizer(handle) {
|
|
|
2548
2555
|
detachFinalizer = (handle) => finalizationRegistry.unregister(handle);
|
|
2549
2556
|
return attachFinalizer(handle);
|
|
2550
2557
|
}
|
|
2558
|
+
// A copy embind made of a returned value and an object JavaScript constructed through a raw constructor (a vector,
|
|
2559
|
+
// a Rust class) are released as one behind a smart pointer is.
|
|
2560
|
+
function ownHandle(handle) {
|
|
2561
|
+
var $$ = handle.$$;
|
|
2562
|
+
if (!$$.smartPtr && !$$.count.owned) {
|
|
2563
|
+
$$.count.owned = true;
|
|
2564
|
+
if (finalizationRegistry) finalizationRegistry.register(handle, { $$: $$ }, handle);
|
|
2565
|
+
}
|
|
2566
|
+
return handle;
|
|
2567
|
+
}
|
|
2551
2568
|
function ClassHandle_clone() {
|
|
2552
2569
|
if (!this.$$.ptr) {
|
|
2553
2570
|
throwInstanceAlreadyDeleted(this);
|
|
@@ -2945,7 +2962,7 @@ function __embind_register_class(rawType,
|
|
|
2945
2962
|
if (undefined === body) {
|
|
2946
2963
|
throw new BindingError(`Tried to invoke ctor of ${name} with invalid number of parameters (${arguments.length}) - expected (${Object.keys(registeredClass.constructor_body).toString()}) parameters instead!`);
|
|
2947
2964
|
}
|
|
2948
|
-
return body.apply(this, arguments);
|
|
2965
|
+
return ownHandle(body.apply(this, arguments));
|
|
2949
2966
|
});
|
|
2950
2967
|
|
|
2951
2968
|
var instancePrototype = Object.create(basePrototype, {
|
|
@@ -4241,7 +4258,8 @@ function toArray(vector) {
|
|
|
4241
4258
|
return output;
|
|
4242
4259
|
}
|
|
4243
4260
|
|
|
4244
|
-
function toVector(
|
|
4261
|
+
function toVector(classOrName, array = []) {
|
|
4262
|
+
const VectorClass = typeof classOrName === 'string' ? Module[classOrName] : classOrName;
|
|
4245
4263
|
const vector = new VectorClass();
|
|
4246
4264
|
array.forEach((item) => {
|
|
4247
4265
|
vector.push_back(item);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossbind/core-embind-jsi",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.64",
|
|
4
4
|
"description": "The Embind JSI integration tool enables seamless C++ integration with React Native and Expo.",
|
|
5
5
|
"homepage": "https://github.com/crossbind/crossbind/tree/main/core/embind-jsi#readme",
|
|
6
6
|
"repository": {
|