summaryrefslogtreecommitdiff
path: root/core/modules.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-03-23 16:00:46 -0600
committerGitHub <noreply@github.com>2023-03-23 16:00:46 -0600
commitad77ba0f7b40760e04b79d9789da16d7c49010b8 (patch)
tree557e87fb172dc034c1b0c0a36a0d824036a1f986 /core/modules.rs
parente8348231df2d2716e9e7ffb85340b773ff58a2f2 (diff)
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.
Diffstat (limited to 'core/modules.rs')
-rw-r--r--core/modules.rs10
1 files changed, 5 insertions, 5 deletions
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<Cow<'static, [u8]>> 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<Vec<u8>> 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<const N: usize> 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<v8::Local<'a, v8::String>> {
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),