@@ -13,6 +13,7 @@ use deno_tls::rustls_native_certs::load_native_certs;
13
13
use deno_tls:: RootCertStoreProvider ;
14
14
use futures_util:: future:: poll_fn;
15
15
use log:: { error, trace} ;
16
+ use once_cell:: sync:: OnceCell ;
16
17
use sb_core:: conn_sync:: ConnSync ;
17
18
use serde:: de:: DeserializeOwned ;
18
19
use std:: collections:: HashMap ;
@@ -74,6 +75,17 @@ impl DenoRuntime {
74
75
#[ allow( clippy:: unnecessary_literal_unwrap) ]
75
76
#[ allow( clippy:: arc_with_non_send_sync) ]
76
77
pub async fn new ( opts : WorkerContextInitOpts ) -> Result < Self , Error > {
78
+ static INITIALZE_V8_PLATFORM : OnceCell < ( ) > = OnceCell :: new ( ) ;
79
+
80
+ INITIALZE_V8_PLATFORM . get_or_init ( || {
81
+ set_v8_flags ( ) ;
82
+
83
+ // NOTE(denoland/deno/20495): Due to the new PKU (Memory Protection Keys)
84
+ // feature introduced in V8 11.6, We need to initialize the V8 platform on
85
+ // the main thread that spawns V8 isolates.
86
+ JsRuntime :: init_platform ( None ) ;
87
+ } ) ;
88
+
77
89
let WorkerContextInitOpts {
78
90
service_path,
79
91
no_module_cache,
@@ -474,6 +486,23 @@ impl DenoRuntime {
474
486
}
475
487
}
476
488
489
+ fn set_v8_flags ( ) {
490
+ let v8_flags = std:: env:: var ( "V8_FLAGS" ) . unwrap_or ( "" . to_string ( ) ) ;
491
+ let mut vec = vec ! [ "" ] ;
492
+
493
+ if v8_flags. is_empty ( ) {
494
+ return ;
495
+ }
496
+
497
+ vec. append ( & mut v8_flags. split ( ' ' ) . collect ( ) ) ;
498
+
499
+ let ignored = deno_core:: v8_set_flags ( vec. iter ( ) . map ( |v| v. to_string ( ) ) . collect ( ) ) ;
500
+
501
+ if * ignored. as_slice ( ) != [ "" ] {
502
+ error ! ( "v8 flags unrecognized {:?}" , ignored) ;
503
+ }
504
+ }
505
+
477
506
#[ cfg( test) ]
478
507
mod test {
479
508
use crate :: deno_runtime:: DenoRuntime ;
0 commit comments