File tree Expand file tree Collapse file tree 6 files changed +44
-2
lines changed 
third_party/closure-compiler/node-externs Expand file tree Collapse file tree 6 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -268,3 +268,6 @@ Navigator.prototype.webkitGetUserMedia = function(
268268 * @type  {symbol } 
269269 */ 
270270Symbol . dispose ; 
271+ 
272+ // Common between node-externs and v8-externs 
273+ var  os  =  { } ; 
Original file line number Diff line number Diff line change @@ -32,3 +32,10 @@ var scriptArgs = [];
3232 * @suppress  {duplicate} 
3333 */ 
3434var  quit  =  function ( status )  { } ; 
35+ 
36+ /** 
37+  * @param  {string } cmd 
38+  * @param  {Array.<string>= } args 
39+  * @return  {string } 
40+  */ 
41+ os . system  =  function  ( cmd ,  args )  { } ; 
Original file line number Diff line number Diff line change @@ -567,6 +567,9 @@ var WasiLibrary = {
567567
568568  // random.h 
569569
570+ #if ENVIRONMENT_MAY_BE_SHELL 
571+   $initRandomFill__deps : [ '$base64Decode '] , 
572+ #endif
570573  $initRandomFill : ( )  =>  { 
571574#if ENVIRONMENT_MAY_BE_NODE  &&  MIN_NODE_VERSION  <  190000 
572575    // This block is not needed on v19+ since crypto.getRandomValues is builtin 
@@ -576,6 +579,18 @@ var WasiLibrary = {
576579    } 
577580#endif // ENVIRONMENT_MAY_BE_NODE 
578581
582+ #if ENVIRONMENT_MAY_BE_SHELL 
583+     if  ( ENVIRONMENT_IS_SHELL )  { 
584+       return  ( view )  =>  { 
585+         if  ( ! os . system )  { 
586+           throw  new  Error ( 'randomFill  not  supported  on  d8  unless  -- enable - os - system  is  passed ') ; 
587+         } 
588+         const  b64  =  os . system ( 'sh' ,  [ '-c' ,  `head -c${ view . byteLength }   /dev/urandom | base64 --wrap=0` ] ) ; 
589+         view . set ( base64Decode ( b64 ) ) ; 
590+       } ; 
591+     } 
592+ #endif
593+ 
579594#if SHARED_MEMORY 
580595    // like with most Web APIs, we can't use Web Crypto API directly on shared memory, 
581596    // so we need to create an intermediate buffer and copy it to the destination 
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ function calculateLibraries() {
7777    libraries . push ( 'libmemoryprofiler.js' ) ; 
7878  } 
7979
80-   if  ( SUPPORT_BASE64_EMBEDDING )  { 
80+   if  ( SUPPORT_BASE64_EMBEDDING   ||   ENVIRONMENT_MAY_BE_SHELL )  { 
8181    libraries . push ( 'libbase64.js' ) ; 
8282  } 
8383
Original file line number Diff line number Diff line change @@ -16026,3 +16026,21 @@ def test_js_base64_api(self):
1602616026    baseline_size = os.path.getsize('baseline.js')
1602716027    js_api_size = os.path.getsize('hello_world.js')
1602816028    self.assertLess(js_api_size, baseline_size)
16029+ 
16030+   @requires_v8
16031+   def test_getentropy_d8(self):
16032+     create_file('main.c', '''
16033+       #include <assert.h>
16034+       #include <unistd.h>
16035+ 
16036+       int main() {
16037+         char buf[100];
16038+         assert(getentropy(buf, sizeof(buf)) == 0);
16039+         return 0;
16040+       }
16041+     ''')
16042+ 
16043+     msg = 'randomFill not supported on d8 unless --enable-os-system is passed'
16044+     self.do_runf('main.c', msg, assert_returncode=1)
16045+     self.v8_args += ['--enable-os-system']
16046+     self.do_runf('main.c')
Original file line number Diff line number Diff line change 2727 END_NODE_INCLUDE 
2828 */ 
2929
30- var  os  =  { } ; 
3130
3231/** 
3332 * @return  {string } 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments