@yuneta/gobj-js 7.13.3 → 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.
@@ -1583,7 +1583,7 @@
1583
1583
  let ret = 0;
1584
1584
  if (gobj.gclass.gmt.mt_play) {
1585
1585
  ret = gobj.gclass.gmt.mt_play(gobj);
1586
- if (ret < 0) gobj.playing = false;
1586
+ if (ret < 0 || ret === false) gobj.playing = false;
1587
1587
  }
1588
1588
  return ret;
1589
1589
  }
@@ -1805,17 +1805,39 @@
1805
1805
  /***************************************************************
1806
1806
  * Walking
1807
1807
  ***************************************************************/
1808
+ /***************************************************************
1809
+ * What a WALK CALLBACK answered, as the number the contract is
1810
+ * written in: -1 stop the walk, 0 descend into the children,
1811
+ * >0 do not descend.
1812
+ *
1813
+ * A javascript callback that simply RETURNS NOTHING is the common
1814
+ * case, and `undefined` is neither `< 0` nor `=== 0`, so the walk
1815
+ * used to read it as "do not descend" and skipped the subtree in
1816
+ * silence. Nothing is 0 here — the neutral answer, the one C gives
1817
+ * when an action has nothing to say.
1818
+ *
1819
+ * A boolean is NOT guessed: `true`/`false` could mean either half of
1820
+ * this contract, so it is reported and taken as 0. A walk that
1821
+ * silently loses a subtree is the thing this whole function exists
1822
+ * to stop.
1823
+ ***************************************************************/
1824
+ function walk_ret(ret) {
1825
+ if (typeof ret === "number" && isFinite(ret)) return ret;
1826
+ if (ret === void 0 || ret === null) return 0;
1827
+ log_error(`walk callback must return a NUMBER (-1 stop, 0 descend, >0 skip children), got ${typeof ret}: taken as 0`);
1828
+ return 0;
1829
+ }
1808
1830
  function rc_walk_by_list(iter_, walk_type, cb_walking, user_data, user_data2) {
1809
1831
  let iter = [...iter_];
1810
1832
  let child;
1811
1833
  if (walk_type & walk_type_t.WALK_LAST2FIRST) for (let i = iter.length; i > 0; i--) {
1812
1834
  child = iter[i - 1];
1813
- let ret = cb_walking(child, user_data, user_data2);
1835
+ let ret = walk_ret(cb_walking(child, user_data, user_data2));
1814
1836
  if (ret < 0) return ret;
1815
1837
  }
1816
1838
  else for (let i = 0; i < iter.length; i++) {
1817
1839
  child = iter[i];
1818
- let ret = cb_walking(child, user_data, user_data2);
1840
+ let ret = walk_ret(cb_walking(child, user_data, user_data2));
1819
1841
  if (ret < 0) return ret;
1820
1842
  }
1821
1843
  return 0;
@@ -1868,12 +1890,12 @@
1868
1890
  child = iter[i - 1];
1869
1891
  ret = rc_walk_by_tree([...child.dl_children], walk_type, cb_walking, user_data, user_data2);
1870
1892
  if (ret < 0) return ret;
1871
- ret = cb_walking(child, user_data, user_data2);
1893
+ ret = walk_ret(cb_walking(child, user_data, user_data2));
1872
1894
  if (ret < 0) return ret;
1873
1895
  }
1874
1896
  else for (let i = 0; i < iter.length; i++) {
1875
1897
  child = iter[i];
1876
- ret = cb_walking(child, user_data, user_data2);
1898
+ ret = walk_ret(cb_walking(child, user_data, user_data2));
1877
1899
  if (ret < 0) return ret;
1878
1900
  else if (ret === 0) {
1879
1901
  ret = rc_walk_by_tree([...child.dl_children], walk_type, cb_walking, user_data, user_data2);
@@ -2717,7 +2739,8 @@
2717
2739
  if (kw) trace_json(kw);
2718
2740
  }
2719
2741
  if (publisher.gclass.gmt.mt_subscription_added) {
2720
- if (publisher.gclass.gmt.mt_subscription_added(publisher, subs) < 0) {
2742
+ let result = publisher.gclass.gmt.mt_subscription_added(publisher, subs);
2743
+ if (result < 0 || result === false) {
2721
2744
  _delete_subscription(publisher, subs, true, true);
2722
2745
  subs = 0;
2723
2746
  }
@@ -2866,7 +2889,7 @@
2866
2889
  if (publisher.gclass.gmt.mt_publication_pre_filter) {
2867
2890
  let topublish = publisher.gclass.gmt.mt_publication_pre_filter(publisher, subs, event, kw);
2868
2891
  if (topublish < 0) break;
2869
- else if (topublish === 0) continue;
2892
+ else if (!topublish) continue;
2870
2893
  }
2871
2894
  let subscriber = kw_get_pointer(publisher, subs, "subscriber", null, kw_flag_t.KW_REQUIRED);
2872
2895
  if (!(subscriber && !gobj_is_destroying(subscriber))) continue;
@@ -6437,7 +6460,7 @@
6437
6460
  let iev_kw = iev_msg.kw;
6438
6461
  if (gobj_current_state(gobj) !== "ST_SESSION") {
6439
6462
  if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
6440
- if (gobj_send_event(gobj, iev_event, iev_kw, gobj) === 0) return 0;
6463
+ if (!(gobj_send_event(gobj, iev_event, iev_kw, gobj) < 0)) return 0;
6441
6464
  } else log_error(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${iev_event}`);
6442
6465
  close_websocket(gobj);
6443
6466
  return -1;
@@ -6864,6 +6887,7 @@
6864
6887
  exports.treedb_get_field_desc = treedb_get_field_desc;
6865
6888
  exports.treedb_hook_data_size = treedb_hook_data_size;
6866
6889
  exports.vsprintf = vsprintf;
6890
+ exports.walk_type_t = walk_type_t;
6867
6891
  });
6868
6892
 
6869
6893
  //# sourceMappingURL=gobj-js.umd.js.map