Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(v8): resolve intrinsic eval without compiling source

ldm0122355d872fa
diff --git a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
index fda6a1b11..101f31f25 100644
--- a/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
+++ b/moli-renderer-v8/src/context_bootstrap/runtime_state.rs
@@ -2006,8 +2006,11 @@ fn install_window_runtime_state<'s>(
// classic-script declarations like `var parent = ...` work, without letting
// DOM named items shadow the builtins.
WindowLegacyAliasAccessorsDeclaration::default().initialize(scope, global)?;
- let intrinsic_eval = v8::Script::compile(scope, v8str(scope, "eval"), None)
- .and_then(|script| script.run(scope))
+ // Read the existing V8 intrinsic without compiling a script or invoking
+ // Window's DOM named-property interceptors during bootstrap.
+ let intrinsic_eval = global
+ .get_real_named_property(scope, v8str(scope, "eval").into())
+ .filter(|value| value.is_function())
.ok_or_else(|| anyhow!("failed to resolve intrinsic eval"))?;
set_private_value(scope, global, WINDOW_INTRINSIC_EVAL_SLOT, intrinsic_eval);
WindowEvalGlobalDeclaration::new(intrinsic_eval)
diff --git a/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces.rs b/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces.rs
index f410aba83..ea01e8b76 100644
--- a/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces.rs
+++ b/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces.rs
@@ -1,5 +1,6 @@
use super::*;
+mod eval;
mod rebind;
mod seeds;
diff --git a/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces/eval.rs b/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces/eval.rs
new file mode 100644
index 000000000..69c9f58eb
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/lazy_window_surfaces/eval.rs
@@ -0,0 +1,27 @@
+use super::*;
+
+#[test]
+fn bootstrap_eval_remains_intrinsic_with_dom_named_candidates() {
+ let mut vm = new_parsed_test_vm(
+ "https://bootstrap-intrinsic-eval.test/",
+ "<!doctype html><body><div id=eval></div><form name=eval></form></body>",
+ );
+ assert_eq!(
+ vm.eval(
+ r#"(() => {
+ globalThis.__indirectEvalValue = 11;
+ function direct() {
+ const lexicalValue = 7;
+ return eval('lexicalValue + 1');
+ }
+ const descriptor = Object.getOwnPropertyDescriptor(globalThis, 'eval');
+ return JSON.stringify([
+ typeof eval, eval.name, eval.length, descriptor.value === eval,
+ direct(), (0, eval)('__indirectEvalValue')
+ ]);
+ })()"#,
+ )
+ .expect("direct and indirect builtin eval with DOM named properties"),
+ r#"["function","eval",1,true,8,11]"#
+ );
+}