@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.
@@ -1803,17 +1803,39 @@ var gobjJs = (function(exports) {
1803
1803
  /***************************************************************
1804
1804
  * Walking
1805
1805
  ***************************************************************/
1806
+ /***************************************************************
1807
+ * What a WALK CALLBACK answered, as the number the contract is
1808
+ * written in: -1 stop the walk, 0 descend into the children,
1809
+ * >0 do not descend.
1810
+ *
1811
+ * A javascript callback that simply RETURNS NOTHING is the common
1812
+ * case, and `undefined` is neither `< 0` nor `=== 0`, so the walk
1813
+ * used to read it as "do not descend" and skipped the subtree in
1814
+ * silence. Nothing is 0 here — the neutral answer, the one C gives
1815
+ * when an action has nothing to say.
1816
+ *
1817
+ * A boolean is NOT guessed: `true`/`false` could mean either half of
1818
+ * this contract, so it is reported and taken as 0. A walk that
1819
+ * silently loses a subtree is the thing this whole function exists
1820
+ * to stop.
1821
+ ***************************************************************/
1822
+ function walk_ret(ret) {
1823
+ if (typeof ret === "number" && isFinite(ret)) return ret;
1824
+ if (ret === void 0 || ret === null) return 0;
1825
+ log_error(`walk callback must return a NUMBER (-1 stop, 0 descend, >0 skip children), got ${typeof ret}: taken as 0`);
1826
+ return 0;
1827
+ }
1806
1828
  function rc_walk_by_list(iter_, walk_type, cb_walking, user_data, user_data2) {
1807
1829
  let iter = [...iter_];
1808
1830
  let child;
1809
1831
  if (walk_type & walk_type_t.WALK_LAST2FIRST) for (let i = iter.length; i > 0; i--) {
1810
1832
  child = iter[i - 1];
1811
- let ret = cb_walking(child, user_data, user_data2);
1833
+ let ret = walk_ret(cb_walking(child, user_data, user_data2));
1812
1834
  if (ret < 0) return ret;
1813
1835
  }
1814
1836
  else for (let i = 0; i < iter.length; i++) {
1815
1837
  child = iter[i];
1816
- let ret = cb_walking(child, user_data, user_data2);
1838
+ let ret = walk_ret(cb_walking(child, user_data, user_data2));
1817
1839
  if (ret < 0) return ret;
1818
1840
  }
1819
1841
  return 0;
@@ -1866,12 +1888,12 @@ var gobjJs = (function(exports) {
1866
1888
  child = iter[i - 1];
1867
1889
  ret = rc_walk_by_tree([...child.dl_children], walk_type, cb_walking, user_data, user_data2);
1868
1890
  if (ret < 0) return ret;
1869
- ret = cb_walking(child, user_data, user_data2);
1891
+ ret = walk_ret(cb_walking(child, user_data, user_data2));
1870
1892
  if (ret < 0) return ret;
1871
1893
  }
1872
1894
  else for (let i = 0; i < iter.length; i++) {
1873
1895
  child = iter[i];
1874
- ret = cb_walking(child, user_data, user_data2);
1896
+ ret = walk_ret(cb_walking(child, user_data, user_data2));
1875
1897
  if (ret < 0) return ret;
1876
1898
  else if (ret === 0) {
1877
1899
  ret = rc_walk_by_tree([...child.dl_children], walk_type, cb_walking, user_data, user_data2);
@@ -2995,6 +3017,19 @@ var gobjJs = (function(exports) {
2995
3017
  function set_console_log_enabled(enabled) {
2996
3018
  __console_output_enabled__ = enabled ? true : false;
2997
3019
  }
3020
+ var __console_log_filter__ = null;
3021
+ function set_console_log_filter(fn) {
3022
+ __console_log_filter__ = typeof fn === "function" ? fn : null;
3023
+ }
3024
+ function console_wants(level, msg) {
3025
+ if (!__console_output_enabled__) return false;
3026
+ if (!__console_log_filter__) return true;
3027
+ try {
3028
+ return __console_log_filter__(level, msg) ? true : false;
3029
+ } catch (e) {
3030
+ return true;
3031
+ }
3032
+ }
2998
3033
  var __in_log_callback__ = false;
2999
3034
  function emit_log_callback(level, msg, hora) {
3000
3035
  if (__log_callback__ && !__in_log_callback__) {
@@ -3042,9 +3077,9 @@ var gobjJs = (function(exports) {
3042
3077
  let hora = current_timestamp();
3043
3078
  if (f_error) {
3044
3079
  if (f_error === _console.error) {
3045
- if (__console_output_enabled__) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3080
+ if (console_wants("error", msg)) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3046
3081
  } else {
3047
- if (__console_output_enabled__) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3082
+ if (console_wants("error", msg)) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3048
3083
  f_error(`${hora} ERROR: ${String(msg)}`);
3049
3084
  }
3050
3085
  }
@@ -3055,9 +3090,9 @@ var gobjJs = (function(exports) {
3055
3090
  let hora = current_timestamp();
3056
3091
  if (f_warning) {
3057
3092
  if (f_warning === _console.warn) {
3058
- if (__console_output_enabled__) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3093
+ if (console_wants("warning", msg)) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3059
3094
  } else {
3060
- if (__console_output_enabled__) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3095
+ if (console_wants("warning", msg)) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3061
3096
  f_warning(`${hora} WARNING: ${String(msg)}`);
3062
3097
  }
3063
3098
  }
@@ -3067,7 +3102,7 @@ var gobjJs = (function(exports) {
3067
3102
  let msg = format_log(format);
3068
3103
  let hora = current_timestamp();
3069
3104
  if (f_info) {
3070
- if (__console_output_enabled__) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3105
+ if (console_wants("info", msg)) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3071
3106
  }
3072
3107
  emit_log_callback("info", msg, hora);
3073
3108
  }
@@ -3075,7 +3110,7 @@ var gobjJs = (function(exports) {
3075
3110
  let msg = format_log(format);
3076
3111
  let hora = current_timestamp();
3077
3112
  if (f_debug) {
3078
- if (__console_output_enabled__) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3113
+ if (console_wants("debug", msg)) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3079
3114
  }
3080
3115
  emit_log_callback("debug", msg, hora);
3081
3116
  }
@@ -3083,12 +3118,12 @@ var gobjJs = (function(exports) {
3083
3118
  let msg = format_log(format);
3084
3119
  let hora = current_timestamp();
3085
3120
  if (f_debug) {
3086
- if (__console_output_enabled__) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3121
+ if (console_wants("msg", msg)) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3087
3122
  }
3088
3123
  emit_log_callback("msg", msg, hora);
3089
3124
  }
3090
3125
  function trace_json(jn, msg) {
3091
- if (__console_output_enabled__) {
3126
+ if (console_wants("json", msg)) {
3092
3127
  if (msg) window.console.warn("=====> " + msg);
3093
3128
  window.console.dir(jn);
3094
3129
  }
@@ -6436,7 +6471,7 @@ var gobjJs = (function(exports) {
6436
6471
  let iev_kw = iev_msg.kw;
6437
6472
  if (gobj_current_state(gobj) !== "ST_SESSION") {
6438
6473
  if (gobj_has_event(gobj, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
6439
- if (gobj_send_event(gobj, iev_event, iev_kw, gobj) === 0) return 0;
6474
+ if (!(gobj_send_event(gobj, iev_event, iev_kw, gobj) < 0)) return 0;
6440
6475
  } else log_error(`${gobj_short_name(gobj)}: event UNKNOWN in not-session state ${iev_event}`);
6441
6476
  close_websocket(gobj);
6442
6477
  return -1;
@@ -6840,6 +6875,7 @@ var gobjJs = (function(exports) {
6840
6875
  exports.sdata_flag_t = sdata_flag_t;
6841
6876
  exports.send_http_json_post = send_http_json_post;
6842
6877
  exports.set_console_log_enabled = set_console_log_enabled;
6878
+ exports.set_console_log_filter = set_console_log_filter;
6843
6879
  exports.set_log_callback = set_log_callback;
6844
6880
  exports.set_remote_log_functions = set_remote_log_functions;
6845
6881
  exports.set_timeout = set_timeout;
@@ -6863,6 +6899,7 @@ var gobjJs = (function(exports) {
6863
6899
  exports.treedb_get_field_desc = treedb_get_field_desc;
6864
6900
  exports.treedb_hook_data_size = treedb_hook_data_size;
6865
6901
  exports.vsprintf = vsprintf;
6902
+ exports.walk_type_t = walk_type_t;
6866
6903
  return exports;
6867
6904
  })({});
6868
6905