protobufjs 8.6.3 → 8.6.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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.6.3 (c) 2016, daniel wirtz
3
- * compiled thu, 11 jun 2026 00:02:30 utc
2
+ * protobuf.js v8.6.5 (c) 2016, daniel wirtz
3
+ * compiled tue, 23 jun 2026 14:36:35 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -57,31 +57,33 @@ var Enum = require(5),
57
57
  * @param {Field} field Reflected field
58
58
  * @param {number} fieldIndex Field index
59
59
  * @param {string} prop Property reference
60
+ * @param {string} [dstProp] Repeated destination property reference
60
61
  * @returns {Codegen} Codegen instance
61
62
  * @ignore
62
63
  */
63
- function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
64
- var defaultAlreadyEmitted = false;
64
+ function genValuePartial_fromObject(gen, field, fieldIndex, prop, dstProp) {
65
65
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
66
66
  if (field.resolvedType) {
67
- if (field.resolvedType instanceof Enum) { gen
67
+ if (field.resolvedType instanceof Enum) {
68
+ var dst = dstProp
69
+ ? "m" + dstProp + "[m" + dstProp + ".length]"
70
+ : "m" + prop;
71
+ gen
68
72
  ("switch(d%s){", prop);
69
- for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
70
- // enum unknown values passthrough
71
- if (values[keys[i]] === field.typeDefault && !defaultAlreadyEmitted) { gen
72
- ("default:")
73
- ("if(typeof d%s===\"number\"){m%s=d%s;break}", prop, prop, prop);
74
- if (!field.repeated) gen // fallback to default value only for
75
- // arrays, to avoid leaving holes.
76
- ("break"); // for non-repeated fields, just ignore
77
- defaultAlreadyEmitted = true;
78
- }
79
- gen
73
+ for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) { gen
80
74
  ("case%j:", keys[i])
81
75
  ("case %i:", values[keys[i]])
82
- ("m%s=%j", prop, values[keys[i]])
76
+ ("%s=%j", dst, values[keys[i]])
83
77
  ("break");
84
- } gen
78
+ }
79
+ gen
80
+ ("default:");
81
+ if (field.resolvedType._features.enum_type !== "CLOSED") {
82
+ gen
83
+ ("if(typeof d%s===\"number\"&&(d%s|0)===d%s)", prop, prop, prop)
84
+ ("%s=d%s", dst, prop);
85
+ }
86
+ gen
85
87
  ("}");
86
88
  } else gen
87
89
  ("if(!util.isObject(d%s))", prop)
@@ -184,10 +186,14 @@ converter.fromObject = function fromObject(mtype) {
184
186
  } else if (field.repeated) { gen
185
187
  ("if(d%s){", prop)
186
188
  ("if(!Array.isArray(d%s))", prop)
187
- ("throw TypeError(%j)", field.fullName + ": array expected")
188
- ("m%s=Array(d%s.length)", prop, prop)
189
+ ("throw TypeError(%j)", field.fullName + ": array expected");
190
+ if (field.resolvedType instanceof Enum) gen
191
+ ("m%s=[]", prop);
192
+ else gen
193
+ ("m%s=Array(d%s.length)", prop, prop);
194
+ gen
189
195
  ("for(var i=0;i<d%s.length;++i){", prop);
190
- genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
196
+ genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]", field.resolvedType instanceof Enum ? prop : undefined)
191
197
  ("}")
192
198
  ("}");
193
199
 
@@ -204,6 +210,8 @@ converter.fromObject = function fromObject(mtype) {
204
210
  ("if(d%s.length){", prop);
205
211
  else if (field.type === "bool") gen
206
212
  ("if(d%s){", prop);
213
+ else if (field.type === "double" || field.type === "float") gen
214
+ ("if(!Object.is(Number(d%s),0)){", prop);
207
215
  else if (types.long[field.type] !== undefined) gen
208
216
  ("if(typeof d%s===\"object\"?d%s.low||d%s.high:Number(d%s)!==0){", prop, prop, prop, prop);
209
217
  else gen
@@ -401,6 +409,16 @@ function stringMethod(field) {
401
409
  return field._features.utf8_validation === "VERIFY" ? "stringVerify" : "string";
402
410
  }
403
411
 
412
+ function genPreserveUnknown(gen, ref) {
413
+ /* eslint-disable no-unexpected-multiline */
414
+ return gen
415
+ ("if(!r.discardUnknown){")
416
+ ("util.makeProp(m,\"$unknowns\",false);")
417
+ ("(m.$unknowns||(m.$unknowns=[])).push(%s)", ref)
418
+ ("}");
419
+ /* eslint-enable no-unexpected-multiline */
420
+ }
421
+
404
422
  /**
405
423
  * Generates a decoder specific to the specified message type.
406
424
  * @param {Type} mtype Message type
@@ -409,14 +427,14 @@ function stringMethod(field) {
409
427
  function decoder(mtype) {
410
428
  /* eslint-disable no-unexpected-multiline */
411
429
  var hasMapField = false,
412
- hasImplicitPresenceField = false,
430
+ needsValueVar = false,
413
431
  i = 0;
414
432
  for (; i < mtype.fieldsArray.length; ++i) {
415
433
  var pfield = mtype._fieldsArray[i];
416
434
  if (pfield.map)
417
435
  hasMapField = true;
418
- if (!pfield.repeated && !pfield.map && !pfield.hasPresence)
419
- hasImplicitPresenceField = true;
436
+ if (pfield.resolvedType instanceof Enum || !pfield.repeated && !pfield.map && !pfield.hasPresence)
437
+ needsValueVar = true;
420
438
  }
421
439
  var gen = util.codegen(["r", "l", "z", "q", "g"])
422
440
  ("if(!(r instanceof Reader))")
@@ -424,7 +442,7 @@ function decoder(mtype) {
424
442
  ("if(q===undefined)q=0")
425
443
  ("if(q>Reader.recursionLimit)")
426
444
  ("throw Error(\"max depth exceeded\")")
427
- ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
445
+ ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : needsValueVar ? ",v" : ""))
428
446
  ("while(r.pos<c){")
429
447
  ("var s=r.pos")
430
448
  ("var t=r.tag()")
@@ -436,18 +454,21 @@ function decoder(mtype) {
436
454
  ("var u=t&7")
437
455
  ("switch(t>>>=3){");
438
456
  for (i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
439
- var field = mtype._fieldsArray[i].resolve(),
440
- type = field.resolvedType instanceof Enum ? "int32" : field.type,
441
- ref = "m" + util.safeProp(field.name);
457
+ var field = mtype._fieldsArray[i].resolve(),
458
+ type = field.resolvedType instanceof Enum ? "int32" : field.type,
459
+ ref = "m" + util.safeProp(field.name),
460
+ closed = field.resolvedType instanceof Enum && field.resolvedType._features.enum_type === "CLOSED";
442
461
 
443
462
  // Map fields
444
463
  if (field.map) {
445
464
  gen
446
465
  ("case %i:{", field.id)
447
466
  ("if(u!==2)")
448
- ("break")
467
+ ("break");
468
+ if (!closed) gen
449
469
  ("if(%s===util.emptyObject)", ref)
450
- ("%s={}", ref)
470
+ ("%s={}", ref);
471
+ gen
451
472
  ("var c2=r.uint32()+r.pos");
452
473
 
453
474
  if (types.defaults[field.keyType] !== undefined) gen
@@ -487,6 +508,15 @@ function decoder(mtype) {
487
508
  ("r.skipType(u,q,t2)")
488
509
  ("}");
489
510
 
511
+ if (closed) { gen
512
+ ("if(types[%i].valuesById[v]===undefined){", i);
513
+ genPreserveUnknown(gen, "r.raw(s,r.pos)")
514
+ ("continue")
515
+ ("}")
516
+ ("if(%s===util.emptyObject)", ref)
517
+ ("%s={}", ref);
518
+ }
519
+
490
520
  var val = types.basic[type] === undefined ? "v||new types[" + i + "].ctor" : "v";
491
521
  if (types.long[field.keyType] !== undefined) gen
492
522
  ("%s[typeof k===\"object\"?util.longToHash(k):k]=%s", ref, val);
@@ -504,20 +534,39 @@ function decoder(mtype) {
504
534
  ("{");
505
535
 
506
536
  // Packable (always check for forward and backward compatiblity)
507
- if (types.packed[type] !== undefined) gen
508
- ("if(u===2){")
537
+ if (types.packed[type] !== undefined) {
538
+ gen
539
+ ("if(u===2){");
540
+ if (!closed) gen
509
541
  ("if(!(%s&&%s.length))", ref, ref)
510
- ("%s=[]", ref)
511
- ("var c2=r.uint32()+r.pos")
542
+ ("%s=[]", ref);
543
+ gen
544
+ ("var c2=r.uint32()+r.pos");
545
+ if (closed) {
546
+ gen
547
+ ("while(r.pos<c2){")
548
+ ("s=r.pos")
549
+ ("v=r.%s()", type)
550
+ ("if(types[%i].valuesById[v]!==undefined){", i)
551
+ ("if(!(%s&&%s.length))", ref, ref)
552
+ ("%s=[]", ref)
553
+ ("%s.push(v)", ref)
554
+ ("}else");
555
+ genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
556
+ ("}");
557
+ } else gen
512
558
  ("while(r.pos<c2)")
513
- ("%s.push(r.%s())", ref, type)
559
+ ("%s.push(r.%s())", ref, type);
560
+ gen
514
561
  ("continue")
515
562
  ("}");
563
+ }
516
564
 
517
565
  // Non-packed
518
566
  gen
519
567
  ("if(u!==%i)", types.basic[type] === undefined ? field.delimited ? 3 : 2 : types.basic[type])
520
- ("break")
568
+ ("break");
569
+ if (!closed) gen
521
570
  ("if(!(%s&&%s.length))", ref, ref)
522
571
  ("%s=[]", ref);
523
572
  if (types.basic[type] === undefined) {
@@ -525,6 +574,14 @@ function decoder(mtype) {
525
574
  ("%s.push(types[%i].decode(r,undefined,%i,q+1))", ref, i, field.id * 8 + 4);
526
575
  else gen
527
576
  ("%s.push(types[%i].decode(r,r.uint32(),undefined,q+1))", ref, i);
577
+ } else if (closed) { gen
578
+ ("v=r.%s()", type)
579
+ ("if(types[%i].valuesById[v]!==undefined){", i)
580
+ ("if(!(%s&&%s.length))", ref, ref)
581
+ ("%s=[]", ref)
582
+ ("%s.push(v)", ref)
583
+ ("}else");
584
+ genPreserveUnknown(gen, "r.raw(s,r.pos)");
528
585
  } else gen
529
586
  ("%s.push(r.%s())", ref, type === "string" ? stringMethod(field) : type);
530
587
 
@@ -543,33 +600,55 @@ function decoder(mtype) {
543
600
  gen
544
601
  ("case %i:{", field.id)
545
602
  ("if(u!==%i)", types.basic[type])
546
- ("break")
603
+ ("break");
604
+ if (closed) { gen
605
+ ("v=r.%s()", type)
606
+ ("if(types[%i].valuesById[v]!==undefined){", i)
607
+ ("%s=v", ref);
608
+ if (field.partOf) gen
609
+ ("m%s=%j", util.safeProp(field.partOf.name), field.name);
610
+ gen
611
+ ("}else");
612
+ genPreserveUnknown(gen, "r.raw(s,r.pos)");
613
+ } else gen
547
614
  ("%s=r.%s()", ref, type === "string" ? stringMethod(field) : type);
548
615
  } else {
549
616
  gen
550
617
  ("case %i:{", field.id)
551
618
  ("if(u!==%i)", types.basic[type])
552
619
  ("break");
553
- if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
554
- // TODO: Protoc rejects open enums whose first value is not zero.
555
- // We should do the same, but for v8 this would be a regression.
556
- ("if((v=r.%s())!==%j)", type, field.typeDefault);
557
- else if (type === "string") gen
558
- ("if((v=r.%s()).length)", stringMethod(field));
559
- else if (type === "bytes") gen
560
- ("if((v=r.%s()).length)", type);
561
- else if (types.long[type] !== undefined) gen
562
- ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
563
- else if (type === "double" || type === "float") gen
564
- ("if((v=r.%s())!==0)", type);
565
- else gen
566
- ("if(v=r.%s())", type);
567
- gen
568
- ("%s=v", ref)
569
- ("else")
570
- ("delete %s", ref); // rare/odd case: later default clears earlier non-default
620
+ if (closed) { gen
621
+ ("v=r.%s()", type)
622
+ ("if(types[%i].valuesById[v]!==undefined){", i)
623
+ ("if(v!==%j)", field.typeDefault)
624
+ ("%s=v", ref)
625
+ ("else")
626
+ ("delete %s", ref)
627
+ ("}else{");
628
+ genPreserveUnknown(gen, "r.raw(s,r.pos)")
629
+ ("}");
630
+ } else {
631
+ if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
632
+ // TODO: Protoc rejects open enums whose first value is not zero.
633
+ // We should do the same, but for v8 this would be a regression.
634
+ ("if((v=r.%s())!==%j)", type, field.typeDefault);
635
+ else if (type === "string") gen
636
+ ("if((v=r.%s()).length)", stringMethod(field));
637
+ else if (type === "bytes") gen
638
+ ("if((v=r.%s()).length)", type);
639
+ else if (types.long[type] !== undefined) gen
640
+ ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
641
+ else if (type === "double" || type === "float") gen
642
+ ("if(!Object.is(v=r.%s(),0))", type);
643
+ else gen
644
+ ("if(v=r.%s())", type);
645
+ gen
646
+ ("%s=v", ref)
647
+ ("else")
648
+ ("delete %s", ref); // rare/odd case: later default clears earlier non-default
649
+ }
571
650
  }
572
- if (field.partOf) gen
651
+ if (field.partOf && !closed) gen
573
652
  ("m%s=%j", util.safeProp(field.partOf.name), field.name);
574
653
  gen
575
654
  ("continue")
@@ -579,11 +658,8 @@ function decoder(mtype) {
579
658
  ("}");
580
659
  // Unknown fields
581
660
  gen
582
- ("r.skipType(%s,q,t)", i ? "u" : "t&7")
583
- ("if(!r.discardUnknown){")
584
- ("util.makeProp(m,\"$unknowns\",false);")
585
- ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
586
- ("}")
661
+ ("r.skipType(%s,q,t)", i ? "u" : "t&7");
662
+ genPreserveUnknown(gen, "r.raw(s,r.pos)")
587
663
  ("}")
588
664
  ("if(z!==undefined)")
589
665
  ("throw Error(\"missing end group\")");
@@ -695,8 +771,23 @@ function encoder(mtype) {
695
771
 
696
772
  // Non-repeated
697
773
  } else {
698
- if (!field.required) gen
774
+ if (!field.required)
775
+ if (field.hasPresence || !(field.resolvedType instanceof Enum || types.basic[type] !== undefined)) gen
699
776
  ("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
777
+ else if (field.resolvedType instanceof Enum) gen
778
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==%j)", ref, field.name, ref, field.typeDefault);
779
+ else if (type === "bool") gen
780
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==false)", ref, field.name, ref);
781
+ else if (type === "string") gen
782
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==\"\")", ref, field.name, ref);
783
+ else if (type === "bytes") gen
784
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s.length)", ref, field.name, ref);
785
+ else if (type === "double" || type === "float") gen
786
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&!Object.is(%s,0))", ref, field.name, ref);
787
+ else if (types.long[type] !== undefined) gen
788
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&(typeof %s===\"object\"?%s.low||%s.high:%s!==0))", ref, field.name, ref, ref, ref, ref);
789
+ else gen
790
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==0)", ref, field.name, ref);
700
791
 
701
792
  if (wireType === undefined)
702
793
  genTypePartial(gen, field, index, ref);
@@ -720,7 +811,15 @@ module.exports = Enum;
720
811
 
721
812
  // extends ReflectionObject
722
813
  var ReflectionObject = require(13);
723
- ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
814
+ Enum.prototype = Object.create(ReflectionObject.prototype, {
815
+ constructor: {
816
+ value: Enum,
817
+ writable: true,
818
+ enumerable: false,
819
+ configurable: true
820
+ }
821
+ });
822
+ Enum.className = "Enum";
724
823
 
725
824
  var Namespace = require(12),
726
825
  util = require(24);
@@ -747,7 +846,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
747
846
  * Enum values by id.
748
847
  * @type {Object.<number,string>}
749
848
  */
750
- this.valuesById = {};
849
+ this.valuesById = Object.create(null);
751
850
 
752
851
  /**
753
852
  * Enum values by name.
@@ -953,7 +1052,15 @@ module.exports = Field;
953
1052
 
954
1053
  // extends ReflectionObject
955
1054
  var ReflectionObject = require(13);
956
- ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
1055
+ Field.prototype = Object.create(ReflectionObject.prototype, {
1056
+ constructor: {
1057
+ value: Field,
1058
+ writable: true,
1059
+ enumerable: false,
1060
+ configurable: true
1061
+ }
1062
+ });
1063
+ Field.className = "Field";
957
1064
 
958
1065
  var Enum = require(5),
959
1066
  types = require(23),
@@ -1595,7 +1702,15 @@ module.exports = MapField;
1595
1702
 
1596
1703
  // extends Field
1597
1704
  var Field = require(6);
1598
- ((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
1705
+ MapField.prototype = Object.create(Field.prototype, {
1706
+ constructor: {
1707
+ value: MapField,
1708
+ writable: true,
1709
+ enumerable: false,
1710
+ configurable: true
1711
+ }
1712
+ });
1713
+ MapField.className = "MapField";
1599
1714
 
1600
1715
  var types = require(23),
1601
1716
  util = require(24);
@@ -1872,7 +1987,15 @@ module.exports = Method;
1872
1987
 
1873
1988
  // extends ReflectionObject
1874
1989
  var ReflectionObject = require(13);
1875
- ((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
1990
+ Method.prototype = Object.create(ReflectionObject.prototype, {
1991
+ constructor: {
1992
+ value: Method,
1993
+ writable: true,
1994
+ enumerable: false,
1995
+ configurable: true
1996
+ }
1997
+ });
1998
+ Method.className = "Method";
1876
1999
 
1877
2000
  var util = require(24);
1878
2001
 
@@ -2049,7 +2172,15 @@ module.exports = Namespace;
2049
2172
 
2050
2173
  // extends ReflectionObject
2051
2174
  var ReflectionObject = require(13);
2052
- ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
2175
+ Namespace.prototype = Object.create(ReflectionObject.prototype, {
2176
+ constructor: {
2177
+ value: Namespace,
2178
+ writable: true,
2179
+ enumerable: false,
2180
+ configurable: true
2181
+ }
2182
+ });
2183
+ Namespace.className = "Namespace";
2053
2184
 
2054
2185
  var Field = require(6),
2055
2186
  util = require(24),
@@ -2884,7 +3015,7 @@ ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProt
2884
3015
  * @returns {*} Option value or `undefined` if not set
2885
3016
  */
2886
3017
  ReflectionObject.prototype.getOption = function getOption(name) {
2887
- if (this.options)
3018
+ if (this.options && Object.prototype.hasOwnProperty.call(this.options, name))
2888
3019
  return this.options[name];
2889
3020
  return undefined;
2890
3021
  };
@@ -2903,9 +3034,12 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
2903
3034
  this.options = {};
2904
3035
  if (/^features\./.test(name)) {
2905
3036
  util.setProperty(this.options, name, value, ifNotSet);
2906
- } else if (!ifNotSet || this.options[name] === undefined) {
2907
- if (this.getOption(name) !== value) this.resolved = false;
2908
- this.options[name] = value;
3037
+ } else {
3038
+ var prev = this.getOption(name);
3039
+ if (!ifNotSet || prev === undefined) {
3040
+ if (prev !== value) this.resolved = false;
3041
+ this.options[name] = value;
3042
+ }
2909
3043
  }
2910
3044
 
2911
3045
  return this;
@@ -2967,15 +3101,22 @@ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
2967
3101
 
2968
3102
  /**
2969
3103
  * Converts this instance to its string representation.
3104
+ * @name ReflectionObject#toString
3105
+ * @function
2970
3106
  * @returns {string} Class name[, space, full name]
2971
3107
  */
2972
- ReflectionObject.prototype.toString = function toString() {
2973
- var className = this.constructor.className,
2974
- fullName = this.fullName;
2975
- if (fullName.length)
2976
- return className + " " + fullName;
2977
- return className;
2978
- };
3108
+ Object.defineProperty(ReflectionObject.prototype, "toString", {
3109
+ value: function toString() {
3110
+ var className = this.constructor.className,
3111
+ fullName = this.fullName;
3112
+ if (fullName.length)
3113
+ return className + " " + fullName;
3114
+ return className;
3115
+ },
3116
+ writable: true,
3117
+ enumerable: false,
3118
+ configurable: true
3119
+ });
2979
3120
 
2980
3121
  /**
2981
3122
  * Converts the edition this object is pinned to for JSON format.
@@ -3001,7 +3142,15 @@ module.exports = OneOf;
3001
3142
 
3002
3143
  // extends ReflectionObject
3003
3144
  var ReflectionObject = require(13);
3004
- ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
3145
+ OneOf.prototype = Object.create(ReflectionObject.prototype, {
3146
+ constructor: {
3147
+ value: OneOf,
3148
+ writable: true,
3149
+ enumerable: false,
3150
+ configurable: true
3151
+ }
3152
+ });
3153
+ OneOf.className = "OneOf";
3005
3154
 
3006
3155
  var Field = require(6),
3007
3156
  util = require(24);
@@ -3788,7 +3937,14 @@ module.exports = BufferReader;
3788
3937
 
3789
3938
  // extends Reader
3790
3939
  var Reader = require(15);
3791
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
3940
+ BufferReader.prototype = Object.create(Reader.prototype, {
3941
+ constructor: {
3942
+ value: BufferReader,
3943
+ writable: true,
3944
+ enumerable: false,
3945
+ configurable: true
3946
+ }
3947
+ });
3792
3948
 
3793
3949
  var util = require(33);
3794
3950
 
@@ -3862,7 +4018,15 @@ module.exports = Root;
3862
4018
 
3863
4019
  // extends Namespace
3864
4020
  var Namespace = require(12);
3865
- ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
4021
+ Root.prototype = Object.create(Namespace.prototype, {
4022
+ constructor: {
4023
+ value: Root,
4024
+ writable: true,
4025
+ enumerable: false,
4026
+ configurable: true
4027
+ }
4028
+ });
4029
+ Root.className = "Root";
3866
4030
 
3867
4031
  var Field = require(6),
3868
4032
  Enum = require(5),
@@ -4339,7 +4503,14 @@ module.exports = Service;
4339
4503
  var util = require(33);
4340
4504
 
4341
4505
  // Extends EventEmitter
4342
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
4506
+ Service.prototype = Object.create(util.EventEmitter.prototype, {
4507
+ constructor: {
4508
+ value: Service,
4509
+ writable: true,
4510
+ enumerable: false,
4511
+ configurable: true
4512
+ }
4513
+ });
4343
4514
 
4344
4515
  /**
4345
4516
  * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
@@ -4488,7 +4659,15 @@ module.exports = Service;
4488
4659
 
4489
4660
  // extends Namespace
4490
4661
  var Namespace = require(12);
4491
- ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
4662
+ Service.prototype = Object.create(Namespace.prototype, {
4663
+ constructor: {
4664
+ value: Service,
4665
+ writable: true,
4666
+ enumerable: false,
4667
+ configurable: true
4668
+ }
4669
+ });
4670
+ Service.className = "Service";
4492
4671
 
4493
4672
  var Method = require(11),
4494
4673
  util = require(24),
@@ -4688,7 +4867,15 @@ module.exports = Type;
4688
4867
 
4689
4868
  // extends Namespace
4690
4869
  var Namespace = require(12);
4691
- ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
4870
+ Type.prototype = Object.create(Namespace.prototype, {
4871
+ constructor: {
4872
+ value: Type,
4873
+ writable: true,
4874
+ enumerable: false,
4875
+ configurable: true
4876
+ }
4877
+ });
4878
+ Type.className = "Type";
4692
4879
 
4693
4880
  var Enum = require(5),
4694
4881
  OneOf = require(14),
@@ -4853,7 +5040,13 @@ Object.defineProperties(Type.prototype, {
4853
5040
  // Ensure proper prototype
4854
5041
  var prototype = ctor.prototype;
4855
5042
  if (!(prototype instanceof Message)) {
4856
- (ctor.prototype = new Message()).constructor = ctor;
5043
+ ctor.prototype = new Message();
5044
+ Object.defineProperty(ctor.prototype, "constructor", {
5045
+ value: ctor,
5046
+ writable: true,
5047
+ enumerable: false,
5048
+ configurable: true
5049
+ });
4857
5050
  util.merge(ctor.prototype, prototype);
4858
5051
  }
4859
5052
 
@@ -6088,7 +6281,12 @@ function codegen(functionParams, functionName) {
6088
6281
  return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
6089
6282
  }
6090
6283
 
6091
- Codegen.toString = toString;
6284
+ Object.defineProperty(Codegen, "toString", {
6285
+ value: toString,
6286
+ writable: true,
6287
+ enumerable: true,
6288
+ configurable: true
6289
+ });
6092
6290
  return Codegen;
6093
6291
  }
6094
6292
 
@@ -6875,6 +7073,7 @@ LongBits.prototype.length = function length() {
6875
7073
 
6876
7074
  },{"33":33}],33:[function(require,module,exports){
6877
7075
  "use strict";
7076
+ /* global globalThis */
6878
7077
  var util = exports;
6879
7078
 
6880
7079
  // used to return a Promise where callback is omitted
@@ -6929,6 +7128,7 @@ util.isNode = Boolean(typeof global !== "undefined"
6929
7128
  util.global = util.isNode && global
6930
7129
  || typeof window !== "undefined" && window
6931
7130
  || typeof self !== "undefined" && self
7131
+ || typeof globalThis !== "undefined" && globalThis
6932
7132
  || this; // eslint-disable-line no-invalid-this
6933
7133
 
6934
7134
  /**
@@ -7043,6 +7243,28 @@ util.newBuffer = function newBuffer(sizeOrArray) {
7043
7243
  : new Uint8Array(sizeOrArray);
7044
7244
  };
7045
7245
 
7246
+ /**
7247
+ * Prepends a raw field tag to raw field data.
7248
+ * @param {number} id Field id
7249
+ * @param {number} wireType Wire type
7250
+ * @param {Uint8Array} data Raw field data
7251
+ * @returns {Uint8Array|Buffer} Raw field bytes
7252
+ * @ignore
7253
+ */
7254
+ util.rawField = function rawField(id, wireType, data) {
7255
+ var out = [],
7256
+ tag = id << 3 | wireType;
7257
+ tag >>>= 0;
7258
+ while (tag > 127) {
7259
+ out.push(tag & 127 | 128);
7260
+ tag >>>= 7;
7261
+ }
7262
+ out.push(tag);
7263
+ for (var i = 0; i < data.length; ++i)
7264
+ out.push(data[i]);
7265
+ return util.newBuffer(out);
7266
+ };
7267
+
7046
7268
  /**
7047
7269
  * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
7048
7270
  * @type {Constructor<Uint8Array>}
@@ -7156,7 +7378,7 @@ function merge(dst) { // used by converters
7156
7378
  if (!src)
7157
7379
  continue;
7158
7380
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
7159
- if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
7381
+ if (!isUnsafeProperty(keys[i]) && (!ifNotSet || !Object.prototype.hasOwnProperty.call(dst, keys[i]) || dst[keys[i]] === undefined))
7160
7382
  dst[keys[i]] = src[keys[i]];
7161
7383
  }
7162
7384
  return dst;
@@ -7561,7 +7783,14 @@ function pool(alloc, slice, size) {
7561
7783
  */
7562
7784
  var utf8 = exports,
7563
7785
  replacementChar = "\ufffd",
7786
+ strictDecoder;
7787
+
7788
+ try {
7564
7789
  strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
7790
+ } catch (err) {
7791
+ // "fatal" option is not supported on Node.js compiled without ICU
7792
+ strictDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
7793
+ }
7565
7794
 
7566
7795
  /**
7567
7796
  * Calculates the UTF8 byte length of a string.
@@ -7756,16 +7985,21 @@ function invalid(field, expected) {
7756
7985
  */
7757
7986
  function genVerifyValue(gen, field, fieldIndex, ref) {
7758
7987
  /* eslint-disable no-unexpected-multiline */
7759
- if (field.resolvedType) {
7760
- if (field.resolvedType instanceof Enum) { gen
7761
- ("switch(%s){", ref)
7762
- ("default:")
7988
+ var resolvedType = field.resolvedType;
7989
+ if (resolvedType) {
7990
+ if (resolvedType instanceof Enum) {
7991
+ if (resolvedType._features.enum_type === "CLOSED") { gen
7992
+ ("switch(%s){", ref)
7993
+ ("default:")
7994
+ ("return%j", invalid(field, "enum value"));
7995
+ for (var keys = Object.keys(resolvedType.values), j = 0; j < keys.length; ++j) gen
7996
+ ("case %i:", resolvedType.values[keys[j]]);
7997
+ gen
7998
+ ("break")
7999
+ ("}");
8000
+ } else gen
8001
+ ("if(typeof %s!==\"number\"||(%s|0)!==%s)", ref, ref, ref)
7763
8002
  ("return%j", invalid(field, "enum value"));
7764
- for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
7765
- ("case %i:", field.resolvedType.values[keys[j]]);
7766
- gen
7767
- ("break")
7768
- ("}");
7769
8003
  } else {
7770
8004
  gen
7771
8005
  ("{")
@@ -8527,7 +8761,14 @@ module.exports = BufferWriter;
8527
8761
 
8528
8762
  // extends Writer
8529
8763
  var Writer = require(40);
8530
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
8764
+ BufferWriter.prototype = Object.create(Writer.prototype, {
8765
+ constructor: {
8766
+ value: BufferWriter,
8767
+ writable: true,
8768
+ enumerable: false,
8769
+ configurable: true
8770
+ }
8771
+ });
8531
8772
 
8532
8773
  var util = require(33);
8533
8774