| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent abea0af commit 0aed332
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -809,6 +809,15 @@ imports and they cannot be inspected via `WebAssembly.Module.imports(mod)` | |||
| 809 | 809 | or virtualized unless recompiling the module using the direct | |
| 810 | 810 | `WebAssembly.compile` API with string builtins disabled. | |
| 811 | 811 | ||
| 812 | + String constants may also be imported from the `wasm:js/string-constants` builtin | ||
| 813 | + import URL, allowing static JS string globals to be defined: | ||
| 814 | + | ||
| 815 | + ```text | ||
| 816 | + (module | ||
| 817 | + (import "wasm:js/string-constants" "hello" (global $hello externref)) | ||
| 818 | + ) | ||
| 819 | + ``` | ||
| 820 | + | ||
| 812 | 821 | Importing a module in the source phase before it has been instantiated will also | |
| 813 | 822 | use the compile-time builtins automatically: | |
| 814 | 823 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -522,6 +522,7 @@ translators.set('wasm', function(url, translateContext) { | |||
| 522 | 522 | try { | |
| 523 | 523 | compiled = new WebAssembly.Module(source, { | |
| 524 | 524 | builtins: ['js-string'], | |
| 525 | + importedStringConstants: 'wasm:js/string-constants', | ||
| 525 | 526 | }); | |
| 526 | 527 | } catch (err) { | |
| 527 | 528 | err.message = errPath(url) + ': ' + err.message; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,11 +4,15 @@ | |||
| 4 | 4 | (import "wasm:js-string" "length" (func $string_length (param externref) (result i32))) | |
| 5 | 5 | (import "wasm:js-string" "concat" (func $string_concat (param externref externref) (result (ref extern)))) | |
| 6 | 6 | (import "wasm:js-string" "equals" (func $string_equals (param externref externref) (result i32))) | |
| 7 | + | ||
| 8 | + ;; Import a string constant via importedStringConstants | ||
| 9 | + (import "wasm:js/string-constants" "hello" (global $hello externref)) | ||
| 7 | 10 | ||
| 8 | 11 | ;; Export functions that use the builtins | |
| 9 | 12 | (export "getLength" (func $get_length)) | |
| 10 | 13 | (export "concatStrings" (func $concat_strings)) | |
| 11 | 14 | (export "compareStrings" (func $compare_strings)) | |
| 15 | + (export "getHello" (func $get_hello)) | ||
| 12 | 16 | ||
| 13 | 17 | (func $get_length (param $str externref) (result i32) | |
| 14 | 18 | local.get $str | |
@@ -26,4 +30,8 @@ | |||
| 26 | 30 | local.get $str2 | |
| 27 | 31 | call $string_equals | |
| 28 | 32 | ) | |
| 33 | + | ||
| 34 | + (func $get_hello (result externref) | ||
| 35 | + global.get $hello | ||
| 36 | + ) | ||
| 29 | 37 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,3 +6,4 @@ strictEqual(wasmExports.getLength('hello'), 5); | |||
| 6 | 6 | strictEqual(wasmExports.concatStrings('hello', ' world'), 'hello world'); | |
| 7 | 7 | strictEqual(wasmExports.compareStrings('test', 'test'), 1); | |
| 8 | 8 | strictEqual(wasmExports.compareStrings('test', 'different'), 0); | |
| 9 | + strictEqual(wasmExports.getHello(), 'hello'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments