feat(workspace): R2.4 core runtime — lazy load, poison on trap, offline re-instantiation, per-generation sheet handles
packages/core-wasm: browser-safe CoreRuntime (synchronous calls once ready; a WebAssembly.RuntimeError poisons the instance, the call answers internal, a fresh instance comes from the kept compiled module and a glue record imported in advance; at most 3 recoveries per page; retry after a load failure), SheetSession (handle rebuilt per instance generation, never called on a dropped one; invalid_sheet without poisoning), Node source. crates/wasm: SheetHandle (sheet held in the module memory). Two builds: pkg/ shipped without trap exports (checked), pkg-proofs/ for the trap tests; BUILD_STAMP (hash of the Rust sources) refused when missing or stale by the vitest global setup instead of skipping. Failure envelope carries a numeric found version; compact JS-number output.
This commit is contained in:
1 parent
22fea8736d
commit
343d6f4c1f
22 files changed
+783
-180
No files matched your search
@@ -176,6 +176,34 @@ pub fn to_js_pretty<T: Serialize + ?Sized>(value: &T) -> Result<String, serde_js
|
||||
String::from_utf8(buffer).map_err(<serde_json::Error as serde::ser::Error>::custom)
|
||||
}
|
||||
|
||||
/// `serde_json`'s compact formatter with JavaScript float printing (`JSON.stringify(value)`).
|
||||
#[derive(Default)]
|
||||
pub struct JsCompactFormatter;
|
||||
|
||||
impl Formatter for JsCompactFormatter {
|
||||
fn write_f32<W>(&mut self, writer: &mut W, value: f32) -> io::Result<()>
|
||||
where
|
||||
W: ?Sized + io::Write,
|
||||
{
|
||||
writer.write_all(js_number(f64::from(value)).as_bytes())
|
||||
}
|
||||
|
||||
fn write_f64<W>(&mut self, writer: &mut W, value: f64) -> io::Result<()>
|
||||
where
|
||||
W: ?Sized + io::Write,
|
||||
{
|
||||
writer.write_all(js_number(value).as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
/// Serialises `value` as `JSON.stringify(value)` would.
|
||||
pub fn to_js_compact<T: Serialize + ?Sized>(value: &T) -> Result<String, serde_json::Error> {
|
||||
let mut buffer = Vec::new();
|
||||
let mut serializer = serde_json::Serializer::with_formatter(&mut buffer, JsCompactFormatter);
|
||||
value.serialize(&mut serializer)?;
|
||||
String::from_utf8(buffer).map_err(<serde_json::Error as serde::ser::Error>::custom)
|
||||
}
|
||||
|
||||
/// Parses JSON text and re-emits it in the JavaScript pretty form, keeping the key order.
|
||||
pub fn pretty_js_round_trip(text: &str) -> Result<String, serde_json::Error> {
|
||||
let value: serde_json::Value = serde_json::from_str(text)?;
|
||||
@@ -215,6 +243,15 @@ mod tests {
|
||||
assert_eq!(js_number(f64::INFINITY), "null");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_output_prints_floats_as_javascript() {
|
||||
let value = serde_json::json!({"a": [1.0, 0.5, 1e21], "b": "\u{1}"});
|
||||
assert_eq!(
|
||||
to_js_compact(&value).ok().as_deref(),
|
||||
Some(r#"{"a":[1,0.5,1e+21],"b":"\u0001"}"#)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pretty_output_matches_the_javascript_shape() {
|
||||
let text = r#"{"b":[1,2.0,{"c":[]}],"a":{},"d":"é\u0001","e":-0.0}"#;
|
||||
|
||||
Reference in new issue
Block a user