Skip to content

Commit

Permalink
Avoid a closure and move some clones
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jun 13, 2022
1 parent d1fce74 commit e375afd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
10 changes: 3 additions & 7 deletions boa_engine/src/builtins/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,10 @@ impl Eval {

// Because of implementation details the following code differs from the spec.

// Parse the script body (11.a - 11.d)
// TODO: Implement errors for 11.e - 11.h
let body = match context
.parse_eval(x.as_bytes(), direct, strict)
.map_err(|e| e.to_string())
{
// Parse the script body and handle early errors (6 - 11)
let body = match context.parse_eval(x.as_bytes(), direct, strict) {
Ok(body) => body,
Err(e) => return context.throw_syntax_error(e),
Err(e) => return context.throw_syntax_error(e.to_string()),
};

// 12 - 13 are implicit in the call of `Context::compile_with_new_declarative`.
Expand Down
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ impl Function {
}

/// Sets the `[[HomeObject]]` slot if present.
pub(crate) fn set_home_object(&mut self, object: &JsObject) {
pub(crate) fn set_home_object(&mut self, object: JsObject) {
if let Self::Ordinary { home_object, .. } = self {
*home_object = Some(object.clone());
*home_object = Some(object);
}
}

Expand Down
20 changes: 10 additions & 10 deletions boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Context {
let class_function = class_object_mut
.as_function_mut()
.expect("class must be function object");
class_function.set_home_object(&proto);
class_function.set_home_object(proto.clone());
}

proto
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("must be function object")
.set_home_object(home_object);
.set_home_object(home_object.clone());

self.vm.push(home);
self.vm.push(function);
Expand Down Expand Up @@ -802,7 +802,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("method must be function object")
.set_home_object(&object);
.set_home_object(object.clone());
let name = self.vm.frame().code.names[index as usize];
let name = self.interner().resolve_expect(name);
object.__define_own_property__(
Expand Down Expand Up @@ -865,7 +865,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("method must be function object")
.set_home_object(&object);
.set_home_object(object.clone());
let key = key.to_property_key(self)?;
object.__define_own_property__(
key,
Expand Down Expand Up @@ -912,7 +912,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("method must be function object")
.set_home_object(&object);
.set_home_object(object.clone());
let name = self.vm.frame().code.names[index as usize];
let name = self.interner().resolve_expect(name).into();
let set = object
Expand Down Expand Up @@ -964,7 +964,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("method must be function object")
.set_home_object(&object);
.set_home_object(object.clone());
let name = key.to_property_key(self)?;
let set = object
.__get_own_property__(&name, self)?
Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("method must be function object")
.set_home_object(&object);
.set_home_object(object.clone());
let name = self.vm.frame().code.names[index as usize];
let name = self.interner().resolve_expect(name).into();
let get = object
Expand Down Expand Up @@ -1068,7 +1068,7 @@ impl Context {
.borrow_mut()
.as_function_mut()
.expect("method must be function object")
.set_home_object(&object);
.set_home_object(object.clone());
let name = key.to_property_key(self)?;
let get = object
.__get_own_property__(&name, self)?
Expand Down Expand Up @@ -1228,7 +1228,7 @@ impl Context {
let class_object = class_value
.as_object()
.expect("class must be function object");
field_function.set_home_object(class_object);
field_function.set_home_object(class_object.clone());
class_object
.borrow_mut()
.as_function_mut()
Expand All @@ -1254,7 +1254,7 @@ impl Context {
let class_object = class_value
.as_object()
.expect("class must be function object");
field_function.set_home_object(class_object);
field_function.set_home_object(class_object.clone());
class_object
.borrow_mut()
.as_function_mut()
Expand Down

0 comments on commit e375afd

Please sign in to comment.