@crossbind/port-gdal-standalone-napi 0.0.0-bootstrap.0 → 2.0.0-beta.63

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.
Files changed (179) hide show
  1. package/LICENSE +2593 -0
  2. package/README.md +16 -3
  3. package/dist/data/certs/cacert.pem +3480 -0
  4. package/dist/data/gdal/GDALLogoBW.svg +138 -0
  5. package/dist/data/gdal/GDALLogoColor.svg +126 -0
  6. package/dist/data/gdal/GDALLogoGS.svg +126 -0
  7. package/dist/data/gdal/LICENSE.TXT +467 -0
  8. package/dist/data/gdal/MM_m_idofic.csv +320 -0
  9. package/dist/data/gdal/cubewerx_extra.wkt +48 -0
  10. package/dist/data/gdal/default.rsc +0 -0
  11. package/dist/data/gdal/ecw_cs.wkt +1453 -0
  12. package/dist/data/gdal/eedaconf.json +23 -0
  13. package/dist/data/gdal/epsg.wkt +1 -0
  14. package/dist/data/gdal/esri_StatePlane_extra.wkt +631 -0
  15. package/dist/data/gdal/gdal_algorithm.schema.json +240 -0
  16. package/dist/data/gdal/gdalg.schema.json +36 -0
  17. package/dist/data/gdal/gdalicon.png +0 -0
  18. package/dist/data/gdal/gdalinfo_output.schema.json +390 -0
  19. package/dist/data/gdal/gdalmdiminfo_output.schema.json +393 -0
  20. package/dist/data/gdal/gdaltileindex.xsd +264 -0
  21. package/dist/data/gdal/gdalvrt.xsd +948 -0
  22. package/dist/data/gdal/gfs.xsd +246 -0
  23. package/dist/data/gdal/gml_registry.xml +117 -0
  24. package/dist/data/gdal/gml_registry.xsd +66 -0
  25. package/dist/data/gdal/grib2_center.csv +251 -0
  26. package/dist/data/gdal/grib2_process.csv +102 -0
  27. package/dist/data/gdal/grib2_subcenter.csv +63 -0
  28. package/dist/data/gdal/grib2_table_4_2_0_0.csv +261 -0
  29. package/dist/data/gdal/grib2_table_4_2_0_1.csv +261 -0
  30. package/dist/data/gdal/grib2_table_4_2_0_13.csv +261 -0
  31. package/dist/data/gdal/grib2_table_4_2_0_14.csv +261 -0
  32. package/dist/data/gdal/grib2_table_4_2_0_15.csv +261 -0
  33. package/dist/data/gdal/grib2_table_4_2_0_16.csv +261 -0
  34. package/dist/data/gdal/grib2_table_4_2_0_17.csv +261 -0
  35. package/dist/data/gdal/grib2_table_4_2_0_18.csv +261 -0
  36. package/dist/data/gdal/grib2_table_4_2_0_19.csv +261 -0
  37. package/dist/data/gdal/grib2_table_4_2_0_190.csv +261 -0
  38. package/dist/data/gdal/grib2_table_4_2_0_191.csv +261 -0
  39. package/dist/data/gdal/grib2_table_4_2_0_2.csv +261 -0
  40. package/dist/data/gdal/grib2_table_4_2_0_20.csv +261 -0
  41. package/dist/data/gdal/grib2_table_4_2_0_21.csv +261 -0
  42. package/dist/data/gdal/grib2_table_4_2_0_22.csv +261 -0
  43. package/dist/data/gdal/grib2_table_4_2_0_3.csv +261 -0
  44. package/dist/data/gdal/grib2_table_4_2_0_4.csv +261 -0
  45. package/dist/data/gdal/grib2_table_4_2_0_5.csv +261 -0
  46. package/dist/data/gdal/grib2_table_4_2_0_6.csv +261 -0
  47. package/dist/data/gdal/grib2_table_4_2_0_7.csv +261 -0
  48. package/dist/data/gdal/grib2_table_4_2_10_0.csv +261 -0
  49. package/dist/data/gdal/grib2_table_4_2_10_1.csv +261 -0
  50. package/dist/data/gdal/grib2_table_4_2_10_191.csv +261 -0
  51. package/dist/data/gdal/grib2_table_4_2_10_2.csv +261 -0
  52. package/dist/data/gdal/grib2_table_4_2_10_3.csv +261 -0
  53. package/dist/data/gdal/grib2_table_4_2_10_4.csv +261 -0
  54. package/dist/data/gdal/grib2_table_4_2_1_0.csv +261 -0
  55. package/dist/data/gdal/grib2_table_4_2_1_1.csv +261 -0
  56. package/dist/data/gdal/grib2_table_4_2_1_2.csv +261 -0
  57. package/dist/data/gdal/grib2_table_4_2_20_0.csv +261 -0
  58. package/dist/data/gdal/grib2_table_4_2_20_1.csv +261 -0
  59. package/dist/data/gdal/grib2_table_4_2_20_2.csv +261 -0
  60. package/dist/data/gdal/grib2_table_4_2_20_3.csv +261 -0
  61. package/dist/data/gdal/grib2_table_4_2_2_0.csv +261 -0
  62. package/dist/data/gdal/grib2_table_4_2_2_3.csv +261 -0
  63. package/dist/data/gdal/grib2_table_4_2_2_4.csv +261 -0
  64. package/dist/data/gdal/grib2_table_4_2_2_5.csv +261 -0
  65. package/dist/data/gdal/grib2_table_4_2_2_6.csv +261 -0
  66. package/dist/data/gdal/grib2_table_4_2_2_7.csv +261 -0
  67. package/dist/data/gdal/grib2_table_4_2_3_0.csv +261 -0
  68. package/dist/data/gdal/grib2_table_4_2_3_1.csv +261 -0
  69. package/dist/data/gdal/grib2_table_4_2_3_2.csv +243 -0
  70. package/dist/data/gdal/grib2_table_4_2_3_3.csv +261 -0
  71. package/dist/data/gdal/grib2_table_4_2_3_4.csv +261 -0
  72. package/dist/data/gdal/grib2_table_4_2_3_5.csv +261 -0
  73. package/dist/data/gdal/grib2_table_4_2_3_6.csv +261 -0
  74. package/dist/data/gdal/grib2_table_4_2_4_0.csv +261 -0
  75. package/dist/data/gdal/grib2_table_4_2_4_1.csv +261 -0
  76. package/dist/data/gdal/grib2_table_4_2_4_10.csv +261 -0
  77. package/dist/data/gdal/grib2_table_4_2_4_2.csv +261 -0
  78. package/dist/data/gdal/grib2_table_4_2_4_3.csv +261 -0
  79. package/dist/data/gdal/grib2_table_4_2_4_4.csv +261 -0
  80. package/dist/data/gdal/grib2_table_4_2_4_5.csv +261 -0
  81. package/dist/data/gdal/grib2_table_4_2_4_6.csv +261 -0
  82. package/dist/data/gdal/grib2_table_4_2_4_7.csv +261 -0
  83. package/dist/data/gdal/grib2_table_4_2_4_8.csv +261 -0
  84. package/dist/data/gdal/grib2_table_4_2_4_9.csv +261 -0
  85. package/dist/data/gdal/grib2_table_4_2_local_Canada.csv +5 -0
  86. package/dist/data/gdal/grib2_table_4_2_local_HPC.csv +2 -0
  87. package/dist/data/gdal/grib2_table_4_2_local_MRMS.csv +175 -0
  88. package/dist/data/gdal/grib2_table_4_2_local_NCEP.csv +401 -0
  89. package/dist/data/gdal/grib2_table_4_2_local_NDFD.csv +38 -0
  90. package/dist/data/gdal/grib2_table_4_2_local_index.csv +7 -0
  91. package/dist/data/gdal/grib2_table_4_5.csv +261 -0
  92. package/dist/data/gdal/grib2_table_versions.csv +3 -0
  93. package/dist/data/gdal/gt_datum.csv +229 -0
  94. package/dist/data/gdal/gt_ellips.csv +24 -0
  95. package/dist/data/gdal/header.dxf +1138 -0
  96. package/dist/data/gdal/inspire_cp_BasicPropertyUnit.gfs +57 -0
  97. package/dist/data/gdal/inspire_cp_CadastralBoundary.gfs +60 -0
  98. package/dist/data/gdal/inspire_cp_CadastralParcel.gfs +81 -0
  99. package/dist/data/gdal/inspire_cp_CadastralZoning.gfs +161 -0
  100. package/dist/data/gdal/jpfgdgml_AdmArea.gfs +59 -0
  101. package/dist/data/gdal/jpfgdgml_AdmBdry.gfs +49 -0
  102. package/dist/data/gdal/jpfgdgml_AdmPt.gfs +59 -0
  103. package/dist/data/gdal/jpfgdgml_BldA.gfs +54 -0
  104. package/dist/data/gdal/jpfgdgml_BldL.gfs +54 -0
  105. package/dist/data/gdal/jpfgdgml_Cntr.gfs +54 -0
  106. package/dist/data/gdal/jpfgdgml_CommBdry.gfs +49 -0
  107. package/dist/data/gdal/jpfgdgml_CommPt.gfs +59 -0
  108. package/dist/data/gdal/jpfgdgml_Cstline.gfs +54 -0
  109. package/dist/data/gdal/jpfgdgml_ElevPt.gfs +54 -0
  110. package/dist/data/gdal/jpfgdgml_GCP.gfs +94 -0
  111. package/dist/data/gdal/jpfgdgml_LeveeEdge.gfs +49 -0
  112. package/dist/data/gdal/jpfgdgml_RailCL.gfs +54 -0
  113. package/dist/data/gdal/jpfgdgml_RdASL.gfs +44 -0
  114. package/dist/data/gdal/jpfgdgml_RdArea.gfs +54 -0
  115. package/dist/data/gdal/jpfgdgml_RdCompt.gfs +59 -0
  116. package/dist/data/gdal/jpfgdgml_RdEdg.gfs +59 -0
  117. package/dist/data/gdal/jpfgdgml_RdMgtBdry.gfs +49 -0
  118. package/dist/data/gdal/jpfgdgml_RdSgmtA.gfs +59 -0
  119. package/dist/data/gdal/jpfgdgml_RvrMgtBdry.gfs +49 -0
  120. package/dist/data/gdal/jpfgdgml_SBAPt.gfs +49 -0
  121. package/dist/data/gdal/jpfgdgml_SBArea.gfs +54 -0
  122. package/dist/data/gdal/jpfgdgml_SBBdry.gfs +44 -0
  123. package/dist/data/gdal/jpfgdgml_WA.gfs +54 -0
  124. package/dist/data/gdal/jpfgdgml_WL.gfs +54 -0
  125. package/dist/data/gdal/jpfgdgml_WStrA.gfs +54 -0
  126. package/dist/data/gdal/jpfgdgml_WStrL.gfs +54 -0
  127. package/dist/data/gdal/leaflet_template.html +102 -0
  128. package/dist/data/gdal/nitf_spec.xml +3508 -0
  129. package/dist/data/gdal/nitf_spec.xsd +178 -0
  130. package/dist/data/gdal/ogr_fields_override.schema.json +278 -0
  131. package/dist/data/gdal/ogrinfo_output.schema.json +532 -0
  132. package/dist/data/gdal/ogrvrt.xsd +526 -0
  133. package/dist/data/gdal/osmconf.ini +134 -0
  134. package/dist/data/gdal/ozi_datum.csv +131 -0
  135. package/dist/data/gdal/ozi_ellips.csv +35 -0
  136. package/dist/data/gdal/pci_datum.txt +530 -0
  137. package/dist/data/gdal/pci_ellips.txt +129 -0
  138. package/dist/data/gdal/pdfcomposition.xsd +703 -0
  139. package/dist/data/gdal/plscenesconf.json +1985 -0
  140. package/dist/data/gdal/ruian_vf_ob_v1.gfs +1455 -0
  141. package/dist/data/gdal/ruian_vf_st_uvoh_v1.gfs +86 -0
  142. package/dist/data/gdal/ruian_vf_st_v1.gfs +1489 -0
  143. package/dist/data/gdal/ruian_vf_v1.gfs +2126 -0
  144. package/dist/data/gdal/s57agencies.csv +249 -0
  145. package/dist/data/gdal/s57attributes.csv +484 -0
  146. package/dist/data/gdal/s57expectedinput.csv +1008 -0
  147. package/dist/data/gdal/s57objectclasses.csv +287 -0
  148. package/dist/data/gdal/seed_2d.dgn +0 -0
  149. package/dist/data/gdal/seed_3d.dgn +0 -0
  150. package/dist/data/gdal/stateplane.csv +259 -0
  151. package/dist/data/gdal/template_tiles.mapml +26 -0
  152. package/dist/data/gdal/tms_LINZAntarticaMapTileGrid.json +190 -0
  153. package/dist/data/gdal/tms_MapML_APSTILE.json +268 -0
  154. package/dist/data/gdal/tms_MapML_CBMTILE.json +346 -0
  155. package/dist/data/gdal/tms_NZTM2000.json +243 -0
  156. package/dist/data/gdal/trailer.dxf +434 -0
  157. package/dist/data/gdal/vdv452.xml +349 -0
  158. package/dist/data/gdal/vdv452.xsd +45 -0
  159. package/dist/data/proj/CH +22 -0
  160. package/dist/data/proj/GL27 +23 -0
  161. package/dist/data/proj/ITRF2000 +24 -0
  162. package/dist/data/proj/ITRF2008 +94 -0
  163. package/dist/data/proj/ITRF2014 +55 -0
  164. package/dist/data/proj/ITRF2020 +91 -0
  165. package/dist/data/proj/deformation_model.schema.json +582 -0
  166. package/dist/data/proj/nad.lst +142 -0
  167. package/dist/data/proj/nad27 +810 -0
  168. package/dist/data/proj/nad83 +745 -0
  169. package/dist/data/proj/other.extra +53 -0
  170. package/dist/data/proj/proj.db +0 -0
  171. package/dist/data/proj/proj.ini +59 -0
  172. package/dist/data/proj/projjson.schema.json +1174 -0
  173. package/dist/data/proj/triangulation.schema.json +214 -0
  174. package/dist/data/proj/world +214 -0
  175. package/dist/gdal-standalone-napi.native.cjs +3884 -0
  176. package/dist/node/napi.d.mts +2644 -0
  177. package/dist/node/napi.mjs +4918 -0
  178. package/package.json +63 -6
  179. package/sbom.cdx.json +412 -0
