1
+ var console = { log : function ( ) { } } ;
1
2
var is_browser = ( typeof ( self ) !== "undefined" || typeof ( window ) !== "undefined" ) ;
2
3
3
4
var FS ;
@@ -46,17 +47,29 @@ var mkdir = function(id, pseudo_path, pseudo_name) {
46
47
47
48
48
49
var getFile = function ( id , pseudo_path , pseudo_name ) {
49
- var array = FS . root . contents [ pseudo_name ] . contents ;
50
- var binary_data = new Uint8Array ( array ) ;
50
+ try {
51
+ var parentObj = FS . root ;
52
+ var path = pseudo_path . split ( '/' ) ;
53
+ for ( var i = 1 ; i < path . length ; i ++ ) {
54
+ if ( path [ i ] != '' )
55
+ parentObj = parentObj . contents [ path [ i ] ] ;
56
+ }
57
+
58
+ var array = parentObj . contents [ pseudo_name ] . contents ;
59
+ var binary_data = new Uint8Array ( array ) ;
51
60
52
- var chunk_size = 1000 ;
53
- var chunk_count = Math . ceil ( binary_data . length / chunk_size ) ;
61
+ var chunk_size = 1000 ;
62
+ var chunk_count = Math . max ( 1 , Math . ceil ( binary_data . length / chunk_size ) ) ;
54
63
55
- for ( var i = 0 ; i < chunk_count ; i ++ ) {
56
- var chunk = binary_data . subarray ( i * chunk_size , Math . min ( ( i + 1 ) * chunk_size , binary_data . length ) ) ;
64
+ for ( var i = 0 ; i < chunk_count ; i ++ ) {
65
+ var chunk = binary_data . subarray ( i * chunk_size , Math . min ( ( i + 1 ) * chunk_size , binary_data . length ) ) ;
57
66
58
- var str_chunk = String [ 'fromCharCode' ] . apply ( null , chunk ) ;
59
- self . postMessage ( JSON . stringify ( { 'id' : id , 'chunk_id' : i , 'chunk_count' : chunk_count , 'contents' : str_chunk } ) ) ;
67
+ var str_chunk = String [ 'fromCharCode' ] . apply ( null , chunk ) ;
68
+ self . postMessage ( JSON . stringify ( { 'id' : id , 'chunk_id' : i , 'chunk_count' : chunk_count , 'contents' : str_chunk } ) ) ;
69
+ }
70
+ }
71
+ catch ( e ) {
72
+ self . postMessage ( JSON . stringify ( { 'id' : id , 'chunk_id' : 0 , 'chunk_count' : 0 , 'error' : true } ) ) ;
60
73
}
61
74
} ;
62
75
@@ -78,6 +91,16 @@ self['onmessage'] = function(ev) {
78
91
79
92
if ( msg [ 'cmd' ] === 'run' ) {
80
93
try {
94
+ shouldRunNow = true ;
95
+
96
+ if ( 'egd-pool' in FS . root . contents [ 'dev' ] . contents ) {
97
+ var rand_count = 0 ;
98
+ var rand_contents = FS . root . contents [ 'dev' ] . contents [ 'egd-pool' ] . contents ;
99
+ var rand = new Uint8Array ( rand_contents ) ;
100
+ FS . createDevice ( '/dev' , 'urandom' , function ( ) { rand_count ++ ; if ( rand_count >= rand . length ) { Module . print ( "Out of entropy!" ) ; throw Error ( "Out of entropy" ) ; } return rand [ rand_count - 1 ] ; } ) ;
101
+ FS . createDevice ( '/dev' , 'random' , function ( ) { rand_count ++ ; if ( rand_count >= rand . length ) { Module . print ( "Out of entropy!" ) ; throw Error ( "Out of entropy" ) ; } return rand [ rand_count - 1 ] ; } ) ;
102
+ }
103
+
81
104
Module [ 'run' ] ( msg [ 'args' ] ) ;
82
105
}
83
106
catch ( e ) {
0 commit comments