Switch to using JSON for wasm.
rust-build Build rust-build has failed Details
clippy Build clippy has failed Details
rustfmt Build rustfmt has succeeded Details
rust-foreign-document-test Build rust-foreign-document-test has succeeded Details
rust-test Build rust-test has succeeded Details

serde_wasm_bindgen was silently dropping many attributes (I suspect it is triggered by serde flatten) so this switches to serializing to JSON for passing values from wasm to js.
main
Tom Alexander 3 months ago
parent 64bb597908
commit 8406d37991
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -52,6 +52,7 @@ path = "src/lib.rs"
[dependencies]
futures = { version = "0.3.28", optional = true }
gloo-utils = "0.2.0"
nom = "7.1.1"
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-otlp = { version = "0.13.0", optional = true }

@ -1,3 +1,6 @@
use gloo_utils::format::JsValueSerdeExt;
use wasm_bindgen::JsValue;
use crate::parser::parse_with_settings;
use crate::settings::GlobalSettings;
use crate::wasm::ParseResult;
@ -8,17 +11,15 @@ pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
let rust_parsed = match parse_with_settings(org_contents, &GlobalSettings::default()) {
Ok(document) => document,
Err(err) => {
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
.unwrap();
return JsValue::from_serde(&ParseResult::Error(format!("{:?}", err))).unwrap();
}
};
let to_wasm_context = ToWasmContext::new(org_contents);
let wasm_document = match rust_parsed.to_wasm(to_wasm_context) {
Ok(document) => document,
Err(err) => {
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
.unwrap();
return JsValue::from_serde(&ParseResult::Error(format!("{:?}", err))).unwrap();
}
};
serde_wasm_bindgen::to_value(&ParseResult::Success(wasm_document)).unwrap()
JsValue::from_serde(&ParseResult::Success(wasm_document)).unwrap()
}

Loading…
Cancel
Save