Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Oct 25, 2023
1 parent 1d9cf6c commit eacc048
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion boa_engine/src/environments/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,11 @@ impl Context<'_> {
}
}

/// Return the environment at the given index. Panics if the index is out of range.
/// Return the environment at the given index.
///
/// # Panics
///
/// Panics if the `index` is out of range.
pub(crate) fn environment_expect(&self, index: u32) -> &Environment {
self.vm
.environments
Expand Down
30 changes: 24 additions & 6 deletions boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,31 +251,49 @@ impl CodeBlock {
.find(|(_, handler)| handler.contains(pc))
}

/// Get the [`JsString`] constant from the [`CodeBlock`].
///
/// # Panics
///
/// If the type of the [`Constant`] is not [`Constant::String`].
/// Or `index` is greater or equal to length of `constants`.
pub(crate) fn constant_string_expect(&self, index: usize) -> JsString {
if let Constant::String(value) = &self.constants[index] {
if let Some(Constant::String(value)) = self.constants.get(index) {
return value.clone();
}

panic!("there should be a string constant at index {index}")
panic!("expected string constant at index {index}")
}

/// Get the function ([`Gc<CodeBlock>`]) constant from the [`CodeBlock`].
///
/// # Panics
///
/// If the type of the [`Constant`] is not [`Constant::Function`].
/// Or `index` is greater or equal to length of `constants`.
pub(crate) fn constant_function_expect(&self, index: usize) -> Gc<Self> {
if let Constant::Function(value) = &self.constants[index] {
if let Some(Constant::Function(value)) = self.constants.get(index) {
return value.clone();
}

panic!("there should be a function constant at index {index}")
panic!("expected function constant at index {index}")
}

/// Get the [`CompileTimeEnvironment`] constant from the [`CodeBlock`].
///
/// # Panics
///
/// If the type of the [`Constant`] is not [`Constant::CompileTimeEnvironment`].
/// Or `index` is greater or equal to length of `constants`.
pub(crate) fn constant_compile_time_environment_expect(
&self,
index: usize,
) -> Rc<CompileTimeEnvironment> {
if let Constant::CompileTimeEnvironment(value) = &self.constants[index] {
if let Some(Constant::CompileTimeEnvironment(value)) = self.constants.get(index) {
return value.clone();
}

panic!("there should be a compile time environment constant at index {index}")
panic!("expected compile time environment constant at index {index}")
}
}

Expand Down

0 comments on commit eacc048

Please sign in to comment.