@@ -60,7 +60,11 @@ pub enum NonstandardOutgoing {
60
60
kind : VectorKind ,
61
61
} ,
62
62
63
+ /// A Rust String (or &str) which might be cached, and might be `None`.
63
64
///
65
+ /// If `offset` is 0 then it is cached, and the cached JsValue's index is in `length`.
66
+ ///
67
+ /// If `offset` and `length` are both 0, then it is `None`.
64
68
CachedString {
65
69
offset : u32 ,
66
70
length : u32 ,
@@ -247,16 +251,7 @@ impl OutgoingBuilder<'_> {
247
251
Descriptor :: Ref ( d) => self . process_ref ( false , d) ?,
248
252
Descriptor :: RefMut ( d) => self . process_ref ( true , d) ?,
249
253
250
- Descriptor :: CachedString => {
251
- let offset = self . push_wasm ( ValType :: I32 ) ;
252
- let length = self . push_wasm ( ValType :: I32 ) ;
253
- self . webidl . push ( ast:: WebidlScalarType :: Any ) ;
254
- self . bindings . push ( NonstandardOutgoing :: CachedString {
255
- offset,
256
- length,
257
- owned : true ,
258
- } )
259
- }
254
+ Descriptor :: CachedString => self . cached_string ( true ) ,
260
255
261
256
Descriptor :: Vector ( _) | Descriptor :: String => {
262
257
let kind = arg. vector_kind ( ) . ok_or_else ( || {
@@ -299,16 +294,7 @@ impl OutgoingBuilder<'_> {
299
294
self . bindings
300
295
. push ( NonstandardOutgoing :: BorrowedAnyref { idx } ) ;
301
296
}
302
- Descriptor :: CachedString => {
303
- let offset = self . push_wasm ( ValType :: I32 ) ;
304
- let length = self . push_wasm ( ValType :: I32 ) ;
305
- self . webidl . push ( ast:: WebidlScalarType :: DomString ) ;
306
- self . bindings . push ( NonstandardOutgoing :: CachedString {
307
- offset,
308
- length,
309
- owned : false ,
310
- } )
311
- }
297
+ Descriptor :: CachedString => self . cached_string ( false ) ,
312
298
Descriptor :: Slice ( _) | Descriptor :: String => {
313
299
use wasm_webidl_bindings:: ast:: WebidlScalarType :: * ;
314
300
@@ -451,16 +437,7 @@ impl OutgoingBuilder<'_> {
451
437
Descriptor :: Ref ( d) => self . process_option_ref ( false , d) ?,
452
438
Descriptor :: RefMut ( d) => self . process_option_ref ( true , d) ?,
453
439
454
- Descriptor :: CachedString => {
455
- let offset = self . push_wasm ( ValType :: I32 ) ;
456
- let length = self . push_wasm ( ValType :: I32 ) ;
457
- self . webidl . push ( ast:: WebidlScalarType :: DomString ) ;
458
- self . bindings . push ( NonstandardOutgoing :: CachedString {
459
- offset,
460
- length,
461
- owned : true ,
462
- } )
463
- }
440
+ Descriptor :: CachedString => self . cached_string ( true ) ,
464
441
465
442
Descriptor :: String | Descriptor :: Vector ( _) => {
466
443
let kind = arg. vector_kind ( ) . ok_or_else ( || {
@@ -495,16 +472,7 @@ impl OutgoingBuilder<'_> {
495
472
self . bindings
496
473
. push ( NonstandardOutgoing :: BorrowedAnyref { idx } ) ;
497
474
}
498
- Descriptor :: CachedString => {
499
- let offset = self . push_wasm ( ValType :: I32 ) ;
500
- let length = self . push_wasm ( ValType :: I32 ) ;
501
- self . webidl . push ( ast:: WebidlScalarType :: DomString ) ;
502
- self . bindings . push ( NonstandardOutgoing :: CachedString {
503
- offset,
504
- length,
505
- owned : false ,
506
- } )
507
- }
475
+ Descriptor :: CachedString => self . cached_string ( false ) ,
508
476
Descriptor :: String | Descriptor :: Slice ( _) => {
509
477
let kind = arg. vector_kind ( ) . ok_or_else ( || {
510
478
format_err ! (
@@ -555,6 +523,17 @@ impl OutgoingBuilder<'_> {
555
523
. push ( NonstandardOutgoing :: Standard ( binding. into ( ) ) ) ;
556
524
}
557
525
526
+ fn cached_string ( & mut self , owned : bool ) {
527
+ let offset = self . push_wasm ( ValType :: I32 ) ;
528
+ let length = self . push_wasm ( ValType :: I32 ) ;
529
+ self . webidl . push ( ast:: WebidlScalarType :: DomString ) ;
530
+ self . bindings . push ( NonstandardOutgoing :: CachedString {
531
+ offset,
532
+ length,
533
+ owned,
534
+ } )
535
+ }
536
+
558
537
fn option_native ( & mut self , signed : bool , ty : ValType ) {
559
538
let present = self . push_wasm ( ValType :: I32 ) ;
560
539
let val = self . push_wasm ( ty) ;
0 commit comments