Merge pull request #2875 from constraintAutomaton/feature/wasm-result-iterator
Make `WasmQueryState` Iterable in JavaScript
This commit is contained in:
16
src/wasm.rs
16
src/wasm.rs
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user