protobufjs 7.5.6 → 7.5.8
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.
- package/dist/light/protobuf.js +39 -13
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +2 -2
- package/dist/minimal/protobuf.min.js +2 -2
- package/dist/protobuf.js +74 -43
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +18 -5
- package/package.json +1 -1
- package/src/namespace.js +11 -5
- package/src/parse.js +35 -30
- package/src/root.js +4 -2
- package/src/service.js +4 -2
- package/src/type.js +4 -2
- package/src/util.js +14 -0
package/index.d.ts
CHANGED
|
@@ -714,10 +714,11 @@ export class Namespace extends NamespaceBase {
|
|
|
714
714
|
* Constructs a namespace from JSON.
|
|
715
715
|
* @param name Namespace name
|
|
716
716
|
* @param json JSON object
|
|
717
|
+
* @param [depth] Current nesting depth, defaults to `0`
|
|
717
718
|
* @returns Created namespace
|
|
718
719
|
* @throws {TypeError} If arguments are invalid
|
|
719
720
|
*/
|
|
720
|
-
public static fromJSON(name: string, json: { [k: string]: any }): Namespace;
|
|
721
|
+
public static fromJSON(name: string, json: { [k: string]: any }, depth?: number): Namespace;
|
|
721
722
|
|
|
722
723
|
/**
|
|
723
724
|
* Converts an array of reflection objects to JSON.
|
|
@@ -769,9 +770,10 @@ export abstract class NamespaceBase extends ReflectionObject {
|
|
|
769
770
|
/**
|
|
770
771
|
* Adds nested objects to this namespace from nested object descriptors.
|
|
771
772
|
* @param nestedJson Any nested object descriptors
|
|
773
|
+
* @param [depth] Current nesting depth, defaults to `0`
|
|
772
774
|
* @returns `this`
|
|
773
775
|
*/
|
|
774
|
-
public addJSON(nestedJson: { [k: string]: AnyNestedObject }): Namespace;
|
|
776
|
+
public addJSON(nestedJson: { [k: string]: AnyNestedObject }, depth?: number): Namespace;
|
|
775
777
|
|
|
776
778
|
/**
|
|
777
779
|
* Gets the nested object of the specified name.
|
|
@@ -1318,9 +1320,10 @@ export class Root extends NamespaceBase {
|
|
|
1318
1320
|
* Loads a namespace descriptor into a root namespace.
|
|
1319
1321
|
* @param json Namespace descriptor
|
|
1320
1322
|
* @param [root] Root namespace, defaults to create a new one if omitted
|
|
1323
|
+
* @param [depth] Current nesting depth, defaults to `0`
|
|
1321
1324
|
* @returns Root namespace
|
|
1322
1325
|
*/
|
|
1323
|
-
public static fromJSON(json: INamespace, root?: Root): Root;
|
|
1326
|
+
public static fromJSON(json: INamespace, root?: Root, depth?: number): Root;
|
|
1324
1327
|
|
|
1325
1328
|
/**
|
|
1326
1329
|
* Resolves the path of an imported file, relative to the importing origin.
|
|
@@ -1471,10 +1474,11 @@ export class Service extends NamespaceBase {
|
|
|
1471
1474
|
* Constructs a service from a service descriptor.
|
|
1472
1475
|
* @param name Service name
|
|
1473
1476
|
* @param json Service descriptor
|
|
1477
|
+
* @param [depth] Current nesting depth, defaults to `0`
|
|
1474
1478
|
* @returns Created service
|
|
1475
1479
|
* @throws {TypeError} If arguments are invalid
|
|
1476
1480
|
*/
|
|
1477
|
-
public static fromJSON(name: string, json: IService): Service;
|
|
1481
|
+
public static fromJSON(name: string, json: IService, depth?: number): Service;
|
|
1478
1482
|
|
|
1479
1483
|
/**
|
|
1480
1484
|
* Converts this service to a service descriptor.
|
|
@@ -1625,9 +1629,10 @@ export class Type extends NamespaceBase {
|
|
|
1625
1629
|
* Creates a message type from a message type descriptor.
|
|
1626
1630
|
* @param name Message name
|
|
1627
1631
|
* @param json Message type descriptor
|
|
1632
|
+
* @param [depth] Current nesting depth, defaults to `0`
|
|
1628
1633
|
* @returns Created message type
|
|
1629
1634
|
*/
|
|
1630
|
-
public static fromJSON(name: string, json: IType): Type;
|
|
1635
|
+
public static fromJSON(name: string, json: IType, depth?: number): Type;
|
|
1631
1636
|
|
|
1632
1637
|
/**
|
|
1633
1638
|
* Converts this message type to a message type descriptor.
|
|
@@ -2199,6 +2204,14 @@ export namespace util {
|
|
|
2199
2204
|
/** Node's fs module if available. */
|
|
2200
2205
|
let fs: { [k: string]: any };
|
|
2201
2206
|
|
|
2207
|
+
/**
|
|
2208
|
+
* Checks a recursion depth.
|
|
2209
|
+
* @param depth Depth of recursion
|
|
2210
|
+
* @returns Depth of recursion
|
|
2211
|
+
* @throws {Error} If depth exceeds util.recursionLimit
|
|
2212
|
+
*/
|
|
2213
|
+
function checkDepth(depth: (number|undefined)): number;
|
|
2214
|
+
|
|
2202
2215
|
/**
|
|
2203
2216
|
* Converts an object's values to an array.
|
|
2204
2217
|
* @param object Object to convert
|
package/package.json
CHANGED
package/src/namespace.js
CHANGED
|
@@ -29,11 +29,13 @@ var Type, // cyclic
|
|
|
29
29
|
* @function
|
|
30
30
|
* @param {string} name Namespace name
|
|
31
31
|
* @param {Object.<string,*>} json JSON object
|
|
32
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
32
33
|
* @returns {Namespace} Created namespace
|
|
33
34
|
* @throws {TypeError} If arguments are invalid
|
|
34
35
|
*/
|
|
35
|
-
Namespace.fromJSON = function fromJSON(name, json) {
|
|
36
|
-
|
|
36
|
+
Namespace.fromJSON = function fromJSON(name, json, depth) {
|
|
37
|
+
depth = util.checkDepth(depth);
|
|
38
|
+
return new Namespace(name, json.options).addJSON(json.nested, depth);
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
/**
|
|
@@ -191,9 +193,11 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
191
193
|
/**
|
|
192
194
|
* Adds nested objects to this namespace from nested object descriptors.
|
|
193
195
|
* @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
|
|
196
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
194
197
|
* @returns {Namespace} `this`
|
|
195
198
|
*/
|
|
196
|
-
Namespace.prototype.addJSON = function addJSON(nestedJson) {
|
|
199
|
+
Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
|
|
200
|
+
depth = util.checkDepth(depth);
|
|
197
201
|
var ns = this;
|
|
198
202
|
/* istanbul ignore else */
|
|
199
203
|
if (nestedJson) {
|
|
@@ -208,7 +212,7 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
|
|
|
208
212
|
? Service.fromJSON
|
|
209
213
|
: nested.id !== undefined
|
|
210
214
|
? Field.fromJSON
|
|
211
|
-
: Namespace.fromJSON )(names[i], nested)
|
|
215
|
+
: Namespace.fromJSON )(names[i], nested, depth + 1)
|
|
212
216
|
);
|
|
213
217
|
}
|
|
214
218
|
}
|
|
@@ -466,8 +470,10 @@ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
|
|
|
466
470
|
// Otherwise try each nested namespace
|
|
467
471
|
} else {
|
|
468
472
|
for (var i = 0; i < this.nestedArray.length; ++i)
|
|
469
|
-
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
|
|
473
|
+
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
|
|
470
474
|
exact = found;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
471
477
|
}
|
|
472
478
|
|
|
473
479
|
// Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
|
package/src/parse.js
CHANGED
|
@@ -301,7 +301,8 @@ function parse(source, root, options) {
|
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
|
|
304
|
-
function parseCommon(parent, token) {
|
|
304
|
+
function parseCommon(parent, token, depth) {
|
|
305
|
+
depth = util.checkDepth(depth);
|
|
305
306
|
switch (token) {
|
|
306
307
|
|
|
307
308
|
case "option":
|
|
@@ -310,7 +311,7 @@ function parse(source, root, options) {
|
|
|
310
311
|
return true;
|
|
311
312
|
|
|
312
313
|
case "message":
|
|
313
|
-
parseType(parent, token);
|
|
314
|
+
parseType(parent, token, depth + 1);
|
|
314
315
|
return true;
|
|
315
316
|
|
|
316
317
|
case "enum":
|
|
@@ -318,11 +319,11 @@ function parse(source, root, options) {
|
|
|
318
319
|
return true;
|
|
319
320
|
|
|
320
321
|
case "service":
|
|
321
|
-
parseService(parent, token);
|
|
322
|
+
parseService(parent, token, depth + 1);
|
|
322
323
|
return true;
|
|
323
324
|
|
|
324
325
|
case "extend":
|
|
325
|
-
parseExtension(parent, token);
|
|
326
|
+
parseExtension(parent, token, depth);
|
|
326
327
|
return true;
|
|
327
328
|
}
|
|
328
329
|
return false;
|
|
@@ -350,7 +351,8 @@ function parse(source, root, options) {
|
|
|
350
351
|
}
|
|
351
352
|
}
|
|
352
353
|
|
|
353
|
-
function parseType(parent, token) {
|
|
354
|
+
function parseType(parent, token, depth) {
|
|
355
|
+
depth = util.checkDepth(depth);
|
|
354
356
|
|
|
355
357
|
/* istanbul ignore if */
|
|
356
358
|
if (!nameRe.test(token = next()))
|
|
@@ -358,7 +360,7 @@ function parse(source, root, options) {
|
|
|
358
360
|
|
|
359
361
|
var type = new Type(token);
|
|
360
362
|
ifBlock(type, function parseType_block(token) {
|
|
361
|
-
if (parseCommon(type, token))
|
|
363
|
+
if (parseCommon(type, token, depth))
|
|
362
364
|
return;
|
|
363
365
|
|
|
364
366
|
switch (token) {
|
|
@@ -372,22 +374,22 @@ function parse(source, root, options) {
|
|
|
372
374
|
throw illegal(token);
|
|
373
375
|
/* eslint-disable no-fallthrough */
|
|
374
376
|
case "repeated":
|
|
375
|
-
parseField(type, token);
|
|
377
|
+
parseField(type, token, undefined, depth + 1);
|
|
376
378
|
break;
|
|
377
379
|
|
|
378
380
|
case "optional":
|
|
379
381
|
/* istanbul ignore if */
|
|
380
382
|
if (edition === "proto3") {
|
|
381
|
-
parseField(type, "proto3_optional");
|
|
383
|
+
parseField(type, "proto3_optional", undefined, depth + 1);
|
|
382
384
|
} else if (edition !== "proto2") {
|
|
383
385
|
throw illegal(token);
|
|
384
386
|
} else {
|
|
385
|
-
parseField(type, "optional");
|
|
387
|
+
parseField(type, "optional", undefined, depth + 1);
|
|
386
388
|
}
|
|
387
389
|
break;
|
|
388
390
|
|
|
389
391
|
case "oneof":
|
|
390
|
-
parseOneOf(type, token);
|
|
392
|
+
parseOneOf(type, token, depth + 1);
|
|
391
393
|
break;
|
|
392
394
|
|
|
393
395
|
case "extensions":
|
|
@@ -405,7 +407,7 @@ function parse(source, root, options) {
|
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
push(token);
|
|
408
|
-
parseField(type, "optional");
|
|
410
|
+
parseField(type, "optional", undefined, depth + 1);
|
|
409
411
|
break;
|
|
410
412
|
}
|
|
411
413
|
});
|
|
@@ -415,10 +417,10 @@ function parse(source, root, options) {
|
|
|
415
417
|
}
|
|
416
418
|
}
|
|
417
419
|
|
|
418
|
-
function parseField(parent, rule, extend) {
|
|
420
|
+
function parseField(parent, rule, extend, depth) {
|
|
419
421
|
var type = next();
|
|
420
422
|
if (type === "group") {
|
|
421
|
-
parseGroup(parent, rule);
|
|
423
|
+
parseGroup(parent, rule, depth);
|
|
422
424
|
return;
|
|
423
425
|
}
|
|
424
426
|
// Type names can consume multiple tokens, in multiple variants:
|
|
@@ -475,7 +477,8 @@ function parse(source, root, options) {
|
|
|
475
477
|
}
|
|
476
478
|
}
|
|
477
479
|
|
|
478
|
-
function parseGroup(parent, rule) {
|
|
480
|
+
function parseGroup(parent, rule, depth) {
|
|
481
|
+
depth = util.checkDepth(depth);
|
|
479
482
|
if (edition >= 2023) {
|
|
480
483
|
throw illegal("group");
|
|
481
484
|
}
|
|
@@ -503,20 +506,20 @@ function parse(source, root, options) {
|
|
|
503
506
|
break;
|
|
504
507
|
case "required":
|
|
505
508
|
case "repeated":
|
|
506
|
-
parseField(type, token);
|
|
509
|
+
parseField(type, token, undefined, depth + 1);
|
|
507
510
|
break;
|
|
508
511
|
|
|
509
512
|
case "optional":
|
|
510
513
|
/* istanbul ignore if */
|
|
511
514
|
if (edition === "proto3") {
|
|
512
|
-
parseField(type, "proto3_optional");
|
|
515
|
+
parseField(type, "proto3_optional", undefined, depth + 1);
|
|
513
516
|
} else {
|
|
514
|
-
parseField(type, "optional");
|
|
517
|
+
parseField(type, "optional", undefined, depth + 1);
|
|
515
518
|
}
|
|
516
519
|
break;
|
|
517
520
|
|
|
518
521
|
case "message":
|
|
519
|
-
parseType(type, token);
|
|
522
|
+
parseType(type, token, depth + 1);
|
|
520
523
|
break;
|
|
521
524
|
|
|
522
525
|
case "enum":
|
|
@@ -575,7 +578,7 @@ function parse(source, root, options) {
|
|
|
575
578
|
parent.add(field);
|
|
576
579
|
}
|
|
577
580
|
|
|
578
|
-
function parseOneOf(parent, token) {
|
|
581
|
+
function parseOneOf(parent, token, depth) {
|
|
579
582
|
|
|
580
583
|
/* istanbul ignore if */
|
|
581
584
|
if (!nameRe.test(token = next()))
|
|
@@ -588,7 +591,7 @@ function parse(source, root, options) {
|
|
|
588
591
|
skip(";");
|
|
589
592
|
} else {
|
|
590
593
|
push(token);
|
|
591
|
-
parseField(oneof, "optional");
|
|
594
|
+
parseField(oneof, "optional", undefined, depth);
|
|
592
595
|
}
|
|
593
596
|
});
|
|
594
597
|
parent.add(oneof);
|
|
@@ -693,7 +696,8 @@ function parse(source, root, options) {
|
|
|
693
696
|
setParsedOption(parent, option, optionValue, propName);
|
|
694
697
|
}
|
|
695
698
|
|
|
696
|
-
function parseOptionValue(parent, name) {
|
|
699
|
+
function parseOptionValue(parent, name, depth) {
|
|
700
|
+
depth = util.checkDepth(depth);
|
|
697
701
|
// { a: "foo" b { c: "bar" } }
|
|
698
702
|
if (skip("{", true)) {
|
|
699
703
|
var objectResult = {};
|
|
@@ -716,7 +720,7 @@ function parse(source, root, options) {
|
|
|
716
720
|
// option (my_option) = {
|
|
717
721
|
// repeated_value: [ "foo", "bar" ]
|
|
718
722
|
// };
|
|
719
|
-
value = parseOptionValue(parent, name + "." + token);
|
|
723
|
+
value = parseOptionValue(parent, name + "." + token, depth + 1);
|
|
720
724
|
} else if (peek() === "[") {
|
|
721
725
|
value = [];
|
|
722
726
|
var lastValue;
|
|
@@ -781,7 +785,8 @@ function parse(source, root, options) {
|
|
|
781
785
|
return parent;
|
|
782
786
|
}
|
|
783
787
|
|
|
784
|
-
function parseService(parent, token) {
|
|
788
|
+
function parseService(parent, token, depth) {
|
|
789
|
+
depth = util.checkDepth(depth);
|
|
785
790
|
|
|
786
791
|
/* istanbul ignore if */
|
|
787
792
|
if (!nameRe.test(token = next()))
|
|
@@ -789,7 +794,7 @@ function parse(source, root, options) {
|
|
|
789
794
|
|
|
790
795
|
var service = new Service(token);
|
|
791
796
|
ifBlock(service, function parseService_block(token) {
|
|
792
|
-
if (parseCommon(service, token)) {
|
|
797
|
+
if (parseCommon(service, token, depth)) {
|
|
793
798
|
return;
|
|
794
799
|
}
|
|
795
800
|
|
|
@@ -855,7 +860,7 @@ function parse(source, root, options) {
|
|
|
855
860
|
parent.add(method);
|
|
856
861
|
}
|
|
857
862
|
|
|
858
|
-
function parseExtension(parent, token) {
|
|
863
|
+
function parseExtension(parent, token, depth) {
|
|
859
864
|
|
|
860
865
|
/* istanbul ignore if */
|
|
861
866
|
if (!typeRefRe.test(token = next()))
|
|
@@ -867,15 +872,15 @@ function parse(source, root, options) {
|
|
|
867
872
|
|
|
868
873
|
case "required":
|
|
869
874
|
case "repeated":
|
|
870
|
-
parseField(parent, token, reference);
|
|
875
|
+
parseField(parent, token, reference, depth + 1);
|
|
871
876
|
break;
|
|
872
877
|
|
|
873
878
|
case "optional":
|
|
874
879
|
/* istanbul ignore if */
|
|
875
880
|
if (edition === "proto3") {
|
|
876
|
-
parseField(parent, "proto3_optional", reference);
|
|
881
|
+
parseField(parent, "proto3_optional", reference, depth + 1);
|
|
877
882
|
} else {
|
|
878
|
-
parseField(parent, "optional", reference);
|
|
883
|
+
parseField(parent, "optional", reference, depth + 1);
|
|
879
884
|
}
|
|
880
885
|
break;
|
|
881
886
|
|
|
@@ -884,7 +889,7 @@ function parse(source, root, options) {
|
|
|
884
889
|
if (edition === "proto2" || !typeRefRe.test(token))
|
|
885
890
|
throw illegal(token);
|
|
886
891
|
push(token);
|
|
887
|
-
parseField(parent, "optional", reference);
|
|
892
|
+
parseField(parent, "optional", reference, depth + 1);
|
|
888
893
|
break;
|
|
889
894
|
}
|
|
890
895
|
});
|
|
@@ -936,7 +941,7 @@ function parse(source, root, options) {
|
|
|
936
941
|
default:
|
|
937
942
|
|
|
938
943
|
/* istanbul ignore else */
|
|
939
|
-
if (parseCommon(ptr, token)) {
|
|
944
|
+
if (parseCommon(ptr, token, 0)) {
|
|
940
945
|
head = false;
|
|
941
946
|
continue;
|
|
942
947
|
}
|
package/src/root.js
CHANGED
|
@@ -55,14 +55,16 @@ function Root(options) {
|
|
|
55
55
|
* Loads a namespace descriptor into a root namespace.
|
|
56
56
|
* @param {INamespace} json Namespace descriptor
|
|
57
57
|
* @param {Root} [root] Root namespace, defaults to create a new one if omitted
|
|
58
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
58
59
|
* @returns {Root} Root namespace
|
|
59
60
|
*/
|
|
60
|
-
Root.fromJSON = function fromJSON(json, root) {
|
|
61
|
+
Root.fromJSON = function fromJSON(json, root, depth) {
|
|
62
|
+
depth = util.checkDepth(depth);
|
|
61
63
|
if (!root)
|
|
62
64
|
root = new Root();
|
|
63
65
|
if (json.options)
|
|
64
66
|
root.setOptions(json.options);
|
|
65
|
-
return root.addJSON(json.nested).resolveAll();
|
|
67
|
+
return root.addJSON(json.nested, depth).resolveAll();
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
/**
|
package/src/service.js
CHANGED
|
@@ -48,17 +48,19 @@ function Service(name, options) {
|
|
|
48
48
|
* Constructs a service from a service descriptor.
|
|
49
49
|
* @param {string} name Service name
|
|
50
50
|
* @param {IService} json Service descriptor
|
|
51
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
51
52
|
* @returns {Service} Created service
|
|
52
53
|
* @throws {TypeError} If arguments are invalid
|
|
53
54
|
*/
|
|
54
|
-
Service.fromJSON = function fromJSON(name, json) {
|
|
55
|
+
Service.fromJSON = function fromJSON(name, json, depth) {
|
|
56
|
+
depth = util.checkDepth(depth);
|
|
55
57
|
var service = new Service(name, json.options);
|
|
56
58
|
/* istanbul ignore else */
|
|
57
59
|
if (json.methods)
|
|
58
60
|
for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
|
|
59
61
|
service.add(Method.fromJSON(names[i], json.methods[names[i]]));
|
|
60
62
|
if (json.nested)
|
|
61
|
-
service.addJSON(json.nested);
|
|
63
|
+
service.addJSON(json.nested, depth);
|
|
62
64
|
if (json.edition)
|
|
63
65
|
service._edition = json.edition;
|
|
64
66
|
service.comment = json.comment;
|
package/src/type.js
CHANGED
|
@@ -233,9 +233,11 @@ function clearCache(type) {
|
|
|
233
233
|
* Creates a message type from a message type descriptor.
|
|
234
234
|
* @param {string} name Message name
|
|
235
235
|
* @param {IType} json Message type descriptor
|
|
236
|
+
* @param {number} [depth] Current nesting depth, defaults to `0`
|
|
236
237
|
* @returns {Type} Created message type
|
|
237
238
|
*/
|
|
238
|
-
Type.fromJSON = function fromJSON(name, json) {
|
|
239
|
+
Type.fromJSON = function fromJSON(name, json, depth) {
|
|
240
|
+
depth = util.checkDepth(depth);
|
|
239
241
|
var type = new Type(name, json.options);
|
|
240
242
|
type.extensions = json.extensions;
|
|
241
243
|
type.reserved = json.reserved;
|
|
@@ -262,7 +264,7 @@ Type.fromJSON = function fromJSON(name, json) {
|
|
|
262
264
|
? Enum.fromJSON
|
|
263
265
|
: nested.methods !== undefined
|
|
264
266
|
? Service.fromJSON
|
|
265
|
-
: Namespace.fromJSON )(names[i], nested)
|
|
267
|
+
: Namespace.fromJSON )(names[i], nested, depth + 1)
|
|
266
268
|
);
|
|
267
269
|
}
|
|
268
270
|
if (json.extensions && json.extensions.length)
|
package/src/util.js
CHANGED
|
@@ -25,6 +25,20 @@ var reservedRe = util.patterns.reservedRe,
|
|
|
25
25
|
*/
|
|
26
26
|
util.fs = util.inquire("fs");
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Checks a recursion depth.
|
|
30
|
+
* @param {number|undefined} depth Depth of recursion
|
|
31
|
+
* @returns {number} Depth of recursion
|
|
32
|
+
* @throws {Error} If depth exceeds util.recursionLimit
|
|
33
|
+
*/
|
|
34
|
+
util.checkDepth = function checkDepth(depth) {
|
|
35
|
+
if (depth === undefined)
|
|
36
|
+
depth = 0;
|
|
37
|
+
if (depth > util.recursionLimit)
|
|
38
|
+
throw Error("max depth exceeded");
|
|
39
|
+
return depth;
|
|
40
|
+
};
|
|
41
|
+
|
|
28
42
|
/**
|
|
29
43
|
* Converts an object's values to an array.
|
|
30
44
|
* @param {Object.<string,*>} object Object to convert
|