Truly independent web browser
LibJS: Look up what code leaves unbound only where it matters
Andreas Klingdc3a75606e7b
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rsindex 7f27211c0b2..35f2ce2b606 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs@@ -1910,7 +1910,7 @@ impl Generator<'_> {resolution,));}- let enclosing_code = EnclosingCode::of_function(row, &mut entries, &self.enclosing_code);+ let enclosing_code = EnclosingCode::of_function(row, &mut entries, &self.enclosing_code, has_direct_eval);self.context.scope.scope_resolutions = entries;enclosing_code};diff --git a/Libraries/LibJS/Rust/src/parser/resolve.rs b/Libraries/LibJS/Rust/src/parser/resolve.rsindex 20b6266bfcf..73d4676cb33 100644--- a/Libraries/LibJS/Rust/src/parser/resolve.rs+++ b/Libraries/LibJS/Rust/src/parser/resolve.rs@@ -487,6 +487,8 @@ pub struct EnclosingCode {/// What the functions nested in this code see of it, unless it has none.resolutions: Option<OuterResolutions>,parent: Option<Arc<EnclosingCode>>,+ /// Whether what this code leaves unbound can go through a direct `eval` of its own.+ has_direct_eval: bool,}impl EnclosingCode {@@ -495,15 +497,22 @@ impl EnclosingCode {row: NONE,resolutions: tree.outer_resolutions.clone(),parent: None,+ has_direct_eval: true,})}/// The code of the function at `row`, from what it found out about what is nested in it itself.- pub(crate) fn of_function(row: u32, entries: &mut Vec<(u64, Resolution)>, parent: &Arc<Self>) -> Arc<Self> {+ pub(crate) fn of_function(+ row: u32,+ entries: &mut Vec<(u64, Resolution)>,+ parent: &Arc<Self>,+ has_direct_eval: bool,+ ) -> Arc<Self> {Arc::new(Self {row,resolutions: Some(OuterResolutions::new(entries)),parent: Some(parent.clone()),+ has_direct_eval,})}@@ -529,11 +538,14 @@ impl EnclosingCode {}return resolution;}- // NB: The name goes through all the scopes of this code that are around the function.- outermost_unbound_name = resolutions- .get(function, Name(N_DOT_UNBOUND))- .expect("the code around a function resolved what it does not bind");- is_inside_scope_with_eval |= outermost_unbound_name.is_inside_tree_scope_with_eval();+ // NB: The name goes through all the scopes of this code that are around the function. Only the outermost+ // code has the last word on it, and other code only matters if it has an `eval`.+ if enclosing.has_direct_eval || enclosing.parent.is_none() {+ outermost_unbound_name = resolutions+ .get(function, Name(N_DOT_UNBOUND))+ .expect("the code around a function resolved what it does not bind");+ is_inside_scope_with_eval |= outermost_unbound_name.is_inside_tree_scope_with_eval();+ }function = enclosing.row;code = enclosing.parent.as_ref();}