@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.
@@ -1580,7 +1580,7 @@ function gobj_play(gobj) {
1580
1580
  let ret = 0;
1581
1581
  if (gobj.gclass.gmt.mt_play) {
1582
1582
  ret = gobj.gclass.gmt.mt_play(gobj);
1583
- if (ret < 0) gobj.playing = false;
1583
+ if (ret < 0 || ret === false) gobj.playing = false;
1584
1584
  }
1585
1585
  return ret;
1586
1586
  }
@@ -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);
@@ -2714,7 +2736,8 @@ function gobj_subscribe_event(publisher, event, kw, subscriber) {
2714
2736
  if (kw) trace_json(kw);
2715
2737
  }
2716
2738
  if (publisher.gclass.gmt.mt_subscription_added) {
2717
- if (publisher.gclass.gmt.mt_subscription_added(publisher, subs) < 0) {
2739
+ let result = publisher.gclass.gmt.mt_subscription_added(publisher, subs);
2740
+ if (result < 0 || result === false) {
2718
2741
  _delete_subscription(publisher, subs, true, true);
2719
2742
  subs = 0;
2720
2743
  }
@@ -2863,7 +2886,7 @@ function gobj_publish_event(publisher, event, kw) {
2863
2886
  if (publisher.gclass.gmt.mt_publication_pre_filter) {
2864
2887
  let topublish = publisher.gclass.gmt.mt_publication_pre_filter(publisher, subs, event, kw);
2865
2888
  if (topublish < 0) break;
2866
- else if (topublish === 0) continue;
2889
+ else if (!topublish) continue;
2867
2890
  }
2868
2891
  let subscriber = kw_get_pointer(publisher, subs, "subscriber", null, kw_flag_t.KW_REQUIRED);
2869
2892
  if (!(subscriber && !gobj_is_destroying(subscriber))) continue;
@@ -6434,7 +6457,7 @@ function ac_on_message(gobj, event, kw, src) {
6434
6457
  let iev_kw = iev_msg.kw;
6435
6458
  if (gobj_current_state(gobj) !== "ST_SESSION") {
6436
6459
  if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
6437
- 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;
6438
6461
  } else log_error(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${iev_event}`);
6439
6462
  close_websocket(gobj);
6440
6463
  return -1;
@@ -6861,5 +6884,6 @@ exports.treedb_encoder_fkey = treedb_encoder_fkey;
6861
6884
  exports.treedb_get_field_desc = treedb_get_field_desc;
6862
6885
  exports.treedb_hook_data_size = treedb_hook_data_size;
6863
6886
  exports.vsprintf = vsprintf;
6887
+ exports.walk_type_t = walk_type_t;
6864
6888
 
6865
6889
  //# sourceMappingURL=gobj-js.cjs.js.map