@c9up/orbit 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/Cargo.lock +9 -16
  2. package/Cargo.toml +4 -0
  3. package/README.md +7 -1
  4. package/android/src/main/java/com/c9up/orbit/OrbitInput.kt +18 -2
  5. package/crates/orbit-host/Cargo.toml +1 -1
  6. package/crates/orbit-host/src/lib.rs +549 -115
  7. package/crates/orbit-host/src/vector.rs +312 -56
  8. package/dist/color.d.ts.map +1 -1
  9. package/dist/color.js +3 -3
  10. package/dist/color.js.map +1 -1
  11. package/dist/commit.d.ts +32 -0
  12. package/dist/commit.d.ts.map +1 -1
  13. package/dist/commit.js +142 -12
  14. package/dist/commit.js.map +1 -1
  15. package/dist/errors.d.ts +60 -26
  16. package/dist/errors.d.ts.map +1 -1
  17. package/dist/errors.js +85 -11
  18. package/dist/errors.js.map +1 -1
  19. package/dist/host.d.ts.map +1 -1
  20. package/dist/host.js +4 -2
  21. package/dist/host.js.map +1 -1
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +3 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/motion.d.ts.map +1 -1
  27. package/dist/motion.js +7 -6
  28. package/dist/motion.js.map +1 -1
  29. package/dist/pages.d.ts.map +1 -1
  30. package/dist/pages.js +3 -3
  31. package/dist/pages.js.map +1 -1
  32. package/dist/react-native/index.d.ts +9 -1
  33. package/dist/react-native/index.d.ts.map +1 -1
  34. package/dist/react-native/index.js +33 -5
  35. package/dist/react-native/index.js.map +1 -1
  36. package/dist/report.d.ts +13 -0
  37. package/dist/report.d.ts.map +1 -0
  38. package/dist/report.js +22 -0
  39. package/dist/report.js.map +1 -0
  40. package/dist/server.d.ts +27 -3
  41. package/dist/server.d.ts.map +1 -1
  42. package/dist/server.js +15 -7
  43. package/dist/server.js.map +1 -1
  44. package/dist/stack.d.ts.map +1 -1
  45. package/dist/stack.js +3 -3
  46. package/dist/stack.js.map +1 -1
  47. package/dist/styles.d.ts.map +1 -1
  48. package/dist/styles.js +2 -2
  49. package/dist/styles.js.map +1 -1
  50. package/dist/template.d.ts.map +1 -1
  51. package/dist/template.js +56 -12
  52. package/dist/template.js.map +1 -1
  53. package/dist/textDecoder.d.ts +29 -0
  54. package/dist/textDecoder.d.ts.map +1 -0
  55. package/dist/textDecoder.js +149 -0
  56. package/dist/textDecoder.js.map +1 -0
  57. package/dist/url.d.ts.map +1 -1
  58. package/dist/url.js +4 -3
  59. package/dist/url.js.map +1 -1
  60. package/package.json +13 -7
  61. package/scripts/build-android.sh +0 -0
  62. package/src/color.ts +5 -10
  63. package/src/commit.ts +184 -17
  64. package/src/errors.ts +174 -44
  65. package/src/host.ts +4 -5
  66. package/src/index.ts +5 -1
  67. package/src/motion.ts +8 -6
  68. package/src/pages.ts +3 -6
  69. package/src/react-native/index.ts +46 -7
  70. package/src/react-native/react-native.d.ts +8 -0
  71. package/src/report.ts +25 -0
  72. package/src/server.ts +50 -14
  73. package/src/stack.ts +3 -9
  74. package/src/styles.ts +2 -5
  75. package/src/template.ts +65 -41
  76. package/src/textDecoder.ts +162 -0
  77. package/src/url.ts +10 -3
@@ -10,6 +10,9 @@
10
10
  //! a compact binary list of mount operations for the platform layer (Kotlin)
11
11
  //! to apply to real views. Nodes no longer reachable from the root are dropped
12
12
  //! and their tags reported back so JS can forget them.
13
+ //!
14
+ //! A batch the host refuses may have been applied in part; JS then sends what
15
+ //! it carried again, so `"c"` on a tag the host holds replaces that node.
13
16
 
14
17
  use std::cell::RefCell;
15
18
  use std::collections::hash_map::DefaultHasher;
@@ -29,6 +32,13 @@ use taffy::prelude::*;
29
32
  pub type MeasureFn = extern "C" fn(spans: *const u8, len: usize, max_width: f32) -> u64;
30
33
 
31
34
  // Mount operation codes, shared with OrbitHost.kt.
35
+ /// How deep views may nest under the root (the root is level 1). taffy lays
36
+ /// a tree out by recursing once per level on the caller's stack — React
37
+ /// Native's JS thread, about 1 MiB — at about 6 KB a level (x86_64, release):
38
+ /// some 170 levels overflow it, and a stack overflow is not a panic
39
+ /// `catch_unwind` could stop. Deeper is refused, coded, before any layout.
40
+ pub const MAX_DEPTH: usize = 100;
41
+
32
42
  const OP_CREATE: u8 = 1;
33
43
  const OP_DELETE: u8 = 2;
34
44
  const OP_CHILDREN: u8 = 3;
@@ -157,6 +167,8 @@ pub struct CommitInfo {
157
167
  pub diff_us: u128,
158
168
  pub measures: u32,
159
169
  pub nodes: usize,
170
+ /// Values of drawings left out, coded (`E_ORBIT_SVG_VALUE: …`).
171
+ pub warnings: Vec<String>,
160
172
  }
161
173
 
162
174
  pub struct Host {
@@ -238,25 +250,41 @@ fn length_percentage_auto(v: &Value) -> LengthPercentageAuto {
238
250
  }
239
251
  }
240
252
 
253
+ /// A min or max size. Unparseable means no bound, as it did when these took a
254
+ /// `Dimension`; a margin or inset parses `length_percentage_auto` instead,
255
+ /// where unparseable means zero.
256
+ fn size_bound(v: &Value) -> LengthPercentageAuto {
257
+ match v {
258
+ Value::String(s) if s.ends_with('%') => s
259
+ .trim_end_matches('%')
260
+ .parse::<f32>()
261
+ .map(|p| LengthPercentageAuto::percent(p / 100.0))
262
+ .unwrap_or(LengthPercentageAuto::auto()),
263
+ _ => num(v)
264
+ .map(LengthPercentageAuto::length)
265
+ .unwrap_or(LengthPercentageAuto::auto()),
266
+ }
267
+ }
268
+
241
269
  fn align(v: &Value) -> Option<AlignItems> {
242
270
  match v.as_str()? {
243
- "flex-start" | "start" => Some(AlignItems::FlexStart),
244
- "flex-end" | "end" => Some(AlignItems::FlexEnd),
245
- "center" => Some(AlignItems::Center),
246
- "stretch" => Some(AlignItems::Stretch),
247
- "baseline" => Some(AlignItems::Baseline),
271
+ "flex-start" | "start" => Some(AlignItems::FLEX_START),
272
+ "flex-end" | "end" => Some(AlignItems::FLEX_END),
273
+ "center" => Some(AlignItems::CENTER),
274
+ "stretch" => Some(AlignItems::STRETCH),
275
+ "baseline" => Some(AlignItems::BASELINE),
248
276
  _ => None,
249
277
  }
250
278
  }
