Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
fix: form scripts run on Android, where the script engine stopped on every one (#30)
Joshc1199027ee53
diff --git a/crates/js/Cargo.toml b/crates/js/Cargo.tomlindex c0df850..7d701ef 100644--- a/crates/js/Cargo.toml+++ b/crates/js/Cargo.toml@@ -18,3 +18,8 @@ chrono = { workspace = true }[target.'cfg(target_arch = "wasm32")'.dependencies]boa_engine = { version = "0.22.0", default-features = false, features = ["annex-b", "js"] }++# Android tags heap pointers in their top byte, which boa's NaN-boxed values can't hold: every+# script stopped with "not compatible with a nan-boxed `JsValueInner`". The enum-based values there.+[target.'cfg(target_os = "android")'.dependencies]+boa_engine = { version = "0.22.0", default-features = false, features = ["annex-b", "jsvalue-enum"] }diff --git a/crates/js/src/lib.rs b/crates/js/src/lib.rsindex f2221f7..255a841 100644--- a/crates/js/src/lib.rs+++ b/crates/js/src/lib.rs@@ -1202,7 +1202,11 @@ pub fn run_shared(script: &str, event: &Event, doc: &DocInfo, fields: Arc<Vec<Fi.stack_size(SCRIPT_STACK).spawn_scoped(scope, || run_here(script, event, doc, fields, doc_scripts, limits));match spawned {- Ok(thread) => thread.join().unwrap_or_else(|_| failed("the script stopped with an internal error".into())),+ Ok(thread) => thread.join().unwrap_or_else(|panic| {+ // what went wrong, for the console: a panic's message is a &str or a String+ let why = panic.downcast_ref::<&str>().map(|s| s.to_string()).or_else(|| panic.downcast_ref::<String>().cloned());+ failed(format!("the script stopped with an internal error{}", why.map(|w| format!(": {w}")).unwrap_or_default()))+ }),Err(e) => failed(format!("the script engine could not start: {e}")),}})