@yuneta/gobj-js 7.13.4 → 7.13.6

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.
@@ -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);
@@ -2997,6 +3019,19 @@
2997
3019
  function set_console_log_enabled(enabled) {
2998
3020
  __console_output_enabled__ = enabled ? true : false;
2999
3021
  }
3022
+ var __console_log_filter__ = null;
3023
+ function set_console_log_filter(fn) {
3024
+ __console_log_filter__ = typeof fn === "function" ? fn : null;
3025
+ }
3026
+ function console_wants(level, msg) {
3027
+ if (!__console_output_enabled__) return false;
3028
+ if (!__console_log_filter__) return true;
3029
+ try {
3030
+ return __console_log_filter__(level, msg) ? true : false;
3031
+ } catch (e) {
3032
+ return true;
3033
+ }
3034
+ }
3000
3035
  var __in_log_callback__ = false;
3001
3036
  function emit_log_callback(level, msg, hora) {
3002
3037
  if (__log_callback__ && !__in_log_callback__) {
@@ -3044,9 +3079,9 @@
3044
3079
  let hora = current_timestamp();
3045
3080
  if (f_error) {
3046
3081
  if (f_error === _console.error) {
3047
- if (__console_output_enabled__) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3082
+ if (console_wants("error", msg)) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3048
3083
  } else {
3049
- if (__console_output_enabled__) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3084
+ if (console_wants("error", msg)) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3050
3085
  f_error(`${hora} ERROR: ${String(msg)}`);
3051
3086
  }
3052
3087
  }
@@ -3057,9 +3092,9 @@
3057
3092
  let hora = current_timestamp();
3058
3093
  if (f_warning) {
3059
3094
  if (f_warning === _console.warn) {
3060
- if (__console_output_enabled__) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3095
+ if (console_wants("warning", msg)) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3061
3096
  } else {
3062
- if (__console_output_enabled__) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3097
+ if (console_wants("warning", msg)) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3063
3098
  f_warning(`${hora} WARNING: ${String(msg)}`);
3064
3099
  }
3065
3100
  }
@@ -3069,7 +3104,7 @@
3069
3104
  let msg = format_log(format);
3070
3105
  let hora = current_timestamp();
3071
3106
  if (f_info) {
3072
- if (__console_output_enabled__) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3107
+ if (console_wants("info", msg)) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3073
3108
  }
3074
3109
  emit_log_callback("info", msg, hora);
3075
3110
  }
@@ -3077,7 +3112,7 @@
3077
3112
  let msg = format_log(format);
3078
3113
  let hora = current_timestamp();
3079
3114
  if (f_debug) {
3080
- if (__console_output_enabled__) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3115
+ if (console_wants("debug", msg)) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3081
3116
  }
3082
3117
  emit_log_callback("debug", msg, hora);
3083
3118
  }
@@ -3085,12 +3120,12 @@
3085
3120
  let msg = format_log(format);
3086
3121
  let hora = current_timestamp();
3087
3122
  if (f_debug) {
3088
- if (__console_output_enabled__) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3123
+ if (console_wants("msg", msg)) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3089
3124
  }
3090
3125
  emit_log_callback("msg", msg, hora);
3091
3126
  }
3092
3127
  function trace_json(jn, msg) {
3093
- if (__console_output_enabled__) {
3128
+ if (console_wants("json", msg)) {
3094
3129
  if (msg) window.console.warn("=====> " + msg);
3095
3130
  window.console.dir(jn);
3096
3131
  }
@@ -6438,7 +6473,7 @@
6438
6473
  let iev_kw = iev_msg.kw;
6439
6474
  if (gobj_current_state(gobj) !== "ST_SESSION") {
6440
6475
  if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
6441
- if (gobj_send_event(gobj, iev_event, iev_kw, gobj) === 0) return 0;
6476
+ if (!(gobj_send_event(gobj, iev_event, iev_kw, gobj) < 0)) return 0;
6442
6477
  } else log_error(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${iev_event}`);
6443
6478
  close_websocket(gobj);
6444
6479
  return -1;
@@ -6842,6 +6877,7 @@
6842
6877
  exports.sdata_flag_t = sdata_flag_t;
6843
6878
  exports.send_http_json_post = send_http_json_post;
6844
6879
  exports.set_console_log_enabled = set_console_log_enabled;
6880
+ exports.set_console_log_filter = set_console_log_filter;
6845
6881
  exports.set_log_callback = set_log_callback;
6846
6882
  exports.set_remote_log_functions = set_remote_log_functions;
6847
6883
  exports.set_timeout = set_timeout;
@@ -6865,6 +6901,7 @@
6865
6901
  exports.treedb_get_field_desc = treedb_get_field_desc;
6866
6902
  exports.treedb_hook_data_size = treedb_hook_data_size;
6867
6903
  exports.vsprintf = vsprintf;
6904
+ exports.walk_type_t = walk_type_t;
6868
6905
  });
6869
6906
 
6870
6907
  //# sourceMappingURL=gobj-js.umd.js.map