@yuneta/gobj-js 7.26.13 → 7.26.15

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.
@@ -3284,13 +3284,20 @@
3284
3284
  }
3285
3285
  /************************************************************
3286
3286
  * JSON.stringify for a log line: a circular object (a gobj,
3287
- * a DOM node) must not make the log call itself throw.
3287
+ * a DOM node), a BigInt or a toJSON() that throws must not make
3288
+ * the log call itself throw -- and neither must the fallback:
3289
+ * String() throws too, on an object with no prototype or with a
3290
+ * toString() that throws.
3288
3291
  ************************************************************/
3289
3292
  function log_stringify(v) {
3290
3293
  try {
3291
3294
  return JSON.stringify(v);
3292
3295
  } catch (e) {
3293
- return String(v);
3296
+ try {
3297
+ return String(v);
3298
+ } catch (e2) {
3299
+ return `<${typeof v}: not printable>`;
3300
+ }
3294
3301
  }
3295
3302
  }
3296
3303
  function format_log(format) {
@@ -4340,8 +4347,10 @@
4340
4347
  /************************************************************
4341
4348
  * As the C kw_get_dict(): a dict found is the answer, and
4342
4349
  * anything else gives the default back AS GIVEN (null stays
4343
- * null). KW_CREATE stores a dict default, never a null one.
4344
- * Before gobj-js 7.25.2 the answer went through Object(), so a
4350
+ * null). KW_CREATE stores a dict default, never a null one, and
4351
+ * replaces a null at the path; over another type it logs and
4352
+ * gives the default back unwritten (C returns NULL there, SDK
4353
+ * 7.26.9). Before gobj-js 7.25.2 the answer went through Object(), so a
4345
4354
  * null default came back as {} and a 0 as a Number object.
4346
4355
  ************************************************************/
4347
4356
  function kw_get_dict(gobj, kw, path, default_value, flag) {
@@ -4362,8 +4371,12 @@
4362
4371
  return default_value;
4363
4372
  }
4364
4373
  if (!is_object(v)) {
4365
- if (required) {
4366
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'`);
4374
+ if (create && v === null && is_object(default_value)) {
4375
+ kw_set_dict_value(gobj, kw, path, default_value);
4376
+ return default_value;
4377
+ }
4378
+ if (required || create) {
4379
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json dict: '${path}'` + (create ? ", cannot create" : ""));
4367
4380
  trace_json_masked(kw);
4368
4381
  }
4369
4382
  return default_value;
@@ -4397,7 +4410,9 @@
4397
4410
  /************************************************************
4398
4411
  * As the C kw_get_list(): a list found is the answer, and
4399
4412
  * anything else gives the default back AS GIVEN. KW_CREATE
4400
- * stores a list default, never a null one. Before gobj-js
4413
+ * stores a list default, never a null one, and replaces a null
4414
+ * at the path; over another type it logs and gives the default
4415
+ * back unwritten (C returns NULL there, SDK 7.26.9). Before gobj-js
4401
4416
  * 7.25.2 the answer went through Array(), which WRAPS its
4402
4417
  * argument: a list found came back as [list], a default of []
4403
4418
  * as [[]] and a null one as [null].
@@ -4420,8 +4435,12 @@
4420
4435
  return default_value;
4421
4436
  }
4422
4437
  if (!is_array(v)) {
4423
- if (required) {
4424
- log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'`);
4438
+ if (create && v === null && is_array(default_value)) {
4439
+ kw_set_dict_value(gobj, kw, path, default_value);
4440
+ return default_value;
4441
+ }
4442
+ if (required || create) {
4443
+ log_error(`${gobj ? gobj_short_name(gobj) + ": " : ""}path MUST BE a json list: '${path}'` + (create ? ", cannot create" : ""));
4425
4444
  trace_json_masked(kw);
4426
4445
  }
4427
4446
  return default_value;
@@ -5254,7 +5273,7 @@
5254
5273
  return null;
5255
5274
  }
5256
5275
  if (!is_object(kw) || empty_string(kw["id"])) {
5257
- log_error(`jdb_update: record without id: ${JSON.stringify(kw)}`);
5276
+ log_error(`jdb_update: record without id: ${log_stringify(kw)}`);
5258
5277
  return null;
5259
5278
  }
5260
5279
  if (!is_string(path)) {
@@ -5307,7 +5326,7 @@
5307
5326
  return null;
5308
5327
  }
5309
5328
  if (!is_object(kw) || empty_string(kw["id"])) {
5310
- log_error(`jdb_delete: record without id: ${JSON.stringify(kw)}`);
5329
+ log_error(`jdb_delete: record without id: ${log_stringify(kw)}`);
5311
5330
  return null;
5312
5331
  }
5313
5332
  if (!is_string(path)) {