diff --git a/src/lib/builtins/error.rs b/src/lib/builtins/error.rs index a272a8561e..592a12c74d 100644 --- a/src/lib/builtins/error.rs +++ b/src/lib/builtins/error.rs @@ -29,7 +29,7 @@ pub fn make_error(this: &Value, args: &[Value], _: &mut Interpreter) -> ResultVa pub fn to_string(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { let name = this.get_field_slice("name"); let message = this.get_field_slice("message"); - Ok(to_value(format!("{}: {}", name, message).to_string())) + Ok(to_value(format!("{}: {}", name, message))) } /// Create a new `Error` object pub fn _create(global: &Value) -> Value { diff --git a/src/lib/builtins/object.rs b/src/lib/builtins/object.rs index 01cb83209c..258f0a806e 100644 --- a/src/lib/builtins/object.rs +++ b/src/lib/builtins/object.rs @@ -57,7 +57,7 @@ impl Object { pub fn create(proto: Value) -> Object { let mut obj = Object::default(); obj.internal_slots - .insert(INSTANCE_PROTOTYPE.to_string(), proto.clone()); + .insert(INSTANCE_PROTOTYPE.to_string(), proto); obj.internal_slots .insert("extensible".to_string(), to_value(true)); obj @@ -345,10 +345,9 @@ impl Object { .to_string() .parse::() .expect("parsing failed"); - self.sym_properties.insert(sym_id, current.clone()); + self.sym_properties.insert(sym_id, current); } else { - self.properties - .insert(property_key.clone(), current.clone()); + self.properties.insert(property_key.clone(), current); } // 7 } else if current.is_data_descriptor() && desc.is_data_descriptor() { diff --git a/src/lib/builtins/string.rs b/src/lib/builtins/string.rs index fdc78dc2e5..b746e3266b 100644 --- a/src/lib/builtins/string.rs +++ b/src/lib/builtins/string.rs @@ -54,7 +54,7 @@ pub fn call_string(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValu pub fn to_string(this: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { // Get String from String Object and send it back as a new value let primitive_val = this.get_internal_slot("StringData"); - Ok(to_value(format!("{}", primitive_val).to_string())) + Ok(to_value(format!("{}", primitive_val))) } /// Returns a single element String containing the code unit at index pos within the String value @@ -129,9 +129,7 @@ pub fn char_code_at(this: &Value, args: &[Value], ctx: &mut Interpreter) -> Resu pub fn concat(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { // First we get it the actual string a private field stored on the object only the engine has access to. // Then we convert it into a Rust String by wrapping it in from_value - let primitive_val: String = ctx.value_to_rust_string(this); - - let mut new_str = primitive_val.clone(); + let mut new_str = ctx.value_to_rust_string(this); for arg in args { let concat_str: String = from_value(arg.clone()).expect("failed to get argument value"); @@ -422,7 +420,7 @@ pub fn last_index_of(this: &Value, args: &[Value], ctx: &mut Interpreter) -> Res /// otherwise null is returned if no match is found. /// pub fn r#match(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { - let re = make_regexp(&to_value(Object::default()), &[args[0].clone()], ctx)?.clone(); + let re = make_regexp(&to_value(Object::default()), &[args[0].clone()], ctx)?; regexp_match(&re, ctx.value_to_rust_string(this), ctx) } @@ -716,8 +714,7 @@ pub fn match_all(this: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultV &[to_value(String::new()), to_value(String::from("g"))], ctx, ), - }? - .clone(); + }?; regexp_match_all(&re, ctx.value_to_rust_string(this)) } diff --git a/src/lib/builtins/symbol.rs b/src/lib/builtins/symbol.rs index e2250c4877..c05e008985 100644 --- a/src/lib/builtins/symbol.rs +++ b/src/lib/builtins/symbol.rs @@ -61,14 +61,14 @@ pub fn create_constructor(global: &Value) -> Value { // Symbol.prototype[[Prototype]] points to Object.prototype // Symbol Constructor -> Symbol Prototype -> Object Prototype let object_prototype = global.get_field_slice("Object").get_field_slice(PROTOTYPE); - symbol_prototype.set_internal_slot(INSTANCE_PROTOTYPE, object_prototype.clone()); + symbol_prototype.set_internal_slot(INSTANCE_PROTOTYPE, object_prototype); symbol_prototype.set_method("toString", to_string); let symbol_prototype_val = to_value(symbol_prototype); let symbol_constructor_value = to_value(symbol_constructor); symbol_prototype_val.set_field_slice("construcotor", symbol_constructor_value.clone()); - symbol_constructor_value.set_field_slice(PROTOTYPE, symbol_prototype_val.clone()); + symbol_constructor_value.set_field_slice(PROTOTYPE, symbol_prototype_val); symbol_constructor_value } diff --git a/src/lib/builtins/value.rs b/src/lib/builtins/value.rs index 69503d79d8..3c60a00c5b 100644 --- a/src/lib/builtins/value.rs +++ b/src/lib/builtins/value.rs @@ -455,7 +455,7 @@ impl ValueData { // Symbols get saved into a different bucket to general properties if field.is_symbol() { - obj.borrow_mut().set(field.clone(), val.clone()); + obj.borrow_mut().set(field, val.clone()); } else { obj.borrow_mut() .set(to_value(field.to_string()), val.clone()); diff --git a/src/lib/environment/global_environment_record.rs b/src/lib/environment/global_environment_record.rs index 5ce164287b..fc72655b4f 100644 --- a/src/lib/environment/global_environment_record.rs +++ b/src/lib/environment/global_environment_record.rs @@ -105,7 +105,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { } self.declarative_record - .create_mutable_binding(name.clone(), deletion) + .create_mutable_binding(name, deletion) } fn create_immutable_binding(&mut self, name: String, strict: bool) -> bool { @@ -115,7 +115,7 @@ impl EnvironmentRecordTrait for GlobalEnvironmentRecord { } self.declarative_record - .create_immutable_binding(name.clone(), strict) + .create_immutable_binding(name, strict) } fn initialize_binding(&mut self, name: &str, value: Value) { diff --git a/src/lib/environment/object_environment_record.rs b/src/lib/environment/object_environment_record.rs index d007ae1153..03448c19b7 100644 --- a/src/lib/environment/object_environment_record.rs +++ b/src/lib/environment/object_environment_record.rs @@ -67,7 +67,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { debug_assert!(value.is_object() || value.is_function()); let bindings = &mut self.bindings; - bindings.update_prop(name, Some(value.clone()), None, None, Some(strict)); + bindings.update_prop(name, Some(value), None, None, Some(strict)); } fn get_binding_value(&self, name: &str, strict: bool) -> Value { diff --git a/src/lib/exec.rs b/src/lib/exec.rs index c4bba87b3f..f014c48a43 100644 --- a/src/lib/exec.rs +++ b/src/lib/exec.rs @@ -172,7 +172,7 @@ impl Executor for Interpreter { }) } ExprDef::Switch(ref val_e, ref vals, ref default) => { - let val = self.run(val_e)?.clone(); + let val = self.run(val_e)?; let mut result = Gc::new(ValueData::Null); let mut matched = false; for tup in vals.iter() { @@ -340,7 +340,7 @@ impl Executor for Interpreter { let v_r_a = self.run(obj)?; let v_a = (*v_r_a.borrow().get_field_slice(field)).clone(); let v_b = (*self.run(b)?).clone(); - let value = exec_assign_op(op, v_a, v_b.clone()); + let value = exec_assign_op(op, v_a, v_b); v_r_a .borrow() .set_field_slice(&field.clone(), value.clone()); @@ -377,7 +377,7 @@ impl Executor for Interpreter { let env = &mut self.realm.environment; env.push(new_function_environment( construct.clone(), - this.clone(), + this, Some(env.get_current_environment_ref().clone()), )); diff --git a/src/lib/syntax/parser.rs b/src/lib/syntax/parser.rs index 8c06794f3a..819f7f36ce 100644 --- a/src/lib/syntax/parser.rs +++ b/src/lib/syntax/parser.rs @@ -68,7 +68,7 @@ impl Parser { _ => { return Err(ParseError::Expected( vec![TokenData::Identifier("identifier".to_string())], - tk.clone(), + tk, "function arguments", )) } @@ -193,9 +193,7 @@ impl Parser { Ok(Expr::new(ExprDef::ConstDecl(vars))) } - Keyword::Return => Ok(Expr::new(ExprDef::Return(Some(Box::new( - self.parse()?.clone(), - ))))), + Keyword::Return => Ok(Expr::new(ExprDef::Return(Some(Box::new(self.parse()?))))), Keyword::New => { let call = self.parse()?; match call.def { @@ -310,7 +308,7 @@ impl Parser { _ => { return Err(ParseError::Expected( vec![TokenData::Identifier("identifier".to_string())], - tk.clone(), + tk, "function name", )) } @@ -382,7 +380,7 @@ impl Parser { if let ExprDef::UnaryOp(UnaryOp::Spread, _) = next.def { return Err(ParseError::Expected( vec![TokenData::Punctuator(Punctuator::CloseParen)], - next_tok.clone(), + next_tok, "arrow function", )); } @@ -425,7 +423,7 @@ impl Parser { vec![TokenData::Identifier( "identifier".to_string(), )], - ident_token.clone(), + ident_token, "arrow function", )); } @@ -439,7 +437,7 @@ impl Parser { vec![TokenData::Identifier( "identifier".to_string(), )], - curr_tk.clone(), + curr_tk, "arrow function", )) } @@ -499,7 +497,7 @@ impl Parser { TokenData::Punctuator(Punctuator::Comma), TokenData::Punctuator(Punctuator::CloseBracket), ], - token.clone(), + token, "array declaration", )); } @@ -850,11 +848,7 @@ impl Parser { Expr::new(ExprDef::BinOp( op2.clone(), b.clone(), - Box::new(Expr::new(ExprDef::BinOp( - op.clone(), - Box::new(orig), - a.clone(), - ))), + Box::new(Expr::new(ExprDef::BinOp(op, Box::new(orig), a.clone()))), )) } else { Expr::new(ExprDef::BinOp(op, Box::new(orig), Box::new(next.clone())))