File tree Expand file tree Collapse file tree 6 files changed +61
-1
lines changed
crates/cli-support/src/js Expand file tree Collapse file tree 6 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -1499,12 +1499,19 @@ impl<'a> Context<'a> {
1499
1499
arg = arg.slice(offset);
1500
1500
ptr = wasm.__wbindgen_realloc(ptr, size, size = offset + arg.length * 3);
1501
1501
const view = getUint8Memory().subarray(ptr + offset, ptr + size);
1502
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1503
+ {}
1502
1504
offset += cachedTextEncoder.encodeInto(arg, view).written;
1503
1505
}}
1504
1506
WASM_VECTOR_LEN = offset;
1505
1507
return ptr;
1506
1508
" ,
1507
- start_encoding_as_ascii
1509
+ start_encoding_as_ascii,
1510
+ if self . config. debug {
1511
+ "if (ret.read != arg.length) throw new Error('failed to pass whole string');"
1512
+ } else {
1513
+ ""
1514
+ } ,
1508
1515
) ;
1509
1516
1510
1517
// Looks like `encodeInto` doesn't currently work when the memory passed
Original file line number Diff line number Diff line change @@ -50,3 +50,4 @@ pub fn import_export_same_name() {
50
50
pub mod snippets;
51
51
pub mod modules;
52
52
pub mod anyref_heap_live_count;
53
+ pub mod strings;
Original file line number Diff line number Diff line change
1
+ export function test_string_roundtrip ( f ) {
2
+ const test = expected => {
3
+ const actual = f ( expected ) ;
4
+ if ( actual === expected )
5
+ return ;
6
+ throw new Error ( `string roundtrip "${ actual } " != "${ expected } "` ) ;
7
+ } ;
8
+
9
+ test ( '' ) ;
10
+ test ( 'a' ) ;
11
+ test ( '💖' ) ;
12
+
13
+ test ( 'a longer string' ) ;
14
+ test ( 'a longer 💖 string' ) ;
15
+ }
Original file line number Diff line number Diff line change
1
+ use wasm_bindgen:: prelude:: * ;
2
+ use wasm_bindgen_test:: * ;
3
+
4
+ #[ wasm_bindgen( module = "/tests/headless/strings.js" ) ]
5
+ extern "C" {
6
+ fn test_string_roundtrip ( c : & Closure < Fn ( String ) -> String > ) ;
7
+ }
8
+
9
+ #[ wasm_bindgen_test]
10
+ fn string_roundtrip ( ) {
11
+ test_string_roundtrip ( & Closure :: wrap ( Box :: new ( |s| s) ) ) ;
12
+ }
Original file line number Diff line number Diff line change @@ -92,3 +92,16 @@ exports.RenamedInRust = class {};
92
92
exports . new_renamed = ( ) => new exports . RenamedInRust ;
93
93
94
94
exports . import_export_same_name = ( ) => { } ;
95
+
96
+ exports . test_string_roundtrip = ( ) => {
97
+ const test = s => {
98
+ assert . strictEqual ( wasm . do_string_roundtrip ( s ) , s ) ;
99
+ } ;
100
+
101
+ test ( '' ) ;
102
+ test ( 'a' ) ;
103
+ test ( '💖' ) ;
104
+
105
+ test ( 'a longer string' ) ;
106
+ test ( 'a longer 💖 string' ) ;
107
+ } ;
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ extern "C" {
27
27
#[ wasm_bindgen( js_name = RenamedInRust ) ]
28
28
type Renamed ;
29
29
fn new_renamed ( ) -> Renamed ;
30
+
31
+ fn test_string_roundtrip ( ) ;
30
32
}
31
33
32
34
#[ wasm_bindgen_test]
@@ -201,3 +203,13 @@ fn renaming_imports_and_instanceof() {
201
203
pub fn import_export_same_name ( ) {
202
204
js_import_export_same_name ( ) ;
203
205
}
206
+
207
+ #[ wasm_bindgen_test]
208
+ fn string_roundtrip ( ) {
209
+ test_string_roundtrip ( ) ;
210
+ }
211
+
212
+ #[ wasm_bindgen]
213
+ pub fn do_string_roundtrip ( s : String ) -> String {
214
+ s
215
+ }
You can’t perform that action at this time.
0 commit comments