@powersync-community/sync-config-rewriter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/lib/compiled.mjs +378 -0
- package/lib/compiled.support.js +1 -0
- package/lib/compiled.wasm +0 -0
- package/lib/compiled.wasm.map +1 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +17 -0
- package/package.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
This exposes the [Sync Config rewriter](github.com/powersync-community/bucket-definitions-to-sync-streams)
|
|
2
|
+
as a package usable from JavaScript.
|
|
3
|
+
|
|
4
|
+
## Instantiation
|
|
5
|
+
|
|
6
|
+
This package requires you to load a compiled WebAssembly file, which depends on your target platform.
|
|
7
|
+
|
|
8
|
+
On Node.JS, resolve and load the WASM file:
|
|
9
|
+
|
|
10
|
+
```TypeScript
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
import { instantiate } from "@powersync-community/sync-config-rewriter";
|
|
15
|
+
|
|
16
|
+
const wasmBuffer = readFileSync(
|
|
17
|
+
fileURLToPath(
|
|
18
|
+
import.meta
|
|
19
|
+
.resolve("@powersync-community/sync-config-rewriter/compiled.wasm"),
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const module = await instantiate(wasmBuffer);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For web apps bundled with vite, use [explicit URL imports](https://vite.dev/guide/assets#explicit-url-imports):
|
|
27
|
+
|
|
28
|
+
```TypeScript
|
|
29
|
+
import { instantiate } from "@powersync-community/sync-config-rewriter";
|
|
30
|
+
import wasmUrl from "@powersync-community/sync-config-rewriter/compiled.wasm?url";
|
|
31
|
+
|
|
32
|
+
const module = await instantiate(fetch(wasmUrl));
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Development
|
|
36
|
+
|
|
37
|
+
To release a version of this package, update the `version` entry in
|
|
38
|
+
`package.json`, merge to `main` and manually trigger the `publish_npm`
|
|
39
|
+
workflow.
|
package/lib/compiled.mjs
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
// Compiles a dart2wasm-generated main module from `source` which can then
|
|
2
|
+
// instantiatable via the `instantiate` method.
|
|
3
|
+
//
|
|
4
|
+
// `source` needs to be a `Response` object (or promise thereof) e.g. created
|
|
5
|
+
// via the `fetch()` JS API.
|
|
6
|
+
export async function compileStreaming(source) {
|
|
7
|
+
const builtins = {builtins: ['js-string']};
|
|
8
|
+
return new CompiledApp(
|
|
9
|
+
await WebAssembly.compileStreaming(source, builtins), builtins);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Compiles a dart2wasm-generated wasm modules from `bytes` which is then
|
|
13
|
+
// instantiatable via the `instantiate` method.
|
|
14
|
+
export async function compile(bytes) {
|
|
15
|
+
const builtins = {builtins: ['js-string']};
|
|
16
|
+
return new CompiledApp(await WebAssembly.compile(bytes, builtins), builtins);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// DEPRECATED: Please use `compile` or `compileStreaming` to get a compiled app,
|
|
20
|
+
// use `instantiate` method to get an instantiated app and then call
|
|
21
|
+
// `invokeMain` to invoke the main function.
|
|
22
|
+
export async function instantiate(modulePromise, importObjectPromise) {
|
|
23
|
+
var moduleOrCompiledApp = await modulePromise;
|
|
24
|
+
if (!(moduleOrCompiledApp instanceof CompiledApp)) {
|
|
25
|
+
moduleOrCompiledApp = new CompiledApp(moduleOrCompiledApp);
|
|
26
|
+
}
|
|
27
|
+
const instantiatedApp = await moduleOrCompiledApp.instantiate(await importObjectPromise);
|
|
28
|
+
return instantiatedApp.instantiatedModule;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// DEPRECATED: Please use `compile` or `compileStreaming` to get a compiled app,
|
|
32
|
+
// use `instantiate` method to get an instantiated app and then call
|
|
33
|
+
// `invokeMain` to invoke the main function.
|
|
34
|
+
export const invoke = (moduleInstance, ...args) => {
|
|
35
|
+
moduleInstance.exports.$invokeMain(args);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class CompiledApp {
|
|
39
|
+
constructor(module, builtins) {
|
|
40
|
+
this.module = module;
|
|
41
|
+
this.builtins = builtins;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The second argument is an options object containing:
|
|
45
|
+
// `loadDeferredModule` is a JS function that takes a module name matching a
|
|
46
|
+
// wasm file produced by the dart2wasm compiler and returns the bytes to
|
|
47
|
+
// load the module. These bytes can be in either a format supported by
|
|
48
|
+
// `WebAssembly.compile` or `WebAssembly.compileStreaming`.
|
|
49
|
+
// `loadDynamicModule` is a JS function that takes two string names matching,
|
|
50
|
+
// in order, a wasm file produced by the dart2wasm compiler during dynamic
|
|
51
|
+
// module compilation and a corresponding js file produced by the same
|
|
52
|
+
// compilation. It should return a JS Array containing 2 elements. The first
|
|
53
|
+
// should be the bytes for the wasm module in a format supported by
|
|
54
|
+
// `WebAssembly.compile` or `WebAssembly.compileStreaming`. The second
|
|
55
|
+
// should be the result of using the JS 'import' API on the js file path.
|
|
56
|
+
// `loadDeferredId` is a JS function that takes a string corresponding to a load
|
|
57
|
+
// ID generated by the compiler when 'load-ids' option is passed. Each load
|
|
58
|
+
// ID maps to one or more WASM modules produced by the compiler. This
|
|
59
|
+
// function should return an array of byte arrays corresponding to all the
|
|
60
|
+
// modules specified by that load ID. The arrays should be in a format
|
|
61
|
+
// supported by `WebAssembly.compile` or `WebAssembly.compileStreaming`.
|
|
62
|
+
async instantiate(additionalImports,
|
|
63
|
+
{loadDeferredModule, loadDynamicModule, loadDeferredId} = {}) {
|
|
64
|
+
let dartInstance;
|
|
65
|
+
|
|
66
|
+
// Prints to the console
|
|
67
|
+
function printToConsole(value) {
|
|
68
|
+
if (typeof dartPrint == "function") {
|
|
69
|
+
dartPrint(value);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (typeof console == "object" && typeof console.log != "undefined") {
|
|
73
|
+
console.log(value);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (typeof print == "function") {
|
|
77
|
+
print(value);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw "Unable to print message: " + value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// A special symbol attached to functions that wrap Dart functions.
|
|
85
|
+
const jsWrappedDartFunctionSymbol = Symbol("JSWrappedDartFunction");
|
|
86
|
+
|
|
87
|
+
function finalizeWrapper(dartFunction, wrapped) {
|
|
88
|
+
wrapped.dartFunction = dartFunction;
|
|
89
|
+
wrapped[jsWrappedDartFunctionSymbol] = true;
|
|
90
|
+
return wrapped;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Imports
|
|
94
|
+
const dart2wasm = {
|
|
95
|
+
_8: s => {
|
|
96
|
+
if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(s)) {
|
|
97
|
+
return NaN;
|
|
98
|
+
}
|
|
99
|
+
return parseFloat(s);
|
|
100
|
+
},
|
|
101
|
+
_9: () => new Error().stack,
|
|
102
|
+
_13: () => {
|
|
103
|
+
// On browsers return `globalThis.location.href`
|
|
104
|
+
if (globalThis.location != null) {
|
|
105
|
+
return globalThis.location.href;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
},
|
|
109
|
+
_14: () => {
|
|
110
|
+
return typeof process != "undefined" &&
|
|
111
|
+
Object.prototype.toString.call(process) == "[object process]" &&
|
|
112
|
+
process.platform == "win32"
|
|
113
|
+
},
|
|
114
|
+
_18: (exn) => exn.toString(),
|
|
115
|
+
_19: (exn) => exn.stack,
|
|
116
|
+
_20: (exn) => {
|
|
117
|
+
let stackString = exn.toString();
|
|
118
|
+
let frames = stackString.split('\n');
|
|
119
|
+
let drop = 2;
|
|
120
|
+
if (frames[0] === 'Error') {
|
|
121
|
+
drop += 1;
|
|
122
|
+
}
|
|
123
|
+
return frames.slice(drop).join('\n');
|
|
124
|
+
},
|
|
125
|
+
_33: s => JSON.stringify(s),
|
|
126
|
+
_34: s => printToConsole(s),
|
|
127
|
+
_35: (o, p, r) => o.replaceAll(p, () => r),
|
|
128
|
+
_37: Function.prototype.call.bind(String.prototype.toLowerCase),
|
|
129
|
+
_38: s => s.toUpperCase(),
|
|
130
|
+
_39: s => s.trim(),
|
|
131
|
+
_41: s => s.trimRight(),
|
|
132
|
+
_42: (string, times) => string.repeat(times),
|
|
133
|
+
_43: Function.prototype.call.bind(String.prototype.indexOf),
|
|
134
|
+
_44: (s, p, i) => s.lastIndexOf(p, i),
|
|
135
|
+
_45: (string, token) => string.split(token),
|
|
136
|
+
_46: Object.is,
|
|
137
|
+
_81: () => new Array(),
|
|
138
|
+
_82: x0 => new Array(x0),
|
|
139
|
+
_86: (x0,x1) => x0[x1],
|
|
140
|
+
_87: (x0,x1,x2) => { x0[x1] = x2 },
|
|
141
|
+
_91: (x0,x1,x2) => new DataView(x0,x1,x2),
|
|
142
|
+
_93: x0 => new Int8Array(x0),
|
|
143
|
+
_94: (x0,x1,x2) => new Uint8Array(x0,x1,x2),
|
|
144
|
+
_95: x0 => new Uint8Array(x0),
|
|
145
|
+
_97: x0 => new Uint8ClampedArray(x0),
|
|
146
|
+
_99: x0 => new Int16Array(x0),
|
|
147
|
+
_101: x0 => new Uint16Array(x0),
|
|
148
|
+
_103: x0 => new Int32Array(x0),
|
|
149
|
+
_105: x0 => new Uint32Array(x0),
|
|
150
|
+
_107: x0 => new Float32Array(x0),
|
|
151
|
+
_109: x0 => new Float64Array(x0),
|
|
152
|
+
_134: x0 => x0.random(),
|
|
153
|
+
_137: () => globalThis.Math,
|
|
154
|
+
_154: (c) =>
|
|
155
|
+
queueMicrotask(() => dartInstance.exports.$invokeCallback(c)),
|
|
156
|
+
_156: (s, m) => {
|
|
157
|
+
try {
|
|
158
|
+
return new RegExp(s, m);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
return String(e);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
_157: (x0,x1) => x0.exec(x1),
|
|
164
|
+
_158: (x0,x1) => x0.test(x1),
|
|
165
|
+
_159: x0 => x0.pop(),
|
|
166
|
+
_161: o => o === undefined,
|
|
167
|
+
_163: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
|
|
168
|
+
_166: o => o instanceof RegExp,
|
|
169
|
+
_167: (l, r) => l === r,
|
|
170
|
+
_168: o => o,
|
|
171
|
+
_169: o => o,
|
|
172
|
+
_170: o => o,
|
|
173
|
+
_171: b => !!b,
|
|
174
|
+
_172: o => o.length,
|
|
175
|
+
_174: (o, i) => o[i],
|
|
176
|
+
_175: f => f.dartFunction,
|
|
177
|
+
_182: (o, p) => o[p],
|
|
178
|
+
_186: o => String(o),
|
|
179
|
+
_187: (p, s, f) => p.then(s, (e) => f(e, e === undefined)),
|
|
180
|
+
_188: (module,f) => finalizeWrapper(f, function(x0) { return module.exports._188(f,arguments.length,x0) }),
|
|
181
|
+
_189: (module,f) => finalizeWrapper(f, function(x0,x1) { return module.exports._189(f,arguments.length,x0,x1) }),
|
|
182
|
+
_190: o => {
|
|
183
|
+
if (o === undefined) return 1;
|
|
184
|
+
var type = typeof o;
|
|
185
|
+
if (type === 'boolean') return 2;
|
|
186
|
+
if (type === 'number') return 3;
|
|
187
|
+
if (type === 'string') return 4;
|
|
188
|
+
if (o instanceof Array) return 5;
|
|
189
|
+
if (ArrayBuffer.isView(o)) {
|
|
190
|
+
if (o instanceof Int8Array) return 6;
|
|
191
|
+
if (o instanceof Uint8Array) return 7;
|
|
192
|
+
if (o instanceof Uint8ClampedArray) return 8;
|
|
193
|
+
if (o instanceof Int16Array) return 9;
|
|
194
|
+
if (o instanceof Uint16Array) return 10;
|
|
195
|
+
if (o instanceof Int32Array) return 11;
|
|
196
|
+
if (o instanceof Uint32Array) return 12;
|
|
197
|
+
if (o instanceof Float32Array) return 13;
|
|
198
|
+
if (o instanceof Float64Array) return 14;
|
|
199
|
+
if (o instanceof DataView) return 15;
|
|
200
|
+
}
|
|
201
|
+
if (o instanceof ArrayBuffer) return 16;
|
|
202
|
+
// Feature check for `SharedArrayBuffer` before doing a type-check.
|
|
203
|
+
if (globalThis.SharedArrayBuffer !== undefined &&
|
|
204
|
+
o instanceof SharedArrayBuffer) {
|
|
205
|
+
return 17;
|
|
206
|
+
}
|
|
207
|
+
if (o instanceof Promise) return 18;
|
|
208
|
+
return 19;
|
|
209
|
+
},
|
|
210
|
+
_191: o => [o],
|
|
211
|
+
_192: (o0, o1) => [o0, o1],
|
|
212
|
+
_193: (o0, o1, o2) => [o0, o1, o2],
|
|
213
|
+
_194: (o0, o1, o2, o3) => [o0, o1, o2, o3],
|
|
214
|
+
_195: (jsArray, jsArrayOffset, wasmArray, wasmArrayOffset, length) => {
|
|
215
|
+
const getValue = dartInstance.exports.$wasmI8ArrayGet;
|
|
216
|
+
for (let i = 0; i < length; i++) {
|
|
217
|
+
jsArray[jsArrayOffset + i] = getValue(wasmArray, wasmArrayOffset + i);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
_197: (jsArray, jsArrayOffset, wasmArray, wasmArrayOffset, length) => {
|
|
221
|
+
const getValue = dartInstance.exports.$wasmI16ArrayGet;
|
|
222
|
+
for (let i = 0; i < length; i++) {
|
|
223
|
+
jsArray[jsArrayOffset + i] = getValue(wasmArray, wasmArrayOffset + i);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
_199: (jsArray, jsArrayOffset, wasmArray, wasmArrayOffset, length) => {
|
|
227
|
+
const getValue = dartInstance.exports.$wasmI32ArrayGet;
|
|
228
|
+
for (let i = 0; i < length; i++) {
|
|
229
|
+
jsArray[jsArrayOffset + i] = getValue(wasmArray, wasmArrayOffset + i);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
_205: x0 => new ArrayBuffer(x0),
|
|
233
|
+
_208: x0 => x0.index,
|
|
234
|
+
_210: x0 => x0.flags,
|
|
235
|
+
_211: x0 => x0.multiline,
|
|
236
|
+
_212: x0 => x0.ignoreCase,
|
|
237
|
+
_213: x0 => x0.unicode,
|
|
238
|
+
_214: x0 => x0.dotAll,
|
|
239
|
+
_215: (x0,x1) => { x0.lastIndex = x1 },
|
|
240
|
+
_220: o => o instanceof Array,
|
|
241
|
+
_230: (a, b) => a == b ? 0 : (a > b ? 1 : -1),
|
|
242
|
+
_231: a => a.length,
|
|
243
|
+
_233: (a, i) => a[i],
|
|
244
|
+
_234: (a, i, v) => a[i] = v,
|
|
245
|
+
_239: o => o instanceof Uint8Array,
|
|
246
|
+
_240: (o, start, length) => new Uint8Array(o.buffer, o.byteOffset + start, length),
|
|
247
|
+
_241: o => o instanceof Int8Array,
|
|
248
|
+
_242: (o, start, length) => new Int8Array(o.buffer, o.byteOffset + start, length),
|
|
249
|
+
_243: o => o instanceof Uint8ClampedArray,
|
|
250
|
+
_244: (o, start, length) => new Uint8ClampedArray(o.buffer, o.byteOffset + start, length),
|
|
251
|
+
_245: o => o instanceof Uint16Array,
|
|
252
|
+
_246: (o, start, length) => new Uint16Array(o.buffer, o.byteOffset + start, length),
|
|
253
|
+
_247: o => o instanceof Int16Array,
|
|
254
|
+
_248: (o, start, length) => new Int16Array(o.buffer, o.byteOffset + start, length),
|
|
255
|
+
_249: o => o instanceof Uint32Array,
|
|
256
|
+
_250: (o, start, length) => new Uint32Array(o.buffer, o.byteOffset + start, length),
|
|
257
|
+
_251: o => o instanceof Int32Array,
|
|
258
|
+
_252: (o, start, length) => new Int32Array(o.buffer, o.byteOffset + start, length),
|
|
259
|
+
_255: o => o instanceof Float32Array,
|
|
260
|
+
_256: (o, start, length) => new Float32Array(o.buffer, o.byteOffset + start, length),
|
|
261
|
+
_257: o => o instanceof Float64Array,
|
|
262
|
+
_258: (o, start, length) => new Float64Array(o.buffer, o.byteOffset + start, length),
|
|
263
|
+
_259: (t, s) => t.set(s),
|
|
264
|
+
_261: (o) => new DataView(o.buffer, o.byteOffset, o.byteLength),
|
|
265
|
+
_263: o => o.buffer,
|
|
266
|
+
_264: o => o.byteOffset,
|
|
267
|
+
_265: Function.prototype.call.bind(Object.getOwnPropertyDescriptor(DataView.prototype, 'byteLength').get),
|
|
268
|
+
_266: (b, o) => new DataView(b, o),
|
|
269
|
+
_267: (b, o, l) => new DataView(b, o, l),
|
|
270
|
+
_268: Function.prototype.call.bind(DataView.prototype.getUint8),
|
|
271
|
+
_269: Function.prototype.call.bind(DataView.prototype.setUint8),
|
|
272
|
+
_270: Function.prototype.call.bind(DataView.prototype.getInt8),
|
|
273
|
+
_271: Function.prototype.call.bind(DataView.prototype.setInt8),
|
|
274
|
+
_272: Function.prototype.call.bind(DataView.prototype.getUint16),
|
|
275
|
+
_273: Function.prototype.call.bind(DataView.prototype.setUint16),
|
|
276
|
+
_274: Function.prototype.call.bind(DataView.prototype.getInt16),
|
|
277
|
+
_275: Function.prototype.call.bind(DataView.prototype.setInt16),
|
|
278
|
+
_276: Function.prototype.call.bind(DataView.prototype.getUint32),
|
|
279
|
+
_277: Function.prototype.call.bind(DataView.prototype.setUint32),
|
|
280
|
+
_278: Function.prototype.call.bind(DataView.prototype.getInt32),
|
|
281
|
+
_279: Function.prototype.call.bind(DataView.prototype.setInt32),
|
|
282
|
+
_284: Function.prototype.call.bind(DataView.prototype.getFloat32),
|
|
283
|
+
_285: Function.prototype.call.bind(DataView.prototype.setFloat32),
|
|
284
|
+
_286: Function.prototype.call.bind(DataView.prototype.getFloat64),
|
|
285
|
+
_287: Function.prototype.call.bind(DataView.prototype.setFloat64),
|
|
286
|
+
_288: Function.prototype.call.bind(Number.prototype.toString),
|
|
287
|
+
_289: Function.prototype.call.bind(BigInt.prototype.toString),
|
|
288
|
+
_290: Function.prototype.call.bind(Number.prototype.toString),
|
|
289
|
+
_295: (x0,x1,x2) => ({startOffset: x0,length: x1,message: x2}),
|
|
290
|
+
_296: (x0,x1,x2) => ({type: x0,diagnostics: x1,internalMessage: x2}),
|
|
291
|
+
_297: (x0,x1) => ({type: x0,result: x1}),
|
|
292
|
+
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const baseImports = {
|
|
296
|
+
dart2wasm: dart2wasm,
|
|
297
|
+
Math: Math,
|
|
298
|
+
Date: Date,
|
|
299
|
+
Object: Object,
|
|
300
|
+
Array: Array,
|
|
301
|
+
Reflect: Reflect,
|
|
302
|
+
WebAssembly: {
|
|
303
|
+
JSTag: WebAssembly.JSTag,
|
|
304
|
+
},
|
|
305
|
+
"": new Proxy({}, { get(_, prop) { return prop; } }),
|
|
306
|
+
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const jsStringPolyfill = {
|
|
310
|
+
"charCodeAt": (s, i) => s.charCodeAt(i),
|
|
311
|
+
"compare": (s1, s2) => {
|
|
312
|
+
if (s1 < s2) return -1;
|
|
313
|
+
if (s1 > s2) return 1;
|
|
314
|
+
return 0;
|
|
315
|
+
},
|
|
316
|
+
"concat": (s1, s2) => s1 + s2,
|
|
317
|
+
"equals": (s1, s2) => s1 === s2,
|
|
318
|
+
"fromCharCode": (i) => String.fromCharCode(i),
|
|
319
|
+
"length": (s) => s.length,
|
|
320
|
+
"substring": (s, a, b) => s.substring(a, b),
|
|
321
|
+
"fromCharCodeArray": (a, start, end) => {
|
|
322
|
+
if (end <= start) return '';
|
|
323
|
+
|
|
324
|
+
const read = dartInstance.exports.$wasmI16ArrayGet;
|
|
325
|
+
let result = '';
|
|
326
|
+
let index = start;
|
|
327
|
+
const chunkLength = Math.min(end - index, 500);
|
|
328
|
+
let array = new Array(chunkLength);
|
|
329
|
+
while (index < end) {
|
|
330
|
+
const newChunkLength = Math.min(end - index, 500);
|
|
331
|
+
for (let i = 0; i < newChunkLength; i++) {
|
|
332
|
+
array[i] = read(a, index++);
|
|
333
|
+
}
|
|
334
|
+
if (newChunkLength < chunkLength) {
|
|
335
|
+
array = array.slice(0, newChunkLength);
|
|
336
|
+
}
|
|
337
|
+
result += String.fromCharCode(...array);
|
|
338
|
+
}
|
|
339
|
+
return result;
|
|
340
|
+
},
|
|
341
|
+
"intoCharCodeArray": (s, a, start) => {
|
|
342
|
+
if (s === '') return 0;
|
|
343
|
+
|
|
344
|
+
const write = dartInstance.exports.$wasmI16ArraySet;
|
|
345
|
+
for (var i = 0; i < s.length; ++i) {
|
|
346
|
+
write(a, start++, s.charCodeAt(i));
|
|
347
|
+
}
|
|
348
|
+
return s.length;
|
|
349
|
+
},
|
|
350
|
+
"test": (s) => typeof s == "string",
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
dartInstance = await WebAssembly.instantiate(this.module, {
|
|
357
|
+
...baseImports,
|
|
358
|
+
...additionalImports,
|
|
359
|
+
|
|
360
|
+
"wasm:js-string": jsStringPolyfill,
|
|
361
|
+
});
|
|
362
|
+
dartInstance.exports.$setThisModule(dartInstance);
|
|
363
|
+
|
|
364
|
+
return new InstantiatedApp(this, dartInstance);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
class InstantiatedApp {
|
|
369
|
+
constructor(compiledApp, instantiatedModule) {
|
|
370
|
+
this.compiledApp = compiledApp;
|
|
371
|
+
this.instantiatedModule = instantiatedModule;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Call the main function with the given arguments.
|
|
375
|
+
invokeMain(...args) {
|
|
376
|
+
this.instantiatedModule.exports.$invokeMain(args);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,95,1,120,0])))
|
|
Binary file
|