@wasm-fmt/dart_fmt 0.2.0 → 0.4.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/CHANGELOG.md +14 -1
- package/README.md +48 -19
- package/dart_fmt.d.ts +23 -24
- package/dart_fmt.mjs +329 -291
- package/dart_fmt.support.js +1 -0
- package/dart_fmt.unopt.wasm +0 -0
- package/dart_fmt.unopt.wasm.map +3 -3
- package/dart_fmt.wasm +0 -0
- package/dart_fmt.wasm.map +1 -1
- package/dart_fmt_esm.js +10 -0
- package/dart_fmt_node.js +10 -7
- package/dart_fmt_vite.js +4 -2
- package/dart_fmt_web.d.ts +41 -0
- package/dart_fmt_web.js +75 -0
- package/jsr.jsonc +18 -29
- package/package.json +60 -35
- package/wasm-fmt-dart_fmt-0.4.0.tgz +0 -0
- package/dart_fmt.js +0 -84
- package/wasm-fmt-dart_fmt-0.2.0.tgz +0 -0
package/dart_fmt.mjs
CHANGED
|
@@ -1,12 +1,59 @@
|
|
|
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
|
+
}
|
|
1
18
|
|
|
2
|
-
// `
|
|
3
|
-
//
|
|
4
|
-
// `
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
// `loadDeferredWasm` 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
|
+
instantiate(additionalImports, {loadDeferredWasm, loadDynamicModule} = {}) {
|
|
10
57
|
let dartInstance;
|
|
11
58
|
|
|
12
59
|
// Prints to the console
|
|
@@ -24,20 +71,7 @@ export const instantiate = async (modulePromise, importObjectPromise) => {
|
|
|
24
71
|
return;
|
|
25
72
|
}
|
|
26
73
|
|
|
27
|
-
throw "Unable to print message: " +
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Converts a Dart List to a JS array. Any Dart objects will be converted, but
|
|
31
|
-
// this will be cheap for JSValues.
|
|
32
|
-
function arrayFromDartList(constructor, list) {
|
|
33
|
-
const exports = dartInstance.exports;
|
|
34
|
-
const read = exports.$listRead;
|
|
35
|
-
const length = exports.$listLength(list);
|
|
36
|
-
const array = new constructor(length);
|
|
37
|
-
for (let i = 0; i < length; i++) {
|
|
38
|
-
array[i] = read(list, i);
|
|
39
|
-
}
|
|
40
|
-
return array;
|
|
74
|
+
throw "Unable to print message: " + value;
|
|
41
75
|
}
|
|
42
76
|
|
|
43
77
|
// A special symbol attached to functions that wrap Dart functions.
|
|
@@ -51,300 +85,304 @@ export const instantiate = async (modulePromise, importObjectPromise) => {
|
|
|
51
85
|
|
|
52
86
|
// Imports
|
|
53
87
|
const dart2wasm = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
_36: x0 => new Array(x0),
|
|
89
|
+
_38: x0 => x0.length,
|
|
90
|
+
_40: (x0,x1) => x0[x1],
|
|
91
|
+
_41: (x0,x1,x2) => { x0[x1] = x2 },
|
|
92
|
+
_45: (x0,x1,x2) => new DataView(x0,x1,x2),
|
|
93
|
+
_47: x0 => new Int8Array(x0),
|
|
94
|
+
_48: (x0,x1,x2) => new Uint8Array(x0,x1,x2),
|
|
95
|
+
_49: x0 => new Uint8Array(x0),
|
|
96
|
+
_51: x0 => new Uint8ClampedArray(x0),
|
|
97
|
+
_53: x0 => new Int16Array(x0),
|
|
98
|
+
_55: x0 => new Uint16Array(x0),
|
|
99
|
+
_57: x0 => new Int32Array(x0),
|
|
100
|
+
_59: x0 => new Uint32Array(x0),
|
|
101
|
+
_61: x0 => new Float32Array(x0),
|
|
102
|
+
_63: x0 => new Float64Array(x0),
|
|
103
|
+
_73: (s) => +s,
|
|
104
|
+
_77: s => {
|
|
105
|
+
if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(s)) {
|
|
106
|
+
return NaN;
|
|
107
|
+
}
|
|
108
|
+
return parseFloat(s);
|
|
109
|
+
},
|
|
110
|
+
_78: () => {
|
|
111
|
+
let stackString = new Error().stack.toString();
|
|
112
|
+
let frames = stackString.split('\n');
|
|
113
|
+
let drop = 2;
|
|
114
|
+
if (frames[0] === 'Error') {
|
|
115
|
+
drop += 1;
|
|
116
|
+
}
|
|
117
|
+
return frames.slice(drop).join('\n');
|
|
118
|
+
},
|
|
119
|
+
_82: () => {
|
|
120
|
+
// On browsers return `globalThis.location.href`
|
|
121
|
+
if (globalThis.location != null) {
|
|
122
|
+
return globalThis.location.href;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
},
|
|
126
|
+
_83: () => {
|
|
79
127
|
return typeof process != "undefined" &&
|
|
80
128
|
Object.prototype.toString.call(process) == "[object process]" &&
|
|
81
129
|
process.platform == "win32"
|
|
82
130
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
_165:
|
|
129
|
-
_166:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
_205:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
_210: o => o instanceof Int32Array,
|
|
154
|
-
_211: o => o instanceof Uint32Array,
|
|
155
|
-
_212: o => o instanceof Float32Array,
|
|
156
|
-
_213: o => o instanceof Float64Array,
|
|
157
|
-
_214: o => o instanceof ArrayBuffer,
|
|
158
|
-
_215: o => o instanceof DataView,
|
|
159
|
-
_216: o => o instanceof Array,
|
|
160
|
-
_217: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
|
|
161
|
-
_220: o => o instanceof RegExp,
|
|
162
|
-
_221: (l, r) => l === r,
|
|
163
|
-
_222: o => o,
|
|
164
|
-
_223: o => o,
|
|
165
|
-
_224: o => o,
|
|
166
|
-
_225: b => !!b,
|
|
167
|
-
_226: o => o.length,
|
|
168
|
-
_229: (o, i) => o[i],
|
|
169
|
-
_230: f => f.dartFunction,
|
|
170
|
-
_231: l => arrayFromDartList(Int8Array, l),
|
|
171
|
-
_232: (data, length) => {
|
|
172
|
-
const jsBytes = new Uint8Array(length);
|
|
173
|
-
const getByte = dartInstance.exports.$uint8ListGet;
|
|
174
|
-
for (let i = 0; i < length; i++) {
|
|
175
|
-
jsBytes[i] = getByte(data, i);
|
|
176
|
-
}
|
|
177
|
-
return jsBytes;
|
|
178
|
-
},
|
|
179
|
-
_233: l => arrayFromDartList(Uint8ClampedArray, l),
|
|
180
|
-
_234: l => arrayFromDartList(Int16Array, l),
|
|
181
|
-
_235: l => arrayFromDartList(Uint16Array, l),
|
|
182
|
-
_236: l => arrayFromDartList(Int32Array, l),
|
|
183
|
-
_237: l => arrayFromDartList(Uint32Array, l),
|
|
184
|
-
_238: l => arrayFromDartList(Float32Array, l),
|
|
185
|
-
_239: l => arrayFromDartList(Float64Array, l),
|
|
186
|
-
_240: (data, length) => {
|
|
187
|
-
const read = dartInstance.exports.$byteDataGetUint8;
|
|
188
|
-
const view = new DataView(new ArrayBuffer(length));
|
|
189
|
-
for (let i = 0; i < length; i++) {
|
|
190
|
-
view.setUint8(i, read(data, i));
|
|
191
|
-
}
|
|
192
|
-
return view;
|
|
193
|
-
},
|
|
194
|
-
_241: l => arrayFromDartList(Array, l),
|
|
195
|
-
_242: (s, length) => {
|
|
196
|
-
if (length == 0) return '';
|
|
197
|
-
|
|
198
|
-
const read = dartInstance.exports.$stringRead1;
|
|
199
|
-
let result = '';
|
|
200
|
-
let index = 0;
|
|
201
|
-
const chunkLength = Math.min(length - index, 500);
|
|
202
|
-
let array = new Array(chunkLength);
|
|
203
|
-
while (index < length) {
|
|
204
|
-
const newChunkLength = Math.min(length - index, 500);
|
|
205
|
-
for (let i = 0; i < newChunkLength; i++) {
|
|
206
|
-
array[i] = read(s, index++);
|
|
207
|
-
}
|
|
208
|
-
if (newChunkLength < chunkLength) {
|
|
209
|
-
array = array.slice(0, newChunkLength);
|
|
210
|
-
}
|
|
211
|
-
result += String.fromCharCode(...array);
|
|
131
|
+
_99: s => JSON.stringify(s),
|
|
132
|
+
_100: s => printToConsole(s),
|
|
133
|
+
_101: (o, p, r) => o.replaceAll(p, () => r),
|
|
134
|
+
_103: Function.prototype.call.bind(String.prototype.toLowerCase),
|
|
135
|
+
_104: s => s.toUpperCase(),
|
|
136
|
+
_105: s => s.trim(),
|
|
137
|
+
_108: (string, times) => string.repeat(times),
|
|
138
|
+
_109: Function.prototype.call.bind(String.prototype.indexOf),
|
|
139
|
+
_110: (s, p, i) => s.lastIndexOf(p, i),
|
|
140
|
+
_111: (string, token) => string.split(token),
|
|
141
|
+
_112: Object.is,
|
|
142
|
+
_113: o => o instanceof Array,
|
|
143
|
+
_123: (a, b) => a == b ? 0 : (a > b ? 1 : -1),
|
|
144
|
+
_124: a => a.length,
|
|
145
|
+
_126: (a, i) => a[i],
|
|
146
|
+
_127: (a, i, v) => a[i] = v,
|
|
147
|
+
_132: o => o instanceof Uint8Array,
|
|
148
|
+
_133: (o, start, length) => new Uint8Array(o.buffer, o.byteOffset + start, length),
|
|
149
|
+
_134: o => o instanceof Int8Array,
|
|
150
|
+
_135: (o, start, length) => new Int8Array(o.buffer, o.byteOffset + start, length),
|
|
151
|
+
_136: o => o instanceof Uint8ClampedArray,
|
|
152
|
+
_137: (o, start, length) => new Uint8ClampedArray(o.buffer, o.byteOffset + start, length),
|
|
153
|
+
_138: o => o instanceof Uint16Array,
|
|
154
|
+
_139: (o, start, length) => new Uint16Array(o.buffer, o.byteOffset + start, length),
|
|
155
|
+
_140: o => o instanceof Int16Array,
|
|
156
|
+
_141: (o, start, length) => new Int16Array(o.buffer, o.byteOffset + start, length),
|
|
157
|
+
_142: o => o instanceof Uint32Array,
|
|
158
|
+
_143: (o, start, length) => new Uint32Array(o.buffer, o.byteOffset + start, length),
|
|
159
|
+
_144: o => o instanceof Int32Array,
|
|
160
|
+
_145: (o, start, length) => new Int32Array(o.buffer, o.byteOffset + start, length),
|
|
161
|
+
_148: o => o instanceof Float32Array,
|
|
162
|
+
_149: (o, start, length) => new Float32Array(o.buffer, o.byteOffset + start, length),
|
|
163
|
+
_150: o => o instanceof Float64Array,
|
|
164
|
+
_151: (o, start, length) => new Float64Array(o.buffer, o.byteOffset + start, length),
|
|
165
|
+
_152: (t, s) => t.set(s),
|
|
166
|
+
_154: (o) => new DataView(o.buffer, o.byteOffset, o.byteLength),
|
|
167
|
+
_156: o => o.buffer,
|
|
168
|
+
_157: o => o.byteOffset,
|
|
169
|
+
_158: Function.prototype.call.bind(Object.getOwnPropertyDescriptor(DataView.prototype, 'byteLength').get),
|
|
170
|
+
_159: (b, o) => new DataView(b, o),
|
|
171
|
+
_160: (b, o, l) => new DataView(b, o, l),
|
|
172
|
+
_161: Function.prototype.call.bind(DataView.prototype.getUint8),
|
|
173
|
+
_162: Function.prototype.call.bind(DataView.prototype.setUint8),
|
|
174
|
+
_163: Function.prototype.call.bind(DataView.prototype.getInt8),
|
|
175
|
+
_164: Function.prototype.call.bind(DataView.prototype.setInt8),
|
|
176
|
+
_165: Function.prototype.call.bind(DataView.prototype.getUint16),
|
|
177
|
+
_166: Function.prototype.call.bind(DataView.prototype.setUint16),
|
|
178
|
+
_167: Function.prototype.call.bind(DataView.prototype.getInt16),
|
|
179
|
+
_168: Function.prototype.call.bind(DataView.prototype.setInt16),
|
|
180
|
+
_169: Function.prototype.call.bind(DataView.prototype.getUint32),
|
|
181
|
+
_170: Function.prototype.call.bind(DataView.prototype.setUint32),
|
|
182
|
+
_171: Function.prototype.call.bind(DataView.prototype.getInt32),
|
|
183
|
+
_172: Function.prototype.call.bind(DataView.prototype.setInt32),
|
|
184
|
+
_177: Function.prototype.call.bind(DataView.prototype.getFloat32),
|
|
185
|
+
_178: Function.prototype.call.bind(DataView.prototype.setFloat32),
|
|
186
|
+
_179: Function.prototype.call.bind(DataView.prototype.getFloat64),
|
|
187
|
+
_180: Function.prototype.call.bind(DataView.prototype.setFloat64),
|
|
188
|
+
_181: () => new Object(),
|
|
189
|
+
_182: (x0,x1) => { x0.success = x1 },
|
|
190
|
+
_183: (x0,x1) => { x0.code = x1 },
|
|
191
|
+
_184: (x0,x1) => { x0.error = x1 },
|
|
192
|
+
_185: x0 => { this.format = x0 },
|
|
193
|
+
_186: f => finalizeWrapper(f, function(x0,x1,x2) { return dartInstance.exports._186(f,arguments.length,x0,x1,x2) }),
|
|
194
|
+
_203: (c) =>
|
|
195
|
+
queueMicrotask(() => dartInstance.exports.$invokeCallback(c)),
|
|
196
|
+
_205: (s, m) => {
|
|
197
|
+
try {
|
|
198
|
+
return new RegExp(s, m);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
return String(e);
|
|
212
201
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
202
|
+
},
|
|
203
|
+
_206: (x0,x1) => x0.exec(x1),
|
|
204
|
+
_207: (x0,x1) => x0.test(x1),
|
|
205
|
+
_208: x0 => x0.pop(),
|
|
206
|
+
_210: o => o === undefined,
|
|
207
|
+
_212: o => typeof o === 'function' && o[jsWrappedDartFunctionSymbol] === true,
|
|
208
|
+
_215: o => o instanceof RegExp,
|
|
209
|
+
_216: (l, r) => l === r,
|
|
210
|
+
_217: o => o,
|
|
211
|
+
_218: o => o,
|
|
212
|
+
_219: o => o,
|
|
213
|
+
_220: b => !!b,
|
|
214
|
+
_221: o => o.length,
|
|
215
|
+
_223: (o, i) => o[i],
|
|
216
|
+
_224: f => f.dartFunction,
|
|
217
|
+
_231: (o, p) => o[p],
|
|
218
|
+
_235: o => String(o),
|
|
219
|
+
_236: (p, s, f) => p.then(s, (e) => f(e, e === undefined)),
|
|
220
|
+
_237: f => finalizeWrapper(f, function(x0) { return dartInstance.exports._237(f,arguments.length,x0) }),
|
|
221
|
+
_238: f => finalizeWrapper(f, function(x0,x1) { return dartInstance.exports._238(f,arguments.length,x0,x1) }),
|
|
222
|
+
_239: o => {
|
|
223
|
+
if (o === undefined) return 1;
|
|
224
|
+
var type = typeof o;
|
|
225
|
+
if (type === 'boolean') return 2;
|
|
226
|
+
if (type === 'number') return 3;
|
|
227
|
+
if (type === 'string') return 4;
|
|
228
|
+
if (o instanceof Array) return 5;
|
|
229
|
+
if (ArrayBuffer.isView(o)) {
|
|
230
|
+
if (o instanceof Int8Array) return 6;
|
|
231
|
+
if (o instanceof Uint8Array) return 7;
|
|
232
|
+
if (o instanceof Uint8ClampedArray) return 8;
|
|
233
|
+
if (o instanceof Int16Array) return 9;
|
|
234
|
+
if (o instanceof Uint16Array) return 10;
|
|
235
|
+
if (o instanceof Int32Array) return 11;
|
|
236
|
+
if (o instanceof Uint32Array) return 12;
|
|
237
|
+
if (o instanceof Float32Array) return 13;
|
|
238
|
+
if (o instanceof Float64Array) return 14;
|
|
239
|
+
if (o instanceof DataView) return 15;
|
|
228
240
|
}
|
|
229
|
-
if (
|
|
230
|
-
|
|
241
|
+
if (o instanceof ArrayBuffer) return 16;
|
|
242
|
+
// Feature check for `SharedArrayBuffer` before doing a type-check.
|
|
243
|
+
if (globalThis.SharedArrayBuffer !== undefined &&
|
|
244
|
+
o instanceof SharedArrayBuffer) {
|
|
245
|
+
return 17;
|
|
231
246
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
let range = 0;
|
|
240
|
-
for (let i = 0; i < length; i++) {
|
|
241
|
-
range |= s.codePointAt(i);
|
|
242
|
-
}
|
|
243
|
-
const exports = dartInstance.exports;
|
|
244
|
-
if (range < 256) {
|
|
245
|
-
if (length <= 10) {
|
|
246
|
-
if (length == 1) {
|
|
247
|
-
return exports.$stringAllocate1_1(s.codePointAt(0));
|
|
248
|
-
}
|
|
249
|
-
if (length == 2) {
|
|
250
|
-
return exports.$stringAllocate1_2(s.codePointAt(0), s.codePointAt(1));
|
|
251
|
-
}
|
|
252
|
-
if (length == 3) {
|
|
253
|
-
return exports.$stringAllocate1_3(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2));
|
|
254
|
-
}
|
|
255
|
-
if (length == 4) {
|
|
256
|
-
return exports.$stringAllocate1_4(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3));
|
|
257
|
-
}
|
|
258
|
-
if (length == 5) {
|
|
259
|
-
return exports.$stringAllocate1_5(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4));
|
|
260
|
-
}
|
|
261
|
-
if (length == 6) {
|
|
262
|
-
return exports.$stringAllocate1_6(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5));
|
|
263
|
-
}
|
|
264
|
-
if (length == 7) {
|
|
265
|
-
return exports.$stringAllocate1_7(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6));
|
|
266
|
-
}
|
|
267
|
-
if (length == 8) {
|
|
268
|
-
return exports.$stringAllocate1_8(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6), s.codePointAt(7));
|
|
269
|
-
}
|
|
270
|
-
if (length == 9) {
|
|
271
|
-
return exports.$stringAllocate1_9(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6), s.codePointAt(7), s.codePointAt(8));
|
|
272
|
-
}
|
|
273
|
-
if (length == 10) {
|
|
274
|
-
return exports.$stringAllocate1_10(s.codePointAt(0), s.codePointAt(1), s.codePointAt(2), s.codePointAt(3), s.codePointAt(4), s.codePointAt(5), s.codePointAt(6), s.codePointAt(7), s.codePointAt(8), s.codePointAt(9));
|
|
275
|
-
}
|
|
247
|
+
if (o instanceof Promise) return 18;
|
|
248
|
+
return 19;
|
|
249
|
+
},
|
|
250
|
+
_244: (jsArray, jsArrayOffset, wasmArray, wasmArrayOffset, length) => {
|
|
251
|
+
const getValue = dartInstance.exports.$wasmI8ArrayGet;
|
|
252
|
+
for (let i = 0; i < length; i++) {
|
|
253
|
+
jsArray[jsArrayOffset + i] = getValue(wasmArray, wasmArrayOffset + i);
|
|
276
254
|
}
|
|
277
|
-
|
|
278
|
-
|
|
255
|
+
},
|
|
256
|
+
_246: (jsArray, jsArrayOffset, wasmArray, wasmArrayOffset, length) => {
|
|
257
|
+
const getValue = dartInstance.exports.$wasmI16ArrayGet;
|
|
279
258
|
for (let i = 0; i < length; i++) {
|
|
280
|
-
|
|
259
|
+
jsArray[jsArrayOffset + i] = getValue(wasmArray, wasmArrayOffset + i);
|
|
281
260
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
const write = exports.$stringWrite2;
|
|
261
|
+
},
|
|
262
|
+
_248: (jsArray, jsArrayOffset, wasmArray, wasmArrayOffset, length) => {
|
|
263
|
+
const getValue = dartInstance.exports.$wasmI32ArrayGet;
|
|
286
264
|
for (let i = 0; i < length; i++) {
|
|
287
|
-
|
|
265
|
+
jsArray[jsArrayOffset + i] = getValue(wasmArray, wasmArrayOffset + i);
|
|
288
266
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
_271: x0 => x0.dotAll,
|
|
305
|
-
_272: (x0,x1) => x0.lastIndex = x1
|
|
267
|
+
},
|
|
268
|
+
_254: x0 => new ArrayBuffer(x0),
|
|
269
|
+
_257: x0 => x0.index,
|
|
270
|
+
_259: x0 => x0.flags,
|
|
271
|
+
_260: x0 => x0.multiline,
|
|
272
|
+
_261: x0 => x0.ignoreCase,
|
|
273
|
+
_262: x0 => x0.unicode,
|
|
274
|
+
_263: x0 => x0.dotAll,
|
|
275
|
+
_264: (x0,x1) => { x0.lastIndex = x1 },
|
|
276
|
+
_269: x0 => x0.random(),
|
|
277
|
+
_272: () => globalThis.Math,
|
|
278
|
+
_273: Function.prototype.call.bind(Number.prototype.toString),
|
|
279
|
+
_274: Function.prototype.call.bind(BigInt.prototype.toString),
|
|
280
|
+
_275: Function.prototype.call.bind(Number.prototype.toString),
|
|
281
|
+
|
|
306
282
|
};
|
|
307
283
|
|
|
308
284
|
const baseImports = {
|
|
309
|
-
|
|
310
|
-
|
|
285
|
+
dart2wasm: dart2wasm,
|
|
286
|
+
Math: Math,
|
|
287
|
+
Date: Date,
|
|
288
|
+
Object: Object,
|
|
289
|
+
Array: Array,
|
|
290
|
+
Reflect: Reflect,
|
|
291
|
+
S: new Proxy({}, { get(_, prop) { return prop; } }),
|
|
311
292
|
|
|
312
|
-
Math: Math,
|
|
313
|
-
Date: Date,
|
|
314
|
-
Object: Object,
|
|
315
|
-
Array: Array,
|
|
316
|
-
Reflect: Reflect,
|
|
317
293
|
};
|
|
318
294
|
|
|
319
295
|
const jsStringPolyfill = {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
296
|
+
"charCodeAt": (s, i) => s.charCodeAt(i),
|
|
297
|
+
"compare": (s1, s2) => {
|
|
298
|
+
if (s1 < s2) return -1;
|
|
299
|
+
if (s1 > s2) return 1;
|
|
300
|
+
return 0;
|
|
301
|
+
},
|
|
302
|
+
"concat": (s1, s2) => s1 + s2,
|
|
303
|
+
"equals": (s1, s2) => s1 === s2,
|
|
304
|
+
"fromCharCode": (i) => String.fromCharCode(i),
|
|
305
|
+
"length": (s) => s?.length||0,
|
|
306
|
+
"substring": (s, a, b) => s.substring(a, b),
|
|
307
|
+
"fromCharCodeArray": (a, start, end) => {
|
|
308
|
+
if (end <= start) return '';
|
|
309
|
+
|
|
310
|
+
const read = dartInstance.exports.$wasmI16ArrayGet;
|
|
311
|
+
let result = '';
|
|
312
|
+
let index = start;
|
|
313
|
+
const chunkLength = Math.min(end - index, 500);
|
|
314
|
+
let array = new Array(chunkLength);
|
|
315
|
+
while (index < end) {
|
|
316
|
+
const newChunkLength = Math.min(end - index, 500);
|
|
317
|
+
for (let i = 0; i < newChunkLength; i++) {
|
|
318
|
+
array[i] = read(a, index++);
|
|
319
|
+
}
|
|
320
|
+
if (newChunkLength < chunkLength) {
|
|
321
|
+
array = array.slice(0, newChunkLength);
|
|
322
|
+
}
|
|
323
|
+
result += String.fromCharCode(...array);
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
},
|
|
327
|
+
"intoCharCodeArray": (s, a, start) => {
|
|
328
|
+
if (s === '') return 0;
|
|
329
|
+
|
|
330
|
+
const write = dartInstance.exports.$wasmI16ArraySet;
|
|
331
|
+
for (var i = 0; i < s.length; ++i) {
|
|
332
|
+
write(a, start++, s.charCodeAt(i));
|
|
333
|
+
}
|
|
334
|
+
return s.length;
|
|
335
|
+
},
|
|
336
|
+
"test": (s) => typeof s == "string",
|
|
331
337
|
};
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
dartInstance = new WebAssembly.Instance(this.module, {
|
|
343
|
+
...baseImports,
|
|
344
|
+
...additionalImports,
|
|
345
|
+
|
|
346
|
+
"wasm:js-string": jsStringPolyfill,
|
|
337
347
|
});
|
|
338
348
|
|
|
339
|
-
return dartInstance;
|
|
349
|
+
return new InstantiatedApp(this, dartInstance);
|
|
350
|
+
}
|
|
340
351
|
}
|
|
341
352
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
353
|
+
class InstantiatedApp {
|
|
354
|
+
constructor(compiledApp, instantiatedModule) {
|
|
355
|
+
this.compiledApp = compiledApp;
|
|
356
|
+
this.instantiatedModule = instantiatedModule;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Call the main function with the given arguments.
|
|
360
|
+
invokeMain(...args) {
|
|
361
|
+
this.instantiatedModule.exports.$invokeMain(args);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
365
|
+
export function initSync(module, compileOptions = { builtins: ["js-string"] }) {
|
|
366
|
+
const app = new CompiledApp(module, compileOptions).instantiate();
|
|
367
|
+
app.invokeMain();
|
|
368
|
+
return app;
|
|
347
369
|
}
|
|
348
370
|
|
|
371
|
+
export function formatWrapper(app, source, filename = "stdin.dart", config = {}) {
|
|
372
|
+
const options = { lineEnding: "\n" };
|
|
373
|
+
if (config.line_width) {
|
|
374
|
+
options.pageWidth = config.line_width;
|
|
375
|
+
}
|
|
376
|
+
if (config.line_ending === "crlf") {
|
|
377
|
+
options.lineEnding = "\r\n";
|
|
378
|
+
}
|
|
379
|
+
if (config.language_version) {
|
|
380
|
+
options.languageVersion = config.language_version;
|
|
381
|
+
}
|
|
349
382
|
|
|
350
|
-
|
|
383
|
+
const result = app.compiledApp.format(source, filename, JSON.stringify(options));
|
|
384
|
+
if (result.success) {
|
|
385
|
+
return result.code;
|
|
386
|
+
}
|
|
387
|
+
throw new Error(result.error);
|
|
388
|
+
}
|