Skip to content

Commit

Permalink
Fixed clippy errors (#222)
Browse files Browse the repository at this point in the history
* Fixed clippy errors
  • Loading branch information
IovoslavIovchev authored and jasonwilliams committed Jan 14, 2020
1 parent e38ac20 commit 5aabe98
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/lib/builtins/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/lib/builtins/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -345,10 +345,9 @@ impl Object {
.to_string()
.parse::<i32>()
.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() {
Expand Down
11 changes: 4 additions & 7 deletions src/lib/builtins/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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.
/// <https://tc39.es/ecma262/#sec-string.prototype.match>
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)
}

Expand Down Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/builtins/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/builtins/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/lib/environment/global_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/environment/object_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()),
));

Expand Down
22 changes: 8 additions & 14 deletions src/lib/syntax/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Parser {
_ => {
return Err(ParseError::Expected(
vec![TokenData::Identifier("identifier".to_string())],
tk.clone(),
tk,
"function arguments",
))
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -310,7 +308,7 @@ impl Parser {
_ => {
return Err(ParseError::Expected(
vec![TokenData::Identifier("identifier".to_string())],
tk.clone(),
tk,
"function name",
))
}
Expand Down Expand Up @@ -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",
));
}
Expand Down Expand Up @@ -425,7 +423,7 @@ impl Parser {
vec![TokenData::Identifier(
"identifier".to_string(),
)],
ident_token.clone(),
ident_token,
"arrow function",
));
}
Expand All @@ -439,7 +437,7 @@ impl Parser {
vec![TokenData::Identifier(
"identifier".to_string(),
)],
curr_tk.clone(),
curr_tk,
"arrow function",
))
}
Expand Down Expand Up @@ -499,7 +497,7 @@ impl Parser {
TokenData::Punctuator(Punctuator::Comma),
TokenData::Punctuator(Punctuator::CloseBracket),
],
token.clone(),
token,
"array declaration",
));
}
Expand Down Expand Up @@ -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())))
Expand Down

0 comments on commit 5aabe98

Please sign in to comment.