* feat(cli): add --v8-flags plumbing to configure V8 at startup (#130) Obscura had no way to pass flags to V8, so users hitting OOM on pages larger than ~5MB had no escape hatch. Adds a generic passthrough rather than a one-off heap knob, so future V8 tuning needs no new code. - New `obscura_js::set_v8_flags` (Once-guarded, empty-string no-op). - Global `--v8-flags <FLAGS>` arg with `allow_hyphen_values = true`, applied once in `main` before any isolate is created. - Usage: `obscura --v8-flags "--max-old-space-size=4096" fetch <url>`. Closes #130. * test(cli): expand --v8-flags coverage with normalize helper Extract normalize_v8_flags() from main() so the trim/empty-check logic is unit-testable without needing to invoke V8. Adds parse-coverage tests for --v8-flags with serve/scrape subcommands and empty-string values, plus pure-function tests for the normalizer.
This commit is contained in:
1 parent
7b209dc655
commit
cb701fc2d8
3 files changed
+154
-1
No files matched your search
@@ -4,7 +4,9 @@ extern crate html5ever;
|
||||
pub mod module_loader;
|
||||
pub mod runtime;
|
||||
pub mod ops;
|
||||
pub mod v8_flags;
|
||||
pub mod v8_lock;
|
||||
pub mod markdown;
|
||||
|
||||
pub use markdown::HTML_TO_MARKDOWN_JS;
|
||||
pub use v8_flags::set_v8_flags;
|
||||
@@ -0,0 +1,37 @@
|
||||
use std::sync::Once;
|
||||
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
/// Apply user-supplied V8 flags exactly once, before the first isolate is
|
||||
/// created.
|
||||
///
|
||||
/// `flags` is a raw V8 flag string in the same form V8/Chromium/Node accept
|
||||
/// (e.g. `"--max-old-space-size=4096 --max-semi-space-size=64"`). An empty or
|
||||
/// whitespace-only string is a no-op and does not consume the one-shot guard,
|
||||
/// so a later non-empty call still takes effect.
|
||||
///
|
||||
/// V8 ignores `set_flags_from_string` once the platform is initialized, so the
|
||||
/// first non-empty call must run before any `JsRuntime` is constructed.
|
||||
/// Subsequent calls are silently dropped.
|
||||
pub fn set_v8_flags(flags: &str) {
|
||||
let trimmed = flags.trim();
|
||||
if trimmed.is_empty() {
|
||||
return;
|
||||
}
|
||||
INIT.call_once(|| {
|
||||
deno_core::v8::V8::set_flags_from_string(trimmed);
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn empty_is_noop() {
|
||||
// Must not panic and must not consume the Once guard.
|
||||
set_v8_flags("");
|
||||
set_v8_flags(" ");
|
||||
set_v8_flags("\t\n");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user