Skip to content

Commit

Permalink
Merge pull request #81 from y21/holey-arrays
Browse files Browse the repository at this point in the history
Experimental support for holey arrays
  • Loading branch information
y21 authored Mar 17, 2024
2 parents e352f58 + 2b90244 commit 61a0ba3
Show file tree
Hide file tree
Showing 7 changed files with 864 additions and 290 deletions.
7 changes: 7 additions & 0 deletions crates/dash_vm/src/gc/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ unsafe impl<T: Trace> Trace for Vec<T> {
}
}

unsafe impl<A: Trace, B: Trace> Trace for (A, B) {
fn trace(&self, cx: &mut TraceCtxt<'_>) {
self.0.trace(cx);
self.1.trace(cx);
}
}

unsafe impl<T: Trace> Trace for HashSet<T> {
fn trace(&self, cx: &mut TraceCtxt<'_>) {
for t in self.iter() {
Expand Down
11 changes: 7 additions & 4 deletions crates/dash_vm/src/js_std/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use crate::value::{array, Root, Value, ValueContext};

pub fn constructor(cx: CallContext) -> Result<Value, Value> {
let size = cx.args.first().unwrap_or_undefined().to_length_u(cx.scope)?;
// TODO: filling it with undefined values isn't right, but we don't have holey arrays yet.
let array = Array::from_vec(cx.scope, vec![PropertyValue::static_default(Value::undefined()); size]);
let array = Array::with_hole(cx.scope, size);
Ok(cx.scope.register(array).into())
}

Expand Down Expand Up @@ -146,8 +145,12 @@ pub fn fill(cx: CallContext) -> Result<Value, Value> {
let value = cx.args.first().unwrap_or_undefined();

for i in 0..len {
let pk = cx.scope.intern_usize(i);
this.set_property(cx.scope, pk.into(), PropertyValue::static_default(value.clone()))?;
array::spec_array_set_property(cx.scope, &this, i, PropertyValue::static_default(value.clone()))?;
}

if let Some(arr) = cx.this.downcast_ref::<Array>() {
// all holes were replaced with values, so there cannot be holes
arr.force_convert_to_non_holey();
}

Ok(this)
Expand Down
279 changes: 0 additions & 279 deletions crates/dash_vm/src/value/array.rs

This file was deleted.

Loading

0 comments on commit 61a0ba3

Please sign in to comment.