@@ -69,11 +69,11 @@ export class FileStat {
69
69
creation_time : f64 ;
70
70
71
71
constructor ( st_buf : usize ) {
72
- this . file_type = load < u8 > ( st_buf + 16 ) ;
73
- this . file_size = load < u64 > ( st_buf + 24 ) ;
74
- this . access_time = ( load < u64 > ( st_buf + 32 ) as f64 ) / 1e9 ;
75
- this . modification_time = ( load < u64 > ( st_buf + 40 ) as f64 ) / 1e9 ;
76
- this . creation_time = ( load < u64 > ( st_buf + 48 ) as f64 ) / 1e9 ;
72
+ this . file_type = load < u8 > ( st_buf , 16 ) ;
73
+ this . file_size = load < u64 > ( st_buf , 24 ) ;
74
+ this . access_time = ( load < u64 > ( st_buf , 32 ) as f64 ) / 1e9 ;
75
+ this . modification_time = ( load < u64 > ( st_buf , 40 ) as f64 ) / 1e9 ;
76
+ this . creation_time = ( load < u64 > ( st_buf , 48 ) as f64 ) / 1e9 ;
77
77
}
78
78
}
79
79
@@ -152,7 +152,7 @@ export class Descriptor {
152
152
if ( fd_fdstat_get ( this . rawfd , changetype < fdstat > ( st_buf ) ) !== errno . SUCCESS ) {
153
153
throw new WASAError ( "Unable to get the file type" ) ;
154
154
}
155
- let file_type : u8 = load < u8 > ( st_buf ) ;
155
+ let file_type = load < u8 > ( st_buf ) ;
156
156
157
157
return file_type ;
158
158
}
@@ -219,8 +219,12 @@ export class Descriptor {
219
219
*/
220
220
futimes ( atime : f64 , mtime : f64 ) : bool {
221
221
return (
222
- fd_filestat_set_times ( this . rawfd , ( atime * 1e9 ) as u64 , ( mtime * 1e9 ) as u64 ,
223
- fstflags . SET_ATIM | fstflags . SET_ATIM ) === errno . SUCCESS
222
+ fd_filestat_set_times (
223
+ this . rawfd ,
224
+ ( atime * 1e9 ) as u64 ,
225
+ ( mtime * 1e9 ) as u64 ,
226
+ fstflags . SET_ATIM | fstflags . SET_ATIM
227
+ ) === errno . SUCCESS
224
228
) ;
225
229
}
226
230
@@ -243,8 +247,8 @@ export class Descriptor {
243
247
* Return the directory associated to that descriptor
244
248
*/
245
249
dirName ( ) : String {
246
- let path_max : usize = 4096 ;
247
- for ( ; ; ) {
250
+ let path_max = 4096 as usize ;
251
+ while ( true ) {
248
252
let path_buf = changetype < usize > ( new ArrayBuffer ( path_max ) ) ;
249
253
let ret = fd_prestat_dir_name ( this . rawfd , path_buf , path_max ) ;
250
254
if ( ret === errno . NAMETOOLONG ) {
@@ -270,7 +274,7 @@ export class Descriptor {
270
274
* Write data to a file descriptor
271
275
* @param data data
272
276
*/
273
- write ( data : Array < u8 > ) : void {
277
+ write ( data : u8 [ ] ) : void {
274
278
let data_buf_len = data . length ;
275
279
let data_buf = changetype < usize > ( new ArrayBuffer ( data_buf_len ) ) ;
276
280
for ( let i = 0 ; i < data_buf_len ; i ++ ) {
@@ -327,9 +331,9 @@ export class Descriptor {
327
331
* @param chunk_size chunk size (default: 4096)
328
332
*/
329
333
read (
330
- data : Array < u8 > = [ ] ,
334
+ data : u8 [ ] = [ ] ,
331
335
chunk_size : usize = 4096
332
- ) : Array < u8 > | null {
336
+ ) : u8 [ ] | null {
333
337
let data_partial_len = chunk_size ;
334
338
let data_partial = changetype < usize > ( new ArrayBuffer ( data_partial_len ) ) ;
335
339
let iov = changetype < usize > ( new ArrayBuffer ( 2 * sizeof < usize > ( ) ) ) ;
@@ -343,10 +347,7 @@ export class Descriptor {
343
347
data . push ( load < u8 > ( data_partial + i ) ) ;
344
348
}
345
349
}
346
- if ( read <= 0 ) {
347
- return null ;
348
- }
349
- return data ;
350
+ return read <= 0 ? null : data ;
350
351
}
351
352
352
353
/**
@@ -355,7 +356,7 @@ export class Descriptor {
355
356
* @param chunk_size chunk size (default: 4096)
356
357
*/
357
358
readAll (
358
- data : Array < u8 > = [ ] ,
359
+ data : u8 [ ] = [ ] ,
359
360
chunk_size : usize = 4096
360
361
) : Array < u8 > | null {
361
362
let data_partial_len = chunk_size ;
@@ -365,7 +366,7 @@ export class Descriptor {
365
366
store < u32 > ( iov + sizeof < usize > ( ) , data_partial_len ) ;
366
367
let read_ptr = changetype < usize > ( new ArrayBuffer ( sizeof < usize > ( ) ) ) ;
367
368
let read : usize = 0 ;
368
- for ( ; ; ) {
369
+ while ( true ) {
369
370
if ( fd_read ( this . rawfd , iov , 1 , read_ptr ) !== errno . SUCCESS ) {
370
371
break ;
371
372
}
@@ -397,9 +398,7 @@ export class Descriptor {
397
398
for ( let i = 0 ; i < s_utf8_len ; i ++ ) {
398
399
store < u8 > ( s_utf8_buf + i , s_utf8 [ i ] ) ;
399
400
}
400
- let s = String . UTF8 . decodeUnsafe ( s_utf8_buf , s_utf8 . length ) ;
401
-
402
- return s ;
401
+ return String . UTF8 . decodeUnsafe ( s_utf8_buf , s_utf8 . length ) ;
403
402
}
404
403
405
404
/**
@@ -443,28 +442,37 @@ export class FileSystem {
443
442
let fd_lookup_flags = lookupflags . SYMLINK_FOLLOW ;
444
443
let fd_oflags : u16 = 0 ;
445
444
let fd_rights : u64 = 0 ;
446
- if ( flags === "r" ) {
447
- fd_rights = rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . FD_READDIR ;
448
- } else if ( flags === "r+" ) {
445
+ if ( flags == "r" ) {
446
+ fd_rights =
447
+ rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET |
448
+ rights . FD_READDIR ;
449
+ } else if ( flags == "r+" ) {
449
450
fd_rights =
450
- rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . FD_WRITE |
451
- rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . PATH_CREATE_FILE ;
452
- } else if ( flags === "w" ) {
451
+ rights . FD_WRITE |
452
+ rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET |
453
+ rights . PATH_CREATE_FILE ;
454
+ } else if ( flags == "w" ) {
453
455
fd_oflags = oflags . CREAT | oflags . TRUNC ;
454
- fd_rights = rights . FD_WRITE | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . PATH_CREATE_FILE ;
455
- } else if ( flags === "wx" ) {
456
+ fd_rights =
457
+ rights . FD_WRITE | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET |
458
+ rights . PATH_CREATE_FILE ;
459
+ } else if ( flags == "wx" ) {
456
460
fd_oflags = oflags . CREAT | oflags . TRUNC | oflags . EXCL ;
457
- fd_rights = rights . FD_WRITE | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . PATH_CREATE_FILE ;
458
- } else if ( flags === "w+" ) {
461
+ fd_rights =
462
+ rights . FD_WRITE | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET |
463
+ rights . PATH_CREATE_FILE ;
464
+ } else if ( flags == "w+" ) {
459
465
fd_oflags = oflags . CREAT | oflags . TRUNC ;
460
466
fd_rights =
461
- rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . FD_WRITE |
462
- rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . PATH_CREATE_FILE ;
463
- } else if ( flags === "xw+" ) {
467
+ rights . FD_WRITE |
468
+ rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET |
469
+ rights . PATH_CREATE_FILE ;
470
+ } else if ( flags == "xw+" ) {
464
471
fd_oflags = oflags . CREAT | oflags . TRUNC | oflags . EXCL ;
465
472
fd_rights =
466
- rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . FD_WRITE |
467
- rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET | rights . PATH_CREATE_FILE ;
473
+ rights . FD_WRITE |
474
+ rights . FD_READ | rights . FD_SEEK | rights . FD_TELL | rights . FD_FILESTAT_GET |
475
+ rights . PATH_CREATE_FILE ;
468
476
} else {
469
477
return null ;
470
478
}
@@ -476,8 +484,7 @@ export class FileSystem {
476
484
let res = path_open (
477
485
dirfd as fd ,
478
486
fd_lookup_flags ,
479
- path_utf8 ,
480
- path_utf8_len ,
487
+ path_utf8 , path_utf8_len ,
481
488
fd_oflags ,
482
489
fd_rights ,
483
490
fd_rights_inherited ,
@@ -488,7 +495,6 @@ export class FileSystem {
488
495
return null ;
489
496
}
490
497
let fd = load < u32 > ( fd_buf ) ;
491
-
492
498
return new Descriptor ( fd ) ;
493
499
}
494
500
@@ -517,8 +523,12 @@ export class FileSystem {
517
523
let path_utf8 = changetype < usize > ( String . UTF8 . encode ( path ) ) ;
518
524
let fd_lookup_flags = lookupflags . SYMLINK_FOLLOW ;
519
525
let st_buf = changetype < usize > ( new ArrayBuffer ( 56 ) ) ;
520
- let res = path_filestat_get ( dirfd , fd_lookup_flags , path_utf8 , path_utf8_len ,
521
- changetype < filestat > ( st_buf ) ) ;
526
+ let res = path_filestat_get (
527
+ dirfd ,
528
+ fd_lookup_flags ,
529
+ path_utf8 , path_utf8_len ,
530
+ changetype < filestat > ( st_buf )
531
+ ) ;
522
532
523
533
return res === errno . SUCCESS ;
524
534
}
@@ -537,8 +547,13 @@ export class FileSystem {
537
547
let new_path_utf8_len : usize = String . UTF8 . byteLength ( new_path ) ;
538
548
let new_path_utf8 = changetype < usize > ( String . UTF8 . encode ( new_path ) ) ;
539
549
let fd_lookup_flags = lookupflags . SYMLINK_FOLLOW ;
540
- let res = path_link ( old_dirfd , fd_lookup_flags , old_path_utf8 , old_path_utf8_len ,
541
- new_dirfd , new_path_utf8 , new_path_utf8_len ) ;
550
+ let res = path_link (
551
+ old_dirfd ,
552
+ fd_lookup_flags ,
553
+ old_path_utf8 , old_path_utf8_len ,
554
+ new_dirfd ,
555
+ new_path_utf8 , new_path_utf8_len
556
+ ) ;
542
557
543
558
return res === errno . SUCCESS ;
544
559
}
@@ -555,8 +570,11 @@ export class FileSystem {
555
570
let new_dirfd = this . dirfdForPath ( new_path ) ;
556
571
let new_path_utf8_len : usize = String . UTF8 . byteLength ( new_path ) ;
557
572
let new_path_utf8 = changetype < usize > ( String . UTF8 . encode ( new_path ) ) ;
558
- let res = path_symlink ( old_path_utf8 , old_path_utf8_len ,
559
- new_dirfd , new_path_utf8 , new_path_utf8_len ) ;
573
+ let res = path_symlink (
574
+ old_path_utf8 , old_path_utf8_len ,
575
+ new_dirfd ,
576
+ new_path_utf8 , new_path_utf8_len
577
+ ) ;
560
578
561
579
return res === errno . SUCCESS ;
562
580
}
@@ -600,7 +618,12 @@ export class FileSystem {
600
618
let path_utf8 = changetype < usize > ( String . UTF8 . encode ( path ) ) ;
601
619
let fd_lookup_flags = lookupflags . SYMLINK_FOLLOW ;
602
620
let st_buf = changetype < usize > ( new ArrayBuffer ( 56 ) ) ;
603
- if ( path_filestat_get ( dirfd , fd_lookup_flags , path_utf8 , path_utf8_len , changetype < filestat > ( st_buf ) ) !== errno . SUCCESS ) {
621
+ if ( path_filestat_get (
622
+ dirfd ,
623
+ fd_lookup_flags ,
624
+ path_utf8 , path_utf8_len ,
625
+ changetype < filestat > ( st_buf )
626
+ ) !== errno . SUCCESS ) {
604
627
throw new WASAError ( "Unable to get the file information" ) ;
605
628
}
606
629
return new FileStat ( st_buf ) ;
@@ -617,7 +640,12 @@ export class FileSystem {
617
640
let path_utf8 = changetype < usize > ( String . UTF8 . encode ( path ) ) ;
618
641
let fd_lookup_flags = 0 ;
619
642
let st_buf = changetype < usize > ( new ArrayBuffer ( 56 ) ) ;
620
- if ( path_filestat_get ( dirfd , fd_lookup_flags , path_utf8 , path_utf8_len , changetype < filestat > ( st_buf ) ) !== errno . SUCCESS ) {
643
+ if ( path_filestat_get (
644
+ dirfd ,
645
+ fd_lookup_flags ,
646
+ path_utf8 , path_utf8_len ,
647
+ changetype < filestat > ( st_buf )
648
+ ) !== errno . SUCCESS ) {
621
649
throw new WASAError ( "Unable to get the file information" ) ;
622
650
}
623
651
return new FileStat ( st_buf ) ;
@@ -636,8 +664,12 @@ export class FileSystem {
636
664
let new_dirfd = this . dirfdForPath ( new_path ) ;
637
665
let new_path_utf8_len : usize = String . UTF8 . byteLength ( new_path ) ;
638
666
let new_path_utf8 = changetype < usize > ( String . UTF8 . encode ( new_path ) ) ;
639
- let res = path_rename ( old_dirfd , old_path_utf8 , old_path_utf8_len ,
640
- new_dirfd , new_path_utf8 , new_path_utf8_len ) ;
667
+ let res = path_rename (
668
+ old_dirfd ,
669
+ old_path_utf8 , old_path_utf8_len ,
670
+ new_dirfd ,
671
+ new_path_utf8 , new_path_utf8_len
672
+ ) ;
641
673
642
674
return res === errno . SUCCESS ;
643
675
}
@@ -836,16 +868,17 @@ export class Environ {
836
868
*/
837
869
get ( key : string ) : string | null {
838
870
for ( let i = 0 , j = this . env . length ; i < j ; i ++ ) {
839
- if ( this . env [ i ] . key === key ) {
840
- return this . env [ i ] . value ;
871
+ let pair = this . env [ i ] ;
872
+ if ( pair . key == key ) {
873
+ return pair . value ;
841
874
}
842
875
}
843
876
return null ;
844
877
}
845
878
}
846
879
847
880
export class CommandLine {
848
- args : Array < string > ;
881
+ args : string [ ] ;
849
882
850
883
constructor ( ) {
851
884
this . args = [ ] ;
@@ -909,12 +942,13 @@ class StringUtils {
909
942
910
943
@global
911
944
export function wasi_abort (
912
- message : string | null = "" ,
913
- fileName : string | null = "" ,
945
+ message : string = "" ,
946
+ fileName : string = "" ,
914
947
lineNumber : u32 = 0 ,
915
948
columnNumber : u32 = 0
916
949
) : void {
917
- Console . error ( fileName ! + ":" + lineNumber . toString ( ) + ":" + columnNumber . toString ( ) +
918
- ": error: " + message ! ) ;
950
+ Console . error (
951
+ fileName + ":" + lineNumber . toString ( ) + ":" + columnNumber . toString ( ) + ": error: " + message
952
+ ) ;
919
953
proc_exit ( 255 ) ;
920
954
}
0 commit comments