File tree 6 files changed +44
-2
lines changed
third_party/closure-compiler/node-externs
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(
268
268
* @type {symbol }
269
269
*/
270
270
Symbol . 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 = [];
32
32
* @suppress {duplicate}
33
33
*/
34
34
var 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 = {
567
567
568
568
// random.h
569
569
570
+ #if ENVIRONMENT_MAY_BE_SHELL
571
+ $initRandomFill__deps : [ '$base64Decode '] ,
572
+ #endif
570
573
$initRandomFill : ( ) => {
571
574
#if ENVIRONMENT_MAY_BE_NODE && MIN_NODE_VERSION < 190000
572
575
// This block is not needed on v19+ since crypto.getRandomValues is builtin
@@ -576,6 +579,18 @@ var WasiLibrary = {
576
579
}
577
580
#endif // ENVIRONMENT_MAY_BE_NODE
578
581
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
+
579
594
#if SHARED_MEMORY
580
595
// like with most Web APIs, we can't use Web Crypto API directly on shared memory,
581
596
// 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() {
77
77
libraries . push ( 'libmemoryprofiler.js' ) ;
78
78
}
79
79
80
- if ( SUPPORT_BASE64_EMBEDDING ) {
80
+ if ( SUPPORT_BASE64_EMBEDDING || ENVIRONMENT_MAY_BE_SHELL ) {
81
81
libraries . push ( 'libbase64.js' ) ;
82
82
}
83
83
Original file line number Diff line number Diff line change @@ -16026,3 +16026,21 @@ def test_js_base64_api(self):
16026
16026
baseline_size = os.path.getsize('baseline.js')
16027
16027
js_api_size = os.path.getsize('hello_world.js')
16028
16028
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 27
27
END_NODE_INCLUDE
28
28
*/
29
29
30
- var os = { } ;
31
30
32
31
/**
33
32
* @return {string }
You can’t perform that action at this time.
0 commit comments