Skip to content

Commit 2d4d230

Browse files
committed
refactor: set v8 flags before initialize v8 platform
After the v8 platform had initialized, it was no longer able to set the v8 flags, so it is necessary to adjust the invocation order of the set v8 flag function to avoid v8's static assertion. (cherry picked from commit bd19752)
1 parent ac43e1e commit 2d4d230

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

crates/base/src/commands.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::server::{Server, ServerCodes, WorkerEntrypoints};
22
use anyhow::Error;
33
use deno_core::JsRuntime;
4+
use log::error;
45
use tokio::sync::mpsc::Sender;
56

67
#[allow(clippy::too_many_arguments)]
@@ -14,6 +15,8 @@ pub async fn start_server(
1415
callback_tx: Option<Sender<ServerCodes>>,
1516
entrypoints: WorkerEntrypoints,
1617
) -> Result<(), Error> {
18+
set_v8_flags();
19+
1720
// NOTE(denoland/deno/20495): Due to the new PKU (Memory Protection Keys)
1821
// feature introduced in V8 11.6, We need to initialize the V8 platform on
1922
// the main thread that spawns V8 isolates.
@@ -32,3 +35,20 @@ pub async fn start_server(
3235
.await?;
3336
server.listen().await
3437
}
38+
39+
fn set_v8_flags() {
40+
let v8_flags = std::env::var("V8_FLAGS").unwrap_or("".to_string());
41+
let mut vec = vec![""];
42+
43+
if v8_flags.is_empty() {
44+
return;
45+
}
46+
47+
vec.append(&mut v8_flags.split(' ').collect());
48+
49+
let ignored = deno_core::v8_set_flags(vec.iter().map(|v| v.to_string()).collect());
50+
51+
if *ignored.as_slice() != [""] {
52+
error!("v8 flags unrecognized {:?}", ignored);
53+
}
54+
}

crates/base/src/deno_runtime.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ fn get_error_class_name(e: &AnyError) -> &'static str {
5858
sb_core::errors_rt::get_error_class_name(e).unwrap_or("Error")
5959
}
6060

61-
fn set_v8_flags() {
62-
let v8_flags = std::env::var("V8_FLAGS").unwrap_or("".to_string());
63-
let mut vec = vec!["IGNORED"];
64-
if v8_flags.is_empty() {
65-
return;
66-
}
67-
68-
vec.append(&mut v8_flags.split(' ').collect());
69-
error!(
70-
"v8 flags unrecognized {:?}",
71-
deno_core::v8_set_flags(vec.iter().map(|v| v.to_string()).collect())
72-
);
73-
}
74-
7561
pub struct DenoRuntime {
7662
pub js_runtime: JsRuntime,
7763
pub env_vars: HashMap<String, String>, // TODO: does this need to be pub?
@@ -95,8 +81,6 @@ impl DenoRuntime {
9581
maybe_module_code,
9682
} = opts;
9783

98-
set_v8_flags();
99-
10084
let user_agent = "supabase-edge-runtime".to_string();
10185
let base_dir_path = std::env::current_dir().map(|p| p.join(&service_path))?;
10286
let base_url = Url::from_directory_path(&base_dir_path).unwrap();

0 commit comments

Comments
 (0)