]> Repositorios git - scryer-prolog.git/commitdiff
Made WasmQueryState an iterable.
authorconstraintAutomaton <[email protected]>
Thu, 10 Apr 2025 17:02:04 +0000 (19:02 +0200)
committerconstraintAutomaton <[email protected]>
Thu, 10 Apr 2025 17:02:04 +0000 (19:02 +0200)
src/wasm.rs

index 10430677ea75260fcb5ccc3d0a5d38b2d11602ae..22234e167410cb8dbcdcc12c73047e8b347a6d04 100644 (file)
@@ -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<LeafAnswer> for JsValue {
     fn from(leaf_answer: LeafAnswer) -> JsValue {
         match leaf_answer {