251
279
 
252
280
  fn justify(v: &Value) -> Option<JustifyContent> {
253
281
  match v.as_str()? {
254
- "flex-start" | "start" => Some(JustifyContent::FlexStart),
255
- "flex-end" | "end" => Some(JustifyContent::FlexEnd),
256
- "center" => Some(JustifyContent::Center),
257
- "space-between" => Some(JustifyContent::SpaceBetween),
258
- "space-around" => Some(JustifyContent::SpaceAround),
259
- "space-evenly" => Some(JustifyContent::SpaceEvenly),
282
+ "flex-start" | "start" => Some(JustifyContent::FLEX_START),
283
+ "flex-end" | "end" => Some(JustifyContent::FLEX_END),
284
+ "center" => Some(JustifyContent::CENTER),
285
+ "space-between" => Some(JustifyContent::SPACE_BETWEEN),
286
+ "space-around" => Some(JustifyContent::SPACE_AROUND),
287
+ "space-evenly" => Some(JustifyContent::SPACE_EVENLY),
260
288
  _ => None,
261
289
  }
262
290
  }
@@ -282,10 +310,14 @@ fn sides<T: Copy>(
282
310
  }
283
311
 
284
312
  fn style_of(props: &Map<String, Value>) -> Style {
285
- // React Native's defaults, not CSS's: column, no shrink.
313
+ // React Native's defaults, not CSS's: column, no shrink, and relative
314
+ // positioning — insets apply to every box and an absolute child is placed
315
+ // in its parent, not in the nearest positioned ancestor (taffy, like CSS,
316
+ // defaults to `static` since 0.15).
286
317
  let mut s = Style {
287
318
  flex_direction: FlexDirection::Column,
288
319
  flex_shrink: 0.0,
320
+ position: Position::Relative,
289
321
  ..Style::default()
290
322
  };
291
323
  if let Some(v) = props.get("flexDirection").and_then(Value::as_str) {
@@ -315,19 +347,30 @@ fn style_of(props: &Map<String, Value>) -> Style {
315
347
  if let Some(v) = props.get("flexBasis") {
316
348
  s.flex_basis = dimension(v);
317
349
  }
318
- s.align_items = props.get("alignItems").and_then(align);
350
+ // `normal` is what an unset value meant: stretch for align-items, start
351
+ // for justify-content, in a flex container.
352
+ s.align_items = props
353
+ .get("alignItems")
354
+ .and_then(align)
355
+ .unwrap_or(AlignItems::NORMAL);
319
356
  s.align_self = props.get("alignSelf").and_then(align);
320
- s.justify_content = props.get("justifyContent").and_then(justify);
357
+ s.justify_content = props
358
+ .get("justifyContent")
359
+ .and_then(justify)
360
+ .unwrap_or(JustifyContent::NORMAL);
361
+ for (key, slot) in [("width", &mut s.size.width), ("height", &mut s.size.height)] {
362
+ if let Some(v) = props.get(key) {
363
+ *slot = dimension(v);
364
+ }
365
+ }
321
366
  for (key, slot) in [
322
- ("width", &mut s.size.width),
323
- ("height", &mut s.size.height),
324
367
  ("minWidth", &mut s.min_size.width),
325
368
  ("minHeight", &mut s.min_size.height),
326
369
  ("maxWidth", &mut s.max_size.width),
327
370
  ("maxHeight", &mut s.max_size.height),
328
371
  ] {
329
372
  if let Some(v) = props.get(key) {
330
- *slot = dimension(v);
373
+ *slot = size_bound(v);
331
374
  }
332
375
  }
333
376
  s.padding = sides(
@@ -619,14 +662,17 @@ impl Host {
619
662
  }
620
663
 
621
664
  /// The Text node a text-bearing node belongs to (itself for a Text).
665
+ /// A path to the root is never longer than the tree is large: a longer
666
+ /// walk is going round a cycle a bad batch made.
622
667
  fn owning_text(&self, mut tag: i32) -> Option<i32> {
623
- loop {
668
+ for _ in 0..=self.nodes.len() {
624
669
  let node = self.nodes.get(&tag)?;
625
670
  if matches!(node.kind, Kind::Text | Kind::TextInput) {
626
671
  return Some(tag);
627
672
  }
628
673
  tag = *self.parent.get(&tag)?;
629
674
  }
675
+ None
630
676
  }
631
677
 
632
678
  /// Where nodes were laid out: `[x, y, width, height]` in the root's
@@ -639,7 +685,13 @@ impl Host {
639
685
  let own = self.tree.layout(id).ok()?;
640
686
  let (mut x, mut y) = (own.location.x, own.location.y);
641
687
  let mut at = tag;
688
+ let mut steps = 0;
642
689
  while let Some(&parent) = self.parent.get(&at) {
690
+ // A cycle a bad batch made (see `owning_text`).
691
+ steps += 1;
692
+ if steps > self.nodes.len() {
693
+ return None;
694
+ }
643
695
  if let Some(id) = self.nodes.get(&parent).and_then(|n| n.taffy) {
644
696
  let layout = self.tree.layout(id).ok()?;
645
697
  x += layout.location.x;
@@ -652,6 +704,52 @@ impl Host {
652
704
  .collect()
653
705
  }
654
706
 
707
+ /// Refuse a tree taffy would recurse into deeper than `MAX_DEPTH`: the
708
+ /// paths taffy follows, walked without recursion. A node reached again
709
+ /// (two parents) is not walked twice; a cycle never ends, so it is
710
+ /// refused as too deep.
711
+ fn check_depth(&self, root: NodeId) -> Result<(), String> {
712
+ let too_deep = || {
713
+ format!(
714
+ "E_ORBIT_TREE_TOO_DEEP: the views nest more than {MAX_DEPTH} levels deep, \
715
+ more than the host lays out"
716
+ )
717
+ };
718
+ // The levels below and including each node walked whole.
719
+ let mut height: HashMap<NodeId, usize> = HashMap::new();
720
+ // The path being walked: each node, its children, the next one to visit,
721
+ // and the tallest child seen so far.
722
+ let children = |id: NodeId| self.tree.children(id).unwrap_or_default();
723
+ let mut path: Vec<(NodeId, Vec<NodeId>, usize, usize)> = vec![(root, children(root), 0, 0)];
724
+ while let Some(top) = path.last_mut() {
725
+ let (id, kids, next, tallest) = (top.0, &top.1, top.2, top.3);
726
+ if let Some(&child) = kids.get(next) {
727
+ top.2 += 1;
728
+ let level = path.len() + 1;
729
+ if let Some(&h) = height.get(&child) {
730
+ if level - 1 + h > MAX_DEPTH {
731
+ return Err(too_deep());
732
+ }
733
+ if let Some(top) = path.last_mut() {
734
+ top.3 = top.3.max(h);
735
+ }
736
+ continue;
737
+ }
738
+ if level > MAX_DEPTH {
739
+ return Err(too_deep());
740
+ }
741
+ path.push((child, children(child), 0, 0));
742
+ } else {
743
+ path.pop();
744
+ height.insert(id, tallest + 1);
745
+ if let Some(parent) = path.last_mut() {
746
+ parent.3 = parent.3.max(tallest + 1);
747
+ }
748
+ }
749
+ }
750
+ Ok(())
751
+ }
752
+
655
753
  pub fn commit(&mut self, ops_json: &[u8], out: &mut Vec<u8>) -> Result<CommitInfo, String> {
656
754
  let mut info = CommitInfo::default();
657
755
  let t0 = Instant::now();
@@ -676,9 +774,15 @@ impl Host {
676
774
  .unwrap_or("")
677
775
  .to_owned();
678
776
  let vector = match (kind, props.get("vector")) {
679
- (Kind::Vector, Some(v)) => vector::encode(v)?,
777
+ (Kind::Vector, Some(v)) => vector::encode(v, &mut info.warnings),
680
778
  _ => Vec::new(),
681
779
  };
780
+ // Sent again after a refused batch the host had applied in part.
781
+ if let Some(old) = self.nodes.remove(&tag) {
782
+ if let Some(id) = old.taffy {
783
+ let _ = self.tree.remove(id);
784
+ }
785
+ }
682
786
  if kind.is_layout() {
683
787
  let flags = gesture_flags(&props);
684
788
  gesture::with(|g| g.set_node(tag, flags, kind == Kind::Scroll));
@@ -721,7 +825,7 @@ impl Host {
721
825
  node.text = t.to_owned();
722
826
  }
723
827
  if let (Kind::Vector, Some(v)) = (node.kind, patch.get("vector")) {
724
- node.vector = vector::encode(v)?;
828
+ node.vector = vector::encode(v, &mut info.warnings);
725
829
  }
726
830
  node.props.extend(patch);
727
831
  if let Some(id) = node.taffy {
@@ -793,6 +897,7 @@ impl Host {
793
897
  let Some(root_id) = self.nodes.get(&root).and_then(|n| n.taffy) else {
794
898
  return Ok(info);
795
899
  };
900
+ self.check_depth(root_id)?;
796
901
  let t1 = Instant::now();
797
902
  let mut root_style = self.tree.style(root_id).map_err(|e| e.to_string())?.clone();
798
903
  root_style.size = Size {
@@ -824,65 +929,76 @@ impl Host {
824
929
  width: AvailableSpace::Definite(self.viewport.0),
825
930
  height: AvailableSpace::Definite(self.viewport.1),
826
931
  },
827
- |known, available, _id, ctx, _style| {
828
- if let (Some(w), Some(h)) = (known.width, known.height) {
829
- return Size {
830
- width: w,
831
- height: h,
832
- };
833
- }
834
- let Some(tag) = ctx.map(|t| *t) else {
835
- return Size::ZERO;
836
- };
837
- let Some(encoded) = spans.get(&tag) else {
838
- return Size::ZERO;
839
- };
840
- let max_width = known.width.unwrap_or(match available.width {
841
- AvailableSpace::Definite(w) => w,
842
- AvailableSpace::MinContent => 0.0,
843
- AvailableSpace::MaxContent => f32::INFINITY,
844
- });
845
- let mut hasher = DefaultHasher::new();
846
- encoded.hash(&mut hasher);
847
- let hash = hasher.finish();
848
- let mut call = |width: f32| {
849
- measures += 1;
850
- match measure {
851
- Some(f) => {
852
- let packed = f(encoded.as_ptr(), encoded.len(), width);
853
- (
854
- f32::from_bits((packed >> 32) as u32),
855
- f32::from_bits(packed as u32),
856
- )
932
+ |input, _id, ctx, style| {
933
+ // Since taffy 0.14 the leaf's box model (padding, border,
934
+ // min/max, aspect ratio) is the caller's: compute_leaf_layout
935
+ // applies it around the content measure, as taffy did itself.
936
+ let tag = ctx.map(|t| *t);
937
+ taffy::compute_leaf_layout(
938
+ input,
939
+ style,
940
+ |_, _| 0.0,
941
+ |known, available| {
942
+ if let (Some(w), Some(h)) = (known.width, known.height) {
943
+ return Size {
944
+ width: w,
945
+ height: h,
946
+ };
857
947
  }
858
- // Desktop tests: 7 dp per byte, 16 dp per line.
859
- None => ((encoded.len() as f32 * 7.0).min(width), 16.0),
860
- }
861
- };
862
- // One platform call per text in the common case: its natural
863
- // size answers every constraint at least that wide. Only a
864
- // narrower constraint (wrapping) costs another call.
865
- let natural = *measure_cache
866
- .entry((hash, f32::INFINITY.to_bits()))
867
- .or_insert_with(|| call(f32::INFINITY));
868
- let (w, h) = if max_width >= natural.0 {
869
- natural
870
- } else {
871
- *measure_cache
872
- .entry((hash, max_width.to_bits()))
873
- .or_insert_with(|| call(max_width))
874
- };
875
- // A field is as wide as its box says, like an HTML input:
876
- // its text does not size it. 160 dp when nothing does.
877
- let w = if inputs.contains(&tag) {
878
- DEFAULT_INPUT_WIDTH
879
- } else {
880
- w
881
- };
882
- Size {
883
- width: known.width.unwrap_or(w),
884
- height: known.height.unwrap_or(h),
885
- }
948
+ let Some(tag) = tag else {
949
+ return Size::ZERO;
950
+ };
951
+ let Some(encoded) = spans.get(&tag) else {
952
+ return Size::ZERO;
953
+ };
954
+ let max_width = known.width.unwrap_or(match available.width {
955
+ AvailableSpace::Definite(w) => w,
956
+ AvailableSpace::MinContent => 0.0,
957
+ AvailableSpace::MaxContent => f32::INFINITY,
958
+ });
959
+ let mut hasher = DefaultHasher::new();
960
+ encoded.hash(&mut hasher);
961
+ let hash = hasher.finish();
962
+ let mut call = |width: f32| {
963
+ measures += 1;
964
+ match measure {
965
+ Some(f) => {
966
+ let packed = f(encoded.as_ptr(), encoded.len(), width);
967
+ (
968
+ f32::from_bits((packed >> 32) as u32),
969
+ f32::from_bits(packed as u32),
970
+ )
971
+ }
972
+ // Desktop tests: 7 dp per byte, 16 dp per line.
973
+ None => ((encoded.len() as f32 * 7.0).min(width), 16.0),
974
+ }
975
+ };
976
+ // One platform call per text in the common case: its natural
977
+ // size answers every constraint at least that wide. Only a
978
+ // narrower constraint (wrapping) costs another call.
979
+ let natural = *measure_cache
980
+ .entry((hash, f32::INFINITY.to_bits()))
981
+ .or_insert_with(|| call(f32::INFINITY));
982
+ let (w, h) = if max_width >= natural.0 {
983
+ natural
984
+ } else {
985
+ *measure_cache
986
+ .entry((hash, max_width.to_bits()))
987
+ .or_insert_with(|| call(max_width))
988
+ };
989
+ // A field is as wide as its box says, like an HTML input:
990
+ // its text does not size it. 160 dp when nothing does.
991
+ let w = if inputs.contains(&tag) {
992
+ DEFAULT_INPUT_WIDTH
993
+ } else {
994
+ w
995
+ };
996
+ Size {
997
+ width: known.width.unwrap_or(w),
998
+ height: known.height.unwrap_or(h),
999
+ }
1000
+ },
1001
+ )
886
1002
  },
887
1003
  )
888
1004
  .map_err(|e| e.to_string())?;
@@ -1093,23 +1209,48 @@ impl OrbitBuf {
1093
1209
  }
1094
1210
  }
1095
1211
 
1212
+ /// Run an exported function's body. A panic must not unwind into the C++
1213
+ /// caller (that aborts the app): it becomes `fallback()` instead. This covers
1214
+ /// panics only — a stack overflow is not one, which is what `MAX_DEPTH` is for.
1215
+ fn guarded<T>(fallback: impl FnOnce() -> T, body: impl FnOnce() -> T) -> T {
1216
+ std::panic::catch_unwind(std::panic::AssertUnwindSafe(body)).unwrap_or_else(|_| fallback())
1217
+ }
1218
+
1219
+ /// `len` items at `ptr`, or none when there are none (a null pointer included).
1220
+ ///
1221
+ /// # Safety
1222
+ /// When `len > 0`, `ptr` must point to `len` readable items.
1223
+ unsafe fn items<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
1224
+ if ptr.is_null() || len == 0 {
1225
+ &[]
1226
+ } else {
1227
+ std::slice::from_raw_parts(ptr, len)
1228
+ }
1229
+ }
1230
+
1096
1231
  /// # Safety
1097
1232
  /// `buf` must come from this library and be freed once.
1098
1233
  #[no_mangle]
1099
1234
  pub unsafe extern "C" fn orbit_buf_free(buf: OrbitBuf) {
1100
1235
  if !buf.ptr.is_null() {
1101
- drop(Vec::from_raw_parts(buf.ptr, buf.len, buf.cap));
1236
+ guarded(
1237
+ || (),
1238
+ || drop(Vec::from_raw_parts(buf.ptr, buf.len, buf.cap)),
1239
+ );
1102
1240
  }
1103
1241
  }
1104
1242
 
1105
1243
  #[no_mangle]
1106
1244
  pub extern "C" fn orbit_set_measure(measure: MeasureFn) {
1107
- HOST.with(|h| h.borrow_mut().set_measure(measure));
1245
+ guarded(|| (), || HOST.with(|h| h.borrow_mut().set_measure(measure)));
1108
1246
  }
1109
1247
 
1110
1248
  #[no_mangle]
1111
1249
  pub extern "C" fn orbit_set_viewport(width: f32, height: f32) {
1112
- HOST.with(|h| h.borrow_mut().set_viewport(width, height));
1250
+ guarded(
1251
+ || (),
1252
+ || HOST.with(|h| h.borrow_mut().set_viewport(width, height)),
1253
+ );
1113
1254
  }
1114
1255
 
1115
1256
  fn panic_message(payload: Box<dyn std::any::Any + Send>) -> String {
@@ -1129,6 +1270,7 @@ fn info_json(info: &CommitInfo, ops_bytes: usize) -> String {
1129
1270
  "measures": info.measures,
1130
1271
  "nodes": info.nodes,
1131
1272
  "opsBytes": ops_bytes,
1273
+ "warnings": info.warnings,
1132
1274
  })
1133
1275
  .to_string()
1134
1276
  }
@@ -1147,8 +1289,11 @@ pub unsafe extern "C" fn orbit_touch(
1147
1289
  hit: i32,
1148
1290
  out: *mut OrbitBuf,
1149
1291
  ) {
1150
- let mut commands = Vec::new();
1151
- gesture::with(|g| g.touch(action, x, y, now_ns, hit, &mut commands));
1292
+ let commands = guarded(Vec::new, || {
1293
+ let mut commands = Vec::new();
1294
+ gesture::with(|g| g.touch(action, x, y, now_ns, hit, &mut commands));
1295
+ commands
1296
+ });
1152
1297
  *out = OrbitBuf::from_vec(commands);
1153
1298
  }
1154
1299
 
@@ -1158,27 +1303,37 @@ pub unsafe extern "C" fn orbit_touch(
1158
1303
  /// `out` must be valid.
1159
1304
  #[no_mangle]
1160
1305
  pub unsafe extern "C" fn orbit_gesture_tick(now_ns: i64, out: *mut OrbitBuf) {
1161
- let mut commands = Vec::new();
1162
- gesture::with(|g| g.tick(now_ns, &mut commands));
1306
+ let commands = guarded(Vec::new, || {
1307
+ let mut commands = Vec::new();
1308
+ gesture::with(|g| g.tick(now_ns, &mut commands));
1309
+ commands
1310
+ });
1163
1311
  *out = OrbitBuf::from_vec(commands);
1164
1312
  }
1165
1313
 
1166
1314
  /// The frames of a JSON array of tags, as a JSON array of `[x, y, w, h]` or
1167
- /// null (see `Host::frames`). Returns 0, or 1 with `{"error": …}`.
1315
+ /// null (see `Host::frames`). Returns 0, 1 with `{"error": …}`, or 2 when it
1316
+ /// panicked.
1168
1317
  ///
1169
1318
  /// # Safety
1170
1319
  /// `tags` must point to `len` readable bytes; `out` must be valid.
1171
1320
  #[no_mangle]
1172
1321
  pub unsafe extern "C" fn orbit_layout(tags: *const u8, len: usize, out: *mut OrbitBuf) -> i32 {
1173
- let input = std::slice::from_raw_parts(tags, len);
1174
- let (code, json) = match serde_json::from_slice::<Vec<i32>>(input) {
1322
+ let input = items(tags, len);
1323
+ let result = std::panic::catch_unwind(|| match serde_json::from_slice::<Vec<i32>>(input) {
1175
1324
  Ok(tags) => (
1176
1325
  0,
1177
1326
  serde_json::to_string(&HOST.with(|h| h.borrow().frames(&tags)))
1178
1327
  .unwrap_or_else(|_| "[]".to_owned()),
1179
1328
  ),
1180
1329
  Err(e) => (1, serde_json::json!({ "error": e.to_string() }).to_string()),
1181
- };
1330
+ });
1331
+ let (code, json) = result.unwrap_or_else(|p| {
1332
+ (
1333
+ 2,
1334
+ serde_json::json!({ "error": panic_message(p) }).to_string(),
1335
+ )
1336
+ });
1182
1337
  *out = OrbitBuf::from_vec(json.into_bytes());
1183
1338
  code
1184
1339
  }
@@ -1195,7 +1350,7 @@ pub unsafe extern "C" fn orbit_commit(
1195
1350
  mount_ops: *mut OrbitBuf,
1196
1351
  info: *mut OrbitBuf,
1197
1352
  ) -> i32 {
1198
- let input = std::slice::from_raw_parts(ops, len);
1353
+ let input = items(ops, len);
1199
1354
  let result = std::panic::catch_unwind(|| {
1200
1355
  HOST.with(|h| {
1201
1356
  let mut out = Vec::new();
@@ -1222,7 +1377,7 @@ pub unsafe extern "C" fn orbit_commit(
1222
1377
 
1223
1378
  #[no_mangle]
1224
1379
  pub extern "C" fn orbit_motion_value(tag: i32, initial: f64) {
1225
- motion::with(|m| m.value(tag, initial));
1380
+ guarded(|| (), || motion::with(|m| m.value(tag, initial)));
1226
1381
  }
1227
1382
 
1228
1383
  /// # Safety
@@ -1235,19 +1390,22 @@ pub unsafe extern "C" fn orbit_motion_interpolate(
1235
1390
  to: *const f64,
1236
1391
  len: usize,
1237
1392
  ) {
1238
- let from = std::slice::from_raw_parts(from, len).to_vec();
1239
- let to = std::slice::from_raw_parts(to, len).to_vec();
1240
- motion::with(|m| m.interpolation(tag, input, from, to));
1393
+ let from = items(from, len).to_vec();
1394
+ let to = items(to, len).to_vec();
1395
+ guarded(
1396
+ || (),
1397
+ || motion::with(|m| m.interpolation(tag, input, from, to)),
1398
+ );
1241
1399
  }
1242
1400
 
1243
1401
  #[no_mangle]
1244
1402
  pub extern "C" fn orbit_motion_set(tag: i32, value: f64) {
1245
- motion::with(|m| m.set(tag, value));
1403
+ guarded(|| (), || motion::with(|m| m.set(tag, value)));
1246
1404
  }
1247
1405
 
1248
1406
  #[no_mangle]
1249
1407
  pub extern "C" fn orbit_motion_stop(tag: i32) {
1250
- motion::with(|m| m.stop(tag));
1408
+ guarded(|| (), || motion::with(|m| m.stop(tag)));
1251
1409
  }
1252
1410
 
1253
1411
  /// # Safety
@@ -1260,28 +1418,37 @@ pub unsafe extern "C" fn orbit_motion_frames(
1260
1418
  to: f64,
1261
1419
  looping: bool,
1262
1420
  ) {
1263
- let frames = std::slice::from_raw_parts(frames, len).to_vec();
1264
- motion::with(|m| m.frames(tag, frames, to, looping));
1421
+ let frames = items(frames, len).to_vec();
1422
+ guarded(
1423
+ || (),
1424
+ || motion::with(|m| m.frames(tag, frames, to, looping)),
1425
+ );
1265
1426
  }
1266
1427
 
1267
1428
  #[no_mangle]
1268
1429
  pub extern "C" fn orbit_motion_spring(tag: i32, to: f64, stiffness: f64, damping: f64, mass: f64) {
1269
- motion::with(|m| m.spring(tag, to, stiffness, damping, mass));
1430
+ guarded(
1431
+ || (),
1432
+ || motion::with(|m| m.spring(tag, to, stiffness, damping, mass)),
1433
+ );
1270
1434
  }
1271
1435
 
1272
1436
  #[no_mangle]
1273
1437
  pub extern "C" fn orbit_motion_dispose(tag: i32) {
1274
- motion::with(|m| m.dispose(tag));
1438
+ guarded(|| (), || motion::with(|m| m.dispose(tag)));
1275
1439
  }
1276
1440
 
1277
1441
  #[no_mangle]
1278
1442
  pub extern "C" fn orbit_motion_bind(view: i32, prop: u8, node: i32) {
1279
- motion::with(|m| m.bind(view, prop, node));
1443
+ guarded(|| (), || motion::with(|m| m.bind(view, prop, node)));
1280
1444
  }
1281
1445
 
1282
1446
  #[no_mangle]
1283
1447
  pub extern "C" fn orbit_motion_bind_scroll(scroll_view: i32, value: i32) {
1284
- motion::with(|m| m.bind_scroll(scroll_view, value));
1448
+ guarded(
1449
+ || (),
1450
+ || motion::with(|m| m.bind_scroll(scroll_view, value)),
1451
+ );
1285
1452
  }
1286
1453
 
1287
1454
  /// Advance every animation to `now_ns` (UI thread). `scroll_tags`/`scroll_y`
@@ -1298,19 +1465,17 @@ pub unsafe extern "C" fn orbit_motion_tick(
1298
1465
  count: usize,
1299
1466
  out: *mut OrbitBuf,
1300
1467
  ) -> i32 {
1301
- let tags = if count == 0 {
1302
- &[][..]
1303
- } else {
1304
- std::slice::from_raw_parts(scroll_tags, count)
1305
- };
1306
- let ys = if count == 0 {
1307
- &[][..]
1308
- } else {
1309
- std::slice::from_raw_parts(scroll_y, count)
1310
- };
1468
+ let tags = items(scroll_tags, count);
1469
+ let ys = items(scroll_y, count);
1311
1470
  let scrolls: Vec<(i32, f32)> = tags.iter().copied().zip(ys.iter().copied()).collect();
1312
- let mut buf = Vec::new();
1313
- let active = motion::with(|m| m.tick(now_ns, &scrolls, &mut buf));
1471
+ let (active, buf) = guarded(
1472
+ || (false, Vec::new()),
1473
+ || {
1474
+ let mut buf = Vec::new();
1475
+ let active = motion::with(|m| m.tick(now_ns, &scrolls, &mut buf));
1476
+ (active, buf)
1477
+ },
1478
+ );
1314
1479
  *out = OrbitBuf::from_vec(buf);
1315
1480
  i32::from(active)
1316
1481
  }
@@ -1468,7 +1633,9 @@ mod tests {
1468
1633
  assert_eq!(codes(&third), vec![OP_VECTOR]);
1469
1634
 
1470
1635
  let broken = r#"[["u",3,{"vector":{"root":{"t":"svg","a":{"viewBox":"0 0 1 1"},"c":[{"t":"path","a":{"d":"M0 0 Q"}}]}}}]]"#;
1471
- assert!(host.commit(broken.as_bytes(), &mut Vec::new()).is_err());
1636
+ // Path data in error is drawn up to the error and reported, not refused.
1637
+ let (_, info) = commit(&mut host, broken);
1638
+ assert_eq!(info.warnings.len(), 1);
1472
1639
  }
1473
1640
 
1474
1641
  #[test]
@@ -1605,4 +1772,271 @@ mod tests {
1605
1772
  assert_eq!(info.deleted, vec![3]);
1606
1773
  assert_eq!(codes(&out), vec![OP_CHILDREN, OP_DELETE]);
1607
1774
  }
1775
+
1776
+ /// Frames of every tag in `tags`, in the root's coordinates.
1777
+ fn layout_of(ops: &str, tags: &[i32]) -> Vec<Option<[f32; 4]>> {
1778
+ let mut host = Host::default();
1779
+ host.set_viewport(300.0, 600.0);
1780
+ commit(&mut host, ops);
1781
+ host.frames(tags)
1782
+ }
1783
+
1784
+ /// The boxes React Native's rules give, checked against the frames taffy
1785
+ /// 0.9 produced before the move to 0.15 (identical on every scene): an
1786
+ /// absolute child placed in its parent, insets moving an in-flow box,
1787
+ /// alignment, min/max sizes (unparseable means no bound), wrapping, flex
1788
+ /// sizing, aspect ratio, a measured text in a padded box, a scroll view.
1789
+ #[test]
1790
+ fn lays_out_boxes_by_react_natives_rules() {
1791
+ type Frames = Vec<Option<[f32; 4]>>;
1792
+ let scenes: &[(&str, &[i32], Frames)] = &[
1793
+ // absolute child of a nested box: placed in its parent, insets from it
1794
+ (
1795
+ r#"[["c",1,"RCTView",{"padding":10}],["c",3,"RCTView",{"margin":20,"height":100,"padding":5}],
1796
+ ["c",5,"RCTView",{"position":"absolute","top":4,"right":6,"width":30,"height":30}],
1797
+ ["c",7,"RCTView",{"position":"absolute","left":"10%","bottom":0,"height":10,"right":0}],
1798
+ ["k",3,[5,7]],["k",1,[3]],["r",1]]"#,
1799
+ &[3, 5, 7],
1800
+ vec![
1801
+ Some([30.0, 30.0, 240.0, 100.0]),
1802
+ Some([234.0, 34.0, 30.0, 30.0]),
1803
+ Some([54.0, 120.0, 216.0, 10.0]),
1804
+ ],
1805
+ ),
1806
+ // insets on an in-flow box move it (relative positioning)
1807
+ (
1808
+ r#"[["c",1,"RCTView",{}],["c",3,"RCTView",{"height":40,"top":7,"left":9}],["c",5,"RCTView",{"height":40}],
1809
+ ["k",1,[3,5]],["r",1]]"#,
1810
+ &[3, 5],
1811
+ vec![
1812
+ Some([9.0, 7.0, 300.0, 40.0]),
1813
+ Some([0.0, 40.0, 300.0, 40.0]),
1814
+ ],
1815
+ ),
1816
+ // alignment: center, flex-end, space-between, alignSelf, stretch by default
1817
+ (
1818
+ r#"[["c",1,"RCTView",{"flexDirection":"row","justifyContent":"space-between","alignItems":"center","height":100}],
1819
+ ["c",3,"RCTView",{"width":50,"height":20}],["c",5,"RCTView",{"width":50,"alignSelf":"stretch"}],
1820
+ ["c",7,"RCTView",{"width":50,"height":30,"alignSelf":"flex-end"}],
1821
+ ["c",9,"RCTView",{"height":60}],["c",11,"RCTView",{"height":10,"marginHorizontal":15}],
1822
+ ["k",9,[11]],["k",1,[3,5,7]],["c",13,"RCTView",{}],["k",13,[1,9]],["r",13]]"#,
1823
+ &[1, 3, 5, 7, 9, 11],
1824
+ vec![
1825
+ Some([0.0, 0.0, 300.0, 100.0]),
1826
+ Some([0.0, 40.0, 50.0, 20.0]),
1827
+ Some([125.0, 0.0, 50.0, 100.0]),
1828
+ Some([250.0, 70.0, 50.0, 30.0]),
1829
+ Some([0.0, 100.0, 300.0, 60.0]),
1830
+ Some([15.0, 100.0, 270.0, 10.0]),
1831
+ ],
1832
+ ),
1833
+ // justify center / flex-end, space-around, space-evenly
1834
+ (
1835
+ r#"[["c",1,"RCTView",{}],["c",3,"RCTView",{"flexDirection":"row","justifyContent":"center","height":20}],
1836
+ ["c",5,"RCTView",{"width":40,"height":10}],["c",7,"RCTView",{"flexDirection":"row","justifyContent":"space-evenly","height":20}],
1837
+ ["c",9,"RCTView",{"width":40,"height":10}],["c",11,"RCTView",{"width":40,"height":10}],
1838
+ ["k",3,[5]],["k",7,[9,11]],["k",1,[3,7]],["r",1]]"#,
1839
+ &[5, 9, 11],
1840
+ vec![
1841
+ Some([130.0, 0.0, 40.0, 10.0]),
1842
+ Some([73.0, 20.0, 40.0, 10.0]),
1843
+ Some([187.0, 20.0, 40.0, 10.0]),
1844
+ ],
1845
+ ),
1846
+ // min / max sizes: lengths, percentages, unparseable values
1847
+ (
1848
+ r#"[["c",1,"RCTView",{"alignItems":"flex-start"}],["c",3,"RCTView",{"minWidth":120,"height":10}],
1849
+ ["c",5,"RCTView",{"width":250,"maxWidth":"50%","height":10}],["c",7,"RCTView",{"maxWidth":"wide","width":200,"height":10}],
1850
+ ["c",9,"RCTView",{"minHeight":"nope","height":10,"width":10}],["c",11,"RCTView",{"flex":1,"maxHeight":50}],
1851
+ ["k",1,[3,5,7,9,11]],["r",1]]"#,
1852
+ &[3, 5, 7, 9, 11],
1853
+ vec![
1854
+ Some([0.0, 0.0, 120.0, 10.0]),
1855
+ Some([0.0, 10.0, 150.0, 10.0]),
1856
+ Some([0.0, 20.0, 200.0, 10.0]),
1857
+ Some([0.0, 30.0, 10.0, 10.0]),
1858
+ Some([0.0, 40.0, 0.0, 50.0]),
1859
+ ],
1860
+ ),
1861
+ // wrap, flex grow / shrink / basis, aspect ratio, percentage widths
1862
+ (
1863
+ r#"[["c",1,"RCTView",{"flexDirection":"row","flexWrap":"wrap","padding":4}],
1864
+ ["c",3,"RCTView",{"width":"40%","aspectRatio":2}],["c",5,"RCTView",{"width":"40%","height":15}],
1865
+ ["c",7,"RCTView",{"width":"40%","height":25}],["c",9,"RCTView",{"flexGrow":1,"height":5}],
1866
+ ["c",11,"RCTView",{"flexDirection":"row","height":30}],["c",13,"RCTView",{"flex":1}],["c",15,"RCTView",{"flex":2}],
1867
+ ["c",17,"RCTView",{"flexBasis":60,"flexShrink":1}],["k",11,[13,15,17]],
1868
+ ["c",19,"RCTView",{}],["k",1,[3,5,7,9]],["k",19,[1,11]],["r",19]]"#,
1869
+ &[1, 3, 5, 7, 9, 13, 15, 17],
1870
+ vec![
1871
+ Some([0.0, 0.0, 300.0, 91.0]),
1872
+ Some([4.0, 4.0, 117.0, 58.0]),
1873
+ Some([121.0, 4.0, 117.0, 15.0]),
1874
+ Some([4.0, 62.0, 117.0, 25.0]),
1875
+ Some([121.0, 62.0, 175.0, 5.0]),
1876
+ Some([0.0, 91.0, 80.0, 30.0]),
1877
+ Some([80.0, 91.0, 160.0, 30.0]),
1878
+ Some([240.0, 91.0, 60.0, 30.0]),
1879
+ ],
1880
+ ),
1881
+ // measured text in a padded, bordered box, wrapping under a narrow width
1882
+ (
1883
+ r#"[["c",1,"RCTView",{"alignItems":"flex-start"}],["c",3,"RCTText",{"fontSize":12,"padding":6,"borderWidth":2}],
1884
+ ["c",5,"RCTRawText",{"text":"hello world"}],["c",7,"RCTText",{"fontSize":12,"width":40,"paddingHorizontal":3}],
1885
+ ["c",9,"RCTRawText",{"text":"a long sentence that wraps"}],["k",3,[5]],["k",7,[9]],["k",1,[3,7]],["r",1]]"#,
1886
+ &[3, 7],
1887
+ vec![Some([0.0, 0.0, 268.0, 32.0]), Some([0.0, 32.0, 40.0, 16.0])],
1888
+ ),
1889
+ // scroll view: content child grows past the frame
1890
+ (
1891
+ r#"[["c",1,"RCTView",{}],["c",3,"RCTScrollView",{"height":100}],["c",5,"RCTView",{}],
1892
+ ["c",7,"RCTView",{"height":400}],["k",5,[7]],["k",3,[5]],["k",1,[3]],["r",1]]"#,
1893
+ &[3, 5, 7],
1894
+ vec![
1895
+ Some([0.0, 0.0, 300.0, 100.0]),
1896
+ Some([0.0, 0.0, 300.0, 400.0]),
1897
+ Some([0.0, 0.0, 300.0, 400.0]),
1898
+ ],
1899
+ ),
1900
+ ];
1901
+ for (i, (ops, tags, expected)) in scenes.iter().enumerate() {
1902
+ assert_eq!(&layout_of(ops, tags), expected, "scene {i}");
1903
+ }
1904
+ }
1905
+
1906
+ /// A chain of `depth` nested views, `extra` ops appended before the root.
1907
+ fn chain(depth: usize, extra: &str) -> String {
1908
+ let mut ops = String::from("[");
1909
+ for i in 1..=depth {
1910
+ ops.push_str(&format!(r#"["c",{},"RCTView",{{"padding":1}}],"#, i * 2));
1911
+ }
1912
+ for i in 1..depth {
1913
+ ops.push_str(&format!(r#"["k",{},[{}]],"#, i * 2, i * 2 + 2));
1914
+ }
1915
+ ops.push_str(extra);
1916
+ ops.push_str(r#"["r",2]]"#);
1917
+ ops
1918
+ }
1919
+
1920
+ #[test]
1921
+ fn refuses_views_nested_deeper_than_the_bound_before_layout() {
1922
+ let mut host = Host::default();
1923
+ host.set_viewport(300.0, 600.0);
1924
+ let mut out = Vec::new();
1925
+ assert!(host
1926
+ .commit(chain(MAX_DEPTH, "").as_bytes(), &mut out)
1927
+ .is_ok());
1928
+ let mut host = Host::default();
1929
+ let mut out = Vec::new();
1930
+ let error = host
1931
+ .commit(chain(MAX_DEPTH + 1, "").as_bytes(), &mut out)
1932
+ .unwrap_err();
1933
+ assert!(error.starts_with("E_ORBIT_TREE_TOO_DEEP: "), "{error}");
1934
+ assert!(out.is_empty());
1935
+ // Text runs are not laid out: a deep chain of them does not count.
1936
+ let mut ops = chain(MAX_DEPTH - 1, "");
1937
+ ops.truncate(ops.len() - r#"["r",2]]"#.len());
1938
+ let last = MAX_DEPTH * 2 - 2;
1939
+ ops.push_str(&format!(
1940
+ r#"["c",9001,"RCTText",{{}}],["c",9003,"RCTVirtualText",{{}}],["c",9005,"RCTRawText",{{"text":"x"}}],["k",9003,[9005]],["k",9001,[9003]],["k",{last},[9001]],["r",2]]"#
1941
+ ));
1942
+ let mut host = Host::default();
1943
+ assert!(host.commit(ops.as_bytes(), &mut Vec::new()).is_ok());
1944
+ }
1945
+
1946
+ #[test]
1947
+ fn refuses_a_cycle_and_counts_a_moved_view_where_it_is() {
1948
+ // 2 → 4 → 6 → 2: the walk taffy would do never ends.
1949
+ let mut host = Host::default();
1950
+ let error = host
1951
+ .commit(chain(3, r#"["k",6,[2]],"#).as_bytes(), &mut Vec::new())
1952
+ .unwrap_err();
1953
+ assert!(error.starts_with("E_ORBIT_TREE_TOO_DEEP: "), "{error}");
1954
+ // A view listed under a second parent moves there, as taffy moves it:
1955
+ // the deepest one of a chain of MAX_DEPTH, moved under the root.
1956
+ let mut host = Host::default();
1957
+ let moved = chain(MAX_DEPTH, &format!(r#"["k",2,[4,{}]],"#, MAX_DEPTH * 2));
1958
+ assert!(host.commit(moved.as_bytes(), &mut Vec::new()).is_ok());
1959
+ let deeper = chain(
1960
+ MAX_DEPTH + 1,
1961
+ &format!(r#"["k",2,[4,{}]],"#, MAX_DEPTH * 2 + 2),
1962
+ );
1963
+ assert!(Host::default()
1964
+ .commit(deeper.as_bytes(), &mut Vec::new())
1965
+ .is_ok());
1966
+ let error = Host::default()
1967
+ .commit(chain(MAX_DEPTH + 1, "").as_bytes(), &mut Vec::new())
1968
+ .unwrap_err();
1969
+ assert!(error.starts_with("E_ORBIT_TREE_TOO_DEEP: "), "{error}");
1970
+ }
1971
+
1972
+ #[test]
1973
+ fn creating_a_tag_it_holds_replaces_that_node() {
1974
+ let mut host = Host::default();
1975
+ host.set_viewport(300.0, 600.0);
1976
+ let ops = r#"[["c",1,"RCTView",{}],["c",3,"RCTView",{"height":20}],["k",1,[3]],["r",1]]"#;
1977
+ commit(&mut host, ops);
1978
+ let before = host.tree.total_node_count();
1979
+ // A refused batch sent again: the same creates and children.
1980
+ let (_, info) = commit(
1981
+ &mut host,
1982
+ r#"[["c",3,"RCTView",{"height":30}],["k",1,[3]]]"#,
1983
+ );
1984
+ assert_eq!(host.tree.total_node_count(), before);
1985
+ assert!(info.deleted.is_empty());
1986
+ assert_eq!(host.frames(&[3]), vec![Some([0.0, 0.0, 300.0, 30.0])]);
1987
+ }
1988
+
1989
+ #[test]
1990
+ fn a_drawing_value_it_cannot_read_costs_that_shape_not_the_commit() {
1991
+ let mut host = Host::default();
1992
+ host.set_viewport(300.0, 600.0);
1993
+ let ops = r#"[["c",1,"RCTView",{}],["c",3,"OrbitVector",{"width":100,"height":50,"vector":{"color":-16777216,"root":
1994
+ {"t":"svg","a":{"viewBox":"0 0 100 50"},"c":[
1995
+ {"t":"rect","a":{"width":"40","height":"NaN"},"c":[]},
1996
+ {"t":"g","a":{"transform":")("},"c":[]},
1997
+ {"t":"rect","a":{"width":"40","height":"20"},"c":[]}]}}}],["k",1,[3]],["r",1]]"#;
1998
+ let (out, info) = commit(&mut host, ops);
1999
+ assert!(codes(&out).contains(&OP_VECTOR));
2000
+ assert_eq!(info.warnings.len(), 1);
2001
+ assert!(info.warnings[0].starts_with("E_ORBIT_SVG_VALUE: "));
2002
+ // A patch too.
2003
+ let (_, info) = commit(
2004
+ &mut host,
2005
+ r#"[["u",3,{"vector":{"root":{"t":"svg","c":[{"t":"path","a":{"d":"M0 0 L1 NaN"}}]}}}]]"#,
2006
+ );
2007
+ assert_eq!(info.warnings.len(), 1);
2008
+ let json = info_json(&info, 0);
2009
+ assert!(
2010
+ json.contains(r#""warnings":["E_ORBIT_SVG_VALUE: "#),
2011
+ "{json}"
2012
+ );
2013
+ }
2014
+
2015
+ #[test]
2016
+ fn a_panic_never_leaves_an_exported_function() {
2017
+ assert_eq!(guarded(|| 7, || panic!("boom")), 7);
2018
+ assert_eq!(guarded(|| 7, || 3), 3);
2019
+ assert!(unsafe { items::<u8>(std::ptr::null(), 4) }.is_empty());
2020
+ // The C ABI with nothing to read and nothing to tick.
2021
+ let mut out = OrbitBuf {
2022
+ ptr: std::ptr::null_mut(),
2023
+ len: 0,
2024
+ cap: 0,
2025
+ };
2026
+ let code = unsafe { orbit_layout(std::ptr::null(), 0, &mut out) };
2027
+ assert_eq!(code, 1);
2028
+ unsafe { orbit_buf_free(out) };
2029
+ let mut out = OrbitBuf {
2030
+ ptr: std::ptr::null_mut(),
2031
+ len: 0,
2032
+ cap: 0,
2033
+ };
2034
+ let active =
2035
+ unsafe { orbit_motion_tick(0, std::ptr::null(), std::ptr::null(), 0, &mut out) };
2036
+ assert_eq!(active, 0);
2037
+ unsafe { orbit_buf_free(out) };
2038
+ unsafe { orbit_motion_interpolate(1, 2, std::ptr::null(), std::ptr::null(), 0) };
2039
+ unsafe { orbit_motion_frames(1, std::ptr::null(), 0, 1.0, false) };
2040
+ orbit_motion_dispose(1);
2041
+ }
1608
2042
  }