Truly independent web browser
LibJS: Drop the associated Operand type of ConstantPool
Shannon Booth8800d4e1098a
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/context.rsindex 769be44a5c4..7091d34c71f 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/context.rs@@ -461,10 +461,8 @@ impl<'t> Generator<'t> {}impl ConstantPool for Generator<'_> {- type Operand = Operand;-- fn get_constant(&self, operand: &Operand) -> Option<&ConstantValue> {- Generator::get_constant(self, *operand)+ fn get_constant(&self, operand: Operand) -> Option<&ConstantValue> {+ Generator::get_constant(self, operand)}fn add_constant_number(&mut self, value: f64) -> Operand {diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rsindex 75b048c0dd1..2caf70f4772 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs@@ -2585,7 +2585,7 @@ impl Generator<'_> {let (rhs, _) = self.pop_operand();let (lhs, first_temporary) = self.pop_operand();if lhs.is_constant() && rhs.is_constant() {- let folded = try_constant_fold_binary(self, operator, &lhs, &rhs);+ let folded = try_constant_fold_binary(self, operator, lhs, rhs);if let Some(folded) = folded {self.release_temporaries_from(first_temporary);self.push_value(folded, first_temporary);@@ -2663,7 +2663,7 @@ impl Generator<'_> {pub(super) fn unary(&mut self, operator: UnaryOp) {let (value, first_temporary) = self.pop_operand();if value.is_constant()- && let Some(folded) = try_constant_fold_unary(self, operator, &value)+ && let Some(folded) = try_constant_fold_unary(self, operator, value){self.release_temporaries_from(first_temporary);self.push_value(folded, first_temporary);diff --git a/Libraries/LibJS/Rust/src/bytecode/constant_fold.rs b/Libraries/LibJS/Rust/src/bytecode/constant_fold.rsindex 375cd671c7e..0b882add84a 100644--- a/Libraries/LibJS/Rust/src/bytecode/constant_fold.rs+++ b/Libraries/LibJS/Rust/src/bytecode/constant_fold.rs@@ -21,16 +21,15 @@ use crate::utf16::Utf16View;use ak::Utf16String;use super::executable_data::ConstantValue;+use super::operand::Operand;/// The constants of a generator, as folding sees them.pub(super) trait ConstantPool {- type Operand;-- fn get_constant(&self, operand: &Self::Operand) -> Option<&ConstantValue>;- fn add_constant_number(&mut self, value: f64) -> Self::Operand;- fn add_constant_boolean(&mut self, value: bool) -> Self::Operand;- fn add_constant_string(&mut self, value: Utf16String) -> Self::Operand;- fn add_constant_bigint(&mut self, value: String) -> Self::Operand;+ fn get_constant(&self, operand: Operand) -> Option<&ConstantValue>;+ fn add_constant_number(&mut self, value: f64) -> Operand;+ fn add_constant_boolean(&mut self, value: bool) -> Operand;+ fn add_constant_string(&mut self, value: Utf16String) -> Operand;+ fn add_constant_bigint(&mut self, value: String) -> Operand;}/// Convert a constant value to a boolean, matching JS `ToBoolean`.@@ -125,8 +124,8 @@ pub(super) fn to_u32(n: f64) -> u32 {pub(super) fn try_constant_fold_unary<G: ConstantPool>(generator: &mut G,op: UnaryOp,- operand: &G::Operand,-) -> Option<G::Operand> {+ operand: Operand,+) -> Option<Operand> {let constant = generator.get_constant(operand)?;match op {UnaryOp::Minus => {@@ -230,7 +229,7 @@ fn try_constant_fold_bigint_binary<G: ConstantPool>(op: BinaryOp,a_str: &str,b_str: &str,-) -> Option<G::Operand> {+) -> Option<Operand> {let a = parse_bigint(a_str)?;let b = parse_bigint(b_str)?;match op {@@ -362,9 +361,9 @@ fn compare_bigint_and_number(bigint_str: &str, number: f64) -> Option<Option<stdpub(super) fn try_constant_fold_binary<G: ConstantPool>(generator: &mut G,op: BinaryOp,- lhs: &G::Operand,- rhs: &G::Operand,-) -> Option<G::Operand> {+ lhs: Operand,+ rhs: Operand,+) -> Option<Operand> {let lhs_const = generator.get_constant(lhs)?;let rhs_const = generator.get_constant(rhs)?;