@@ -0,0 +1,3884 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var node_module = require('node:module');
5
+ var path = require('node:path');
6
+
7
+ const globalThis = Object.create(global);
8
+ const Module = (globalThis.Module = {});
9
+ function warnOnce(msg) {
10
+ console.warn(msg);
11
+ }
12
+
13
+ // include: shell.js
14
+ /**
15
+ * @license
16
+ * Copyright 2010 The Emscripten Authors
17
+ * SPDX-License-Identifier: MIT
18
+ */
19
+ // The Module object: Our interface to the outside world. We import
20
+ // and export values on it. There are various ways Module can be used:
21
+ // 1. Not defined. We create it here
22
+ // 2. A function parameter, function(Module) { ..generated code.. }
23
+ // 3. pre-run appended it, var Module = {}; ..generated code..
24
+ // 4. External script tag defines var Module.
25
+ // We need to check if Module already exists (e.g. case 3 above).
26
+ // Substitution will be replaced with actual code on later stage of the build,
27
+ // this way Closure Compiler will not mangle it (e.g. case 4. above).
28
+ // Note that if you want to run closure, and also to use Module
29
+ // after the generated code, you will need to define var Module = {};
30
+ // before the code. Then that object will be used in the code, and you
31
+ // can continue to use Module afterwards as well.
32
+ globalThis.Module = typeof globalThis.Module != 'undefined' ? globalThis.Module : {};
33
+
34
+ // See https://caniuse.com/mdn-javascript_builtins_bigint64array
35
+ // include: polyfill/bigint64array.js
36
+
37
+ if (typeof globalThis.BigInt64Array === "undefined") {
38
+ // BigInt64Array polyfill for Safari versions between v14.0 and v15.0.
39
+ // All browsers other than Safari added BigInt and BigInt64Array at the same
40
+ // time, but Safari introduced BigInt in v14.0 and introduced BigInt64Array in
41
+ // v15.0
42
+
43
+ function partsToBigIntSigned(lower, upper) {
44
+ return BigInt(lower) | (BigInt(upper + 2 * (upper & 0x80000000)) << 32n);
45
+ }
46
+
47
+ function partsToBigIntUnsigned(lower, upper) {
48
+ return BigInt(lower) | (BigInt(upper) << 32n);
49
+ }
50
+
51
+ function bigIntToParts(value) {
52
+ var lower = Number(BigInt(value) & BigInt(0xffffffff)) | 0;
53
+ var upper = Number(BigInt(value) >> 32n) | 0;
54
+ return [lower, upper];
55
+ }
56
+
57
+ function createBigIntArrayShim(partsToBigInt) {
58
+ function createBigInt64Array(array) {
59
+ if (typeof array === "number") {
60
+ array = new Uint32Array(2 * array);
61
+ }
62
+ var orig_array;
63
+ if (!ArrayBuffer.isView(array)) {
64
+ if (array.constructor && array.constructor.name === "ArrayBuffer") {
65
+ array = new Uint32Array(array);
66
+ } else {
67
+ orig_array = array;
68
+ array = new Uint32Array(array.length * 2);
69
+ }
70
+ }
71
+ var proxy = new Proxy(
72
+ {
73
+ slice: function (min, max) {
74
+ if (max === undefined) {
75
+ max = array.length;
76
+ }
77
+ var new_buf = array.slice(min * 2, max * 2);
78
+ return createBigInt64Array(new_buf);
79
+ },
80
+ subarray: function (min, max) {
81
+ var new_buf = array.subarray(min * 2, max * 2);
82
+ return createBigInt64Array(new_buf);
83
+ },
84
+ [Symbol.iterator]: function* () {
85
+ for (var i = 0; i < array.length / 2; i++) {
86
+ yield partsToBigInt(array[2 * i], array[2 * i + 1]);
87
+ }
88
+ },
89
+ BYTES_PER_ELEMENT: 2 * array.BYTES_PER_ELEMENT,
90
+ buffer: array.buffer,
91
+ byteLength: array.byteLength,
92
+ byteOffset: array.byteOffset,
93
+ length: array.length / 2,
94
+ copyWithin: function (target, start, end) {
95
+ array.copyWithin(target * 2, start * 2, end * 2);
96
+ return proxy;
97
+ },
98
+ set: function (source, targetOffset) {
99
+ if (targetOffset === undefined) {
100
+ targetOffset = 0;
101
+ }
102
+ if (2 * (source.length + targetOffset) > array.length) {
103
+ // This is the Chrome error message
104
+ // Firefox: "invalid or out-of-range index"
105
+ throw new RangeError("offset is out of bounds");
106
+ }
107
+ for (var i = 0; i < source.length; i++) {
108
+ var value = source[i];
109
+ var pair = bigIntToParts(value);
110
+ array.set(pair, 2 * (targetOffset + i));
111
+ }
112
+ },
113
+ },
114
+ {
115
+ get: function (target, idx, receiver) {
116
+ if (typeof idx !== "string" || !/^\d+$/.test(idx)) {
117
+ return Reflect.get(target, idx, receiver);
118
+ }
119
+ var lower = array[idx * 2];
120
+ var upper = array[idx * 2 + 1];
121
+ return partsToBigInt(lower, upper);
122
+ },
123
+ set: function (target, idx, value, receiver) {
124
+ if (typeof idx !== "string" || !/^\d+$/.test(idx)) {
125
+ return Reflect.set(target, idx, value, receiver);
126
+ }
127
+ if (typeof value !== "bigint") {
128
+ // Chrome error message, Firefox has no "a" in front if "BigInt".
129
+ throw new TypeError(`Cannot convert ${value} to a BigInt`);
130
+ }
131
+ var pair = bigIntToParts(value);
132
+ array.set(pair, 2 * idx);
133
+ return true;
134
+ },
135
+ }
136
+ );
137
+ if (orig_array) {
138
+ proxy.set(orig_array);
139
+ }
140
+ return proxy;
141
+ }
142
+ return createBigInt64Array;
143
+ }
144
+
145
+ globalThis.BigUint64Array = createBigIntArrayShim(partsToBigIntUnsigned);
146
+ globalThis.BigInt64Array = createBigIntArrayShim(partsToBigIntSigned);
147
+ }
148
+
149
+ // end include: polyfill/bigint64array.js
150
+
151
+ // --pre-jses are emitted after the Module integration code, so that they can
152
+ // refer to Module (if they choose; they can also define Module)
153
+
154
+
155
+ // Sometimes an existing Module object exists with properties
156
+ // meant to overwrite the default module functionality. Here
157
+ // we collect those properties and reapply _after_ we configure
158
+ // the current environment's defaults to avoid having to be so
159
+ // defensive during initialization.
160
+ var moduleOverrides = Object.assign({}, Module);
161
+
162
+ var arguments_ = [];
163
+
164
+ // Determine the runtime environment we are in. You can customize this by
165
+ // setting the ENVIRONMENT setting at compile time (see settings.js).
166
+
167
+ // Attempt to auto-detect the environment
168
+ var ENVIRONMENT_IS_WEB = typeof window == 'object';
169
+ var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';
170
+ // N.b. Electron.js environment is simultaneously a NODE-environment, but
171
+ // also a web environment.
172
+ var ENVIRONMENT_IS_NODE = typeof process == 'object' && typeof process.versions == 'object' && typeof process.versions.node == 'string';
173
+ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
174
+
175
+ if (Module['ENVIRONMENT']) {
176
+ throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)');
177
+ }
178
+
179
+ // `/` should be present at the end if `scriptDirectory` is not empty
180
+ var scriptDirectory = '';
181
+ function locateFile(path) {
182
+ return scriptDirectory + path;
183
+ }
184
+
185
+ if (ENVIRONMENT_IS_SHELL) {
186
+
187
+ if ((typeof process == 'object' && typeof require === 'function') || typeof window == 'object' || typeof importScripts == 'function') throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
188
+
189
+ if (typeof clearTimeout == 'undefined') {
190
+ globalThis.clearTimeout = (id) => { };
191
+ }
192
+
193
+ if (typeof scriptArgs != 'undefined') {
194
+ arguments_ = scriptArgs;
195
+ } else if (typeof arguments != 'undefined') {
196
+ arguments_ = arguments;
197
+ }
198
+
199
+ if (typeof print != 'undefined') {
200
+ // Prefer to use print/printErr where they exist, as they usually work better.
201
+ if (typeof console == 'undefined') console = /** @type{!Console} */({});
202
+ console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
203
+ console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
204
+ }
205
+
206
+ } else
207
+
208
+ // Note that this includes Node.js workers when relevant (pthreads is enabled).
209
+ // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
210
+ // ENVIRONMENT_IS_NODE.
211
+ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
212
+ if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
213
+ scriptDirectory = self.location.href;
214
+ } else if (typeof document != 'undefined' && document.currentScript) { // web
215
+ scriptDirectory = document.currentScript.src;
216
+ }
217
+ // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
218
+ // otherwise, slice off the final part of the url to find the script directory.
219
+ // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
220
+ // and scriptDirectory will correctly be replaced with an empty string.
221
+ // If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
222
+ // they are removed because they could contain a slash.
223
+ if (scriptDirectory.indexOf('blob:') !== 0) {
224
+ scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf('/') + 1);
225
+ } else {
226
+ scriptDirectory = '';
227
+ }
228
+
229
+ if (!(typeof window == 'object' || typeof importScripts == 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
230
+ } else if (!ENVIRONMENT_IS_NODE) {
231
+ // Node is not an error: it hosts this runtime inside a Node-API addon, which uses none of the
232
+ // file-loading hooks above.
233
+ throw new Error('environment detection error');
234
+ }
235
+
236
+ console.log.bind(console);
237
+ var err = console.warn.bind(console);
238
+
239
+ // Merge back in the overrides
240
+ Object.assign(Module, moduleOverrides);
241
+ // Free the object hierarchy contained in the overrides, this lets the GC
242
+ // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
243
+ moduleOverrides = null;
244
+ // checkIncomingModuleAPI();
245
+
246
+ // Emit code to handle expected values on the Module object. This applies Module.x
247
+ // to the proper local x. This has two benefits: first, we only emit it if it is
248
+ // expected to arrive, and second, by using a local everywhere else that can be
249
+ // minified.
250
+ legacyModuleProp('arguments', 'arguments_');
251
+ legacyModuleProp('thisProgram', 'thisProgram');
252
+ legacyModuleProp('quit', 'quit_');
253
+
254
+ // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
255
+ // Assertions on removed incoming Module JS APIs.
256
+ assert(typeof Module['memoryInitializerPrefixURL'] == 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead');
257
+ assert(typeof Module['pthreadMainPrefixURL'] == 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead');
258
+ assert(typeof Module['cdInitializerPrefixURL'] == 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead');
259
+ assert(typeof Module['filePackagePrefixURL'] == 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead');
260
+ assert(typeof Module['read'] == 'undefined', 'Module.read option was removed (modify read_ in JS)');
261
+ assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)');
262
+ assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)');
263
+ assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify setWindowTitle in JS)');
264
+ assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY');
265
+ legacyModuleProp('read', 'read_');
266
+ legacyModuleProp('readAsync', 'readAsync');
267
+ legacyModuleProp('readBinary', 'readBinary');
268
+ legacyModuleProp('setWindowTitle', 'setWindowTitle');
269
+ legacyModuleProp('wasmBinary', 'wasmBinary');
270
+ legacyModuleProp('noExitRuntime', 'noExitRuntime');
271
+
272
+ //========================================
273
+ // Runtime essentials
274
+ //========================================
275
+
276
+ // whether we are quitting the application. no code should run after this.
277
+ // set in exit() and abort()
278
+ var ABORT = false;
279
+
280
+ /** @type {function(*, string=)} */
281
+ function assert(condition, text) {
282
+ if (!condition) {
283
+ abort('Assertion failed' + (text ? ': ' + text : ''));
284
+ }
285
+ }
286
+
287
+ assert(!Module['STACK_SIZE'], 'STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time');
288
+
289
+ assert(typeof Int32Array != 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined,
290
+ 'JS engine does not provide full typed array support');
291
+
292
+ // If memory is defined in wasm, the user can't provide it, or set INITIAL_MEMORY
293
+ assert(!Module['wasmMemory'], 'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally');
294
+ assert(!Module['INITIAL_MEMORY'], 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
295
+
296
+ // end include: runtime_init_table.js
297
+ // include: runtime_stack_check.js
298
+ /**
299
+ * @license
300
+ * Copyright 2019 The Emscripten Authors
301
+ * SPDX-License-Identifier: MIT
302
+ */
303
+
304
+ // end include: runtime_stack_check.js
305
+ // include: runtime_assertions.js
306
+ /**
307
+ * @license
308
+ * Copyright 2019 The Emscripten Authors
309
+ * SPDX-License-Identifier: MIT
310
+ */
311
+
312
+ // Endianness check
313
+ (function () {
314
+ var h16 = new Int16Array(1);
315
+ var h8 = new Int8Array(h16.buffer);
316
+ h16[0] = 0x6373;
317
+ if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian! (Run with -sSUPPORT_BIG_ENDIAN to bypass)';
318
+ })();
319
+
320
+ var runtimeInitialized = false;
321
+
322
+ function initRuntime() {
323
+ assert(!runtimeInitialized);
324
+ runtimeInitialized = true;
325
+ }
326
+
327
+ // include: runtime_math.js
328
+ /**
329
+ * @license
330
+ * Copyright 2019 The Emscripten Authors
331
+ * SPDX-License-Identifier: MIT
332
+ */
333
+
334
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
335
+
336
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
337
+
338
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
339
+
340
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
341
+
342
+ assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
343
+ assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
344
+ assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
345
+ assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill');
346
+
347
+ /** @param {string|number=} what */
348
+ function abort(what) {
349
+
350
+ what = 'Aborted(' + what + ')';
351
+ // TODO(sbc): Should we remove printing and leave it up to whoever
352
+ // catches the exception?
353
+ err(what);
354
+
355
+ ABORT = true;
356
+
357
+ // Use a wasm runtime error, because a JS error might be seen as a foreign
358
+ // exception, which means we'd run destructors on it. We need the error to
359
+ // simply make the program stop.
360
+ // FIXME This approach does not work in Wasm EH because it currently does not assume
361
+ // all RuntimeErrors are from traps; it decides whether a RuntimeError is from
362
+ // a trap or not based on a hidden field within the object. So at the moment
363
+ // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
364
+ // allows this in the wasm spec.
365
+
366
+ // Suppress closure compiler warning here. Closure compiler's builtin extern
367
+ // defintion for WebAssembly.RuntimeError claims it takes no arguments even
368
+ // though it can.
369
+ // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
370
+ /** @suppress {checkTypes} */
371
+ var e = new WebAssembly.RuntimeError(what);
372
+
373
+ // Throw the error whether or not MODULARIZE is set because abort is used
374
+ // in code paths apart from instantiation where an exception is expected
375
+ // to be thrown when abort is called.
376
+ throw e;
377
+ }
378
+
379
+ // include: memoryprofiler.js
380
+ /**
381
+ * @license
382
+ * Copyright 2015 The Emscripten Authors
383
+ * SPDX-License-Identifier: MIT
384
+ */
385
+
386
+ // end include: memoryprofiler.js
387
+ // show errors on likely calls to FS when it was not included
388
+ var FS = {
389
+ error: function () {
390
+ abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM');
391
+ },
392
+ init: function () { FS.error(); },
393
+ createDataFile: function () { FS.error(); },
394
+ createPreloadedFile: function () { FS.error(); },
395
+ createLazyFile: function () { FS.error(); },
396
+ open: function () { FS.error(); },
397
+ mkdev: function () { FS.error(); },
398
+ registerDevice: function () { FS.error(); },
399
+ analyzePath: function () { FS.error(); },
400
+
401
+ ErrnoError: function ErrnoError() { FS.error(); },
402
+ };
403
+ Module['FS_createDataFile'] = FS.createDataFile;
404
+ Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
405
+
406
+ // include: URIUtils.js
407
+ /**
408
+ * @license
409
+ * Copyright 2017 The Emscripten Authors
410
+ * SPDX-License-Identifier: MIT
411
+ */
412
+
413
+ // Prefix of data URIs emitted by SINGLE_FILE and related options.
414
+ var dataURIPrefix = 'data:application/octet-stream;base64,';
415
+
416
+ // Indicates whether filename is a base64 data URI.
417
+ function isDataURI(filename) {
418
+ // Prefix of data URIs emitted by SINGLE_FILE and related options.
419
+ return filename.startsWith(dataURIPrefix);
420
+ }
421
+
422
+ // include: runtime_exceptions.js
423
+ /**
424
+ * @license
425
+ * Copyright 2023 The Emscripten Authors
426
+ * SPDX-License-Identifier: MIT
427
+ */
428
+
429
+ // end include: runtime_exceptions.js
430
+ var wasmBinaryFile;
431
+ wasmBinaryFile = '';
432
+ if (!isDataURI(wasmBinaryFile)) {
433
+ wasmBinaryFile = locateFile(wasmBinaryFile);
434
+ }
435
+
436
+ // include: runtime_debug.js
437
+ /**
438
+ * @license
439
+ * Copyright 2020 The Emscripten Authors
440
+ * SPDX-License-Identifier: MIT
441
+ */
442
+
443
+ function legacyModuleProp(prop, newName) {
444
+ if (!Object.getOwnPropertyDescriptor(Module, prop)) {
445
+ Object.defineProperty(Module, prop, {
446
+ configurable: true,
447
+ get: function () {
448
+ abort('Module.' + prop + ' has been replaced with plain ' + newName + ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)');
449
+ }
450
+ });
451
+ }
452
+ }
453
+
454
+ // forcing the filesystem exports a few things by default
455
+ function isExportedByForceFilesystem(name) {
456
+ return name === 'FS_createPath' ||
457
+ name === 'FS_createDataFile' ||
458
+ name === 'FS_createPreloadedFile' ||
459
+ name === 'FS_unlink' ||
460
+ name === 'addRunDependency' ||
461
+ // The old FS has some functionality that WasmFS lacks.
462
+ name === 'FS_createLazyFile' ||
463
+ name === 'FS_createDevice' ||
464
+ name === 'removeRunDependency';
465
+ }
466
+
467
+ function missingGlobal(sym, msg) {
468
+ if (typeof globalThis !== 'undefined') {
469
+ Object.defineProperty(globalThis, sym, {
470
+ configurable: true,
471
+ get: function () {
472
+ warnOnce('`' + sym + '` is not longer defined by emscripten. ' + msg);
473
+ return undefined;
474
+ }
475
+ });
476
+ }
477
+ }
478
+
479
+ missingGlobal('buffer', 'Please use HEAP8.buffer or wasmMemory.buffer');
480
+
481
+ function missingLibrarySymbol(sym) {
482
+ if (typeof globalThis !== 'undefined' && !Object.getOwnPropertyDescriptor(globalThis, sym)) {
483
+ Object.defineProperty(globalThis, sym, {
484
+ configurable: true,
485
+ get: function () {
486
+ // Can't `abort()` here because it would break code that does runtime
487
+ // checks. e.g. `if (typeof SDL === 'undefined')`.
488
+ var msg = '`' + sym + '` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line';
489
+ // DEFAULT_LIBRARY_FUNCS_TO_INCLUDE requires the name as it appears in
490
+ // library.js, which means $name for a JS name with no prefix, or name
491
+ // for a JS name like _name.
492
+ var librarySymbol = sym;
493
+ if (!librarySymbol.startsWith('_')) {
494
+ librarySymbol = '$' + sym;
495
+ }
496
+ msg += " (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=" + librarySymbol + ")";
497
+ if (isExportedByForceFilesystem(sym)) {
498
+ msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
499
+ }
500
+ warnOnce(msg);
501
+ return undefined;
502
+ }
503
+ });
504
+ }
505
+ // Any symbol that is not included from the JS libary is also (by definition)
506
+ // not exported on the Module object.
507
+ unexportedRuntimeSymbol(sym);
508
+ }
509
+
510
+ function unexportedRuntimeSymbol(sym) {
511
+ if (!Object.getOwnPropertyDescriptor(Module, sym)) {
512
+ Object.defineProperty(Module, sym, {
513
+ configurable: true,
514
+ get: function () {
515
+ var msg = "'" + sym + "' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the FAQ)";
516
+ if (isExportedByForceFilesystem(sym)) {
517
+ msg += '. Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you';
518
+ }
519
+ abort(msg);
520
+ }
521
+ });
522
+ }
523
+ }
524
+
525
+ // end include: runtime_debug.js
526
+ // === Body ===
527
+
528
+
529
+ // end include: preamble.js
530
+
531
+ function embind_init_charCodes() {
532
+ var codes = new Array(256);
533
+ for (var i = 0; i < 256; ++i) {
534
+ codes[i] = String.fromCharCode(i);
535
+ }
536
+ }
537
+ function readLatin1String(ptr) {
538
+ return ptr;
539
+ /* var ret = "";
540
+ var c = ptr;
541
+ while (HEAPU8[c]) {
542
+ ret += embind_charCodes[HEAPU8[c++]];
543
+ }
544
+ return ret; */
545
+ }
546
+
547
+ var awaitingDependencies = {};
548
+
549
+ var registeredTypes = {};
550
+
551
+ var typeDependencies = {};
552
+
553
+ var char_0 = 48;
554
+
555
+ var char_9 = 57;
556
+ function makeLegalFunctionName(name) {
557
+ if (undefined === name) {
558
+ return '_unknown';
559
+ }
560
+ name = name.replace(/[^a-zA-Z0-9_]/g, '$');
561
+ var f = name.charCodeAt(0);
562
+ if (f >= char_0 && f <= char_9) {
563
+ return '_' + name;
564
+ }
565
+ return name;
566
+ }
567
+ function createNamedFunction(name, body) {
568
+ name = makeLegalFunctionName(name);
569
+ // Use an abject with a computed property name to create a new function with
570
+ // a name specified at runtime, but without using `new Function` or `eval`.
571
+ return {
572
+ [name]: function () {
573
+ return body.apply(this, arguments);
574
+ }
575
+ }[name];
576
+ }
577
+ function extendError(baseErrorType, errorName) {
578
+ var errorClass = createNamedFunction(errorName, function (message) {
579
+ this.name = errorName;
580
+ this.message = message;
581
+
582
+ var stack = (new Error(message)).stack;
583
+ if (stack !== undefined) {
584
+ this.stack = this.toString() + '\n' +
585
+ stack.replace(/^Error(:[^\n]*)?\n/, '');
586
+ }
587
+ });
588
+ errorClass.prototype = Object.create(baseErrorType.prototype);
589
+ errorClass.prototype.constructor = errorClass;
590
+ errorClass.prototype.toString = function () {
591
+ if (this.message === undefined) {
592
+ return this.name;
593
+ } else {
594
+ return this.name + ': ' + this.message;
595
+ }
596
+ };
597
+
598
+ return errorClass;
599
+ }
600
+ var BindingError = undefined;
601
+ function throwBindingError(message) {
602
+ console.log(message);
603
+ throw new BindingError(message);
604
+ }
605
+
606
+
607
+
608
+
609
+ var InternalError = undefined;
610
+ function throwInternalError(message) {
611
+ throw new InternalError(message);
612
+ }
613
+ function whenDependentTypesAreResolved(myTypes, dependentTypes, getTypeConverters) {
614
+ myTypes.forEach(function (type) {
615
+ typeDependencies[type] = dependentTypes;
616
+ });
617
+
618
+ function onComplete(typeConverters) {
619
+ var myTypeConverters = getTypeConverters(typeConverters);
620
+ if (myTypeConverters.length !== myTypes.length) {
621
+ throwInternalError('Mismatched type converter count');
622
+ }
623
+ for (var i = 0; i < myTypes.length; ++i) {
624
+ registerType(myTypes[i], myTypeConverters[i]);
625
+ }
626
+ }
627
+
628
+ var typeConverters = new Array(dependentTypes.length);
629
+ var unregisteredTypes = [];
630
+ var registered = 0;
631
+ dependentTypes.forEach((dt, i) => {
632
+ if (registeredTypes.hasOwnProperty(dt)) {
633
+ typeConverters[i] = registeredTypes[dt];
634
+ } else {
635
+ unregisteredTypes.push(dt);
636
+ if (!awaitingDependencies.hasOwnProperty(dt)) {
637
+ awaitingDependencies[dt] = [];
638
+ }
639
+ awaitingDependencies[dt].push(() => {
640
+ typeConverters[i] = registeredTypes[dt];
641
+ ++registered;
642
+ if (registered === unregisteredTypes.length) {
643
+ onComplete(typeConverters);
644
+ }
645
+ });
646
+ }
647
+ });
648
+ if (0 === unregisteredTypes.length) {
649
+ onComplete(typeConverters);
650
+ }
651
+ }
652
+ /** @param {Object=} options */
653
+ function registerType(rawType, registeredInstance, options = {}) {
654
+ // console.log('1', rawType);
655
+ if (!('argPackAdvance' in registeredInstance)) {
656
+ throw new TypeError('registerType registeredInstance requires argPackAdvance');
657
+ }
658
+
659
+ // console.log('2', rawType);
660
+ var name = registeredInstance.name;
661
+ if (!rawType) {
662
+ throwBindingError(`type "${name}" must have a positive integer typeid pointer`);
663
+ }
664
+ // console.log('3', rawType);
665
+ if (registeredTypes.hasOwnProperty(rawType)) {
666
+ if (options.ignoreDuplicateRegistrations) {
667
+ return;
668
+ } else {
669
+ throwBindingError(`Cannot register type '${name}' twice`);
670
+ }
671
+ }
672
+ // console.log('4', rawType);
673
+ registeredTypes[rawType] = registeredInstance;
674
+ delete typeDependencies[rawType];
675
+ // console.log('5', rawType);
676
+ if (awaitingDependencies.hasOwnProperty(rawType)) {
677
+ var callbacks = awaitingDependencies[rawType];
678
+ delete awaitingDependencies[rawType];
679
+ callbacks.forEach((cb) => cb());
680
+ }
681
+ // console.log('6', rawType);
682
+ }
683
+
684
+ function __embind_register_void(rawType, name) {
685
+ name = readLatin1String(name);
686
+ // console.log('__embind_register_void', name, rawType);
687
+ registerType(rawType, {
688
+ isVoid: true, // void return values can be optimized out sometimes
689
+ name: name,
690
+ 'argPackAdvance': 0n,
691
+ 'fromWireType': function () {
692
+ return undefined;
693
+ },
694
+ 'toWireType': function (destructors, o) {
695
+ // TODO: assert if anything else is given?
696
+ return undefined;
697
+ },
698
+ });
699
+ }
700
+ globalThis.__embind_register_void = __embind_register_void;
701
+
702
+ function __embind_register_jsiValue(rawType, name) {
703
+ name = readLatin1String(name);
704
+ // console.log('__embind_register_jsiValue', name, rawType);
705
+ registerType(rawType, {
706
+ isVoid: false, // void return values can be optimized out sometimes
707
+ name: name,
708
+ 'argPackAdvance': 0n,
709
+ 'fromWireType': function (v) {
710
+ return v;
711
+ },
712
+ 'toWireType': function (destructors, o) {
713
+ return o;
714
+ },
715
+ });
716
+ }
717
+ globalThis.__embind_register_jsiValue = __embind_register_jsiValue;
718
+
719
+ // A Rust byte or double slice argument: the view itself reaches the adapter, which reads its
720
+ // elements in place. Another typed array or a plain array is copied into a new view first, and so is
721
+ // a view over a SharedArrayBuffer, which another thread could write during the call.
722
+ function __crossbind_register_typed_arg(rawType, name, isDoubles, isOptional) {
723
+ const View = isDoubles ? Float64Array : Uint8Array;
724
+ const isLent = isDoubles
725
+ ? (value) => value instanceof Float64Array
726
+ : (value) => value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array;
727
+ const Shared = typeof SharedArrayBuffer === 'undefined' ? null : SharedArrayBuffer;
728
+ registerType(rawType, {
729
+ name,
730
+ 'argPackAdvance': 0n,
731
+ 'toWireType': function (destructors, value) {
732
+ if (isOptional && (value === null || value === undefined)) return null;
733
+ if (isLent(value) && !(Shared && value.buffer instanceof Shared)) return value;
734
+ if (Array.isArray(value) || (ArrayBuffer.isView(value) && !(value instanceof DataView))) return View.from(value);
735
+ throwBindingError(`Cannot pass ${embindRepr(value)} as a ${name}`);
736
+ },
737
+ destructorFunction: null,
738
+ });
739
+ }
740
+ globalThis.__crossbind_register_typed_arg = __crossbind_register_typed_arg;
741
+
742
+ function getShiftFromSize(size) {
743
+ switch (size) {
744
+ case 1: return 0;
745
+ case 2: return 1;
746
+ case 4: return 2;
747
+ case 8: return 3;
748
+ case 1n: return 0;
749
+ case 2n: return 1;
750
+ case 4n: return 2;
751
+ case 8n: return 3;
752
+ default:
753
+ throw new TypeError('Unknown type size: ' + size);
754
+ }
755
+ }
756
+
757
+
758
+ function __embind_register_bool(rawType, name, size, trueValue, falseValue) {
759
+ // console.log('bool', name, rawType, size, trueValue, falseValue);
760
+ getShiftFromSize(size);
761
+
762
+ name = readLatin1String(name);
763
+ registerType(rawType, {
764
+ name: name,
765
+ 'fromWireType': function (wt) {
766
+ // ambiguous emscripten ABI: sometimes return values are
767
+ // true or false, and sometimes integers (0 or 1)
768
+ return !!wt;
769
+ },
770
+ 'toWireType': function (destructors, o) {
771
+ return o ? trueValue : falseValue;
772
+ },
773
+ 'argPackAdvance': 8n,
774
+ destructorFunction: null, // This type does not need a destructor
775
+ });
776
+ }
777
+ globalThis.__embind_register_bool = __embind_register_bool;
778
+
779
+ function __embind_register_optional(rawOptionalType, rawInnerType) {
780
+ whenDependentTypesAreResolved([rawOptionalType], [rawInnerType], function (innerTypes) {
781
+ var inner = innerTypes[0];
782
+ return [{
783
+ name: `std::optional<${inner.name}>`,
784
+ // No value crosses as null (a wire of undefined reads the same); a present value
785
+ // rides the inner type's own converters unchanged.
786
+ 'fromWireType': function (wt) {
787
+ if (wt === undefined || wt === null) return null;
788
+ return inner['fromWireType'](wt);
789
+ },
790
+ 'toWireType': function (destructors, o) {
791
+ if (o === undefined || o === null) return undefined;
792
+ return inner['toWireType'](destructors, o);
793
+ },
794
+ 'argPackAdvance': 8n,
795
+ destructorFunction: null,
796
+ }];
797
+ });
798
+ }
799
+ globalThis.__embind_register_optional = __embind_register_optional;
800
+
801
+ function embindRepr(v) {
802
+ if (v === null) {
803
+ return 'null';
804
+ }
805
+ var t = typeof v;
806
+ if (t === 'object' || t === 'array' || t === 'function') {
807
+ return v.toString();
808
+ } else {
809
+ return '' + v;
810
+ }
811
+ }
812
+
813
+
814
+ function __embind_register_integer(primitiveType, name, size, minRange, maxRange) {
815
+ // console.log('integer', name, primitiveType, size, minRange, maxRange);
816
+ name = readLatin1String(name);
817
+ // LLVM doesn't have signed and unsigned 32-bit types, so u32 literals come
818
+ // out as 'i32 -1'. Always treat those as max u32.
819
+ /* if (maxRange === -1) {
820
+ maxRange = 4294967295;
821
+ } */
822
+
823
+ var shift = getShiftFromSize(size);
824
+
825
+ var fromWireType = (value) => value;
826
+
827
+ if (minRange === 0) {
828
+ var bitshift = 32 - 8 * size;
829
+ fromWireType = (value) => (value << bitshift) >>> bitshift;
830
+ }
831
+
832
+ var isUnsignedType = (name.includes('unsigned'));
833
+ // As the wasm glue does (embindArgumentGuards.js): an enum member crosses as its value, and a one-letter string
834
+ // as its code when the integer is a char.
835
+ var fromJs = (value) => {
836
+ if (typeof value == "string" && size == 1 && value.length == 1) return value.charCodeAt(0);
837
+ if (value !== null && typeof value == "object" && typeof value.value == "number") return value.value;
838
+ return value;
839
+ };
840
+ var checkAssertions = (value, toTypeName) => {
841
+ if (typeof value != "number" && typeof value != "boolean" && typeof value != "bigint") {
842
+ throw new TypeError(`Cannot convert "${embindRepr(value)}" to ${toTypeName}`);
843
+ }
844
+ if (value < minRange || (maxRange !== -1 && shift !== 2 && shift !== 3 && value > maxRange)) {
845
+ throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${name}", which is outside the valid range [${minRange}, ${maxRange}]!`);
846
+ }
847
+ };
848
+ var toWireType;
849
+ if (isUnsignedType) {
850
+ toWireType = function (destructors, value) {
851
+ value = fromJs(value);
852
+ checkAssertions(value, this.name);
853
+ return value >>> 0;
854
+ };
855
+ } else {
856
+ toWireType = function (destructors, value) {
857
+ value = fromJs(value);
858
+ checkAssertions(value, this.name);
859
+ // The VM will perform JS to Wasm value conversion, according to the spec:
860
+ // https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
861
+ return value;
862
+ };
863
+ }
864
+ registerType(primitiveType, {
865
+ name: name,
866
+ 'fromWireType': fromWireType,
867
+ 'toWireType': toWireType,
868
+ 'argPackAdvance': 8n,
869
+ destructorFunction: null, // This type does not need a destructor
870
+ });
871
+ }
872
+
873
+ globalThis.__embind_register_integer = __embind_register_integer;
874
+
875
+
876
+
877
+ function __embind_register_bigint(primitiveType, name, size, minRange, maxRange) {
878
+ // console.log('bigint', name, primitiveType, size, minRange, maxRange);
879
+ name = readLatin1String(name);
880
+
881
+ var isUnsignedType = (name.indexOf('u') != -1);
882
+
883
+ // maxRange comes through as -1 for uint64_t (see issue 13902). Work around that temporarily
884
+ if (isUnsignedType) {
885
+ maxRange = (1n << 64n) - 1n;
886
+ }
887
+
888
+ registerType(primitiveType, {
889
+ name: name,
890
+ 'fromWireType': function (value) {
891
+ return value;
892
+ },
893
+ 'toWireType': function (destructors, value) {
894
+ // console.log('__embind_register_bigint - toWireType');
895
+ if (typeof value != "bigint" && typeof value != "number") {
896
+ throw new TypeError(`Cannot convert "${embindRepr(value)}" to ${this.name}`);
897
+ }
898
+ // A Number crosses only while it is an exact integer: BigInt(2**53 + 1) would round
899
+ // silently, and a 64-bit slot deserves the exact value (the wasm glue gets the same rule).
900
+ if (typeof value == "number" && !Number.isSafeInteger(value)) {
901
+ throw new TypeError(`a 64-bit integer parameter takes a BigInt or a safe integer Number, got ${embindRepr(value)}`);
902
+ }
903
+ if (value < minRange || value > maxRange) {
904
+ throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${name}", which is outside the valid range [${minRange}, ${maxRange}]!`);
905
+ }
906
+ return BigInt(value);
907
+ },
908
+ 'argPackAdvance': 8n,
909
+ destructorFunction: null, // This type does not need a destructor
910
+ });
911
+ }
912
+
913
+ globalThis.__embind_register_bigint = __embind_register_bigint;
914
+
915
+
916
+ function __embind_register_float(rawType, name, size) {
917
+ // console.log('float', name, rawType, size);
918
+ name = readLatin1String(name);
919
+ registerType(rawType, {
920
+ name: name,
921
+ 'fromWireType': function (value) {
922
+ return value;
923
+ },
924
+ 'toWireType': function (destructors, value) {
925
+ if (typeof value != "number" && typeof value != "boolean") {
926
+ throw new TypeError(`Cannot convert ${embindRepr(value)} to ${this.name}`);
927
+ }
928
+ // The VM will perform JS to Wasm value conversion, according to the spec:
929
+ // https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
930
+ return value;
931
+ },
932
+ 'argPackAdvance': 8n,
933
+ destructorFunction: null, // This type does not need a destructor
934
+ });
935
+ }
936
+
937
+ globalThis.__embind_register_float = __embind_register_float;
938
+
939
+
940
+ function __embind_register_std_string(rawType, name) {
941
+ name = readLatin1String(name);
942
+
943
+ registerType(rawType, {
944
+ name: name,
945
+ // The C++ BindingType has already turned the std::string into a JS string (wire.h).
946
+ 'fromWireType': function (value) {
947
+ return value;
948
+ },
949
+ 'toWireType': function (destructors, value, usePointer = false) {
950
+ return value;
951
+ /* if (!usePointer) {
952
+ return value;
953
+ }
954
+
955
+ if (value instanceof ArrayBuffer) {
956
+ value = new Uint8Array(value)
957
+ }
958
+ var length;
959
+ var valueIsOfTypeString = typeof value == "string";
960
+ if (!(valueIsOfTypeString || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array)) {
961
+ throwBindingError("Cannot pass non-string to std::string")
962
+ }
963
+ if (stdStringIsUTF8 && valueIsOfTypeString) {
964
+ length = lengthBytesUTF8(value)
965
+ } else {
966
+ length = value.length
967
+ }
968
+ var base = _malloc(4 + length + 1);
969
+ var ptr = base + 4;
970
+
971
+ writeToMemoryUsingShift(base, false, 2, length); // HEAPU32[base >> 2] = length;
972
+ if (stdStringIsUTF8 && valueIsOfTypeString) {
973
+ stringToUTF8(value, ptr, length + 1)
974
+ } else {
975
+ if (valueIsOfTypeString) {
976
+ for (var i = 0; i < length; ++i) {
977
+ var charCode = value.charCodeAt(i);
978
+ if (charCode > 255) {
979
+ _free(ptr);
980
+ throwBindingError("String has UTF-16 code units that do not fit in 8 bits")
981
+ }
982
+ writeToMemoryUsingShift(ptr + i, false, 0, charCode); // HEAPU8[ptr + i] = charCode
983
+ }
984
+ } else {
985
+ for (var i = 0; i < length; ++i) {
986
+ writeToMemoryUsingShift(ptr + i, false, 0, value[i]); //HEAPU8[ptr + i] = value[i]
987
+ }
988
+ }
989
+ }
990
+ if (destructors !== null) {
991
+ destructors.push(_free, base)
992
+ }
993
+ return base; */
994
+ },
995
+ 'argPackAdvance': 8n,
996
+ destructorFunction: function (ptr) { },
997
+ });
998
+ }
999
+
1000
+ globalThis.__embind_register_std_string = __embind_register_std_string;
1001
+
1002
+
1003
+ function __embind_register_std_wstring(rawType, charSize, name) {
1004
+ name = readLatin1String(name);
1005
+ registerType(rawType, {
1006
+ name: name,
1007
+ // The C++ BindingType turns the jsi string into the C++ string and back (wire.h), as it does for std::string.
1008
+ 'fromWireType': function (value) {
1009
+ return value;
1010
+ },
1011
+ 'toWireType': function (destructors, value) {
1012
+ if (!(typeof value == 'string')) {
1013
+ throwBindingError('Cannot pass non-string to C++ string type ' + name);
1014
+ }
1015
+ return value;
1016
+ },
1017
+ 'argPackAdvance': 8n,
1018
+ destructorFunction: function (ptr) { },
1019
+ });
1020
+ }
1021
+
1022
+ globalThis.__embind_register_std_wstring = __embind_register_std_wstring;
1023
+
1024
+ function HandleAllocator() {
1025
+ this.allocated = [undefined];
1026
+ this.freelist = [];
1027
+ this.get = function (id) {
1028
+ // console.log('HandleAllocator get', id);
1029
+ return this.allocated[Number(id)];
1030
+ };
1031
+ this.allocate = function (handle) {
1032
+ var id = this.freelist.pop() || this.allocated.length;
1033
+ // console.log('HandleAllocator allocate', id, JSON.stringify(handle));
1034
+ this.allocated[id] = handle;
1035
+ return BigInt(id);
1036
+ };
1037
+ this.free = function (id) {
1038
+ const id2 = Number(id);
1039
+ // console.log('HandleAllocator free', id);
1040
+ // Set the slot to `undefined` rather than using `delete` here since
1041
+ // apparently arrays with holes in them can be less efficient.
1042
+ if (typeof id2 === 'number' && isFinite(id2)) {
1043
+ this.allocated[id2] = undefined;
1044
+ this.freelist.push(id2);
1045
+ }
1046
+ };
1047
+ }
1048
+ var emval_handles = new HandleAllocator();function __emval_decref(handle) {
1049
+ // console.log('__emval_decref');
1050
+ if (handle >= emval_handles.reserved && 0 === --emval_handles.get(handle).refcount) {
1051
+ emval_handles.free(handle);
1052
+ }
1053
+ // console.log('__emval_decref2');
1054
+ }
1055
+ globalThis.__emval_decref = __emval_decref;
1056
+
1057
+
1058
+
1059
+ function count_emval_handles() {
1060
+ var count = 0;
1061
+ for (var i = emval_handles.reserved; i < emval_handles.allocated.length; ++i) {
1062
+ if (emval_handles.allocated[i] !== undefined) {
1063
+ ++count;
1064
+ }
1065
+ }
1066
+ return count;
1067
+ }
1068
+
1069
+ function init_emval() {
1070
+ // reserve some special values. These never get de-allocated.
1071
+ // The HandleAllocator takes care of reserving zero.
1072
+ emval_handles.allocated.push(
1073
+ { value: undefined },
1074
+ { value: null },
1075
+ { value: true },
1076
+ { value: false },
1077
+ );
1078
+ emval_handles.reserved = emval_handles.allocated.length;
1079
+ Module['count_emval_handles'] = count_emval_handles;
1080
+ }
1081
+ var Emval = {
1082
+ toValue: (handle) => {
1083
+ if (!handle || !emval_handles.get(handle)) {
1084
+ throwBindingError('Cannot use deleted val. handle = ' + handle);
1085
+ }
1086
+ return emval_handles.get(handle).value;
1087
+ }, toHandle: (value) => {
1088
+ // console.log('Emval toHandle', value);
1089
+ switch (value) {
1090
+ case undefined: return 1n;
1091
+ case null: return 2n;
1092
+ case true: return 3n;
1093
+ case false: return 4n;
1094
+ default: {
1095
+ const r = emval_handles.allocate({ refcount: 1, value: value });
1096
+ // console.log('Emval toHandle default: ', r);
1097
+ return r;
1098
+ }
1099
+ }
1100
+ }
1101
+ };
1102
+
1103
+
1104
+
1105
+ function __embind_register_emval(rawType, name) {
1106
+ name = readLatin1String(name);
1107
+ registerType(rawType, {
1108
+ name: name,
1109
+ 'fromWireType': function (handle) {
1110
+ // console.log('emval fromWireType1', registeredTypes[rawType], this.name, handle);
1111
+ var rv = Emval.toValue(handle);
1112
+ // console.log('emval fromWireType2', rv);
1113
+ __emval_decref(handle);
1114
+ // console.log('emval fromWireType 2');
1115
+ return rv;
1116
+ },
1117
+ 'toWireType': function (destructors, value) {
1118
+ // console.log('emval toWireType');
1119
+ return Emval.toHandle(value);
1120
+ },
1121
+ 'argPackAdvance': 8n,
1122
+ destructorFunction: null, // This type does not need a destructor
1123
+
1124
+ // TODO: do we need a deleteObject here? write a test where
1125
+ // emval is passed into JS via an interface
1126
+ });
1127
+ }
1128
+
1129
+ globalThis.__embind_register_emval = __embind_register_emval;
1130
+
1131
+ // crossbind JSON-value hooks (embind-rust serde_json::Value): handle-based on purpose - the
1132
+ // emval string plumbing reads wasm-heap pointers, which the native runtime has none of.
1133
+ function __crossbind_json_to_handle(text) {
1134
+ return Emval.toHandle(JSON.parse(text));
1135
+ }
1136
+ globalThis.__crossbind_json_to_handle = __crossbind_json_to_handle;
1137
+
1138
+ function __crossbind_handle_to_json(handle) {
1139
+ // A Set or Map has no JSON form of its own: write it as the array or object the Rust side
1140
+ // expects, the same rule the web adapter's replacer follows.
1141
+ const s = JSON.stringify(Emval.toValue(handle), (key, value) => {
1142
+ if (value instanceof Set) return Array.from(value);
1143
+ if (value instanceof Map) return Object.fromEntries(value);
1144
+ return value;
1145
+ });
1146
+ __emval_decref(handle);
1147
+ return s === undefined ? 'null' : s;
1148
+ }
1149
+ globalThis.__crossbind_handle_to_json = __crossbind_handle_to_json;
1150
+
1151
+ // crossbind live-value hooks (embind-rust JsValue/JsFunction): handle-based like the JSON pair;
1152
+ // strings travel as jsi strings, handles as the table's BigInts.
1153
+ function __crossbind_v_get(h, key) {
1154
+ return Emval.toHandle(Emval.toValue(h)[key]);
1155
+ }
1156
+ globalThis.__crossbind_v_get = __crossbind_v_get;
1157
+
1158
+ function __crossbind_v_set(h, key, v) {
1159
+ Emval.toValue(h)[key] = Emval.toValue(v);
1160
+ }
1161
+ globalThis.__crossbind_v_set = __crossbind_v_set;
1162
+
1163
+ function __crossbind_v_from_num(v) {
1164
+ return Emval.toHandle(v);
1165
+ }
1166
+ globalThis.__crossbind_v_from_num = __crossbind_v_from_num;
1167
+
1168
+ // A handle's value as a plain array, so the adapter can copy a typed array element by element.
1169
+ function __crossbind_v_to_array(h) {
1170
+ return Array.from(Emval.toValue(h));
1171
+ }
1172
+ globalThis.__crossbind_v_to_array = __crossbind_v_to_array;
1173
+
1174
+ // A handle's own value, so the adapter can copy a typed array straight from its backing store.
1175
+ function __crossbind_v_value(h) {
1176
+ return Emval.toValue(h);
1177
+ }
1178
+ globalThis.__crossbind_v_value = __crossbind_v_value;
1179
+
1180
+ // A typed array's length read here, so no handle is made for the number (web.cpp reads it alike).
1181
+ function __crossbind_v_length(h) {
1182
+ const value = Emval.toValue(h);
1183
+ return value && value.length !== undefined ? value.length : 0;
1184
+ }
1185
+ globalThis.__crossbind_v_length = __crossbind_v_length;
1186
+
1187
+ // Any JS value the adapter already built (a typed array, say) gets a handle of its own.
1188
+ function __crossbind_v_from_value(v) {
1189
+ return Emval.toHandle(v);
1190
+ }
1191
+ globalThis.__crossbind_v_from_value = __crossbind_v_from_value;
1192
+
1193
+ function __crossbind_v_from_bool(v) {
1194
+ return Emval.toHandle(!!v);
1195
+ }
1196
+ globalThis.__crossbind_v_from_bool = __crossbind_v_from_bool;
1197
+
1198
+ function __crossbind_v_from_str(s) {
1199
+ return Emval.toHandle(s);
1200
+ }
1201
+ globalThis.__crossbind_v_from_str = __crossbind_v_from_str;
1202
+
1203
+ function __crossbind_v_kind(h) {
1204
+ const v = Emval.toValue(h);
1205
+ if (v === null || v === undefined) return 0;
1206
+ const t = typeof v;
1207
+ if (t === 'boolean') return 1;
1208
+ if (t === 'number') return 2;
1209
+ if (t === 'string') return 3;
1210
+ if (t === 'function') return 4;
1211
+ return 5;
1212
+ }
1213
+ globalThis.__crossbind_v_kind = __crossbind_v_kind;
1214
+
1215
+ function __crossbind_v_as_num(h) {
1216
+ return Number(Emval.toValue(h));
1217
+ }
1218
+ globalThis.__crossbind_v_as_num = __crossbind_v_as_num;
1219
+
1220
+ function __crossbind_v_as_bool(h) {
1221
+ return Emval.toValue(h) ? 1 : 0;
1222
+ }
1223
+ globalThis.__crossbind_v_as_bool = __crossbind_v_as_bool;
1224
+
1225
+ function __crossbind_v_as_str(h) {
1226
+ return String(Emval.toValue(h));
1227
+ }
1228
+ globalThis.__crossbind_v_as_str = __crossbind_v_as_str;
1229
+
1230
+ function __crossbind_v_call(f, args) {
1231
+ const fn = Emval.toValue(f);
1232
+ return Emval.toHandle(fn(...args.map((a) => Emval.toValue(a))));
1233
+ }
1234
+ globalThis.__crossbind_v_call = __crossbind_v_call;
1235
+
1236
+ function __embind_register_memory_view(rawType, dataTypeIndex, name) {
1237
+ name = readLatin1String(name);
1238
+ registerType(rawType, {
1239
+ name: name,
1240
+ // C++ copies the elements into a typed array of the right kind (wire.h copyToTypedArray).
1241
+ 'fromWireType': function (typedArray) {
1242
+ return typedArray;
1243
+ },
1244
+ 'argPackAdvance': 8n,
1245
+ }, {
1246
+ ignoreDuplicateRegistrations: true,
1247
+ });
1248
+ }
1249
+ globalThis.__embind_register_memory_view = __embind_register_memory_view;
1250
+
1251
+ function runDestructors(destructors) {
1252
+ while (destructors.length) {
1253
+ var ptr = destructors.pop();
1254
+ var del = destructors.pop();
1255
+ del(ptr);
1256
+ }
1257
+ }
1258
+
1259
+
1260
+ function newFunc(constructor, argumentList) {
1261
+ if (!(constructor instanceof Function)) {
1262
+ throw new TypeError(`new_ called with constructor type ${typeof (constructor)} which is not a function`);
1263
+ }
1264
+ /*
1265
+ * Previously, the following line was just:
1266
+ * function dummy() {};
1267
+ * Unfortunately, Chrome was preserving 'dummy' as the object's name, even
1268
+ * though at creation, the 'dummy' has the correct constructor name. Thus,
1269
+ * objects created with IMVU.new would show up in the debugger as 'dummy',
1270
+ * which isn't very helpful. Using IMVU.createNamedFunction addresses the
1271
+ * issue. Doublely-unfortunately, there's no way to write a test for this
1272
+ * behavior. -NRD 2013.02.22
1273
+ */
1274
+ var dummy = createNamedFunction(constructor.name || 'unknownFunctionName', function () { });
1275
+ dummy.prototype = constructor.prototype;
1276
+ var obj = new dummy;
1277
+
1278
+ var r = constructor.apply(obj, argumentList);
1279
+ return (r instanceof Object) ? r : obj;
1280
+ }
1281
+ function craftInvokerFunction(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc, /** boolean= */ isAsync) {
1282
+ // console.log('craftInvokerFunction', humanName, argTypes);
1283
+ // humanName: a human-readable string name for the function to be generated.
1284
+ // argTypes: An array that contains the embind type objects for all types in the function signature.
1285
+ // argTypes[0] is the type object for the function return value.
1286
+ // argTypes[1] is the type object for function this object/class type, or null if not crafting an invoker for a class method.
1287
+ // argTypes[2...] are the actual function parameters.
1288
+ // classType: The embind type object for the class to be bound, or null if this is not a method of a class.
1289
+ // cppInvokerFunc: JS Function object to the C++-side function that interops into C++ code.
1290
+ // cppTargetFunc: Function pointer (an integer to FUNCTION_TABLE) to the target C++ function the cppInvokerFunc will end up calling.
1291
+ // isAsync: Optional. If true, returns an async function. Async bindings are only supported with JSPI.
1292
+ var argCount = argTypes.length;
1293
+
1294
+ if (argCount < 2) {
1295
+ throwBindingError("argTypes array size mismatch! Must at least get return value and 'this' types!");
1296
+ }
1297
+
1298
+ assert(!isAsync, 'Async bindings are only supported with JSPI.');
1299
+
1300
+ var isClassMethodFunc = (argTypes[1] !== null && classType !== null);
1301
+
1302
+ // Free functions with signature "void function()" do not need an invoker that marshalls between wire types.
1303
+ // TODO: This omits argument count check - enable only at -O3 or similar.
1304
+ // if (ENABLE_UNSAFE_OPTS && argCount == 2 && argTypes[0].name == "void" && !isClassMethodFunc) {
1305
+ // return FUNCTION_TABLE[fn];
1306
+ // }
1307
+
1308
+ // Determine if we need to use a dynamic stack to store the destructors for the function parameters.
1309
+ // TODO: Remove this completely once all function invokers are being dynamically generated.
1310
+ var needsDestructorStack = false;
1311
+
1312
+ for (var i = 1; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here.
1313
+ if (argTypes[i] !== null && argTypes[i].destructorFunction === undefined) { // The type does not define a destructor function - must use dynamic stack
1314
+ needsDestructorStack = true;
1315
+ break;
1316
+ }
1317
+ }
1318
+
1319
+ var returns = (argTypes[0].name !== "void");
1320
+
1321
+ var argsList = "";
1322
+ var argsListWired = "";
1323
+ for (var i = 0; i < argCount - 2; ++i) {
1324
+ argsList += (i !== 0 ? ", " : "") + "arg" + i;
1325
+ argsListWired += (i !== 0 ? ", " : "") + "arg" + i + "Wired";
1326
+ }
1327
+
1328
+ var invokerFnBody =
1329
+ "return function " + makeLegalFunctionName(humanName) + "(" + argsList + ") {\n" +
1330
+ "if (arguments.length !== " + (argCount - 2) + ") {\n" +
1331
+ "throwBindingError('function " + humanName + " called with ' + arguments.length + ' arguments, expected " + (argCount - 2) + " args!');\n" +
1332
+ "}\n";
1333
+
1334
+ if (needsDestructorStack) {
1335
+ invokerFnBody += "var destructors = [];\n";
1336
+ }
1337
+
1338
+ var dtorStack = needsDestructorStack ? "destructors" : "null";
1339
+ var args1 = ["throwBindingError", "invoker", "fn", "runDestructors", "retType", "classParam"];
1340
+ var args2 = [throwBindingError, cppInvokerFunc, cppTargetFunc, runDestructors, argTypes[0], argTypes[1]];
1341
+
1342
+ if (isClassMethodFunc) {
1343
+ invokerFnBody += "var thisWired = classParam.toWireType(" + dtorStack + ", this);\n";
1344
+ }
1345
+
1346
+ for (var i = 0; i < argCount - 2; ++i) {
1347
+ invokerFnBody += "var arg" + i + "Wired = argType" + i + ".toWireType(" + dtorStack + ", arg" + i + "); // " + argTypes[i + 2].name + "\n";
1348
+ args1.push("argType" + i);
1349
+ args2.push(argTypes[i + 2]);
1350
+ }
1351
+
1352
+ if (isClassMethodFunc) {
1353
+ argsListWired = "thisWired" + (argsListWired.length > 0 ? ", " : "") + argsListWired;
1354
+ }
1355
+
1356
+ if (cppInvokerFunc.rawFunction) {
1357
+ // Call the host function with a fixed argument list: going through the dyn caller cost a
1358
+ // rest array, a slice and a spread call on every call.
1359
+ // The generated code runs in the global scope, so it reaches the parked error through the object this
1360
+ // module calls globalThis: a Node loader bundle gives each runtime its own.
1361
+ args1.push("raw", "throwParked", "crossbindScope");
1362
+ args2.push(cppInvokerFunc.rawFunction, throwParkedError, globalThis);
1363
+ invokerFnBody +=
1364
+ "crossbindScope.__crossbindParkedError = null;\n" +
1365
+ (returns || isAsync ? "var rv = " : "") + "raw(" + argsListWired + ");\n" +
1366
+ "if (crossbindScope.__crossbindParkedError) throwParked();\n";
1367
+ } else {
1368
+ invokerFnBody +=
1369
+ (returns || isAsync ? "var rv = " : "") + "invoker(fn" + (argsListWired.length > 0 ? ", " : "") + argsListWired + ");\n";
1370
+ }
1371
+
1372
+ if (needsDestructorStack) {
1373
+ invokerFnBody += "runDestructors(destructors);\n";
1374
+ } else {
1375
+ for (var i = isClassMethodFunc ? 1 : 2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
1376
+ var paramName = (i === 1 ? "thisWired" : ("arg" + (i - 2) + "Wired"));
1377
+ if (argTypes[i].destructorFunction !== null) {
1378
+ invokerFnBody += paramName + "_dtor(" + paramName + "); // " + argTypes[i].name + "\n";
1379
+ args1.push(paramName + "_dtor");
1380
+ args2.push(argTypes[i].destructorFunction);
1381
+ }
1382
+ }
1383
+ }
1384
+
1385
+ if (returns) {
1386
+ invokerFnBody += "var ret = retType.fromWireType(rv);\n" +
1387
+ "return ret;\n";
1388
+ }
1389
+
1390
+ invokerFnBody += "}\n";
1391
+
1392
+ args1.push(invokerFnBody);
1393
+ //console.log('newFunc 1', args1);
1394
+ //console.log('newFunc 2', args2);
1395
+
1396
+ return newFunc(Function, args1).apply(null, args2);
1397
+ /* return (...az) => {
1398
+ console.log('craftInvokerFunction2', humanName, az);
1399
+ const y = newFunc(Function, args1).apply(null, args2);
1400
+ const k = y(...az);
1401
+ console.log('craftInvokerFunction21', humanName, k, az);
1402
+ return k;
1403
+ } */
1404
+ }
1405
+
1406
+ function ensureOverloadTable(proto, methodName, humanName) {
1407
+ if (undefined === proto[methodName].overloadTable) {
1408
+ var prevFunc = proto[methodName];
1409
+ // Inject an overload resolver function that routes to the appropriate overload based on the number of arguments.
1410
+ proto[methodName] = function () {
1411
+ // TODO This check can be removed in -O3 level "unsafe" optimizations.
1412
+ if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) {
1413
+ throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${arguments.length}) - expects one of (${proto[methodName].overloadTable})!`);
1414
+ }
1415
+ return proto[methodName].overloadTable[arguments.length].apply(this, arguments);
1416
+ };
1417
+ // Move the previous function into the overload table.
1418
+ proto[methodName].overloadTable = [];
1419
+ proto[methodName].overloadTable[prevFunc.argCount] = prevFunc;
1420
+ }
1421
+ }
1422
+
1423
+ /** @param {number=} numArguments */
1424
+ function exposePublicSymbol(name, value, numArguments) {
1425
+ if (Module.hasOwnProperty(name)) {
1426
+ if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
1427
+ throwBindingError(`Cannot register public name '${name}' twice`);
1428
+ }
1429
+
1430
+ // We are exposing a function with the same name as an existing function. Create an overload table and a function selector
1431
+ // that routes between the two.
1432
+ ensureOverloadTable(Module, name, name);
1433
+ if (Module.hasOwnProperty(numArguments)) {
1434
+ throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
1435
+ }
1436
+ // Add the new function into the overload table.
1437
+ Module[name].overloadTable[numArguments] = value;
1438
+ }
1439
+ else {
1440
+ Module[name] = value;
1441
+ if (undefined !== numArguments) {
1442
+ Module[name].numArguments = numArguments;
1443
+ }
1444
+ }
1445
+ }
1446
+
1447
+ function heap32VectorToArray(count, firstElement) {
1448
+ return firstElement;
1449
+ /* var array = [];
1450
+ for (var i = 0; i < count; i++) {
1451
+ // TODO(https://github.com/emscripten-core/emscripten/issues/17310):
1452
+ // Find a way to hoist the `>> 2` or `>> 3` out of this loop.
1453
+ array.push(Number(HEAPU64[(((firstElement)+(i * 8))>>3)]));
1454
+ }
1455
+ return array; */
1456
+ }
1457
+
1458
+
1459
+ /** @param {number=} numArguments */
1460
+ function replacePublicSymbol(name, value, numArguments) {
1461
+ if (!Module.hasOwnProperty(name)) {
1462
+ throwInternalError('Replacing nonexistant public symbol');
1463
+ }
1464
+ // If there's an overload table for this symbol, replace the symbol in the overload table instead.
1465
+ if (undefined !== Module[name].overloadTable && undefined !== numArguments) {
1466
+ Module[name].overloadTable[numArguments] = value;
1467
+ }
1468
+ else {
1469
+ Module[name] = value;
1470
+ Module[name].argCount = numArguments;
1471
+ }
1472
+ }
1473
+
1474
+
1475
+
1476
+ // A Rust binding cannot throw through Hermes: an exception escaping a host function comes back
1477
+ // as "Exception in HostFunction: ...", with the message rewritten and any property (the error
1478
+ // `code`) gone. The adapter parks the error here instead, and every invoker rethrows it on the
1479
+ // way out, so JS sees an Error this runtime built.
1480
+ globalThis.__crossbind_park_error = function (message, code) {
1481
+ var error = new Error(message);
1482
+ if (code !== undefined) error.code = code;
1483
+ globalThis.__crossbindParkedError = error;
1484
+ };
1485
+
1486
+ function throwParkedError() {
1487
+ const parked = globalThis.__crossbindParkedError;
1488
+ globalThis.__crossbindParkedError = null;
1489
+ throw parked;
1490
+ }
1491
+
1492
+ function getDynCaller(signature, rawFunction, slice) {
1493
+ const caller = (...args) => {
1494
+ //console.log('getDynCallerReturn', signature, rawFunction, args.length, ...args);
1495
+ if (slice) {
1496
+ args = args.slice(1);
1497
+ }
1498
+ globalThis.__crossbindParkedError = null;
1499
+ const result = rawFunction(...args);
1500
+ const parked = globalThis.__crossbindParkedError;
1501
+ if (parked) {
1502
+ globalThis.__crossbindParkedError = null;
1503
+ throw parked;
1504
+ }
1505
+ return result;
1506
+ };
1507
+ // craftInvokerFunction calls a sliced function directly, without the fn argument this drops.
1508
+ if (slice) caller.rawFunction = rawFunction;
1509
+ return caller;
1510
+ }
1511
+
1512
+ function embind__requireFunction(signature, rawFunction, slice = false) {
1513
+ signature = readLatin1String(signature);
1514
+
1515
+ function makeDynCaller() {
1516
+ {
1517
+ return getDynCaller(signature, rawFunction, slice);
1518
+ }
1519
+ }
1520
+
1521
+ var fp = makeDynCaller();
1522
+ if (typeof fp != "function") {
1523
+ throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
1524
+ }
1525
+ return fp;
1526
+ }
1527
+
1528
+
1529
+
1530
+ var UnboundTypeError = undefined;
1531
+
1532
+
1533
+ function ___getTypeName() { }
1534
+
1535
+ function getTypeName(type) {
1536
+ var ptr = ___getTypeName();
1537
+ var rv = readLatin1String(ptr);
1538
+ return rv;
1539
+ }
1540
+ function throwUnboundTypeError(message, types) {
1541
+ var unboundTypes = [];
1542
+ var seen = {};
1543
+ function visit(type) {
1544
+ if (seen[type]) {
1545
+ return;
1546
+ }
1547
+ if (registeredTypes[type]) {
1548
+ return;
1549
+ }
1550
+ if (typeDependencies[type]) {
1551
+ typeDependencies[type].forEach(visit);
1552
+ return;
1553
+ }
1554
+ unboundTypes.push(type);
1555
+ seen[type] = true;
1556
+ }
1557
+ types.forEach(visit);
1558
+
1559
+ throw new UnboundTypeError(message + ': ' + unboundTypes.map(getTypeName).join([', ']));
1560
+ }
1561
+
1562
+ function __embind_register_function(name, argCount, rawArgTypesAddr, signature, rawInvoker, fn, isAsync) {
1563
+ // const argCount = Number(argCount);
1564
+ // console.log('function', name, argCount, rawArgTypesAddr, signature, rawInvoker, fn, isAsync);
1565
+ var argTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
1566
+ name = readLatin1String(name);
1567
+ // console.log('a1');
1568
+ rawInvoker = embind__requireFunction(signature, rawInvoker, true);
1569
+ // console.log('a2');
1570
+ exposePublicSymbol(name, function () {
1571
+ throwUnboundTypeError(`Cannot call ${name} due to unbound types`, argTypes);
1572
+ }, argCount - 1);
1573
+ // console.log('a3');
1574
+ whenDependentTypesAreResolved([], argTypes, function (argTypes) {
1575
+ // console.log('a4', argTypes);
1576
+ var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
1577
+ // console.log('a5');
1578
+ replacePublicSymbol(name, craftInvokerFunction(name, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn, isAsync), argCount - 1);
1579
+ // console.log('a6');
1580
+ return [];
1581
+ });
1582
+ // console.log('a7');
1583
+ }
1584
+
1585
+ globalThis.__embind_register_function = __embind_register_function;
1586
+
1587
+ var tupleRegistrations = {};
1588
+
1589
+
1590
+ function __embind_register_value_array(
1591
+ rawType,
1592
+ name,
1593
+ constructorSignature,
1594
+ rawConstructor,
1595
+ destructorSignature,
1596
+ rawDestructor
1597
+ ) {
1598
+ tupleRegistrations[rawType] = {
1599
+ name: readLatin1String(name),
1600
+ rawConstructor: embind__requireFunction(constructorSignature, rawConstructor),
1601
+ rawDestructor: embind__requireFunction(destructorSignature, rawDestructor),
1602
+ elements: [],
1603
+ };
1604
+ }
1605
+
1606
+ globalThis.__embind_register_value_array = __embind_register_value_array;
1607
+
1608
+ function __embind_register_value_array_element(
1609
+ rawTupleType,
1610
+ getterReturnType,
1611
+ getterSignature,
1612
+ getter,
1613
+ getterContext,
1614
+ setterArgumentType,
1615
+ setterSignature,
1616
+ setter,
1617
+ setterContext
1618
+ ) {
1619
+ tupleRegistrations[rawTupleType].elements.push({
1620
+ getterReturnType: getterReturnType,
1621
+ getter: embind__requireFunction(getterSignature, getter),
1622
+ getterContext: getterContext,
1623
+ setterArgumentType: setterArgumentType,
1624
+ setter: embind__requireFunction(setterSignature, setter),
1625
+ setterContext: setterContext,
1626
+ });
1627
+ }
1628
+
1629
+ globalThis.__embind_register_value_array_element = __embind_register_value_array_element;
1630
+
1631
+
1632
+ function __embind_finalize_value_array(rawTupleType) {
1633
+ var reg = tupleRegistrations[rawTupleType];
1634
+ delete tupleRegistrations[rawTupleType];
1635
+ var elements = reg.elements;
1636
+ var elementsLength = elements.length;
1637
+ var elementTypes = elements.map(function (elt) { return elt.getterReturnType; }).
1638
+ concat(elements.map(function (elt) { return elt.setterArgumentType; }));
1639
+
1640
+ var rawConstructor = reg.rawConstructor;
1641
+ var rawDestructor = reg.rawDestructor;
1642
+
1643
+ whenDependentTypesAreResolved([rawTupleType], elementTypes, function (elementTypes) {
1644
+ elements.forEach((elt, i) => {
1645
+ var getterReturnType = elementTypes[i];
1646
+ var getter = elt.getter;
1647
+ var getterContext = elt.getterContext;
1648
+ var setterArgumentType = elementTypes[i + elementsLength];
1649
+ var setter = elt.setter;
1650
+ var setterContext = elt.setterContext;
1651
+ elt.read = (ptr) => {
1652
+ //console.log('elt.read ', ptr);
1653
+ const a = getter(getterContext, ptr);
1654
+ //console.log('elt.read2 ', ptr, a);
1655
+ //console.log('elt.read3 ', ptr, a, getterReturnType['fromWireType'](a));
1656
+ return getterReturnType['fromWireType'](a);
1657
+ };
1658
+ elt.write = (ptr, o) => {
1659
+ //console.log('elt.write ', ptr, o);
1660
+ var destructors = [];
1661
+ setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
1662
+ runDestructors(destructors);
1663
+ };
1664
+ });
1665
+
1666
+ return [{
1667
+ name: reg.name,
1668
+ 'fromWireType': function (ptr) {
1669
+ //console.log('__embind_finalize_value_array fromWireType', reg.name, ptr);
1670
+ var rv = new Array(elementsLength);
1671
+ for (var i = 0; i < elementsLength; ++i) {
1672
+ rv[i] = elements[i].read(ptr);
1673
+ }
1674
+ rawDestructor(ptr);
1675
+ return rv;
1676
+ },
1677
+ 'toWireType': function (destructors, o) {
1678
+ if (elementsLength !== o.length) {
1679
+ throw new TypeError(`Incorrect number of tuple elements for ${reg.name}: expected=${elementsLength}, actual=${o.length}`);
1680
+ }
1681
+ var ptr = rawConstructor();
1682
+ //console.log('__embind_finalize_value_array toWireType', reg.name, ptr);
1683
+ for (var i = 0; i < elementsLength; ++i) {
1684
+ elements[i].write(ptr, o[i]);
1685
+ }
1686
+ if (destructors !== null) {
1687
+ destructors.push(rawDestructor, ptr);
1688
+ }
1689
+ return ptr;
1690
+ },
1691
+ 'argPackAdvance': 8n,
1692
+ destructorFunction: rawDestructor,
1693
+ }];
1694
+ });
1695
+ }
1696
+
1697
+ globalThis.__embind_finalize_value_array = __embind_finalize_value_array;
1698
+
1699
+ var structRegistrations = {};
1700
+
1701
+
1702
+ function __embind_register_value_object(
1703
+ rawType,
1704
+ name,
1705
+ constructorSignature,
1706
+ rawConstructor,
1707
+ destructorSignature,
1708
+ rawDestructor
1709
+ ) {
1710
+ structRegistrations[rawType] = {
1711
+ name: readLatin1String(name),
1712
+ rawConstructor: embind__requireFunction(constructorSignature, rawConstructor),
1713
+ rawDestructor: embind__requireFunction(destructorSignature, rawDestructor),
1714
+ fields: [],
1715
+ };
1716
+ }
1717
+
1718
+ globalThis.__embind_register_value_object = __embind_register_value_object;
1719
+
1720
+
1721
+ function __embind_register_value_object_field(
1722
+ structType,
1723
+ fieldName,
1724
+ getterReturnType,
1725
+ getterSignature,
1726
+ getter,
1727
+ getterContext,
1728
+ setterArgumentType,
1729
+ setterSignature,
1730
+ setter,
1731
+ setterContext
1732
+ ) {
1733
+ structRegistrations[structType].fields.push({
1734
+ fieldName: readLatin1String(fieldName),
1735
+ getterReturnType: getterReturnType,
1736
+ getter: embind__requireFunction(getterSignature, getter),
1737
+ getterContext: getterContext,
1738
+ setterArgumentType: setterArgumentType,
1739
+ setter: embind__requireFunction(setterSignature, setter),
1740
+ setterContext: setterContext,
1741
+ });
1742
+ }
1743
+
1744
+ globalThis.__embind_register_value_object_field = __embind_register_value_object_field;
1745
+
1746
+
1747
+ function __embind_finalize_value_object(structType) {
1748
+ var reg = structRegistrations[structType];
1749
+ delete structRegistrations[structType];
1750
+
1751
+ var rawConstructor = reg.rawConstructor;
1752
+ var rawDestructor = reg.rawDestructor;
1753
+ var fieldRecords = reg.fields;
1754
+ var fieldTypes = fieldRecords.map((field) => field.getterReturnType).
1755
+ concat(fieldRecords.map((field) => field.setterArgumentType));
1756
+ whenDependentTypesAreResolved([structType], fieldTypes, (fieldTypes) => {
1757
+ var fields = {};
1758
+ fieldRecords.forEach((field, i) => {
1759
+ var fieldName = field.fieldName;
1760
+ var getterReturnType = fieldTypes[i];
1761
+ var getter = field.getter;
1762
+ var getterContext = field.getterContext;
1763
+ var setterArgumentType = fieldTypes[i + fieldRecords.length];
1764
+ var setter = field.setter;
1765
+ var setterContext = field.setterContext;
1766
+ fields[fieldName] = {
1767
+ read: (ptr) => {
1768
+ return getterReturnType['fromWireType'](
1769
+ getter(getterContext, ptr));
1770
+ },
1771
+ write: (ptr, o) => {
1772
+ var destructors = [];
1773
+ setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
1774
+ runDestructors(destructors);
1775
+ }
1776
+ };
1777
+ });
1778
+
1779
+ return [{
1780
+ name: reg.name,
1781
+ 'fromWireType': function (ptr) {
1782
+ //console.log('fromWireType __embind_finalize_value_object');
1783
+ var rv = {};
1784
+ for (var i in fields) {
1785
+ rv[i] = fields[i].read(ptr);
1786
+ }
1787
+ rawDestructor(ptr);
1788
+ return rv;
1789
+ },
1790
+ 'toWireType': function (destructors, o) {
1791
+ //console.log('toWireType __embind_finalize_value_object');
1792
+ // todo: Here we have an opportunity for -O3 level "unsafe" optimizations:
1793
+ // assume all fields are present without checking.
1794
+ for (var fieldName in fields) {
1795
+ if (!(fieldName in o)) {
1796
+ throw new TypeError(`Missing field: "${fieldName}"`);
1797
+ }
1798
+ }
1799
+ var ptr = rawConstructor();
1800
+ for (fieldName in fields) {
1801
+ fields[fieldName].write(ptr, o[fieldName]);
1802
+ }
1803
+ if (destructors !== null) {
1804
+ destructors.push(rawDestructor, ptr);
1805
+ }
1806
+ return ptr;
1807
+ },
1808
+ 'argPackAdvance': 8n,
1809
+ destructorFunction: rawDestructor,
1810
+ }];
1811
+ });
1812
+ }
1813
+
1814
+ globalThis.__embind_finalize_value_object = __embind_finalize_value_object;
1815
+
1816
+
1817
+ function ClassHandle_isAliasOf(other) {
1818
+ // console.log('ClassHandle_isAliasOf');
1819
+ if (!(this instanceof ClassHandle)) {
1820
+ return false;
1821
+ }
1822
+ if (!(other instanceof ClassHandle)) {
1823
+ return false;
1824
+ }
1825
+
1826
+ var leftClass = this.$$.ptrType.registeredClass;
1827
+ var left = this.$$.ptr;
1828
+ var rightClass = other.$$.ptrType.registeredClass;
1829
+ var right = other.$$.ptr;
1830
+
1831
+ while (leftClass.baseClass) {
1832
+ left = leftClass.upcast(left);
1833
+ leftClass = leftClass.baseClass;
1834
+ }
1835
+
1836
+ while (rightClass.baseClass) {
1837
+ right = rightClass.upcast(right);
1838
+ rightClass = rightClass.baseClass;
1839
+ }
1840
+
1841
+ return leftClass === rightClass && left === right;
1842
+ }
1843
+
1844
+ function shallowCopyInternalPointer(o) {
1845
+ return {
1846
+ count: o.count,
1847
+ deleteScheduled: o.deleteScheduled,
1848
+ preservePointerOnDelete: o.preservePointerOnDelete,
1849
+ ptr: o.ptr,
1850
+ ptrType: o.ptrType,
1851
+ smartPtr: o.smartPtr,
1852
+ smartPtrType: o.smartPtrType,
1853
+ };
1854
+ }
1855
+
1856
+ function throwInstanceAlreadyDeleted(obj) {
1857
+ function getInstanceTypeName(handle) {
1858
+ return handle.$$.ptrType.registeredClass.name;
1859
+ }
1860
+ throwBindingError(getInstanceTypeName(obj) + ' instance already deleted');
1861
+ }
1862
+
1863
+ var finalizationRegistry = false;
1864
+
1865
+ function detachFinalizer(handle) { }
1866
+
1867
+ function runDestructor($$) {
1868
+ if ($$.smartPtr) {
1869
+ $$.smartPtrType.rawDestructor($$.smartPtr);
1870
+ } else {
1871
+ $$.ptrType.registeredClass.rawDestructor($$.ptr);
1872
+ }
1873
+ }
1874
+ function releaseClassHandle($$) {
1875
+ $$.count.value -= 1;
1876
+ var toDelete = 0 === $$.count.value;
1877
+ if (toDelete) {
1878
+ runDestructor($$);
1879
+ }
1880
+ }
1881
+
1882
+ function downcastPointer(ptr, ptrClass, desiredClass) {
1883
+ if (ptrClass === desiredClass) {
1884
+ return ptr;
1885
+ }
1886
+ if (undefined === desiredClass.baseClass) {
1887
+ return null; // no conversion
1888
+ }
1889
+
1890
+ var rv = downcastPointer(ptr, ptrClass, desiredClass.baseClass);
1891
+ if (rv === null) {
1892
+ return null;
1893
+ }
1894
+ return desiredClass.downcast(rv);
1895
+ }
1896
+
1897
+ var registeredPointers = {};
1898
+
1899
+ function getInheritedInstanceCount() {
1900
+ return Object.keys(registeredInstances).length;
1901
+ }
1902
+
1903
+ function getLiveInheritedInstances() {
1904
+ var rv = [];
1905
+ for (var k in registeredInstances) {
1906
+ if (registeredInstances.hasOwnProperty(k)) {
1907
+ rv.push(registeredInstances[k]);
1908
+ }
1909
+ }
1910
+ return rv;
1911
+ }
1912
+
1913
+ var deletionQueue = [];
1914
+ function flushPendingDeletes() {
1915
+ while (deletionQueue.length) {
1916
+ var obj = deletionQueue.pop();
1917
+ obj.$$.deleteScheduled = false;
1918
+ obj['delete']();
1919
+ }
1920
+ }
1921
+
1922
+ var delayFunction = undefined;
1923
+
1924
+
1925
+ function setDelayFunction(fn) {
1926
+ delayFunction = fn;
1927
+ if (deletionQueue.length && delayFunction) {
1928
+ delayFunction(flushPendingDeletes);
1929
+ }
1930
+ }
1931
+ function init_embind() {
1932
+ Module['getInheritedInstanceCount'] = getInheritedInstanceCount;
1933
+ Module['getLiveInheritedInstances'] = getLiveInheritedInstances;
1934
+ Module['flushPendingDeletes'] = flushPendingDeletes;
1935
+ Module['setDelayFunction'] = setDelayFunction;
1936
+ }
1937
+ var registeredInstances = {};
1938
+
1939
+ function getBasestPointer(class_, ptr) {
1940
+ // console.log('getBasestPointer');
1941
+ if (ptr === undefined) {
1942
+ throwBindingError('ptr should not be undefined');
1943
+ }
1944
+ while (class_.baseClass) {
1945
+ ptr = class_.upcast(ptr);
1946
+ class_ = class_.baseClass;
1947
+ }
1948
+ return ptr;
1949
+ }
1950
+ function getInheritedInstance(class_, ptr) {
1951
+ ptr = getBasestPointer(class_, ptr);
1952
+ return registeredInstances[ptr];
1953
+ }
1954
+
1955
+
1956
+ function makeClassHandle(prototype, record) {
1957
+ //console.log('makeClassHandle', prototype, record);
1958
+ if (!record.ptrType || !record.ptr) {
1959
+ throwInternalError('makeClassHandle requires ptr and ptrType');
1960
+ }
1961
+ var hasSmartPtrType = !!record.smartPtrType;
1962
+ var hasSmartPtr = !!record.smartPtr;
1963
+ if (hasSmartPtrType !== hasSmartPtr) {
1964
+ throwInternalError('Both smartPtrType and smartPtr must be specified');
1965
+ }
1966
+ record.count = { value: 1 };
1967
+ return attachFinalizer(Object.create(prototype, {
1968
+ $$: {
1969
+ value: record,
1970
+ },
1971
+ }));
1972
+ }
1973
+ function RegisteredPointer_fromWireType(ptr) {
1974
+ //console.log('RegisteredPointer_fromWireType', ptr);
1975
+ // ptr is a raw pointer (or a raw smartpointer)
1976
+ // ptr = bigintToI53Checked(ptr);
1977
+ // console.log('RegisteredPointer_fromWireType 2', ptr);
1978
+ // assert(Number.isSafeInteger(ptr));
1979
+
1980
+ // rawPointer is a maybe-null raw pointer
1981
+ var rawPointer = this.getPointee(ptr);
1982
+ //console.log('RegisteredPointer_fromWireType - rawPointer: ', rawPointer);
1983
+
1984
+ if (!rawPointer) {
1985
+ this.destructor(ptr);
1986
+ return null;
1987
+ }
1988
+
1989
+ var registeredInstance = getInheritedInstance(this.registeredClass, rawPointer);
1990
+ //console.log('RegisteredPointer_fromWireType - registeredInstance: ', registeredInstance);
1991
+ if (undefined !== registeredInstance) {
1992
+ // JS object has been neutered, time to repopulate it
1993
+ if (0 === registeredInstance.$$.count.value) {
1994
+ registeredInstance.$$.ptr = rawPointer;
1995
+ registeredInstance.$$.smartPtr = ptr;
1996
+ return registeredInstance['clone']();
1997
+ } else {
1998
+ // else, just increment reference count on existing object
1999
+ // it already has a reference to the smart pointer
2000
+ var rv = registeredInstance['clone']();
2001
+ this.destructor(ptr);
2002
+ return rv;
2003
+ }
2004
+ }
2005
+
2006
+ function makeDefaultHandle() {
2007
+ if (this.isSmartPointer) {
2008
+ return makeClassHandle(this.registeredClass.instancePrototype, {
2009
+ ptrType: this.pointeeType,
2010
+ ptr: rawPointer,
2011
+ smartPtrType: this,
2012
+ smartPtr: ptr,
2013
+ });
2014
+ } else {
2015
+ return makeClassHandle(this.registeredClass.instancePrototype, {
2016
+ ptrType: this,
2017
+ ptr: ptr,
2018
+ });
2019
+ }
2020
+ }
2021
+
2022
+ var actualType = this.registeredClass.getActualType(rawPointer);
2023
+ var registeredPointerRecord = registeredPointers[actualType];
2024
+ //console.log('RegisteredPointer_fromWireType - actualType: ', actualType);
2025
+ //console.log('RegisteredPointer_fromWireType - registeredPointerRecord: ', registeredPointerRecord);
2026
+ if (!registeredPointerRecord) {
2027
+ return makeDefaultHandle.call(this);
2028
+ }
2029
+
2030
+ var toType;
2031
+ if (this.isConst) {
2032
+ toType = registeredPointerRecord.constPointerType;
2033
+ } else {
2034
+ toType = registeredPointerRecord.pointerType;
2035
+ }
2036
+ //console.log('RegisteredPointer_fromWireType - toType: ', toType, this.isConst);
2037
+ var dp = downcastPointer(
2038
+ rawPointer,
2039
+ this.registeredClass,
2040
+ toType.registeredClass);
2041
+ //console.log('RegisteredPointer_fromWireType - downcastPointer: ', dp);
2042
+ //console.log('RegisteredPointer_fromWireType - isSmartPointer: ', this.isSmartPointer);
2043
+ if (dp === null) {
2044
+ return makeDefaultHandle.call(this);
2045
+ }
2046
+ if (this.isSmartPointer) {
2047
+ return makeClassHandle(toType.registeredClass.instancePrototype, {
2048
+ ptrType: toType,
2049
+ ptr: dp,
2050
+ smartPtrType: this,
2051
+ smartPtr: ptr,
2052
+ });
2053
+ } else {
2054
+ return makeClassHandle(toType.registeredClass.instancePrototype, {
2055
+ ptrType: toType,
2056
+ ptr: dp,
2057
+ });
2058
+ }
2059
+ }
2060
+ function attachFinalizer(handle) {
2061
+ //console.log('attachFinalizer', handle);
2062
+ if ('undefined' === typeof FinalizationRegistry) {
2063
+ attachFinalizer = (handle) => handle;
2064
+ return handle;
2065
+ }
2066
+ // If the running environment has a FinalizationRegistry (see
2067
+ // https://github.com/tc39/proposal-weakrefs), then attach finalizers
2068
+ // for class handles. We check for the presence of FinalizationRegistry
2069
+ // at run-time, not build-time.
2070
+ // A collected handle is released without the warning upstream prints under ASSERTIONS, as a release wasm build
2071
+ // does: JavaScript never has to call .delete() on what crossbind hands it.
2072
+ finalizationRegistry = new FinalizationRegistry((info) => {
2073
+ releaseClassHandle(info.$$);
2074
+ });
2075
+ attachFinalizer = (handle) => {
2076
+ var $$ = handle.$$;
2077
+ var hasSmartPtr = !!$$.smartPtr;
2078
+ if (hasSmartPtr) {
2079
+ // We should not call the destructor on raw pointers in case other code expects the pointee to live
2080
+ finalizationRegistry.register(handle, { $$: $$ }, handle);
2081
+ }
2082
+ return handle;
2083
+ };
2084
+ detachFinalizer = (handle) => finalizationRegistry.unregister(handle);
2085
+ return attachFinalizer(handle);
2086
+ }
2087
+ function ClassHandle_clone() {
2088
+ if (!this.$$.ptr) {
2089
+ throwInstanceAlreadyDeleted(this);
2090
+ }
2091
+
2092
+ if (this.$$.preservePointerOnDelete) {
2093
+ this.$$.count.value += 1;
2094
+ return this;
2095
+ } else {
2096
+ var clone = attachFinalizer(Object.create(Object.getPrototypeOf(this), {
2097
+ $$: {
2098
+ value: shallowCopyInternalPointer(this.$$),
2099
+ }
2100
+ }));
2101
+
2102
+ clone.$$.count.value += 1;
2103
+ clone.$$.deleteScheduled = false;
2104
+ return clone;
2105
+ }
2106
+ }
2107
+
2108
+
2109
+
2110
+
2111
+ function ClassHandle_delete() {
2112
+ if (!this.$$.ptr) {
2113
+ throwInstanceAlreadyDeleted(this);
2114
+ }
2115
+
2116
+ if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) {
2117
+ throwBindingError('Object already scheduled for deletion');
2118
+ }
2119
+
2120
+ detachFinalizer(this);
2121
+ releaseClassHandle(this.$$);
2122
+
2123
+ if (!this.$$.preservePointerOnDelete) {
2124
+ this.$$.smartPtr = undefined;
2125
+ this.$$.ptr = undefined;
2126
+ }
2127
+ }
2128
+
2129
+ function ClassHandle_isDeleted() {
2130
+ return !this.$$.ptr;
2131
+ }
2132
+
2133
+
2134
+
2135
+ function ClassHandle_deleteLater() {
2136
+ if (!this.$$.ptr) {
2137
+ throwInstanceAlreadyDeleted(this);
2138
+ }
2139
+ if (this.$$.deleteScheduled && !this.$$.preservePointerOnDelete) {
2140
+ throwBindingError('Object already scheduled for deletion');
2141
+ }
2142
+ deletionQueue.push(this);
2143
+ if (deletionQueue.length === 1 && delayFunction) {
2144
+ delayFunction(flushPendingDeletes);
2145
+ }
2146
+ this.$$.deleteScheduled = true;
2147
+ return this;
2148
+ }
2149
+ function init_ClassHandle() {
2150
+ ClassHandle.prototype['isAliasOf'] = ClassHandle_isAliasOf;
2151
+ ClassHandle.prototype['clone'] = ClassHandle_clone;
2152
+ ClassHandle.prototype['delete'] = ClassHandle_delete;
2153
+ ClassHandle.prototype['isDeleted'] = ClassHandle_isDeleted;
2154
+ ClassHandle.prototype['deleteLater'] = ClassHandle_deleteLater;
2155
+ }
2156
+ function ClassHandle() {
2157
+ }
2158
+
2159
+
2160
+
2161
+
2162
+
2163
+
2164
+ /** @constructor */
2165
+ function RegisteredClass(name,
2166
+ constructor,
2167
+ instancePrototype,
2168
+ rawDestructor,
2169
+ baseClass,
2170
+ getActualType,
2171
+ upcast,
2172
+ downcast) {
2173
+ this.name = name;
2174
+ this.constructor = constructor;
2175
+ this.instancePrototype = instancePrototype;
2176
+ this.rawDestructor = rawDestructor;
2177
+ this.baseClass = baseClass;
2178
+ this.getActualType = getActualType;
2179
+ this.upcast = upcast;
2180
+ this.downcast = downcast;
2181
+ this.pureVirtualFunctions = [];
2182
+ }
2183
+
2184
+
2185
+ function upcastPointer(ptr, ptrClass, desiredClass) {
2186
+ // console.log('upcastPointer');
2187
+ while (ptrClass !== desiredClass) {
2188
+ if (!ptrClass.upcast) {
2189
+ throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`);
2190
+ }
2191
+ ptr = ptrClass.upcast(ptr);
2192
+ ptrClass = ptrClass.baseClass;
2193
+ }
2194
+ return ptr;
2195
+ }
2196
+ function constNoSmartPtrRawPointerToWireType(destructors, handle) {
2197
+ // console.log('constNoSmartPtrRawPointerToWireType');
2198
+ if (handle === null) {
2199
+ if (this.isReference) {
2200
+ throwBindingError('null is not a valid ' + this.name);
2201
+ }
2202
+ return 0;
2203
+ }
2204
+
2205
+ if (!handle.$$) {
2206
+ throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
2207
+ }
2208
+ if (!handle.$$.ptr) {
2209
+ throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
2210
+ }
2211
+ var handleClass = handle.$$.ptrType.registeredClass;
2212
+ var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
2213
+ return ptr;
2214
+ }
2215
+
2216
+
2217
+ function genericPointerToWireType(destructors, handle) {
2218
+ // console.log('genericPointerToWireType');
2219
+ var ptr;
2220
+ if (handle === null) {
2221
+ if (this.isReference) {
2222
+ throwBindingError('null is not a valid ' + this.name);
2223
+ }
2224
+
2225
+ if (this.isSmartPointer) {
2226
+ ptr = this.rawConstructor();
2227
+ if (destructors !== null) {
2228
+ destructors.push(this.rawDestructor, ptr);
2229
+ }
2230
+ return ptr;
2231
+ } else {
2232
+ return 0;
2233
+ }
2234
+ }
2235
+
2236
+ if (!handle.$$) {
2237
+ throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
2238
+ }
2239
+ if (!handle.$$.ptr) {
2240
+ throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`);
2241
+ }
2242
+ if (!this.isConst && handle.$$.ptrType.isConst) {
2243
+ throwBindingError(`Cannot convert argument of type ${(handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name)} to parameter type ${this.name}`);
2244
+ }
2245
+ var handleClass = handle.$$.ptrType.registeredClass;
2246
+ ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
2247
+
2248
+ if (this.isSmartPointer) {
2249
+ // TODO: this is not strictly true
2250
+ // We could support BY_EMVAL conversions from raw pointers to smart pointers
2251
+ // because the smart pointer can hold a reference to the handle
2252
+ if (undefined === handle.$$.smartPtr) {
2253
+ throwBindingError('Passing raw pointer to smart pointer is illegal');
2254
+ }
2255
+
2256
+ switch (this.sharingPolicy) {
2257
+ case 0: // NONE
2258
+ case 0n:
2259
+ // no upcasting
2260
+ if (handle.$$.smartPtrType === this) {
2261
+ ptr = handle.$$.smartPtr;
2262
+ } else {
2263
+ throwBindingError(`Cannot convert argument of type ${(handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name)} to parameter type ${this.name}`);
2264
+ }
2265
+ break;
2266
+
2267
+ case 1: // INTRUSIVE
2268
+ case 1n:
2269
+ ptr = handle.$$.smartPtr;
2270
+ break;
2271
+
2272
+ case 2: // BY_EMVAL
2273
+ case 2n:
2274
+ if (handle.$$.smartPtrType === this) {
2275
+ ptr = handle.$$.smartPtr;
2276
+ } else {
2277
+ var clonedHandle = handle['clone']();
2278
+ const tt = Emval.toHandle(function () {
2279
+ clonedHandle['delete']();
2280
+ });
2281
+ //console.log('this.rawShare(', ptr, tt);
2282
+ ptr = this.rawShare(
2283
+ ptr,
2284
+ tt
2285
+ );
2286
+ //console.log('this.rawShare = ', ptr);
2287
+ if (destructors !== null) {
2288
+ destructors.push(this.rawDestructor, ptr);
2289
+ }
2290
+ }
2291
+ break;
2292
+
2293
+ default:
2294
+ throwBindingError('Unsupporting sharing policy');
2295
+ }
2296
+ }
2297
+ return ptr;
2298
+ }
2299
+
2300
+
2301
+ function nonConstNoSmartPtrRawPointerToWireType(destructors, handle) {
2302
+ // console.log('nonConstNoSmartPtrRawPointerToWireType');
2303
+ if (handle === null) {
2304
+ if (this.isReference) {
2305
+ throwBindingError('null is not a valid ' + this.name);
2306
+ }
2307
+ return 0;
2308
+ }
2309
+ //console.log('nonConstNoSmartPtrRawPointerToWireType 1', handle.$$, handle.smartPtr);
2310
+
2311
+ if (!handle.$$) {
2312
+ throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
2313
+ }
2314
+ //console.log('nonConstNoSmartPtrRawPointerToWireType 2');
2315
+ if (!handle.$$.ptr) {
2316
+ throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`);
2317
+ }
2318
+ //console.log('nonConstNoSmartPtrRawPointerToWireType 3');
2319
+ if (handle.$$.ptrType.isConst) {
2320
+ throwBindingError(`Cannot convert argument of type ${handle.$$.ptrType.name} to parameter type ${this.name}`);
2321
+ }
2322
+ //console.log('nonConstNoSmartPtrRawPointerToWireType 4');
2323
+ var handleClass = handle.$$.ptrType.registeredClass;
2324
+ var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
2325
+ //console.log('nonConstNoSmartPtrRawPointerToWireType 5');
2326
+ return ptr;
2327
+ }
2328
+
2329
+
2330
+ function RegisteredPointer_getPointee(ptr) {
2331
+ //console.log('RegisteredPointer_getPointee', ptr, this.rawGetPointee);
2332
+ if (this.rawGetPointee) {
2333
+ ptr = this.rawGetPointee(ptr);
2334
+ }
2335
+ return ptr;
2336
+ }
2337
+
2338
+ function RegisteredPointer_destructor(ptr) {
2339
+ if (this.rawDestructor) {
2340
+ this.rawDestructor(ptr);
2341
+ }
2342
+ }
2343
+
2344
+ function RegisteredPointer_deleteObject(handle) {
2345
+ if (handle !== null) {
2346
+ handle['delete']();
2347
+ }
2348
+ }
2349
+
2350
+ function init_RegisteredPointer() {
2351
+ RegisteredPointer.prototype.getPointee = RegisteredPointer_getPointee;
2352
+ RegisteredPointer.prototype.destructor = RegisteredPointer_destructor;
2353
+ RegisteredPointer.prototype['argPackAdvance'] = 8n;
2354
+ RegisteredPointer.prototype['deleteObject'] = RegisteredPointer_deleteObject;
2355
+ RegisteredPointer.prototype['fromWireType'] = RegisteredPointer_fromWireType;
2356
+ }
2357
+ /** @constructor
2358
+ @param {*=} pointeeType,
2359
+ @param {*=} sharingPolicy,
2360
+ @param {*=} rawGetPointee,
2361
+ @param {*=} rawConstructor,
2362
+ @param {*=} rawShare,
2363
+ @param {*=} rawDestructor,
2364
+ */
2365
+ function RegisteredPointer(
2366
+ name,
2367
+ registeredClass,
2368
+ isReference,
2369
+ isConst,
2370
+
2371
+ // smart pointer properties
2372
+ isSmartPointer,
2373
+ pointeeType,
2374
+ sharingPolicy,
2375
+ rawGetPointee,
2376
+ rawConstructor,
2377
+ rawShare,
2378
+ rawDestructor
2379
+ ) {
2380
+ this.name = name;
2381
+ this.registeredClass = registeredClass;
2382
+ this.isReference = isReference;
2383
+ this.isConst = isConst;
2384
+
2385
+ // smart pointer properties
2386
+ this.isSmartPointer = isSmartPointer;
2387
+ this.pointeeType = pointeeType;
2388
+ this.sharingPolicy = sharingPolicy;
2389
+ this.rawGetPointee = rawGetPointee;
2390
+ this.rawConstructor = rawConstructor;
2391
+ this.rawShare = rawShare;
2392
+ this.rawDestructor = rawDestructor;
2393
+
2394
+ if (!isSmartPointer && registeredClass.baseClass === undefined) {
2395
+ if (isConst) {
2396
+ this['toWireType'] = constNoSmartPtrRawPointerToWireType;
2397
+ this.destructorFunction = null;
2398
+ } else {
2399
+ this['toWireType'] = nonConstNoSmartPtrRawPointerToWireType;
2400
+ this.destructorFunction = null;
2401
+ }
2402
+ } else {
2403
+ this['toWireType'] = genericPointerToWireType;
2404
+ // Here we must leave this.destructorFunction undefined, since whether genericPointerToWireType returns
2405
+ // a pointer that needs to be freed up is runtime-dependent, and cannot be evaluated at registration time.
2406
+ // TODO: Create an alternative mechanism that allows removing the use of var destructors = []; array in
2407
+ // craftInvokerFunction altogether.
2408
+ }
2409
+ }
2410
+
2411
+
2412
+
2413
+
2414
+ function __embind_register_class(rawType,
2415
+ rawPointerType,
2416
+ rawConstPointerType,
2417
+ baseClassRawType,
2418
+ getActualTypeSignature,
2419
+ getActualType,
2420
+ upcastSignature,
2421
+ upcast,
2422
+ downcastSignature,
2423
+ downcast,
2424
+ name,
2425
+ destructorSignature,
2426
+ rawDestructor) {
2427
+ /* console.log('__embind_register_class', rawType,
2428
+ rawPointerType,
2429
+ rawConstPointerType,
2430
+ baseClassRawType,
2431
+ getActualTypeSignature,
2432
+ getActualType,
2433
+ upcastSignature,
2434
+ upcast,
2435
+ downcastSignature,
2436
+ downcast,
2437
+ name,
2438
+ destructorSignature,
2439
+ rawDestructor); */
2440
+ name = readLatin1String(name);
2441
+ getActualType = embind__requireFunction(getActualTypeSignature, getActualType);
2442
+ if (upcast) {
2443
+ upcast = embind__requireFunction(upcastSignature, upcast);
2444
+ // upcast = (...a) => {console.log('----------------------------->', a); };
2445
+ }
2446
+ if (downcast) {
2447
+ downcast = embind__requireFunction(downcastSignature, downcast);
2448
+ }
2449
+ rawDestructor = embind__requireFunction(destructorSignature, rawDestructor);
2450
+ var legalFunctionName = makeLegalFunctionName(name);
2451
+
2452
+ exposePublicSymbol(legalFunctionName, function () {
2453
+ // this code cannot run if baseClassRawType is zero
2454
+ throwUnboundTypeError(`Cannot construct ${name} due to unbound types`, [baseClassRawType]);
2455
+ });
2456
+
2457
+ whenDependentTypesAreResolved(
2458
+ [rawType, rawPointerType, rawConstPointerType],
2459
+ baseClassRawType ? [baseClassRawType] : [],
2460
+ function (base) {
2461
+ base = base[0];
2462
+
2463
+ var baseClass;
2464
+ var basePrototype;
2465
+ if (baseClassRawType) {
2466
+ baseClass = base.registeredClass;
2467
+ basePrototype = baseClass.instancePrototype;
2468
+ } else {
2469
+ basePrototype = ClassHandle.prototype;
2470
+ }
2471
+ //console.log('__embind_register_class -> ', name, baseClassRawType, baseClass, basePrototype, ClassHandle);
2472
+
2473
+ var constructor = createNamedFunction(legalFunctionName, function () {
2474
+ if (Object.getPrototypeOf(this) !== instancePrototype) {
2475
+ throw new BindingError("Use 'new' to construct " + name);
2476
+ }
2477
+ if (undefined === registeredClass.constructor_body) {
2478
+ throw new BindingError(name + " has no accessible constructor");
2479
+ }
2480
+ var body = registeredClass.constructor_body[arguments.length];
2481
+ if (undefined === body) {
2482
+ 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!`);
2483
+ }
2484
+ return body.apply(this, arguments);
2485
+ });
2486
+
2487
+ var instancePrototype = Object.create(basePrototype, {
2488
+ constructor: { value: constructor },
2489
+ });
2490
+
2491
+ //console.log('__embind_register_class -> instancePrototype: ', name, Object.keys(basePrototype), instancePrototype.constructor);
2492
+
2493
+ constructor.prototype = instancePrototype;
2494
+
2495
+ var registeredClass = new RegisteredClass(name,
2496
+ constructor,
2497
+ instancePrototype,
2498
+ rawDestructor,
2499
+ baseClass,
2500
+ getActualType,
2501
+ upcast,
2502
+ downcast);
2503
+
2504
+ if (registeredClass.baseClass) {
2505
+ // Keep track of class hierarchy. Used to allow sub-classes to inherit class functions.
2506
+ if (registeredClass.baseClass.__derivedClasses === undefined) {
2507
+ registeredClass.baseClass.__derivedClasses = [];
2508
+ }
2509
+
2510
+ registeredClass.baseClass.__derivedClasses.push(registeredClass);
2511
+ }
2512
+
2513
+ var referenceConverter = new RegisteredPointer(name,
2514
+ registeredClass,
2515
+ true,
2516
+ false,
2517
+ false);
2518
+
2519
+ var pointerConverter = new RegisteredPointer(name + '*',
2520
+ registeredClass,
2521
+ false,
2522
+ false,
2523
+ false);
2524
+
2525
+ var constPointerConverter = new RegisteredPointer(name + ' const*',
2526
+ registeredClass,
2527
+ false,
2528
+ true,
2529
+ false);
2530
+
2531
+ registeredPointers[rawType] = {
2532
+ pointerType: pointerConverter,
2533
+ constPointerType: constPointerConverter
2534
+ };
2535
+
2536
+ replacePublicSymbol(legalFunctionName, constructor);
2537
+
2538
+ return [referenceConverter, pointerConverter, constPointerConverter];
2539
+ }
2540
+ );
2541
+ }
2542
+
2543
+ globalThis.__embind_register_class = __embind_register_class;
2544
+
2545
+
2546
+
2547
+
2548
+
2549
+ function __embind_register_class_constructor(
2550
+ rawClassType,
2551
+ argCount,
2552
+ rawArgTypesAddr,
2553
+ invokerSignature,
2554
+ invoker,
2555
+ rawConstructor
2556
+ ) {
2557
+ /* console.log('__embind_register_class_constructor', rawClassType,
2558
+ argCount,
2559
+ rawArgTypesAddr,
2560
+ invokerSignature,
2561
+ invoker,
2562
+ rawConstructor); */
2563
+ assert(argCount > 0);
2564
+ var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
2565
+ invoker = embind__requireFunction(invokerSignature, invoker, true);
2566
+
2567
+ whenDependentTypesAreResolved([], [rawClassType], function (classType) {
2568
+ classType = classType[0];
2569
+ var humanName = 'constructor ' + classType.name;
2570
+
2571
+ if (undefined === classType.registeredClass.constructor_body) {
2572
+ classType.registeredClass.constructor_body = [];
2573
+ }
2574
+ if (undefined !== classType.registeredClass.constructor_body[argCount - 1]) {
2575
+ throw new BindingError(`Cannot register multiple constructors with identical number of parameters (${argCount - 1}) for class '${classType.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);
2576
+ }
2577
+ classType.registeredClass.constructor_body[argCount - 1] = () => {
2578
+ throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`, rawArgTypes);
2579
+ };
2580
+
2581
+ whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) {
2582
+ // Insert empty slot for context type (argTypes[1]).
2583
+ argTypes.splice(1, 0, null);
2584
+ classType.registeredClass.constructor_body[argCount - 1] = craftInvokerFunction(humanName, argTypes, null, invoker, rawConstructor);
2585
+ return [];
2586
+ });
2587
+ return [];
2588
+ });
2589
+ }
2590
+
2591
+ globalThis.__embind_register_class_constructor = __embind_register_class_constructor;
2592
+
2593
+
2594
+
2595
+
2596
+
2597
+ function __embind_register_class_function(rawClassType,
2598
+ methodName,
2599
+ argCount,
2600
+ rawArgTypesAddr, // [ReturnType, ThisType, Args...]
2601
+ invokerSignature,
2602
+ rawInvoker,
2603
+ context,
2604
+ isPureVirtual,
2605
+ isAsync) {
2606
+ // console.log('__embind_register_class_function', methodName, argCount);
2607
+ var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
2608
+ methodName = readLatin1String(methodName);
2609
+ rawInvoker = embind__requireFunction(invokerSignature, rawInvoker, true);
2610
+
2611
+ whenDependentTypesAreResolved([], [rawClassType], function (classType) {
2612
+ //console.log(methodName, argCount);
2613
+ classType = classType[0];
2614
+ var humanName = classType.name + '.' + methodName;
2615
+
2616
+ if (methodName.startsWith("@@")) {
2617
+ methodName = Symbol[methodName.substring(2)];
2618
+ }
2619
+
2620
+ if (isPureVirtual) {
2621
+ classType.registeredClass.pureVirtualFunctions.push(methodName);
2622
+ }
2623
+
2624
+ function unboundTypesHandler() {
2625
+ //console.log(`Cannot call2 ${humanName} due to unbound types`, rawArgTypes, rawArgTypes.map(a => registeredTypes[a]));
2626
+ throwUnboundTypeError(`Cannot call2 ${humanName} due to unbound types`, rawArgTypes);
2627
+ }
2628
+
2629
+ var proto = classType.registeredClass.instancePrototype;
2630
+ var method = proto[methodName];
2631
+ if (undefined === method || (undefined === method.overloadTable && method.className !== classType.name && method.argCount === argCount - 2)) {
2632
+ // This is the first overload to be registered, OR we are replacing a
2633
+ // function in the base class with a function in the derived class.
2634
+ unboundTypesHandler.argCount = argCount - 2;
2635
+ unboundTypesHandler.className = classType.name;
2636
+ proto[methodName] = unboundTypesHandler;
2637
+ } else {
2638
+ // There was an existing function with the same name registered. Set up
2639
+ // a function overload routing table.
2640
+ ensureOverloadTable(proto, methodName, humanName);
2641
+ proto[methodName].overloadTable[argCount - 2] = unboundTypesHandler;
2642
+ }
2643
+
2644
+ whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) {
2645
+ //console.log(methodName);
2646
+ var memberFunction = craftInvokerFunction(humanName, argTypes, classType, rawInvoker, context, isAsync);
2647
+
2648
+ // Replace the initial unbound-handler-stub function with the appropriate member function, now that all types
2649
+ // are resolved. If multiple overloads are registered for this function, the function goes into an overload table.
2650
+ if (undefined === proto[methodName].overloadTable) {
2651
+ // Set argCount in case an overload is registered later
2652
+ memberFunction.argCount = argCount - 2;
2653
+ proto[methodName] = memberFunction;
2654
+ } else {
2655
+ proto[methodName].overloadTable[argCount - 2] = memberFunction;
2656
+ }
2657
+
2658
+ return [];
2659
+ });
2660
+ return [];
2661
+ });
2662
+ }
2663
+
2664
+ globalThis.__embind_register_class_function = __embind_register_class_function;
2665
+
2666
+
2667
+
2668
+
2669
+
2670
+
2671
+ function validateThis(this_, classType, humanName) {
2672
+ if (!(this_ instanceof Object)) {
2673
+ throwBindingError(humanName + ' with invalid "this": ' + this_);
2674
+ }
2675
+ if (!(this_ instanceof classType.registeredClass.constructor)) {
2676
+ throwBindingError(humanName + ' incompatible with "this" of type ' + this_.constructor.name);
2677
+ }
2678
+ if (!this_.$$.ptr) {
2679
+ throwBindingError(`cannot call emscripten binding method ${humanName} on deleted object`);
2680
+ }
2681
+ // console.log('validateThis');
2682
+
2683
+ // todo: kill this
2684
+ return upcastPointer(this_.$$.ptr,
2685
+ this_.$$.ptrType.registeredClass,
2686
+ classType.registeredClass);
2687
+ }
2688
+ function __embind_register_class_property(classType,
2689
+ fieldName,
2690
+ getterReturnType,
2691
+ getterSignature,
2692
+ getter,
2693
+ getterContext,
2694
+ setterArgumentType,
2695
+ setterSignature,
2696
+ setter,
2697
+ setterContext) {
2698
+ fieldName = readLatin1String(fieldName);
2699
+ getter = embind__requireFunction(getterSignature, getter);
2700
+
2701
+ whenDependentTypesAreResolved([], [classType], function (classType) {
2702
+ classType = classType[0];
2703
+ var humanName = classType.name + '.' + fieldName;
2704
+ var desc = {
2705
+ get: function () {
2706
+ throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [getterReturnType, setterArgumentType]);
2707
+ },
2708
+ enumerable: true,
2709
+ configurable: true
2710
+ };
2711
+ if (setter && setterContext) {
2712
+ desc.set = () => {
2713
+ throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [getterReturnType, setterArgumentType]);
2714
+ };
2715
+ } else {
2716
+ desc.set = (v) => {
2717
+ throwBindingError(humanName + ' is a read-only property');
2718
+ };
2719
+ }
2720
+
2721
+ Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
2722
+
2723
+ whenDependentTypesAreResolved(
2724
+ [],
2725
+ (setter && setterContext ? [getterReturnType, setterArgumentType] : [getterReturnType]),
2726
+ function (types) {
2727
+ var getterReturnType = types[0];
2728
+ var desc = {
2729
+ get: function () {
2730
+ // console.log('get -> ', this.$$.ptr);
2731
+ var ptr = validateThis(this, classType, humanName + ' getter');
2732
+ return getterReturnType['fromWireType'](getter(getterContext, ptr));
2733
+ },
2734
+ enumerable: true
2735
+ };
2736
+
2737
+ if (setter && setterContext) {
2738
+ setter = embind__requireFunction(setterSignature, setter);
2739
+ var setterArgumentType = types[1];
2740
+ desc.set = function (v) {
2741
+ // console.log('set -> ', this.$$.ptr);
2742
+ var ptr = validateThis(this, classType, humanName + ' setter');
2743
+ var destructors = [];
2744
+ setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, v));
2745
+ runDestructors(destructors);
2746
+ };
2747
+ }
2748
+
2749
+ // console.log('__embind_register_class_property', fieldName, desc);
2750
+
2751
+ Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
2752
+ return [];
2753
+ });
2754
+
2755
+ return [];
2756
+ });
2757
+ }
2758
+
2759
+ globalThis.__embind_register_class_property = __embind_register_class_property;
2760
+
2761
+
2762
+
2763
+
2764
+
2765
+ function __embind_register_class_class_function(rawClassType,
2766
+ methodName,
2767
+ argCount,
2768
+ rawArgTypesAddr,
2769
+ invokerSignature,
2770
+ rawInvoker,
2771
+ fn,
2772
+ isAsync) {
2773
+ var rawArgTypes = heap32VectorToArray(argCount, rawArgTypesAddr);
2774
+ methodName = readLatin1String(methodName);
2775
+ rawInvoker = embind__requireFunction(invokerSignature, rawInvoker, true);
2776
+ whenDependentTypesAreResolved([], [rawClassType], function (classType) {
2777
+ classType = classType[0];
2778
+ var humanName = classType.name + '.' + methodName;
2779
+
2780
+ function unboundTypesHandler() {
2781
+ throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
2782
+ }
2783
+
2784
+ if (methodName.startsWith("@@")) {
2785
+ methodName = Symbol[methodName.substring(2)];
2786
+ }
2787
+
2788
+ var proto = classType.registeredClass.constructor;
2789
+ if (undefined === proto[methodName]) {
2790
+ // This is the first function to be registered with this name.
2791
+ unboundTypesHandler.argCount = argCount - 1;
2792
+ proto[methodName] = unboundTypesHandler;
2793
+ } else {
2794
+ // There was an existing function with the same name registered. Set up
2795
+ // a function overload routing table.
2796
+ ensureOverloadTable(proto, methodName, humanName);
2797
+ proto[methodName].overloadTable[argCount - 1] = unboundTypesHandler;
2798
+ }
2799
+
2800
+ whenDependentTypesAreResolved([], rawArgTypes, function (argTypes) {
2801
+ // Replace the initial unbound-types-handler stub with the proper
2802
+ // function. If multiple overloads are registered, the function handlers
2803
+ // go into an overload table.
2804
+ var invokerArgsArray = [argTypes[0] /* return value */, null /* no class 'this'*/].concat(argTypes.slice(1) /* actual params */);
2805
+ var func = craftInvokerFunction(humanName, invokerArgsArray, null /* no class 'this'*/, rawInvoker, fn, isAsync);
2806
+ if (undefined === proto[methodName].overloadTable) {
2807
+ func.argCount = argCount - 1;
2808
+ proto[methodName] = func;
2809
+ } else {
2810
+ proto[methodName].overloadTable[argCount - 1] = func;
2811
+ }
2812
+
2813
+ if (classType.registeredClass.__derivedClasses) {
2814
+ for (const derivedClass of classType.registeredClass.__derivedClasses) {
2815
+ if (!derivedClass.constructor.hasOwnProperty(methodName)) {
2816
+ // TODO: Add support for overloads
2817
+ derivedClass.constructor[methodName] = func;
2818
+ }
2819
+ }
2820
+ }
2821
+
2822
+ return [];
2823
+ });
2824
+ return [];
2825
+ });
2826
+ }
2827
+
2828
+ globalThis.__embind_register_class_class_function = __embind_register_class_class_function;
2829
+
2830
+
2831
+
2832
+
2833
+
2834
+ function __embind_register_class_class_property(rawClassType,
2835
+ fieldName,
2836
+ rawFieldType,
2837
+ rawFieldPtr,
2838
+ getterSignature,
2839
+ getter,
2840
+ setterSignature,
2841
+ setter) {
2842
+ fieldName = readLatin1String(fieldName);
2843
+ getter = embind__requireFunction(getterSignature, getter);
2844
+
2845
+ whenDependentTypesAreResolved([], [rawClassType], function (classType) {
2846
+ classType = classType[0];
2847
+ var humanName = classType.name + '.' + fieldName;
2848
+ var desc = {
2849
+ get: function () {
2850
+ throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [rawFieldType]);
2851
+ },
2852
+ enumerable: true,
2853
+ configurable: true
2854
+ };
2855
+ if (setter && setterSignature !== "") {
2856
+ desc.set = () => {
2857
+ throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [rawFieldType]);
2858
+ };
2859
+ } else {
2860
+ desc.set = (v) => {
2861
+ throwBindingError(`${humanName} is a read-only property`);
2862
+ };
2863
+ }
2864
+
2865
+ Object.defineProperty(classType.registeredClass.constructor, fieldName, desc);
2866
+
2867
+ whenDependentTypesAreResolved([], [rawFieldType], function (fieldType) {
2868
+ fieldType = fieldType[0];
2869
+ var desc = {
2870
+ get: function () {
2871
+ return fieldType['fromWireType'](getter(rawFieldPtr));
2872
+ },
2873
+ enumerable: true
2874
+ };
2875
+
2876
+ if (setter && setterSignature !== "") {
2877
+ setter = embind__requireFunction(setterSignature, setter);
2878
+ desc.set = (v) => {
2879
+ var destructors = [];
2880
+ setter(rawFieldPtr, fieldType['toWireType'](destructors, v));
2881
+ runDestructors(destructors);
2882
+ };
2883
+ }
2884
+
2885
+ Object.defineProperty(classType.registeredClass.constructor, fieldName, desc);
2886
+ return [];
2887
+ });
2888
+
2889
+ return [];
2890
+ });
2891
+ }
2892
+
2893
+ globalThis.__embind_register_class_class_property = __embind_register_class_class_property;
2894
+
2895
+ var PureVirtualError = undefined;
2896
+
2897
+
2898
+
2899
+
2900
+ function registerInheritedInstance(class_, ptr, instance) {
2901
+ ptr = getBasestPointer(class_, ptr);
2902
+ if (registeredInstances.hasOwnProperty(ptr)) {
2903
+ throwBindingError('Tried to register registered instance: ' + ptr);
2904
+ } else {
2905
+ registeredInstances[ptr] = instance;
2906
+ }
2907
+ }
2908
+
2909
+
2910
+
2911
+ function requireRegisteredType(rawType, humanName) {
2912
+ //console.log('requireRegisteredType', rawType, humanName);
2913
+ var impl = registeredTypes[rawType];
2914
+ //console.log('requireRegisteredType value: ', impl);
2915
+ if (undefined === impl) {
2916
+ throwBindingError(humanName + " has unknown type " + getTypeName());
2917
+ }
2918
+ return impl;
2919
+ }
2920
+
2921
+
2922
+
2923
+
2924
+ function unregisterInheritedInstance(class_, ptr) {
2925
+ ptr = getBasestPointer(class_, ptr);
2926
+ if (registeredInstances.hasOwnProperty(ptr)) {
2927
+ delete registeredInstances[ptr];
2928
+ } else {
2929
+ throwBindingError('Tried to unregister unregistered instance: ' + ptr);
2930
+ }
2931
+ }
2932
+
2933
+
2934
+ function __embind_create_inheriting_constructor(constructorName, wrapperType, properties) {
2935
+ constructorName = readLatin1String(constructorName);
2936
+ wrapperType = requireRegisteredType(wrapperType, 'wrapper');
2937
+ properties = Emval.toValue(properties);
2938
+
2939
+ var arraySlice = [].slice;
2940
+
2941
+ var registeredClass = wrapperType.registeredClass;
2942
+ var wrapperPrototype = registeredClass.instancePrototype;
2943
+ var baseClass = registeredClass.baseClass;
2944
+ var baseClassPrototype = baseClass.instancePrototype;
2945
+ var baseConstructor = registeredClass.baseClass.constructor;
2946
+ var ctor = createNamedFunction(constructorName, function () {
2947
+ registeredClass.baseClass.pureVirtualFunctions.forEach(function (name) {
2948
+ if (this[name] === baseClassPrototype[name]) {
2949
+ throw new PureVirtualError(`Pure virtual function ${name} must be implemented in JavaScript`);
2950
+ }
2951
+ }.bind(this));
2952
+
2953
+ Object.defineProperty(this, '__parent', {
2954
+ value: wrapperPrototype
2955
+ });
2956
+ this["__construct"].apply(this, arraySlice.call(arguments));
2957
+ });
2958
+
2959
+ // It's a little nasty that we're modifying the wrapper prototype here.
2960
+
2961
+ wrapperPrototype["__construct"] = function __construct() {
2962
+ if (this === wrapperPrototype) {
2963
+ throwBindingError("Pass correct 'this' to __construct");
2964
+ }
2965
+
2966
+ var inner = baseConstructor["implement"].apply(
2967
+ undefined,
2968
+ [this].concat(arraySlice.call(arguments)));
2969
+ detachFinalizer(inner);
2970
+ var $$ = inner.$$;
2971
+ inner["notifyOnDestruction"]();
2972
+ $$.preservePointerOnDelete = true;
2973
+ Object.defineProperties(this, {
2974
+ $$: {
2975
+ value: $$
2976
+ }
2977
+ });
2978
+ attachFinalizer(this);
2979
+ registerInheritedInstance(registeredClass, $$.ptr, this);
2980
+ };
2981
+
2982
+ wrapperPrototype["__destruct"] = function __destruct() {
2983
+ if (this === wrapperPrototype) {
2984
+ throwBindingError("Pass correct 'this' to __destruct");
2985
+ }
2986
+
2987
+ detachFinalizer(this);
2988
+ unregisterInheritedInstance(registeredClass, this.$$.ptr);
2989
+ };
2990
+
2991
+ ctor.prototype = Object.create(wrapperPrototype);
2992
+ for (var p in properties) {
2993
+ ctor.prototype[p] = properties[p];
2994
+ }
2995
+ return Emval.toHandle(ctor);
2996
+ }
2997
+
2998
+ globalThis.__embind_create_inheriting_constructor = __embind_create_inheriting_constructor;
2999
+
3000
+
3001
+ function __embind_register_smart_ptr(rawType,
3002
+ rawPointeeType,
3003
+ name,
3004
+ sharingPolicy,
3005
+ getPointeeSignature,
3006
+ rawGetPointee,
3007
+ constructorSignature,
3008
+ rawConstructor,
3009
+ shareSignature,
3010
+ rawShare,
3011
+ destructorSignature,
3012
+ rawDestructor) {
3013
+ /* console.log('__embind_register_smart_ptr', rawType,
3014
+ rawPointeeType,
3015
+ name,
3016
+ sharingPolicy,
3017
+ getPointeeSignature,
3018
+ rawGetPointee,
3019
+ constructorSignature,
3020
+ rawConstructor,
3021
+ shareSignature,
3022
+ rawShare,
3023
+ destructorSignature,
3024
+ rawDestructor); */
3025
+ name = readLatin1String(name);
3026
+ rawGetPointee = embind__requireFunction(getPointeeSignature, rawGetPointee);
3027
+ rawConstructor = embind__requireFunction(constructorSignature, rawConstructor);
3028
+ rawShare = embind__requireFunction(shareSignature, rawShare);
3029
+ rawDestructor = embind__requireFunction(destructorSignature, rawDestructor);
3030
+
3031
+ whenDependentTypesAreResolved([rawType], [rawPointeeType], function (pointeeType) {
3032
+ pointeeType = pointeeType[0];
3033
+
3034
+ var registeredPointer = new RegisteredPointer(name,
3035
+ pointeeType.registeredClass,
3036
+ false,
3037
+ false,
3038
+ // smart pointer properties
3039
+ true,
3040
+ pointeeType,
3041
+ sharingPolicy,
3042
+ rawGetPointee,
3043
+ rawConstructor,
3044
+ rawShare,
3045
+ rawDestructor);
3046
+ return [registeredPointer];
3047
+ });
3048
+ }
3049
+
3050
+ globalThis.__embind_register_smart_ptr = __embind_register_smart_ptr;
3051
+
3052
+
3053
+
3054
+ function __embind_register_enum(rawType, name, size, isSigned) {
3055
+ name = readLatin1String(name);
3056
+
3057
+ function ctor() { }
3058
+ ctor.values = {};
3059
+
3060
+ registerType(rawType, {
3061
+ name: name,
3062
+ constructor: ctor,
3063
+ 'fromWireType': function (c) {
3064
+ //console.log('__embind_register_enum, fromWireType', ctor, c);
3065
+ return this.constructor.values[c];
3066
+ },
3067
+ 'toWireType': function (destructors, c) {
3068
+ // A number crosses as it is, as the wasm glue takes it; anything but a member or a number throws instead of
3069
+ // crossing as undefined.
3070
+ if (typeof c == "number") return c;
3071
+ if (c !== null && typeof c == "object" && typeof c.value == "number") return c.value;
3072
+ throw new TypeError(`${this.name} takes a member of the enum or its number, got ${embindRepr(c)}`);
3073
+ },
3074
+ 'argPackAdvance': 8n,
3075
+ destructorFunction: null,
3076
+ });
3077
+ exposePublicSymbol(name, ctor);
3078
+ }
3079
+
3080
+ globalThis.__embind_register_enum = __embind_register_enum;
3081
+
3082
+ function __embind_register_enum_value(rawEnumType, name, enumValue) {
3083
+ var enumType = requireRegisteredType(rawEnumType, 'enum');
3084
+ name = readLatin1String(name);
3085
+
3086
+ var Enum = enumType.constructor;
3087
+
3088
+ var Value = Object.create(enumType.constructor.prototype, {
3089
+ value: { value: enumValue },
3090
+ constructor: { value: createNamedFunction(enumType.name + '_' + name, function () { }) },
3091
+ });
3092
+ Enum.values[enumValue] = Value;
3093
+ Enum[name] = Value;
3094
+ }
3095
+ globalThis.__embind_register_enum_value = __embind_register_enum_value;
3096
+
3097
+ function __embind_register_constant(name, type, value) {
3098
+ name = readLatin1String(name);
3099
+ //console.log('-------------- const ---------', name, type, value);
3100
+ whenDependentTypesAreResolved([], [type], function (type) {
3101
+ type = type[0];
3102
+ //console.log('-------------- const ---------', name, type, value);
3103
+ Module[name] = type['fromWireType'](value);
3104
+ return [];
3105
+ });
3106
+ }
3107
+
3108
+ globalThis.__embind_register_constant = __embind_register_constant;
3109
+
3110
+ var emval_symbols = {};
3111
+
3112
+ function __emval_register_symbol(address) {
3113
+ emval_symbols[address] = readLatin1String(address);
3114
+ }
3115
+ globalThis.__emval_register_symbol = __emval_register_symbol;
3116
+
3117
+ function __emval_incref(handle) {
3118
+ // console.log('__emval_incref');
3119
+ if (handle > 4) {
3120
+ emval_handles.get(handle).refcount += 1;
3121
+ }
3122
+ }
3123
+ globalThis.__emval_incref = __emval_incref;
3124
+
3125
+
3126
+
3127
+
3128
+ // __emval_as and __emval_call_method queue one list each; C++ runs it once it has read the
3129
+ // converted value (DestructorsRunner in val.h), so nesting unwinds in order. Called from a C++
3130
+ // destructor, so it must not throw.
3131
+ var emval_destructorsStack = [];
3132
+ function __emval_run_destructors() {
3133
+ var destructors = emval_destructorsStack.pop();
3134
+ if (destructors) {
3135
+ runDestructors(destructors);
3136
+ }
3137
+ }
3138
+ globalThis.__emval_run_destructors = __emval_run_destructors;
3139
+
3140
+
3141
+ function __emval_new_array() {
3142
+ // console.log('__emval_new_array');
3143
+ return Emval.toHandle([]);
3144
+ }
3145
+ globalThis.__emval_new_array = __emval_new_array;
3146
+
3147
+ function __emval_new_array_from_memory_view(view) {
3148
+ // console.log('__emval_new_array_from_memory_view');
3149
+ view = Emval.toValue(view);
3150
+ // using for..loop is faster than Array.from
3151
+ var a = new Array(view.length);
3152
+ for (var i = 0; i < view.length; i++) a[i] = view[i];
3153
+ return Emval.toHandle(a);
3154
+ }
3155
+ globalThis.__emval_new_array_from_memory_view = __emval_new_array_from_memory_view;
3156
+
3157
+ function __emval_new_object() {
3158
+ // console.log('__emval_new_object');
3159
+ return Emval.toHandle({});
3160
+ }
3161
+ globalThis.__emval_new_object = __emval_new_object;
3162
+
3163
+
3164
+ function getStringOrSymbol(address) {
3165
+ var symbol = emval_symbols[address];
3166
+ if (symbol === undefined) {
3167
+ return readLatin1String(address);
3168
+ }
3169
+ return symbol;
3170
+ }
3171
+
3172
+ function __emval_new_cstring(v) {
3173
+ // console.log('__emval_new_cstring');
3174
+ return Emval.toHandle(getStringOrSymbol(v));
3175
+ }
3176
+ globalThis.__emval_new_cstring = __emval_new_cstring;
3177
+
3178
+
3179
+ // C++ decodes both into a JS string before calling (bind.cpp).
3180
+ function __emval_new_u8string(v) {
3181
+ return Emval.toHandle(v);
3182
+ }
3183
+ globalThis.__emval_new_u8string = __emval_new_u8string;
3184
+
3185
+ function __emval_new_u16string(v) {
3186
+ return Emval.toHandle(v);
3187
+ }
3188
+ globalThis.__emval_new_u16string = __emval_new_u16string;
3189
+
3190
+ BigInt.prototype.toJSON = function () { return this.toString() };
3191
+ function __emval_take_value(type, value) {
3192
+ type = requireRegisteredType(type, '_emval_take_value');
3193
+ return Emval.toHandle(type['fromWireType'](value));
3194
+ }
3195
+ globalThis.__emval_take_value = __emval_take_value;
3196
+
3197
+
3198
+ function __emval_new(handle, argCount, argTypes, ...wires) {
3199
+ var constructor = Emval.toValue(handle);
3200
+ return Emval.toHandle(new constructor(...emval_fromWireTypes(argCount, argTypes, wires)));
3201
+ }
3202
+ globalThis.__emval_new = __emval_new;
3203
+
3204
+
3205
+ const globalIgnoreList = [
3206
+ 'jsiArrayBuffer',
3207
+ 'jsiArrayBuffer2',
3208
+ 'jsiArrayBuffer3',
3209
+ 'jsiArrayBuffer4',
3210
+ 'window',
3211
+ 'self',
3212
+ 'DATA_VIEW',
3213
+ 'Module',
3214
+ 'nativeRuntimeScheduler',
3215
+ ];
3216
+
3217
+ function emval_get_global() {
3218
+ if (typeof globalThis == 'object') {
3219
+ const global = {};
3220
+ // for...in: a Node loader bundle's globalThis inherits the global's properties.
3221
+ for (const key in globalThis) {
3222
+ if (!key.startsWith('_') && !globalIgnoreList.includes(key)) global[key] = globalThis[key];
3223
+ }
3224
+
3225
+ return global;
3226
+ }
3227
+ return (function () {
3228
+ return Function;
3229
+ })()('return this')();
3230
+ }
3231
+ function __emval_get_global(name) {
3232
+ if (name === '') {
3233
+ return Emval.toHandle(emval_get_global());
3234
+ } else {
3235
+ //console.log(`1__emval_get_global(${name})`, globalThis[name]);
3236
+ name = getStringOrSymbol(name);
3237
+ return Emval.toHandle(globalThis[name]);
3238
+ }
3239
+ }
3240
+ globalThis.__emval_get_global = __emval_get_global;
3241
+
3242
+
3243
+ function __emval_get_module_property(name) {
3244
+ // console.log('__emval_get_module_property');
3245
+ name = getStringOrSymbol(name);
3246
+ return Emval.toHandle(Module[name]);
3247
+ }
3248
+ globalThis.__emval_get_module_property = __emval_get_module_property;
3249
+
3250
+ function __emval_get_property(handle, key) {
3251
+ //console.log('__emval_get_property', handle, key);
3252
+ handle = Emval.toValue(handle);
3253
+ key = Emval.toValue(key);
3254
+ //console.log('__emval_get_property2', handle, key, handle[key]);
3255
+ return Emval.toHandle(handle[key]);
3256
+ }
3257
+ globalThis.__emval_get_property = __emval_get_property;
3258
+
3259
+ function __emval_set_property(handle, key, value) {
3260
+ // console.log('__emval_set_property');
3261
+ handle = Emval.toValue(handle);
3262
+ key = Emval.toValue(key);
3263
+ value = Emval.toValue(value);
3264
+ handle[key] = value;
3265
+ }
3266
+ globalThis.__emval_set_property = __emval_set_property;
3267
+
3268
+
3269
+ function __emval_as(handle, returnType) {
3270
+ handle = Emval.toValue(handle);
3271
+ returnType = requireRegisteredType(returnType, 'emval::as');
3272
+ var destructors = [];
3273
+ const output = returnType['toWireType'](destructors, handle);
3274
+ emval_destructorsStack.push(destructors);
3275
+ return output;
3276
+ }
3277
+ globalThis.__emval_as = __emval_as;
3278
+
3279
+
3280
+ function __emval_as_int64(handle, returnType) {
3281
+ // console.log('__emval_as_int64');
3282
+ handle = Emval.toValue(handle);
3283
+ returnType = requireRegisteredType(returnType, 'emval::as');
3284
+ return returnType['toWireType'](null, handle);
3285
+ }
3286
+ globalThis.__emval_as_int64 = __emval_as_int64;
3287
+
3288
+
3289
+ function __emval_as_uint64(handle, returnType) {
3290
+ // console.log('__emval_as_uint64');
3291
+ handle = Emval.toValue(handle);
3292
+ returnType = requireRegisteredType(returnType, 'emval::as');
3293
+ return returnType['toWireType'](null, handle);
3294
+ }
3295
+ globalThis.__emval_as_uint64 = __emval_as_uint64;
3296
+
3297
+ function __emval_equals(first, second) {
3298
+ // console.log('__emval_equals');
3299
+ first = Emval.toValue(first);
3300
+ second = Emval.toValue(second);
3301
+ return first == second;
3302
+ }
3303
+ globalThis.__emval_equals = __emval_equals;
3304
+
3305
+ function __emval_strictly_equals(first, second) {
3306
+ // console.log('__emval_strictly_equals');
3307
+ first = Emval.toValue(first);
3308
+ second = Emval.toValue(second);
3309
+ return first === second;
3310
+ }
3311
+ globalThis.__emval_strictly_equals = __emval_strictly_equals;
3312
+
3313
+ function __emval_greater_than(first, second) {
3314
+ // console.log('__emval_greater_than');
3315
+ first = Emval.toValue(first);
3316
+ second = Emval.toValue(second);
3317
+ return first > second;
3318
+ }
3319
+ globalThis.__emval_greater_than = __emval_greater_than;
3320
+
3321
+ function __emval_less_than(first, second) {
3322
+ // console.log('__emval_less_than');
3323
+ first = Emval.toValue(first);
3324
+ second = Emval.toValue(second);
3325
+ return first < second;
3326
+ }
3327
+ globalThis.__emval_less_than = __emval_less_than;
3328
+
3329
+ function __emval_not(object) {
3330
+ // console.log('__emval_not');
3331
+ object = Emval.toValue(object);
3332
+ return !object;
3333
+ }
3334
+ globalThis.__emval_not = __emval_not;
3335
+
3336
+ function emval_lookupTypes(argCount, argTypes) {
3337
+ //console.log('emval_lookupTypes', argCount, argTypes);
3338
+ var a = new Array(argCount);
3339
+ for (var i = 0; i < argCount; ++i) {
3340
+ const memValue = argTypes[i];
3341
+ a[i] = requireRegisteredType(memValue, "parameter " + i);
3342
+ }
3343
+ return a;
3344
+ }
3345
+
3346
+ function emval_fromWireTypes(argCount, argTypes, wires) {
3347
+ var types = emval_lookupTypes(Number(argCount), argTypes);
3348
+ return types.map((type, i) => type['fromWireType'](wires[i]));
3349
+ }
3350
+
3351
+ function __emval_call(handle, argCount, argTypes, ...wires) {
3352
+ handle = Emval.toValue(handle);
3353
+ var rv = handle.apply(undefined, emval_fromWireTypes(argCount, argTypes, wires));
3354
+ return Emval.toHandle(rv);
3355
+ }
3356
+ globalThis.__emval_call = __emval_call;
3357
+
3358
+ var emval_methodCallers = [];
3359
+ function emval_addMethodCaller(caller) {
3360
+ var id = emval_methodCallers.length;
3361
+ emval_methodCallers.push(caller);
3362
+ return BigInt(id);
3363
+ }
3364
+
3365
+
3366
+
3367
+ var emval_registeredMethods = [];
3368
+
3369
+ function __emval_get_method_caller(argCount, argTypes) {
3370
+ argCount = Number(argCount);
3371
+ //console.log('__emval_get_method_caller', argCount, argTypes);
3372
+ var types = emval_lookupTypes(argCount, argTypes);
3373
+ var retType = types[0];
3374
+ var signatureName = retType.name + "_$" + types.slice(1).map(function (t) { return t.name; }).join("_") + "$";
3375
+ var returnId = emval_registeredMethods[signatureName];
3376
+ if (returnId !== undefined) {
3377
+ return returnId;
3378
+ }
3379
+
3380
+ var params = ["retType"];
3381
+ var args = [retType];
3382
+
3383
+ var argsList = ""; // 'arg0, arg1, arg2, ... , argN'
3384
+ var wiresList = ""; // ', wire0, wire1, ... , wireN'
3385
+ for (var i = 0; i < argCount - 1; ++i) {
3386
+ argsList += (i !== 0 ? ", " : "") + "arg" + i;
3387
+ wiresList += ", wire" + i;
3388
+ params.push("argType" + i);
3389
+ args.push(types[1 + i]);
3390
+ }
3391
+ var functionName = makeLegalFunctionName("methodCaller_" + signatureName);
3392
+ var functionBody =
3393
+ "return function " + functionName + "(handle, name, destructors" + wiresList + ") {\n";
3394
+ for (var i = 0; i < argCount - 1; ++i) {
3395
+ functionBody +=
3396
+ " var arg" + i + " = argType" + i + ".fromWireType(wire" + i + ");\n";
3397
+ }
3398
+ functionBody +=
3399
+ " var rv = handle[name](" + argsList + ");\n";
3400
+ for (var i = 0; i < argCount - 1; ++i) {
3401
+ if (types[i + 1]['deleteObject']) {
3402
+ functionBody +=
3403
+ " argType" + i + ".deleteObject(arg" + i + ");\n";
3404
+ }
3405
+ }
3406
+ if (!retType.isVoid) {
3407
+ functionBody +=
3408
+ " return retType.toWireType(destructors, rv, true);\n";
3409
+ }
3410
+ functionBody +=
3411
+ "};\n";
3412
+ params.push(functionBody);
3413
+ var invokerFunction = newFunc(Function, params).apply(null, args);
3414
+ returnId = emval_addMethodCaller(invokerFunction);
3415
+ emval_registeredMethods[signatureName] = returnId;
3416
+ return returnId;
3417
+ }
3418
+ globalThis.__emval_get_method_caller = __emval_get_method_caller;
3419
+
3420
+ function __emval_call_method(caller, handle, methodName, ...wires) {
3421
+ caller = emval_methodCallers[caller];
3422
+ handle = Emval.toValue(handle);
3423
+ methodName = getStringOrSymbol(methodName);
3424
+ var destructors = [];
3425
+ var rv = caller(handle, methodName, destructors, ...wires);
3426
+ emval_destructorsStack.push(destructors);
3427
+ return rv;
3428
+ }
3429
+ globalThis.__emval_call_method = __emval_call_method;
3430
+
3431
+ function __emval_call_void_method(caller, handle, methodName, ...wires) {
3432
+ caller = emval_methodCallers[caller];
3433
+ handle = Emval.toValue(handle);
3434
+ methodName = getStringOrSymbol(methodName);
3435
+ caller(handle, methodName, null, ...wires);
3436
+ }
3437
+ globalThis.__emval_call_void_method = __emval_call_void_method;
3438
+
3439
+ function __emval_typeof(handle) {
3440
+ // console.log('__emval_typeof');
3441
+ handle = Emval.toValue(handle);
3442
+ return Emval.toHandle(typeof handle);
3443
+ }
3444
+ globalThis.__emval_typeof = __emval_typeof;
3445
+
3446
+ function __emval_instanceof(object, constructor) {
3447
+ // console.log('__emval_instanceof');
3448
+ object = Emval.toValue(object);
3449
+ constructor = Emval.toValue(constructor);
3450
+ return object instanceof constructor;
3451
+ }
3452
+ globalThis.__emval_instanceof = __emval_instanceof;
3453
+
3454
+ function __emval_is_number(handle) {
3455
+ // console.log('__emval_is_number');
3456
+ handle = Emval.toValue(handle);
3457
+ return typeof handle == 'number';
3458
+ }
3459
+ globalThis.__emval_is_number = __emval_is_number;
3460
+
3461
+ function __emval_is_string(handle) {
3462
+ // console.log('__emval_is_string');
3463
+ handle = Emval.toValue(handle);
3464
+ return typeof handle == 'string';
3465
+ }
3466
+ globalThis.__emval_is_string = __emval_is_string;
3467
+
3468
+ function __emval_in(item, object) {
3469
+ // console.log('__emval_in');
3470
+ item = Emval.toValue(item);
3471
+ object = Emval.toValue(object);
3472
+ return item in object;
3473
+ }
3474
+ globalThis.__emval_in = __emval_in;
3475
+
3476
+ function __emval_delete(object, property) {
3477
+ // console.log('__emval_delete');
3478
+ object = Emval.toValue(object);
3479
+ property = Emval.toValue(property);
3480
+ return delete object[property];
3481
+ }
3482
+ globalThis.__emval_delete = __emval_delete;
3483
+
3484
+ function __emval_throw(object) {
3485
+ // console.log('__emval_throw');
3486
+ object = Emval.toValue(object);
3487
+ throw object;
3488
+ }
3489
+ globalThis.__emval_throw = __emval_throw;
3490
+ embind_init_charCodes();
3491
+ BindingError = Module['BindingError'] = extendError(Error, 'BindingError');InternalError = Module['InternalError'] = extendError(Error, 'InternalError');init_emval();UnboundTypeError = Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError');init_ClassHandle();
3492
+ init_embind();init_RegisteredPointer();
3493
+
3494
+ PureVirtualError = Module['PureVirtualError'] = extendError(Error, 'PureVirtualError');// EMSCRIPTEN_END_FUNCS
3495
+
3496
+ // include: postamble.js
3497
+ /**
3498
+ * @license
3499
+ * Copyright 2010 The Emscripten Authors
3500
+ * SPDX-License-Identifier: MIT
3501
+ */
3502
+
3503
+ // === Auto-generated postamble setup entry stuff ===
3504
+
3505
+ var missingLibrarySymbols = [
3506
+ 'callRuntimeCallbacks',
3507
+ 'ExitStatus',
3508
+ 'exitJS',
3509
+ 'handleException',
3510
+ 'reallyNegative',
3511
+ 'unSign',
3512
+ 'strLen',
3513
+ 'reSign',
3514
+ 'formatString',
3515
+ 'intArrayFromString',
3516
+ 'intArrayToString',
3517
+ 'AsciiToString',
3518
+ 'stringToAscii',
3519
+ 'stringToNewUTF8',
3520
+ 'stringToUTF8OnStack',
3521
+ 'writeArrayToMemory',
3522
+ 'writeI53ToI64',
3523
+ 'writeI53ToI64Clamped',
3524
+ 'writeI53ToI64Signaling',
3525
+ 'writeI53ToU64Clamped',
3526
+ 'writeI53ToU64Signaling',
3527
+ 'readI53FromI64',
3528
+ 'readI53FromU64',
3529
+ 'convertI32PairToI53',
3530
+ 'convertI32PairToI53Checked',
3531
+ 'convertU32PairToI53'
3532
+ ];
3533
+ missingLibrarySymbols.forEach(missingLibrarySymbol);
3534
+
3535
+ var unexportedSymbols = [
3536
+ 'run',
3537
+ 'addOnPreRun',
3538
+ 'addOnInit',
3539
+ 'addOnPreMain',
3540
+ 'addOnExit',
3541
+ 'addOnPostRun',
3542
+ 'addRunDependency',
3543
+ 'removeRunDependency',
3544
+ 'FS_createFolder',
3545
+ 'FS_createPath',
3546
+ 'FS_createDataFile',
3547
+ 'FS_createLazyFile',
3548
+ 'FS_createLink',
3549
+ 'FS_createDevice',
3550
+ 'FS_unlink',
3551
+ 'out',
3552
+ 'err',
3553
+ 'callMain',
3554
+ 'abort',
3555
+ 'keepRuntimeAlive',
3556
+ 'wasmMemory',
3557
+ 'stackAlloc',
3558
+ 'stackSave',
3559
+ 'stackRestore',
3560
+ 'getTempRet0',
3561
+ 'setTempRet0',
3562
+ 'UTF8Decoder',
3563
+ 'UTF8ArrayToString',
3564
+ 'UTF8ToString',
3565
+ 'stringToUTF8Array',
3566
+ 'stringToUTF8',
3567
+ 'lengthBytesUTF8',
3568
+ 'UTF16Decoder',
3569
+ 'UTF16ToString',
3570
+ 'stringToUTF16',
3571
+ 'lengthBytesUTF16',
3572
+ 'UTF32ToString',
3573
+ 'stringToUTF32',
3574
+ 'lengthBytesUTF32',
3575
+ 'MAX_INT53',
3576
+ 'MIN_INT53',
3577
+ 'bigintToI53Checked',
3578
+ 'getDynCaller',
3579
+ 'getWasmTableEntry',
3580
+ 'HandleAllocator',
3581
+ 'InternalError',
3582
+ 'BindingError',
3583
+ 'UnboundTypeError',
3584
+ 'PureVirtualError',
3585
+ 'init_embind',
3586
+ 'throwInternalError',
3587
+ 'throwBindingError',
3588
+ 'throwUnboundTypeError',
3589
+ 'ensureOverloadTable',
3590
+ 'exposePublicSymbol',
3591
+ 'replacePublicSymbol',
3592
+ 'extendError',
3593
+ 'createNamedFunction',
3594
+ 'embindRepr',
3595
+ 'registeredInstances',
3596
+ 'getBasestPointer',
3597
+ 'registerInheritedInstance',
3598
+ 'unregisterInheritedInstance',
3599
+ 'getInheritedInstance',
3600
+ 'getInheritedInstanceCount',
3601
+ 'getLiveInheritedInstances',
3602
+ 'registeredTypes',
3603
+ 'awaitingDependencies',
3604
+ 'typeDependencies',
3605
+ 'registeredPointers',
3606
+ 'registerType',
3607
+ 'whenDependentTypesAreResolved',
3608
+ 'embind_charCodes',
3609
+ 'embind_init_charCodes',
3610
+ 'readLatin1String',
3611
+ 'getTypeName',
3612
+ 'heap32VectorToArray',
3613
+ 'requireRegisteredType',
3614
+ 'getShiftFromSize',
3615
+ 'integerReadValueFromPointer',
3616
+ 'enumReadValueFromPointer',
3617
+ 'floatReadValueFromPointer',
3618
+ 'simpleReadValueFromPointer',
3619
+ 'runDestructors',
3620
+ 'newFunc',
3621
+ 'craftInvokerFunction',
3622
+ 'embind__requireFunction',
3623
+ 'tupleRegistrations',
3624
+ 'structRegistrations',
3625
+ 'genericPointerToWireType',
3626
+ 'constNoSmartPtrRawPointerToWireType',
3627
+ 'nonConstNoSmartPtrRawPointerToWireType',
3628
+ 'init_RegisteredPointer',
3629
+ 'RegisteredPointer',
3630
+ 'RegisteredPointer_getPointee',
3631
+ 'RegisteredPointer_destructor',
3632
+ 'RegisteredPointer_deleteObject',
3633
+ 'RegisteredPointer_fromWireType',
3634
+ 'runDestructor',
3635
+ 'releaseClassHandle',
3636
+ 'finalizationRegistry',
3637
+ 'detachFinalizer_deps',
3638
+ 'detachFinalizer',
3639
+ 'attachFinalizer',
3640
+ 'makeClassHandle',
3641
+ 'init_ClassHandle',
3642
+ 'ClassHandle',
3643
+ 'ClassHandle_isAliasOf',
3644
+ 'throwInstanceAlreadyDeleted',
3645
+ 'ClassHandle_clone',
3646
+ 'ClassHandle_delete',
3647
+ 'deletionQueue',
3648
+ 'ClassHandle_isDeleted',
3649
+ 'ClassHandle_deleteLater',
3650
+ 'flushPendingDeletes',
3651
+ 'delayFunction',
3652
+ 'setDelayFunction',
3653
+ 'RegisteredClass',
3654
+ 'shallowCopyInternalPointer',
3655
+ 'downcastPointer',
3656
+ 'upcastPointer',
3657
+ 'validateThis',
3658
+ 'char_0',
3659
+ 'char_9',
3660
+ 'makeLegalFunctionName',
3661
+ 'emval_handles',
3662
+ 'emval_symbols',
3663
+ 'init_emval',
3664
+ 'count_emval_handles',
3665
+ 'getStringOrSymbol',
3666
+ 'Emval',
3667
+ 'emval_newers',
3668
+ 'craftEmvalAllocator',
3669
+ 'emval_get_global',
3670
+ 'emval_lookupTypes',
3671
+ 'emval_allocateDestructors',
3672
+ 'emval_methodCallers',
3673
+ 'emval_addMethodCaller',
3674
+ 'emval_registeredMethods',
3675
+ ];
3676
+ unexportedSymbols.forEach(unexportedRuntimeSymbol);
3677
+
3678
+
3679
+
3680
+ var calledRun;
3681
+
3682
+ function run(args = arguments_) {
3683
+
3684
+ function doRun() {
3685
+ // run may have just been called through dependencies being fulfilled just in this very frame,
3686
+ // or while the async setStatus time below was happening
3687
+ if (calledRun) return;
3688
+ calledRun = true;
3689
+ Module['calledRun'] = true;
3690
+
3691
+ if (ABORT) return;
3692
+
3693
+ initRuntime();
3694
+
3695
+ assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
3696
+ }
3697
+
3698
+ {
3699
+ doRun();
3700
+ }
3701
+ }
3702
+
3703
+ run();
3704
+
3705
+ // end include: postamble.js
3706
+ //FORWARDED_DATA:{"librarySymbols":["__embind_register_void","readLatin1String","embind_charCodes","embind_init_charCodes","registerType","awaitingDependencies","registeredTypes","typeDependencies","throwBindingError","BindingError","extendError","createNamedFunction","makeLegalFunctionName","char_0","char_9","whenDependentTypesAreResolved","throwInternalError","InternalError","__embind_register_bool","getShiftFromSize","__embind_register_integer","embindRepr","integerReadValueFromPointer","__embind_register_bigint","__embind_register_float","floatReadValueFromPointer","__embind_register_std_string","simpleReadValueFromPointer","stringToUTF8","stringToUTF8Array","lengthBytesUTF8","_malloc","_free","UTF8ToString","UTF8ArrayToString","UTF8Decoder","__embind_register_std_wstring","UTF16ToString","UTF16Decoder","stringToUTF16","lengthBytesUTF16","UTF32ToString","stringToUTF32","lengthBytesUTF32","__embind_register_emval","__emval_decref","emval_handles","HandleAllocator","Emval","init_emval","count_emval_handles","__embind_register_memory_view","__embind_register_function","craftInvokerFunction","runDestructors","newFunc","exposePublicSymbol","ensureOverloadTable","heap32VectorToArray","replacePublicSymbol","embind__requireFunction","getDynCaller","getWasmTableEntry","throwUnboundTypeError","UnboundTypeError","getTypeName","___getTypeName","__embind_register_value_array","tupleRegistrations","__embind_register_value_array_element","__embind_finalize_value_array","__embind_register_value_object","structRegistrations","__embind_register_value_object_field","__embind_finalize_value_object","__embind_register_class","ClassHandle","init_ClassHandle","ClassHandle_isAliasOf","ClassHandle_clone","shallowCopyInternalPointer","throwInstanceAlreadyDeleted","attachFinalizer","finalizationRegistry","detachFinalizer","releaseClassHandle","runDestructor","RegisteredPointer_fromWireType","downcastPointer","registeredPointers","getInheritedInstance","registeredInstances","init_embind","getInheritedInstanceCount","getLiveInheritedInstances","flushPendingDeletes","deletionQueue","setDelayFunction","delayFunction","getBasestPointer","makeClassHandle","bigintToI53Checked","MAX_INT53","MIN_INT53","ClassHandle_delete","ClassHandle_isDeleted","ClassHandle_deleteLater","RegisteredClass","RegisteredPointer","constNoSmartPtrRawPointerToWireType","upcastPointer","genericPointerToWireType","nonConstNoSmartPtrRawPointerToWireType","init_RegisteredPointer","RegisteredPointer_getPointee","RegisteredPointer_destructor","RegisteredPointer_deleteObject","__embind_register_class_constructor","__embind_register_class_function","__embind_register_class_property","validateThis","__embind_register_class_class_function","__embind_register_class_class_property","__embind_create_inheriting_constructor","PureVirtualError","registerInheritedInstance","requireRegisteredType","unregisterInheritedInstance","__embind_register_smart_ptr","__embind_register_enum","enumReadValueFromPointer","__embind_register_enum_value","__embind_register_constant","__emval_register_symbol","emval_symbols","__emval_incref","__emval_run_destructors","__emval_new_array","__emval_new_array_from_memory_view","__emval_new_object","__emval_new_cstring","getStringOrSymbol","__emval_new_u8string","__emval_new_u16string","__emval_take_value","__emval_new","craftEmvalAllocator","emval_newers","__emval_get_global","emval_get_global","__emval_get_module_property","__emval_get_property","__emval_set_property","__emval_as","__emval_as_int64","__emval_as_uint64","__emval_equals","__emval_strictly_equals","__emval_greater_than","__emval_less_than","__emval_not","__emval_call","emval_lookupTypes","__emval_get_method_caller","emval_addMethodCaller","emval_methodCallers","emval_registeredMethods","__emval_call_method","emval_allocateDestructors","__emval_call_void_method","__emval_typeof","__emval_instanceof","__emval_is_number","__emval_is_string","__emval_in","__emval_delete","__emval_throw"],"warnings":false,"asyncFuncs":[],"ATINITS":"","ATMAINS":"","ATEXITS":""}
3707
+
3708
+ globalThis.Module['ASSERTIONS'] = true;
3709
+ var Module$1 = globalThis.Module;
3710
+
3711
+ function toArray(vector) {
3712
+ const output = [];
3713
+ for (let i = 0; i < vector.size(); i += 1) {
3714
+ output.push(vector.get(i));
3715
+ }
3716
+ return output;
3717
+ }
3718
+
3719
+ function toVector(VectorClass, array = []) {
3720
+ const vector = new VectorClass();
3721
+ array.forEach((item) => {
3722
+ vector.push_back(item);
3723
+ });
3724
+ return vector;
3725
+ }
3726
+
3727
+ globalThis.Module.toArray = toArray;
3728
+ globalThis.Module.toVector = toVector;
3729
+
3730
+ var systemConfig = {"env":{"darwin-arm64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"darwin-x64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"linux-arm64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"linux-x64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"linuxmusl-arm64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"linuxmusl-x64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"win32-arm64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"},"win32-x64":{"GDAL_DATA":"_CROSSBIND_DATA_PATH_/gdal","DXF_FEATURE_LIMIT_PER_BLOCK":"-1","GDAL_ENABLE_DEPRECATED_DRIVER_GTM":"YES","CPL_LOG_ERRORS":"ON","PROJ_DATA":"_CROSSBIND_DATA_PATH_/proj"}},"general":{"name":"gdal-standalone-napi"},"paths":{"addon":"gdal-standalone-napi.{platform}-{arch}.node","addonPackage":"@crossbind/port-gdal-standalone-napi-{platform}-{arch}"}};
3731
+
3732
+ // The platform part of an addon file name. Node reports musl and glibc systems alike as 'linux'; a
3733
+ // process linked against glibc names that glibc in its report header, a musl one does not.
3734
+ function addonPlatform(platform = process.platform, readReport = processReport) {
3735
+ if (platform !== 'linux') return platform;
3736
+ const header = readReport()?.header;
3737
+ return !header || header.glibcVersionRuntime ? 'linux' : 'linuxmusl';
3738
+ }
3739
+
3740
+ function processReport() {
3741
+ if (!process.report) return undefined;
3742
+ // Only the header is read; the network section can stall on DNS lookups.
3743
+ const { excludeNetwork } = process.report;
3744
+ process.report.excludeNetwork = true;
3745
+ try {
3746
+ return process.report.getReport();
3747
+ } finally {
3748
+ process.report.excludeNetwork = excludeNetwork;
3749
+ }
3750
+ }
3751
+
3752
+ // A project's own build leaves the addon beside the loader. A package that publishes one addon per
3753
+ // platform ships it in <package>-<platform>-<arch>, an optional dependency whose main is the addon.
3754
+ function addonLocation({ dir, fileName, packageName, exists, resolve }) {
3755
+ const beside = path.join(dir, fileName);
3756
+ if (exists(beside) || !packageName) return beside;
3757
+ try {
3758
+ return resolve(packageName);
3759
+ } catch {
3760
+ return beside;
3761
+ }
3762
+ }
3763
+
3764
+ // What a process without its addon is told: install the addon package npm left out, learn that the package
3765
+ // publishes none for this machine, or build the addon an app makes itself. published lists the
3766
+ // <platform>-<arch> of every addon the package ships.
3767
+ function missingAddonRemedy({ platform, arch, addonPackage, published }) {
3768
+ const target = `${platform}-${arch}`;
3769
+ if (!addonPackage) return `build it with \`crossbind build -p ${platform} -a ${arch}\``;
3770
+ if (!published.includes(target)) return `this package publishes no addon for ${target}, only for ${published.join(', ')}`;
3771
+ return `install ${addonPackage}, which npm leaves out with --omit=optional; addons exist for ${published.join(', ')}`;
3772
+ }
3773
+
3774
+ // Every package bundles a loader of its own, and Node warns at an eleventh 'exit' listener, so the addons share one,
3775
+ // found by a registered symbol. Each boot moves it to the end of the list: the stops then run after every handler
3776
+ // registered so far, as a listener added at that boot would, since a call into an addon after its stop crashes.
3777
+ const ADDON_STOPS = Symbol.for('crossbind.addonStops.v1');
3778
+
3779
+ function stopOnExit(stop, proc = process) {
3780
+ if (!proc[ADDON_STOPS]) {
3781
+ const stops = [];
3782
+ proc[ADDON_STOPS] = { stops, onExit: () => stops.forEach((stopAddon) => stopAddon()) };
3783
+ }
3784
+ const { stops, onExit } = proc[ADDON_STOPS];
3785
+ stops.push(stop);
3786
+ proc.removeListener('exit', onExit);
3787
+ proc.on('exit', onExit);
3788
+ }
3789
+
3790
+ // Native code cannot read inside an Electron asar archive, so a packaged app keeps what an addon
3791
+ // reads in <archive>.asar.unpacked beside it.
3792
+ function unpackedPath(file, isElectron = Boolean(process.versions.electron)) {
3793
+ return isElectron ? file.replace(/\.asar(?=[\\/]|$)/, '.asar.unpacked') : file;
3794
+ }
3795
+
3796
+ // Entry of the per-project loader crossbind bundles next to the native addons
3797
+ // (dist/<name>.native.cjs). It keeps the wasm build's initNative() contract, so the same app code
3798
+ // runs on either build.
3799
+
3800
+ const platform = addonPlatform();
3801
+ const fill = (pattern) => pattern.replace('{platform}', platform).replace('{arch}', process.arch);
3802
+ const addonPackage = fill(systemConfig.paths.addonPackage) ;
3803
+
3804
+ function addonFile(config) {
3805
+ return config.addonPath ?? addonLocation({
3806
+ dir: __dirname,
3807
+ fileName: fill(systemConfig.paths.addon),
3808
+ packageName: addonPackage,
3809
+ exists: fs.existsSync,
3810
+ resolve: node_module.createRequire(__filename).resolve,
3811
+ });
3812
+ }
3813
+
3814
+ function loadAddon(file) {
3815
+ const addon = { exports: {} };
3816
+ try {
3817
+ process.dlopen(addon, file);
3818
+ } catch (error) {
3819
+ throw new Error(`crossbind: cannot load ${file} - ${fs.existsSync(file) ? error.message : missingAddonRemedy({ platform, arch: process.arch, addonPackage, published: Object.keys(systemConfig.env) })}.`, { cause: error });
3820
+ }
3821
+ return addon.exports;
3822
+ }
3823
+
3824
+ function setEnv(dataPath, runtimeEnv = {}) {
3825
+ const fillDataPath = (value) => String(value).replace('_CROSSBIND_DATA_PATH_', dataPath);
3826
+ // Build-time values are keyed by addon: a target-scoped value must not leak from one arch's
3827
+ // build into another's. They never replace a variable the process already has; values passed to
3828
+ // initNative() do, as in the wasm runtime, even after a package entry booted the addon.
3829
+ Object.entries(systemConfig.env[`${platform}-${process.arch}`] ?? {}).forEach(([key, value]) => {
3830
+ Module$1.Crossbind.setEnv(key, fillDataPath(value), false);
3831
+ });
3832
+ Object.entries(runtimeEnv).forEach(([key, value]) => {
3833
+ Module$1.Crossbind.setEnv(key, fillDataPath(value), true);
3834
+ });
3835
+ }
3836
+
3837
+ let addon = null;
3838
+ let addonDataPath = null;
3839
+
3840
+ function boot(config) {
3841
+ // Loaded and started once per process: Node cannot unload an addon, and a second dlopen gets a
3842
+ // fresh environment whose start() would register every binding twice.
3843
+ if (!addon) {
3844
+ addonDataPath = config.dataPath ?? unpackedPath(path.join(__dirname, 'data'));
3845
+ const loaded = loadAddon(addonFile(config));
3846
+ // The embind runtime this bundle carries keeps its state on crossbindScope (crossbind's utils/scopedEmbind.js).
3847
+ loaded.start(addonDataPath, globalThis);
3848
+ // Native values released after this (thread-local ones die inside exit()) must not call
3849
+ // back into the runtime.
3850
+ stopOnExit(() => loaded.stop());
3851
+ addon = loaded;
3852
+ } else if (config.dataPath && config.dataPath !== addonDataPath) {
3853
+ throw new Error(`crossbind: the addon started with its data at ${addonDataPath}; a process cannot move it to ${config.dataPath}.`);
3854
+ }
3855
+ setEnv(addonDataPath, config.env);
3856
+ return Module$1;
3857
+ }
3858
+
3859
+ let booted = null;
3860
+
3861
+ function initNative(config = {}) {
3862
+ if (!booted) {
3863
+ try {
3864
+ booted = Promise.resolve(boot(config));
3865
+ } catch (error) {
3866
+ // Not remembered: a later call retries, for example once the addon is built.
3867
+ return Promise.reject(error);
3868
+ }
3869
+ }
3870
+ return booted;
3871
+ }
3872
+
3873
+ // Loading an addon is synchronous, so a package entry boots it on require.
3874
+ initNative.sync = function sync(config = {}) {
3875
+ return boot(config);
3876
+ };
3877
+
3878
+ // The wasm runtime's contract: forget the booted module so the next call boots again. Native state
3879
+ // cannot be reset (Node cannot unload an addon), so that call resolves the same module.
3880
+ initNative.terminate = function terminate() {
3881
+ booted = null;
3882
+ };
3883
+
3884
+ module.exports = initNative;