Skip to content

Commit

Permalink
always encode has_default in objdestruct/arraydestruct
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Nov 7, 2024
1 parent f9c2008 commit a270009
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
3 changes: 3 additions & 0 deletions crates/dash_compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
.cp
.add_symbol(name)
.map_err(|_| Error::ConstantPoolLimitExceeded(span))?;
ib.write_bool(false); // Defaults are unsupported
ib.writew(var_id);
ib.writew(ident_id);
}
Expand Down Expand Up @@ -1179,6 +1180,8 @@ impl<'interner> Visitor<Result<(), Error>> for FunctionCompiler<'interner> {
.cp
.add_number(local as f64)
.map_err(|_| Error::ConstantPoolLimitExceeded(span))?;

ib.write_bool(false); // Defaults are unsupported
ib.writew(var_id);
}
ArrayMemberKind::Spread(_) => unimplementedc!(span, "rest operator in array destructuring is unsupported"),
Expand Down
16 changes: 8 additions & 8 deletions crates/dash_vm/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2089,15 +2089,15 @@ mod handlers {
idents.push(ident);
}

let mut prop = obj.get_property(&mut cx, ident.into())?;
let mut prop = obj.get_property(&mut cx, ident.into())?.root(&mut cx.scope);
if has_default {
// NB: we need to at least pop it from the stack even if the property exists
let default = cx.pop_stack();
if prop.is_undefined() {
let default = cx.pop_stack_rooted();
if matches!(prop.unpack(), ValueKind::Undefined(_)) {
prop = default;
}
}
cx.set_local(id as usize, prop);
cx.set_local(id as usize, prop.into());
}

if let Some(rest_id) = rest_id {
Expand Down Expand Up @@ -2132,16 +2132,16 @@ mod handlers {
if let Some((has_default, NumberWConstant(id))) = id {
let id = id as usize;
let key = cx.scope.intern_usize(i);
let mut prop = array.get_property(&mut cx.scope, key.into())?;
let mut prop = array.get_property(&mut cx.scope, key.into())?.root(&mut cx.scope);

if has_default {
// NB: we need to at least pop it from the stack even if the property exists
let default = cx.pop_stack();
if prop.is_undefined() {
let default = cx.pop_stack_rooted();
if matches!(prop.unpack(), ValueKind::Undefined(_)) {
prop = default;
}
}
cx.set_local(id, prop);
cx.set_local(id, prop.into());
}
}

Expand Down
6 changes: 0 additions & 6 deletions crates/dash_vm/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,6 @@ impl Unrooted {
Self { value }
}

/// Checks if this value is undefined.
/// As this does not require access to any garbage collected resources, this operation is safe without rooting.
pub fn is_undefined(self) -> bool {
matches!(self.value.unpack(), ValueKind::Undefined(_))
}

/// Returns an unprotected, unrooted reference to the value.
///
/// # Safety
Expand Down

0 comments on commit a270009

Please sign in to comment.