From 3b2c157e068a05c57e4ab30bb215b62d5c97781e Mon Sep 17 00:00:00 2001 From: y21 <30553356+y21@users.noreply.github.com> Date: Wed, 13 Nov 2024 00:43:50 +0100 Subject: [PATCH] reduce scope of refcell guards --- crates/dash_vm/src/value/array/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/dash_vm/src/value/array/mod.rs b/crates/dash_vm/src/value/array/mod.rs index 38b7ccbc..26ca5ba8 100644 --- a/crates/dash_vm/src/value/array/mod.rs +++ b/crates/dash_vm/src/value/array/mod.rs @@ -234,13 +234,11 @@ impl Object for Array { fn set_property(&self, sc: &mut LocalScope, key: PropertyKey, value: PropertyValue) -> Result<(), Value> { if let PropertyKey::String(key) = &key { - let mut items = self.items.borrow_mut(); - if key.sym() == sym::length { // TODO: this shouldnt be undefined let value = value.kind().get_or_apply(sc, This::Default).root(sc)?; if let Ok(new_len) = u32::try_from(value.to_number(sc)? as usize) { - items.resize(new_len); + self.items.borrow_mut().resize(new_len); return Ok(()); } @@ -249,7 +247,7 @@ impl Object for Array { if let Ok(index) = key.res(sc).parse::() { if index < MAX_LENGTH { - items.set(index, value); + self.items.borrow_mut().set(index, value); return Ok(()); } @@ -381,10 +379,10 @@ impl ArrayIterator { /// Equivalent to calling get_property, but specialized for arrays pub fn spec_array_get_property(scope: &mut LocalScope<'_>, target: &Value, index: usize) -> Result { - if let Some(arr) = target.unpack().downcast_ref::(scope) { - let inner = arr.items.borrow(); - if let Ok(index) = u32::try_from(index) { - if index < MAX_LENGTH { + if let Ok(index) = u32::try_from(index) { + if index < MAX_LENGTH { + if let Some(arr) = target.unpack().downcast_ref::(scope) { + let inner = arr.items.borrow(); return match inner.get(index) { Some(MaybeHoley::Some(value)) => value.get_or_apply(scope, This::Default), Some(MaybeHoley::Hole) | None => Ok(Value::undefined().into()),