From ad77ba0f7b40760e04b79d9789da16d7c49010b8 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Thu, 23 Mar 2023 16:00:46 -0600 Subject: fix(core): panic at build time if extension code contains anything other than 7-bit ASCII (#18372) This will improve diagnostics and catch any non-ASCII extension code early. This will use `debug_assert!` rather than `assert!` to avoid runtime costs, and ensures (in debug_assert mode only) that all extension source files are ASCII as we load them. --- core/modules.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/modules.rs') diff --git a/core/modules.rs b/core/modules.rs index 78efdedfd..cfd68d245 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -309,7 +309,7 @@ impl From> for ModuleCode { impl From<&'static str> for ModuleCode { #[inline(always)] fn from(value: &'static str) -> Self { - assert!(value.is_ascii()); + debug_assert!(value.is_ascii()); ModuleCode::Static(value.as_bytes()) } } @@ -331,7 +331,7 @@ impl From> for ModuleCode { impl From<&'static [u8]> for ModuleCode { #[inline(always)] fn from(value: &'static [u8]) -> Self { - assert!(value.is_ascii()); + debug_assert!(value.is_ascii()); ModuleCode::Static(value) } } @@ -339,7 +339,7 @@ impl From<&'static [u8]> for ModuleCode { impl From<&'static [u8; N]> for ModuleCode { #[inline(always)] fn from(value: &'static [u8; N]) -> Self { - assert!(value.is_ascii()); + debug_assert!(value.is_ascii()); ModuleCode::Static(value) } } @@ -583,7 +583,7 @@ impl ModuleLoader for ExtModuleLoader { let result = if let Some(load_callback) = &self.maybe_load_callback { load_callback(file_source) } else { - match file_source.code.load() { + match file_source.load() { Ok(code) => Ok(code), Err(err) => return futures::future::err(err).boxed_local(), } @@ -1517,7 +1517,7 @@ impl ModuleMap { ) -> Option> { match name { ModuleName::Static(s) => { - assert!(s.is_ascii()); + debug_assert!(s.is_ascii()); v8::String::new_external_onebyte_static(scope, s.as_bytes()) } ModuleName::NotStatic(s) => v8::String::new(scope, s), -- cgit v1.2.3