Made WasmQueryState an iterable.

This commit is contained in:
constraintAutomaton
2025-04-10 19:02:04 +02:00
parent 20525e5013
commit 4e207fc34a

View File

@@ -78,6 +78,7 @@ impl WasmMachine {
), ),
} }
.into(); .into();
self_iterable(&query_state);
Ok(query_state) Ok(query_state)
} }
@@ -174,6 +175,21 @@ impl WasmQueryState {
} }
} }
/// Sets a [JsValue] as the `Symbol.iterator` property of the [JsValue].
///
/// If the [JsValue] conforms to the [JavaScript iterator interface](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators),
/// this function will make the [JsValue] iterable.
#[wasm_bindgen(inline_js = "
export function self_iterable(obj) {
obj[Symbol.iterator] = function () {
return this;
};
}
")]
extern "C" {
fn self_iterable(obj: &JsValue);
}
impl From<LeafAnswer> for JsValue { impl From<LeafAnswer> for JsValue {
fn from(leaf_answer: LeafAnswer) -> JsValue { fn from(leaf_answer: LeafAnswer) -> JsValue {
match leaf_answer { match leaf_answer {