@crossbind/core-embind-jsi 2.0.0-beta.60 → 2.0.0-beta.62
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/cpp/src/crossbind/direct_reads.h +30 -0
- package/cpp/src/emscripten/bind.cpp +129 -175
- package/cpp/src/emscripten/bind.h +45 -45
- package/cpp/src/emscripten/val.h +57 -146
- package/cpp/src/emscripten/wire.h +145 -47
- package/js/embind.js +124 -756
- package/package.json +9 -1
|
@@ -1183,7 +1183,7 @@ public:
|
|
|
1183
1183
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_constructor"),
|
|
1184
1184
|
1,
|
|
1185
1185
|
[destructor](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1186
|
-
ClassType* t = reinterpret_cast<ClassType*>(args[0]
|
|
1186
|
+
ClassType* t = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[0]));
|
|
1187
1187
|
destructor(t);
|
|
1188
1188
|
return facebook::jsi::Value::undefined();
|
|
1189
1189
|
});
|
|
@@ -1216,7 +1216,7 @@ public:
|
|
|
1216
1216
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_array_element_gter1"),
|
|
1217
1217
|
2,
|
|
1218
1218
|
[getter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1219
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1219
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1220
1220
|
return getter(field, *t2);
|
|
1221
1221
|
});
|
|
1222
1222
|
|
|
@@ -1225,7 +1225,7 @@ public:
|
|
|
1225
1225
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_array_element_ster1"),
|
|
1226
1226
|
3,
|
|
1227
1227
|
[setter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1228
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1228
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1229
1229
|
setter(field, *t2, args[2]);
|
|
1230
1230
|
return facebook::jsi::Value::undefined();
|
|
1231
1231
|
});
|
|
@@ -1257,8 +1257,8 @@ public:
|
|
|
1257
1257
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_array_element_gter2"),
|
|
1258
1258
|
2,
|
|
1259
1259
|
[g, getter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1260
|
-
Getter* t = reinterpret_cast<Getter*>(args[0]
|
|
1261
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1260
|
+
Getter* t = reinterpret_cast<Getter*>(internal::bigIntUint64(rt, args[0]));
|
|
1261
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1262
1262
|
return g(getter, *t2);
|
|
1263
1263
|
});
|
|
1264
1264
|
|
|
@@ -1267,8 +1267,8 @@ public:
|
|
|
1267
1267
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_array_element_ster2"),
|
|
1268
1268
|
3,
|
|
1269
1269
|
[s](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1270
|
-
Setter* t = reinterpret_cast<Setter*>(args[0]
|
|
1271
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1270
|
+
Setter* t = reinterpret_cast<Setter*>(internal::bigIntUint64(rt, args[0]));
|
|
1271
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1272
1272
|
s(*t, *t2, args[2]);
|
|
1273
1273
|
return facebook::jsi::Value::undefined();
|
|
1274
1274
|
});
|
|
@@ -1299,8 +1299,8 @@ public:
|
|
|
1299
1299
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_array_element_gter3"),
|
|
1300
1300
|
2,
|
|
1301
1301
|
[getter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1302
|
-
int t1 = static_cast<int>(args[0]
|
|
1303
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1302
|
+
int t1 = static_cast<int>(internal::bigIntUint64(rt, args[0]));
|
|
1303
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1304
1304
|
return getter(t1, *t2);
|
|
1305
1305
|
});
|
|
1306
1306
|
|
|
@@ -1310,8 +1310,8 @@ public:
|
|
|
1310
1310
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_array_element_ster3"),
|
|
1311
1311
|
3,
|
|
1312
1312
|
[setter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1313
|
-
int t1 = static_cast<int>(args[0]
|
|
1314
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1313
|
+
int t1 = static_cast<int>(internal::bigIntUint64(rt, args[0]));
|
|
1314
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1315
1315
|
setter(t1, *t2, args[2]);
|
|
1316
1316
|
return facebook::jsi::Value::undefined();
|
|
1317
1317
|
});
|
|
@@ -1359,7 +1359,7 @@ public:
|
|
|
1359
1359
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_constructor"),
|
|
1360
1360
|
1,
|
|
1361
1361
|
[dtor](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1362
|
-
ClassType* t = reinterpret_cast<ClassType*>(args[0]
|
|
1362
|
+
ClassType* t = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[0]));
|
|
1363
1363
|
dtor(t);
|
|
1364
1364
|
return facebook::jsi::Value::undefined();
|
|
1365
1365
|
});
|
|
@@ -1392,7 +1392,7 @@ public:
|
|
|
1392
1392
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_gter1"),
|
|
1393
1393
|
2,
|
|
1394
1394
|
[getter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1395
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1395
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1396
1396
|
return getter(field, *t2);
|
|
1397
1397
|
});
|
|
1398
1398
|
|
|
@@ -1401,7 +1401,7 @@ public:
|
|
|
1401
1401
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_ster1"),
|
|
1402
1402
|
3,
|
|
1403
1403
|
[setter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1404
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1404
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1405
1405
|
setter(field, *t2, args[2]);
|
|
1406
1406
|
return facebook::jsi::Value::undefined();
|
|
1407
1407
|
});
|
|
@@ -1439,8 +1439,8 @@ public:
|
|
|
1439
1439
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_gter1"),
|
|
1440
1440
|
2,
|
|
1441
1441
|
[getter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1442
|
-
const MemberPointer* t1 = reinterpret_cast<MemberPointer*>(args[0]
|
|
1443
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1442
|
+
const MemberPointer* t1 = reinterpret_cast<MemberPointer*>(internal::bigIntUint64(rt, args[0]));
|
|
1443
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1444
1444
|
return getter(*t1, *t2);
|
|
1445
1445
|
});
|
|
1446
1446
|
|
|
@@ -1449,8 +1449,8 @@ public:
|
|
|
1449
1449
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_ster1"),
|
|
1450
1450
|
3,
|
|
1451
1451
|
[setter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1452
|
-
const MemberPointer* t1 = reinterpret_cast<MemberPointer*>(args[0]
|
|
1453
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1452
|
+
const MemberPointer* t1 = reinterpret_cast<MemberPointer*>(internal::bigIntUint64(rt, args[0]));
|
|
1453
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1454
1454
|
setter(*t1, *t2, args[2]);
|
|
1455
1455
|
return facebook::jsi::Value::undefined();
|
|
1456
1456
|
});
|
|
@@ -1487,8 +1487,8 @@ public:
|
|
|
1487
1487
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_gter2"),
|
|
1488
1488
|
2,
|
|
1489
1489
|
[g, getter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1490
|
-
Getter* t = reinterpret_cast<Getter*>(args[0]
|
|
1491
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1490
|
+
Getter* t = reinterpret_cast<Getter*>(internal::bigIntUint64(rt, args[0]));
|
|
1491
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1492
1492
|
return g(getter, *t2);
|
|
1493
1493
|
});
|
|
1494
1494
|
|
|
@@ -1497,8 +1497,8 @@ public:
|
|
|
1497
1497
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_ster2"),
|
|
1498
1498
|
3,
|
|
1499
1499
|
[s](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1500
|
-
Setter* t = reinterpret_cast<Setter*>(args[0]
|
|
1501
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1500
|
+
Setter* t = reinterpret_cast<Setter*>(internal::bigIntUint64(rt, args[0]));
|
|
1501
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1502
1502
|
s(*t, *t2, args[2]);
|
|
1503
1503
|
return facebook::jsi::Value::undefined();
|
|
1504
1504
|
});
|
|
@@ -1531,8 +1531,8 @@ public:
|
|
|
1531
1531
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_gter3"),
|
|
1532
1532
|
2,
|
|
1533
1533
|
[getter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1534
|
-
int t1 = static_cast<int>(args[0]
|
|
1535
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1534
|
+
int t1 = static_cast<int>(internal::bigIntUint64(rt, args[0]));
|
|
1535
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1536
1536
|
return getter(t1, *t2);
|
|
1537
1537
|
});
|
|
1538
1538
|
|
|
@@ -1541,8 +1541,8 @@ public:
|
|
|
1541
1541
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, "value_object_element_ster3"),
|
|
1542
1542
|
3,
|
|
1543
1543
|
[setter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
1544
|
-
int t1 = static_cast<int>(args[0]
|
|
1545
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
1544
|
+
int t1 = static_cast<int>(internal::bigIntUint64(rt, args[0]));
|
|
1545
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
1546
1546
|
setter(t1, *t2, args[2]);
|
|
1547
1547
|
return facebook::jsi::Value::undefined();
|
|
1548
1548
|
});
|
|
@@ -2159,7 +2159,7 @@ public:
|
|
|
2159
2159
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"__getActualType"),
|
|
2160
2160
|
1,
|
|
2161
2161
|
[_getActualType](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2162
|
-
auto returnValue = _getActualType(reinterpret_cast<ClassType*>(args[0]
|
|
2162
|
+
auto returnValue = _getActualType(reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[0])));
|
|
2163
2163
|
return facebook::jsi::BigInt::fromUint64(rt, reinterpret_cast<uint64_t>(returnValue));
|
|
2164
2164
|
});
|
|
2165
2165
|
|
|
@@ -2168,7 +2168,7 @@ public:
|
|
|
2168
2168
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_upcast"),
|
|
2169
2169
|
1,
|
|
2170
2170
|
[upcast](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2171
|
-
ClassType* t = reinterpret_cast<ClassType*>(args[0]
|
|
2171
|
+
ClassType* t = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[0]));
|
|
2172
2172
|
BaseSpecifier* a = nullptr;
|
|
2173
2173
|
return dsadsa<ClassType, BaseSpecifier>(rt, t, a);
|
|
2174
2174
|
});
|
|
@@ -2178,7 +2178,7 @@ public:
|
|
|
2178
2178
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_downcast"),
|
|
2179
2179
|
1,
|
|
2180
2180
|
[downcast](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2181
|
-
ClassType* t = reinterpret_cast<ClassType*>(args[0]
|
|
2181
|
+
ClassType* t = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[0]));
|
|
2182
2182
|
BaseSpecifier* a = nullptr;
|
|
2183
2183
|
return downcastHelper<ClassType, BaseSpecifier>(rt, t, a);
|
|
2184
2184
|
});
|
|
@@ -2188,7 +2188,7 @@ public:
|
|
|
2188
2188
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_destructor"),
|
|
2189
2189
|
1,
|
|
2190
2190
|
[destructor](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2191
|
-
destructor(reinterpret_cast<ClassType*>(args[0]
|
|
2191
|
+
destructor(reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[0])));
|
|
2192
2192
|
return facebook::jsi::Value::undefined();
|
|
2193
2193
|
});
|
|
2194
2194
|
|
|
@@ -2227,7 +2227,7 @@ public:
|
|
|
2227
2227
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_get"),
|
|
2228
2228
|
1,
|
|
2229
2229
|
[get](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2230
|
-
uint64_t ptrNumber = args[0]
|
|
2230
|
+
uint64_t ptrNumber = internal::bigIntUint64(rt, args[0]);
|
|
2231
2231
|
auto b = *reinterpret_cast<PointerType*>(ptrNumber);
|
|
2232
2232
|
auto a = get(b);
|
|
2233
2233
|
return facebook::jsi::BigInt::fromUint64(rt, reinterpret_cast<uint64_t>(a));
|
|
@@ -2247,10 +2247,10 @@ public:
|
|
|
2247
2247
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_share"),
|
|
2248
2248
|
2,
|
|
2249
2249
|
[share](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2250
|
-
uint64_t pNumber = args[0]
|
|
2250
|
+
uint64_t pNumber = internal::bigIntUint64(rt, args[0]);
|
|
2251
2251
|
auto p = reinterpret_cast<PointeeType*>(pNumber);
|
|
2252
2252
|
// uint64_t vNumber = (uint64_t) args[1].getNumber();
|
|
2253
|
-
uint64_t vNumber = args[1]
|
|
2253
|
+
uint64_t vNumber = internal::bigIntUint64(rt, args[1]);
|
|
2254
2254
|
EM_VAL v = reinterpret_cast<EM_VAL>(vNumber);
|
|
2255
2255
|
auto a = share(p, v);
|
|
2256
2256
|
auto e = facebook::jsi::BigInt::fromUint64(rt, reinterpret_cast<uint64_t>(a));
|
|
@@ -2262,7 +2262,7 @@ public:
|
|
|
2262
2262
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(name)+"_destructor"),
|
|
2263
2263
|
1,
|
|
2264
2264
|
[destructor](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2265
|
-
uint64_t ptrNumber = args[0]
|
|
2265
|
+
uint64_t ptrNumber = internal::bigIntUint64(rt, args[0]);
|
|
2266
2266
|
auto b = reinterpret_cast<PointerType*>(ptrNumber);
|
|
2267
2267
|
destructor(b);
|
|
2268
2268
|
return facebook::jsi::Value::undefined();
|
|
@@ -2403,7 +2403,7 @@ public:
|
|
|
2403
2403
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(fieldName)+"_gter"),
|
|
2404
2404
|
2,
|
|
2405
2405
|
[getter, a](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2406
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
2406
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
2407
2407
|
return getter(a, *t2);
|
|
2408
2408
|
});
|
|
2409
2409
|
|
|
@@ -2441,8 +2441,8 @@ public:
|
|
|
2441
2441
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(fieldName)+"_gter"),
|
|
2442
2442
|
2,
|
|
2443
2443
|
[getter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2444
|
-
FieldType* t = reinterpret_cast<FieldType*>(args[0]
|
|
2445
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
2444
|
+
FieldType* t = reinterpret_cast<FieldType*>(internal::bigIntUint64(rt, args[0]));
|
|
2445
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
2446
2446
|
return getter(field, *t2);
|
|
2447
2447
|
});
|
|
2448
2448
|
|
|
@@ -2451,8 +2451,8 @@ public:
|
|
|
2451
2451
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(fieldName)+"_ster"),
|
|
2452
2452
|
3,
|
|
2453
2453
|
[setter, field](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2454
|
-
FieldType* t = reinterpret_cast<FieldType*>(args[0]
|
|
2455
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
2454
|
+
FieldType* t = reinterpret_cast<FieldType*>(internal::bigIntUint64(rt, args[0]));
|
|
2455
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
2456
2456
|
setter(field, *t2, args[2]);
|
|
2457
2457
|
return facebook::jsi::Value::undefined();
|
|
2458
2458
|
});
|
|
@@ -2487,8 +2487,8 @@ public:
|
|
|
2487
2487
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(fieldName) + "_gter"),
|
|
2488
2488
|
2,
|
|
2489
2489
|
[gter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2490
|
-
Getter* t = reinterpret_cast<Getter*>(args[0]
|
|
2491
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
2490
|
+
Getter* t = reinterpret_cast<Getter*>(internal::bigIntUint64(rt, args[0]));
|
|
2491
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
2492
2492
|
return gter(*t, *t2);
|
|
2493
2493
|
});
|
|
2494
2494
|
|
|
@@ -2536,8 +2536,8 @@ public:
|
|
|
2536
2536
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(fieldName)+"_gter"),
|
|
2537
2537
|
2,
|
|
2538
2538
|
[gter](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2539
|
-
Getter* t = reinterpret_cast<Getter*>(args[0]
|
|
2540
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
2539
|
+
Getter* t = reinterpret_cast<Getter*>(internal::bigIntUint64(rt, args[0]));
|
|
2540
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
2541
2541
|
return gter(*t, *t2);
|
|
2542
2542
|
});
|
|
2543
2543
|
|
|
@@ -2546,8 +2546,8 @@ public:
|
|
|
2546
2546
|
facebook::jsi::PropNameID::forAscii(*jsRuntime, std::string(fieldName)+"_ster"),
|
|
2547
2547
|
3,
|
|
2548
2548
|
[ster](facebook::jsi::Runtime& rt, const facebook::jsi::Value& thisVal, const facebook::jsi::Value* args, size_t count) {
|
|
2549
|
-
Setter* t = reinterpret_cast<Setter*>(args[0]
|
|
2550
|
-
ClassType* t2 = reinterpret_cast<ClassType*>(args[1]
|
|
2549
|
+
Setter* t = reinterpret_cast<Setter*>(internal::bigIntUint64(rt, args[0]));
|
|
2550
|
+
ClassType* t2 = reinterpret_cast<ClassType*>(internal::bigIntUint64(rt, args[1]));
|
|
2551
2551
|
ster(*t, *t2, args[2]);
|
|
2552
2552
|
return facebook::jsi::Value::undefined();
|
|
2553
2553
|
});
|
package/cpp/src/emscripten/val.h
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
#include <climits>
|
|
18
18
|
#include "./wire.h"
|
|
19
19
|
#include <cstdint> // uintptr_t
|
|
20
|
+
#include <stdexcept>
|
|
20
21
|
#include <vector>
|
|
21
22
|
|
|
22
23
|
// #include <android/log.h>
|
|
@@ -48,15 +49,14 @@ enum {
|
|
|
48
49
|
_EMVAL_FALSE = 4
|
|
49
50
|
};
|
|
50
51
|
|
|
51
|
-
typedef struct _EM_DESTRUCTORS* EM_DESTRUCTORS;
|
|
52
52
|
typedef struct _EM_METHOD_CALLER* EM_METHOD_CALLER;
|
|
53
53
|
typedef facebook::jsi::Value EM_GENERIC_WIRE_TYPE;
|
|
54
|
-
typedef const void* EM_VAR_ARGS;
|
|
55
54
|
|
|
56
55
|
void _emval_incref(EM_VAL value);
|
|
57
56
|
void _emval_decref(EM_VAL value);
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
// Runs the destructors the latest _emval_as or _emval_call_method conversion queued.
|
|
59
|
+
void _emval_run_destructors();
|
|
60
60
|
|
|
61
61
|
EM_VAL _emval_new_array();
|
|
62
62
|
EM_VAL _emval_new_array_from_memory_view(EM_VAL mv);
|
|
@@ -65,19 +65,19 @@ EM_VAL _emval_new_cstring(const char*);
|
|
|
65
65
|
EM_VAL _emval_new_u8string(const char*);
|
|
66
66
|
EM_VAL _emval_new_u16string(const char16_t*);
|
|
67
67
|
|
|
68
|
-
EM_VAL _emval_take_value(TYPEID type,
|
|
68
|
+
EM_VAL _emval_take_value(TYPEID type, const facebook::jsi::Value& value);
|
|
69
69
|
|
|
70
70
|
EM_VAL _emval_new(
|
|
71
71
|
EM_VAL value,
|
|
72
72
|
unsigned argCount,
|
|
73
73
|
const TYPEID argTypes[],
|
|
74
|
-
|
|
74
|
+
facebook::jsi::Value* argv);
|
|
75
75
|
|
|
76
76
|
EM_VAL _emval_get_global(const char* name);
|
|
77
77
|
EM_VAL _emval_get_module_property(const char* name);
|
|
78
78
|
EM_VAL _emval_get_property(EM_VAL object, EM_VAL key);
|
|
79
79
|
void _emval_set_property(EM_VAL object, EM_VAL key, EM_VAL value);
|
|
80
|
-
EM_GENERIC_WIRE_TYPE _emval_as(EM_VAL value, TYPEID returnType
|
|
80
|
+
EM_GENERIC_WIRE_TYPE _emval_as(EM_VAL value, TYPEID returnType);
|
|
81
81
|
int64_t _emval_as_int64(EM_VAL value, TYPEID returnType);
|
|
82
82
|
uint64_t _emval_as_uint64(EM_VAL value, TYPEID returnType);
|
|
83
83
|
|
|
@@ -91,7 +91,7 @@ EM_VAL _emval_call(
|
|
|
91
91
|
EM_VAL value,
|
|
92
92
|
unsigned argCount,
|
|
93
93
|
const TYPEID argTypes[],
|
|
94
|
-
|
|
94
|
+
facebook::jsi::Value* argv);
|
|
95
95
|
|
|
96
96
|
// DO NOT call this more than once per signature. It will
|
|
97
97
|
// leak generated function objects!
|
|
@@ -102,13 +102,14 @@ EM_GENERIC_WIRE_TYPE _emval_call_method(
|
|
|
102
102
|
EM_METHOD_CALLER caller,
|
|
103
103
|
EM_VAL handle,
|
|
104
104
|
const char* methodName,
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
unsigned argCount,
|
|
106
|
+
facebook::jsi::Value* argv);
|
|
107
107
|
void _emval_call_void_method(
|
|
108
108
|
EM_METHOD_CALLER caller,
|
|
109
109
|
EM_VAL handle,
|
|
110
110
|
const char* methodName,
|
|
111
|
-
|
|
111
|
+
unsigned argCount,
|
|
112
|
+
facebook::jsi::Value* argv);
|
|
112
113
|
EM_VAL _emval_typeof(EM_VAL value);
|
|
113
114
|
bool _emval_instanceof(EM_VAL object, EM_VAL constructor);
|
|
114
115
|
bool _emval_is_number(EM_VAL object);
|
|
@@ -146,20 +147,17 @@ struct Signature {
|
|
|
146
147
|
}
|
|
147
148
|
};
|
|
148
149
|
|
|
150
|
+
// Scoped to one conversion: every _emval_as / _emval_call_method that returns queues exactly one
|
|
151
|
+
// destructor list in JS, and this runs it once the C++ side has read the value.
|
|
149
152
|
struct DestructorsRunner {
|
|
150
153
|
public:
|
|
151
|
-
|
|
152
|
-
: destructors(d)
|
|
153
|
-
{}
|
|
154
|
+
DestructorsRunner() = default;
|
|
154
155
|
~DestructorsRunner() {
|
|
155
|
-
_emval_run_destructors(
|
|
156
|
+
_emval_run_destructors();
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
DestructorsRunner(const DestructorsRunner&) = delete;
|
|
159
160
|
void operator=(const DestructorsRunner&) = delete;
|
|
160
|
-
|
|
161
|
-
private:
|
|
162
|
-
EM_DESTRUCTORS destructors;
|
|
163
161
|
};
|
|
164
162
|
|
|
165
163
|
template<typename WireType>
|
|
@@ -178,115 +176,27 @@ struct GenericWireTypeConverter<Pointee*> {
|
|
|
178
176
|
|
|
179
177
|
template<typename T>
|
|
180
178
|
T fromGenericWireType(facebook::jsi::Value& g) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
struct PackSize;
|
|
191
|
-
|
|
192
|
-
template<>
|
|
193
|
-
struct PackSize<> {
|
|
194
|
-
static constexpr size_t value = 0;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
template<typename Arg, typename... Args>
|
|
198
|
-
struct PackSize<Arg, Args...> {
|
|
199
|
-
static constexpr size_t value = (sizeof(typename BindingType<Arg>::WireType) + 7) / 8 + PackSize<Args...>::value;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
union GenericWireType {
|
|
203
|
-
union {
|
|
204
|
-
unsigned u;
|
|
205
|
-
float f;
|
|
206
|
-
// Use uint32_t for pointer values. This limits us, for now, to 32-bit
|
|
207
|
-
// address ranges even on wasm64. This is enforced by assertions below.
|
|
208
|
-
// TODO(sbc): Allow full 64-bit address range here under wasm64, most
|
|
209
|
-
// likely by increasing the size of GenericWireType on wasm64.
|
|
210
|
-
uint32_t p;
|
|
211
|
-
} w[2];
|
|
212
|
-
double d;
|
|
213
|
-
uint64_t u;
|
|
214
|
-
};
|
|
215
|
-
static_assert(sizeof(GenericWireType) == 8, "GenericWireType must be 8 bytes");
|
|
216
|
-
static_assert(alignof(GenericWireType) == 8, "GenericWireType must be 8-byte-aligned");
|
|
217
|
-
|
|
218
|
-
inline void writeGenericWireType(GenericWireType*& cursor, float wt) {
|
|
219
|
-
cursor->w[0].f = wt;
|
|
220
|
-
++cursor;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
inline void writeGenericWireType(GenericWireType*& cursor, double wt) {
|
|
224
|
-
cursor->d = wt;
|
|
225
|
-
++cursor;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
inline void writeGenericWireType(GenericWireType*& cursor, int64_t wt) {
|
|
229
|
-
cursor->u = wt;
|
|
230
|
-
++cursor;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
inline void writeGenericWireType(GenericWireType*& cursor, uint64_t wt) {
|
|
234
|
-
cursor->u = wt;
|
|
235
|
-
++cursor;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
template<typename T>
|
|
239
|
-
void writeGenericWireType(GenericWireType*& cursor, T* wt) {
|
|
240
|
-
uint64_t short_ptr = reinterpret_cast<uint64_t>(wt);
|
|
241
|
-
// assert(short_ptr <= UINT32_MAX);
|
|
242
|
-
cursor->u = short_ptr;
|
|
243
|
-
++cursor;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
template<typename ElementType>
|
|
247
|
-
inline void writeGenericWireType(GenericWireType*& cursor, const memory_view<ElementType>& wt) {
|
|
248
|
-
uintptr_t short_ptr = reinterpret_cast<uintptr_t>(wt.data);
|
|
249
|
-
// This wire slot stores the data pointer in 32 bits (upstream wasm32 layout). On 64-bit
|
|
250
|
-
// native a pointer above 4 GiB cannot fit; abort loudly rather than silently truncating to
|
|
251
|
-
// a bogus address (release builds compile out the assert). Full 64-bit memory_view support
|
|
252
|
-
// needs a wider wire encoding on both the writer and the reader.
|
|
253
|
-
assert(short_ptr <= UINT32_MAX);
|
|
254
|
-
if (short_ptr > UINT32_MAX) {
|
|
255
|
-
abort();
|
|
256
|
-
}
|
|
257
|
-
cursor->w[0].u = wt.size;
|
|
258
|
-
cursor->w[1].p = static_cast<uint32_t>(short_ptr);
|
|
259
|
-
++cursor;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
template<typename T>
|
|
263
|
-
void writeGenericWireType(GenericWireType*& cursor, T wt) {
|
|
264
|
-
cursor->w[0].u = static_cast<unsigned>(wt);
|
|
265
|
-
++cursor;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
inline void writeGenericWireTypes(GenericWireType*&) {
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
template<typename First, typename... Rest>
|
|
272
|
-
EMSCRIPTEN_ALWAYS_INLINE void writeGenericWireTypes(GenericWireType*& cursor, First&& first, Rest&&... rest) {
|
|
273
|
-
writeGenericWireType(cursor, BindingType<First>::toWireType(std::forward<First>(first)));
|
|
274
|
-
writeGenericWireTypes(cursor, std::forward<Rest>(rest)...);
|
|
179
|
+
if constexpr (std::is_same<T, std::string>::value) {
|
|
180
|
+
return g.asString(*jsRuntime).utf8(*jsRuntime);
|
|
181
|
+
} else if constexpr (std::is_same<T, facebook::jsi::Value>::value) {
|
|
182
|
+
return std::move(g);
|
|
183
|
+
} else {
|
|
184
|
+
typedef typename BindingType<T>::WireType WireType;
|
|
185
|
+
WireType wt = GenericWireTypeConverter<WireType>::from(g);
|
|
186
|
+
return BindingType<T>::fromWireType(wt);
|
|
187
|
+
}
|
|
275
188
|
}
|
|
276
189
|
|
|
190
|
+
// Arguments cross as the values embind's JS types accept (toWireType2), the same way bound
|
|
191
|
+
// functions return them, never as bytes JS would have to read out of native memory.
|
|
192
|
+
// jsi::Value has no copy constructor: each toWireType2 prvalue initializes its element directly,
|
|
193
|
+
// so routing one through a named const Value first would stop this from compiling.
|
|
277
194
|
template<typename... Args>
|
|
278
|
-
struct
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
writeGenericWireTypes(cursor, std::forward<Args>(args)...);
|
|
282
|
-
}
|
|
195
|
+
struct WireValues {
|
|
196
|
+
explicit WireValues(Args&&... args)
|
|
197
|
+
: values{{BindingType<Args>::toWireType2(*jsRuntime, std::forward<Args>(args))...}} {}
|
|
283
198
|
|
|
284
|
-
|
|
285
|
-
return elements.data();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
private:
|
|
289
|
-
std::array<GenericWireType, PackSize<Args...>::value> elements;
|
|
199
|
+
std::array<facebook::jsi::Value, sizeof...(Args)> values;
|
|
290
200
|
};
|
|
291
201
|
|
|
292
202
|
template<typename ReturnType, typename... Args>
|
|
@@ -294,15 +204,14 @@ struct MethodCaller {
|
|
|
294
204
|
static ReturnType call(EM_VAL handle, const char* methodName, Args&&... args) {
|
|
295
205
|
auto caller = Signature<ReturnType, Args...>::get_method_caller();
|
|
296
206
|
|
|
297
|
-
|
|
298
|
-
EM_DESTRUCTORS destructors;
|
|
207
|
+
WireValues<Args...> argv(std::forward<Args>(args)...);
|
|
299
208
|
EM_GENERIC_WIRE_TYPE result = _emval_call_method(
|
|
300
209
|
caller,
|
|
301
210
|
handle,
|
|
302
211
|
methodName,
|
|
303
|
-
|
|
304
|
-
argv);
|
|
305
|
-
DestructorsRunner rd
|
|
212
|
+
sizeof...(Args),
|
|
213
|
+
argv.values.data());
|
|
214
|
+
DestructorsRunner rd;
|
|
306
215
|
return fromGenericWireType<ReturnType>(result);
|
|
307
216
|
}
|
|
308
217
|
};
|
|
@@ -312,12 +221,13 @@ struct MethodCaller<void, Args...> {
|
|
|
312
221
|
static void call(EM_VAL handle, const char* methodName, Args&&... args) {
|
|
313
222
|
auto caller = Signature<void, Args...>::get_method_caller();
|
|
314
223
|
|
|
315
|
-
|
|
224
|
+
WireValues<Args...> argv(std::forward<Args>(args)...);
|
|
316
225
|
_emval_call_void_method(
|
|
317
226
|
caller,
|
|
318
227
|
handle,
|
|
319
228
|
methodName,
|
|
320
|
-
|
|
229
|
+
sizeof...(Args),
|
|
230
|
+
argv.values.data());
|
|
321
231
|
}
|
|
322
232
|
};
|
|
323
233
|
|
|
@@ -410,9 +320,9 @@ public:
|
|
|
410
320
|
explicit val(T&& value) {
|
|
411
321
|
using namespace internal;
|
|
412
322
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
323
|
+
handle = _emval_take_value(
|
|
324
|
+
internal::TypeID<T>::get(),
|
|
325
|
+
BindingType<T>::toWireType2(*jsRuntime, std::forward<T>(value)));
|
|
416
326
|
}
|
|
417
327
|
|
|
418
328
|
val() : handle(EM_VAL(internal::_EMVAL_UNDEFINED)) {}
|
|
@@ -555,15 +465,10 @@ public:
|
|
|
555
465
|
T as(Policies...) const {
|
|
556
466
|
using namespace internal;
|
|
557
467
|
|
|
558
|
-
typedef BindingType<T> BT;
|
|
559
468
|
typename WithPolicies<Policies...>::template ArgTypeList<T> targetType;
|
|
560
469
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
handle,
|
|
564
|
-
targetType.getTypes()[0],
|
|
565
|
-
&destructors);
|
|
566
|
-
DestructorsRunner dr(destructors);
|
|
470
|
+
EM_GENERIC_WIRE_TYPE result = _emval_as(handle, targetType.getTypes()[0]);
|
|
471
|
+
DestructorsRunner dr;
|
|
567
472
|
return fromGenericWireType<T>(result);
|
|
568
473
|
}
|
|
569
474
|
|
|
@@ -629,8 +534,8 @@ private:
|
|
|
629
534
|
using namespace internal;
|
|
630
535
|
|
|
631
536
|
WithPolicies<>::ArgTypeList<Args...> argList;
|
|
632
|
-
|
|
633
|
-
return val(impl(handle, argList.getCount(), argList.getTypes(), argv));
|
|
537
|
+
WireValues<Args...> argv(std::forward<Args>(args)...);
|
|
538
|
+
return val(impl(handle, argList.getCount(), argList.getTypes(), argv.values.data()));
|
|
634
539
|
}
|
|
635
540
|
|
|
636
541
|
template<typename T>
|
|
@@ -669,7 +574,7 @@ struct BindingType<val> {
|
|
|
669
574
|
static val fromWireType2(facebook::jsi::Runtime& rt, WireType2& v) {
|
|
670
575
|
// return val::undefined();
|
|
671
576
|
// return val::take_ownership(reinterpret_cast<EM_VAL>((int) v.getNumber()));
|
|
672
|
-
return val::take_ownership(reinterpret_cast<EM_VAL>(
|
|
577
|
+
return val::take_ownership(reinterpret_cast<EM_VAL>(bigIntUint64(rt, v)));
|
|
673
578
|
}
|
|
674
579
|
};
|
|
675
580
|
|
|
@@ -690,17 +595,23 @@ std::vector<T> vecFromJSArray(const val& v, Policies... policies) {
|
|
|
690
595
|
|
|
691
596
|
template <typename T>
|
|
692
597
|
std::vector<T> convertJSArrayToNumberVector(const val& v) {
|
|
693
|
-
|
|
598
|
+
// size_t is not a registered embind type on every 64-bit ABI; the length is a Number anyway.
|
|
599
|
+
const double l = v["length"].as<double>();
|
|
600
|
+
if (!(l >= 0 && l <= static_cast<double>(std::vector<T>().max_size()))) {
|
|
601
|
+
throw std::length_error("crossbind: the array length is not a valid size");
|
|
602
|
+
}
|
|
694
603
|
|
|
695
604
|
std::vector<T> rv;
|
|
696
|
-
rv.resize(l);
|
|
605
|
+
rv.resize(static_cast<size_t>(l));
|
|
697
606
|
|
|
698
607
|
// Copy the array into our vector through the use of typed arrays.
|
|
699
608
|
// It will try to convert each element through Number().
|
|
700
609
|
// See https://www.ecma-international.org/ecma-262/6.0/#sec-%typedarray%.prototype.set-array-offset
|
|
701
610
|
// and https://www.ecma-international.org/ecma-262/6.0/#sec-tonumber
|
|
702
|
-
|
|
703
|
-
|
|
611
|
+
// The typed array is JS-owned and copied out: one aliasing rv would need external memory.
|
|
612
|
+
val typedArray = val::global(internal::typedArrayNameOf<T>()).new_(l);
|
|
613
|
+
typedArray.call<void>("set", v);
|
|
614
|
+
internal::copyFromTypedArray(*jsRuntime, typedArray.as<facebook::jsi::Value>(), rv.data(), rv.size() * sizeof(T));
|
|
704
615
|
|
|
705
616
|
return rv;
|
|
706
617
|
}
|