@yuneta/gobj-js 7.13.4 → 7.13.5

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.
@@ -1802,17 +1802,39 @@ function gobj_walk_gobj_children_tree(gobj, walk_type, cb_walking, user_data, us
1802
1802
  /***************************************************************
1803
1803
  * Walking
1804
1804
  ***************************************************************/
1805
+ /***************************************************************
1806
+ * What a WALK CALLBACK answered, as the number the contract is
1807
+ * written in: -1 stop the walk, 0 descend into the children,
1808
+ * >0 do not descend.
1809
+ *
1810
+ * A javascript callback that simply RETURNS NOTHING is the common
1811
+ * case, and `undefined` is neither `< 0` nor `=== 0`, so the walk
1812
+ * used to read it as "do not descend" and skipped the subtree in
1813
+ * silence. Nothing is 0 here — the neutral answer, the one C gives
1814
+ * when an action has nothing to say.
1815
+ *
1816
+ * A boolean is NOT guessed: `true`/`false` could mean either half of
1817
+ * this contract, so it is reported and taken as 0. A walk that
1818
+ * silently loses a subtree is the thing this whole function exists
1819
+ * to stop.
1820
+ ***************************************************************/
1821
+ function walk_ret(ret) {
1822
+ if (typeof ret === "number" && isFinite(ret)) return ret;
1823
+ if (ret === void 0 || ret === null) return 0;
1824
+ log_error(`walk callback must return a NUMBER (-1 stop, 0 descend, >0 skip children), got ${typeof ret}: taken as 0`);
1825
+ return 0;
1826
+ }
1805
1827
  function rc_walk_by_list(iter_, walk_type, cb_walking, user_data, user_data2) {
1806
1828
  let iter = [...iter_];
1807
1829
  let child;
1808
1830
  if (walk_type & walk_type_t.WALK_LAST2FIRST) for (let i = iter.length; i > 0; i--) {
1809
1831
  child = iter[i - 1];
1810
- let ret = cb_walking(child, user_data, user_data2);
1832
+ let ret = walk_ret(cb_walking(child, user_data, user_data2));
1811
1833
  if (ret < 0) return ret;
1812
1834
  }
1813
1835
  else for (let i = 0; i < iter.length; i++) {
1814
1836
  child = iter[i];
1815
- let ret = cb_walking(child, user_data, user_data2);
1837
+ let ret = walk_ret(cb_walking(child, user_data, user_data2));
1816
1838
  if (ret < 0) return ret;
1817
1839
  }
1818
1840
  return 0;
@@ -1865,12 +1887,12 @@ function rc_walk_by_tree(iter, walk_type, cb_walking, user_data, user_data2) {
1865
1887
  child = iter[i - 1];
1866
1888
  ret = rc_walk_by_tree([...child.dl_children], walk_type, cb_walking, user_data, user_data2);
1867
1889
  if (ret < 0) return ret;
1868
- ret = cb_walking(child, user_data, user_data2);
1890
+ ret = walk_ret(cb_walking(child, user_data, user_data2));
1869
1891
  if (ret < 0) return ret;
1870
1892
  }
1871
1893
  else for (let i = 0; i < iter.length; i++) {
1872
1894
  child = iter[i];
1873
- ret = cb_walking(child, user_data, user_data2);
1895
+ ret = walk_ret(cb_walking(child, user_data, user_data2));
1874
1896
  if (ret < 0) return ret;
1875
1897
  else if (ret === 0) {
1876
1898
  ret = rc_walk_by_tree([...child.dl_children], walk_type, cb_walking, user_data, user_data2);
@@ -6435,7 +6457,7 @@ function ac_on_message(gobj, event, kw, src) {
6435
6457
  let iev_kw = iev_msg.kw;
6436
6458
  if (gobj_current_state(gobj) !== "ST_SESSION") {
6437
6459
  if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
6438
- if (gobj_send_event(gobj, iev_event, iev_kw, gobj) === 0) return 0;
6460
+ if (!(gobj_send_event(gobj, iev_event, iev_kw, gobj) < 0)) return 0;
6439
6461
  } else log_error(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${iev_event}`);
6440
6462
  close_websocket(gobj);
6441
6463
  return -1;
@@ -6862,5 +6884,6 @@ exports.treedb_encoder_fkey = treedb_encoder_fkey;
6862
6884
  exports.treedb_get_field_desc = treedb_get_field_desc;
6863
6885
  exports.treedb_hook_data_size = treedb_hook_data_size;
6864
6886
  exports.vsprintf = vsprintf;
6887
+ exports.walk_type_t = walk_type_t;
6865
6888
 
6866
6889
  //# sourceMappingURL=gobj-js.cjs.js.map