-
Notifications
You must be signed in to change notification settings - Fork 6k
Compile dart2wasm modules using the JS runtime exported compileStreaming #51488
Changes from 1 commit
a0a8805
5ecec4a
cc677af
8232d85
0789214
0ebfbf8
4d70159
4064581
adac7ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,7 +151,13 @@ export class FlutterEntrypointLoader { | |
| if (this._ttPolicy != null) { | ||
| jsSupportRuntimeUri = this._ttPolicy.createScriptURL(jsSupportRuntimeUri); | ||
| } | ||
| const dartModulePromise = WebAssembly.compileStreaming(fetch(moduleUri)); | ||
|
|
||
| const stringBuiltinSupported = _detectWasmStringBuiltin(); | ||
|
|
||
| const dartModulePromise = WebAssembly.compileStreaming( | ||
|
||
| fetch(moduleUri), | ||
| stringBuiltinSupported ? {builtins: 'js-string'} : {} | ||
| ); | ||
|
|
||
| const jsSupportRuntime = await import(jsSupportRuntimeUri); | ||
|
|
||
|
|
@@ -171,6 +177,23 @@ export class FlutterEntrypointLoader { | |
| } else { | ||
| imports = {}; | ||
| } | ||
|
|
||
| if (!stringBuiltinSupported) { | ||
| imports['wasm:js-string'] = { | ||
| "charCodeAt": (s, i) => s.charCodeAt(i), | ||
| "compare": (s1, s2) => { | ||
| if (s1 < s2) return -1; | ||
| if (s1 > s2) return 1; | ||
| return 0; | ||
| }, | ||
| "concat": (s1, s2) => s1 + s2, | ||
| "equals": (s1, s2) => s1 === s2, | ||
| "fromCharCode": (i) => String.fromCharCode(i), | ||
| "length": (s) => s.length, | ||
| "substring": (s, a, b) => s.substring(a, b), | ||
| }; | ||
| } | ||
osa1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const moduleInstance = await jsSupportRuntime.instantiate(dartModulePromise, imports); | ||
| await jsSupportRuntime.invoke(moduleInstance); | ||
| } | ||
|
|
@@ -195,4 +218,15 @@ export class FlutterEntrypointLoader { | |
| scriptTag.src = trustedUrl; | ||
| return scriptTag; | ||
| } | ||
|
|
||
| /// Returns whether the `js-string` Wasm built-in is supported. | ||
| _detectWasmStringBuiltin() { | ||
| let bytes = [ | ||
| 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, | ||
| 0, 2, 23, 1, 14, 119, 97, 115, 109, 58, 106, 115, 45, | ||
| 115, 116, 114, 105, 110, 103, 4, 99, 97, 115, 116, 0, 0 | ||
| ]; | ||
| return !WebAssembly.validate( | ||
| new Uint8Array(bytes), {builtins: ['js-string']}); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.