From: constraintAutomaton Date: Thu, 10 Apr 2025 17:02:04 +0000 (+0200) Subject: Made WasmQueryState an iterable. X-Git-Tag: v0.10.0~57^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=4e207fc34adfa2e8c85711fcd0142f4b193ff46c;p=scryer-prolog.git Made WasmQueryState an iterable. --- diff --git a/src/wasm.rs b/src/wasm.rs index 10430677..22234e16 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -78,6 +78,7 @@ impl WasmMachine { ), } .into(); + self_iterable(&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 for JsValue { fn from(leaf_answer: LeafAnswer) -> JsValue { match leaf_answer {