Truly independent web browser
LibJS: Store local variable scopes as source offsets
Shannon Booth7a265c691f85
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rsindex b12354ce684..7d26613c0aa 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/scope.rs@@ -30,6 +30,7 @@ use crate::bytecode::executable_data::PendingSharedFunctionData;use crate::bytecode::executable_data::PrecompiledFunction;use crate::bytecode::instruction::typed as op;use crate::bytecode::operand::*;+use crate::bytecode::source_map::SourceOffset;use crate::parser::EnclosingCode;use crate::parser::FunctionRow;use crate::parser::columns::NONE;@@ -1977,9 +1978,15 @@ impl Generator<'_> {let context = &mut *self.context;let constants = link_block.slice(context.constants.values.drain(..));let scope = &context.scope;- let local_variable_metadata = block.slice(scope.locals.iter().map(|local| LocalVariableMetadata {- is_mutable: local.is_mutable,- scope_range: local.block_range.map(|(start, end)| tree.range_between(start, end)),+ let local_variable_metadata = block.slice(scope.locals.iter().map(|local| {+ let (start, end) = local+ .block_range+ .unwrap_or((SourceOffset::NONE.0, SourceOffset::NONE.0));+ LocalVariableMetadata {+ is_mutable: local.is_mutable,+ scope_start: SourceOffset(start),+ scope_end: SourceOffset(end),+ }}));let local_names = scope.locals.iter().map(|local| (local.name, true));let variable_names = block.slice_of_length(diff --git a/Libraries/LibJS/Rust/src/bytecode/executable.rs b/Libraries/LibJS/Rust/src/bytecode/executable.rsindex bf446e2e799..247b92f5502 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable.rs@@ -1641,16 +1641,21 @@ impl Executable {}pub fn local_variable_scope_range(&self, index: usize) -> Option<LocalVariableScopeRange> {- let position = |position: crate::ast::Position| Position {- line: position.line,- column: position.column,+ let metadata = self.local_variable_metadata()[index];+ if metadata.scope_start == SourceOffset::NONE {+ return None;+ }+ let position = |offset: SourceOffset| {+ let position = self.code.position_source.lines.position(offset.0);+ Position {+ line: position.line,+ column: position.column,+ }};- self.local_variable_metadata()[index]- .scope_range- .map(|range| LocalVariableScopeRange {- start: position(range.start),- end: position(range.end),- })+ Some(LocalVariableScopeRange {+ start: position(metadata.scope_start),+ end: position(metadata.scope_end),+ })}pub fn local_variable_names(&self) -> &[Utf16FlyString] {diff --git a/Libraries/LibJS/Rust/src/bytecode/executable_data.rs b/Libraries/LibJS/Rust/src/bytecode/executable_data.rsindex e950d4cf00f..42915e28033 100644--- a/Libraries/LibJS/Rust/src/bytecode/executable_data.rs+++ b/Libraries/LibJS/Rust/src/bytecode/executable_data.rs@@ -13,7 +13,7 @@ use ak::Utf16String;use super::constant::AbstractOperationKind;use super::constant::WellKnownSymbolKind;use super::operand::PropertyKeyTableIndex;-use super::source_map::SourceOffsetEntry;+use super::source_map::{SourceOffset, SourceOffsetEntry};use crate::ast::FunctionId;use crate::compile::SharedFunctionDescription;use crate::compile::utf16_string_memory_size;@@ -164,7 +164,8 @@ pub struct ExecutableCacheCounts {pub struct LocalVariableMetadata {pub is_mutable: bool,/// The part of the source code in which the local variable is in scope.- pub scope_range: Option<crate::ast::SourceRange>,+ pub scope_start: SourceOffset,+ pub scope_end: SourceOffset,}/// One compiled script, module or function body: everything about it that does not depend on where it runs. Nothing