Skip to content

Commit

Permalink
implement in keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Mar 31, 2024
1 parent fe02401 commit 176c91c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/dash_vm/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod handlers {
use dash_middle::interner::sym;
use if_chain::if_chain;
use smallvec::SmallVec;
use std::ops::{Add, Div, Mul, Rem, Sub};
use std::ops::{Add, ControlFlow, Div, Mul, Rem, Sub};

use crate::frame::{FrameState, TryBlock};
use crate::throw;
Expand Down Expand Up @@ -286,8 +286,26 @@ mod handlers {
Ok(None)
}

pub fn objin<'sc, 'vm>(cx: DispatchContext<'sc, 'vm>) -> Result<Option<HandleResult>, Unrooted> {
throw!(cx, Error, "in keyword is unimplemented");
pub fn objin<'sc, 'vm>(mut cx: DispatchContext<'sc, 'vm>) -> Result<Option<HandleResult>, Unrooted> {
cx.evaluate_binary_with_scope(|property, target, sc| {
let property = property.to_js_string(sc)?;
let found = target
.for_each_prototype(sc, |sc, target| {
let contains = target
.own_keys(sc)?
.iter()
.any(|v| matches!(v, Value::String(s) if *s == property));

if contains {
Ok(ControlFlow::Break(()))
} else {
Ok(ControlFlow::Continue(()))
}
})?
.is_break();

Ok(Value::Boolean(found))
})
}

pub fn instanceof<'sc, 'vm>(mut cx: DispatchContext<'sc, 'vm>) -> Result<Option<HandleResult>, Unrooted> {
Expand Down

0 comments on commit 176c91c

Please sign in to comment.