protobufjs 8.6.4 → 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.
package/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.6.4 (c) 2016, daniel wirtz
3
- * compiled tue, 16 jun 2026 14:35:46 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
  */
@@ -458,31 +458,33 @@ var Enum = require(6),
458
458
  * @param {Field} field Reflected field
459
459
  * @param {number} fieldIndex Field index
460
460
  * @param {string} prop Property reference
461
+ * @param {string} [dstProp] Repeated destination property reference
461
462
  * @returns {Codegen} Codegen instance
462
463
  * @ignore
463
464
  */
464
- function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
465
- var defaultAlreadyEmitted = false;
465
+ function genValuePartial_fromObject(gen, field, fieldIndex, prop, dstProp) {
466
466
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
467
467
  if (field.resolvedType) {
468
- if (field.resolvedType instanceof Enum) { gen
468
+ if (field.resolvedType instanceof Enum) {
469
+ var dst = dstProp
470
+ ? "m" + dstProp + "[m" + dstProp + ".length]"
471
+ : "m" + prop;
472
+ gen
469
473
  ("switch(d%s){", prop);
470
- for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
471
- // enum unknown values passthrough
472
- if (values[keys[i]] === field.typeDefault && !defaultAlreadyEmitted) { gen
473
- ("default:")
474
- ("if(typeof d%s===\"number\"){m%s=d%s;break}", prop, prop, prop);
475
- if (!field.repeated) gen // fallback to default value only for
476
- // arrays, to avoid leaving holes.
477
- ("break"); // for non-repeated fields, just ignore
478
- defaultAlreadyEmitted = true;
479
- }
480
- gen
474
+ for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) { gen
481
475
  ("case%j:", keys[i])
482
476
  ("case %i:", values[keys[i]])
483
- ("m%s=%j", prop, values[keys[i]])
477
+ ("%s=%j", dst, values[keys[i]])
484
478
  ("break");
485
- } gen
479
+ }
480
+ gen
481
+ ("default:");
482
+ if (field.resolvedType._features.enum_type !== "CLOSED") {
483
+ gen
484
+ ("if(typeof d%s===\"number\"&&(d%s|0)===d%s)", prop, prop, prop)
485
+ ("%s=d%s", dst, prop);
486
+ }
487
+ gen
486
488
  ("}");
487
489
  } else gen
488
490
  ("if(!util.isObject(d%s))", prop)
@@ -585,10 +587,14 @@ converter.fromObject = function fromObject(mtype) {
585
587
  } else if (field.repeated) { gen
586
588
  ("if(d%s){", prop)
587
589
  ("if(!Array.isArray(d%s))", prop)
588
- ("throw TypeError(%j)", field.fullName + ": array expected")
589
- ("m%s=Array(d%s.length)", prop, prop)
590
+ ("throw TypeError(%j)", field.fullName + ": array expected");
591
+ if (field.resolvedType instanceof Enum) gen
592
+ ("m%s=[]", prop);
593
+ else gen
594
+ ("m%s=Array(d%s.length)", prop, prop);
595
+ gen
590
596
  ("for(var i=0;i<d%s.length;++i){", prop);
591
- genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
597
+ genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]", field.resolvedType instanceof Enum ? prop : undefined)
592
598
  ("}")
593
599
  ("}");
594
600
 
@@ -605,6 +611,8 @@ converter.fromObject = function fromObject(mtype) {
605
611
  ("if(d%s.length){", prop);
606
612
  else if (field.type === "bool") gen
607
613
  ("if(d%s){", prop);
614
+ else if (field.type === "double" || field.type === "float") gen
615
+ ("if(!Object.is(Number(d%s),0)){", prop);
608
616
  else if (types.long[field.type] !== undefined) gen
609
617
  ("if(typeof d%s===\"object\"?d%s.low||d%s.high:Number(d%s)!==0){", prop, prop, prop, prop);
610
618
  else gen
@@ -802,6 +810,16 @@ function stringMethod(field) {
802
810
  return field._features.utf8_validation === "VERIFY" ? "stringVerify" : "string";
803
811
  }
804
812
 
813
+ function genPreserveUnknown(gen, ref) {
814
+ /* eslint-disable no-unexpected-multiline */
815
+ return gen
816
+ ("if(!r.discardUnknown){")
817
+ ("util.makeProp(m,\"$unknowns\",false);")
818
+ ("(m.$unknowns||(m.$unknowns=[])).push(%s)", ref)
819
+ ("}");
820
+ /* eslint-enable no-unexpected-multiline */
821
+ }
822
+
805
823
  /**
806
824
  * Generates a decoder specific to the specified message type.
807
825
  * @param {Type} mtype Message type
@@ -810,14 +828,14 @@ function stringMethod(field) {
810
828
  function decoder(mtype) {
811
829
  /* eslint-disable no-unexpected-multiline */
812
830
  var hasMapField = false,
813
- hasImplicitPresenceField = false,
831
+ needsValueVar = false,
814
832
  i = 0;
815
833
  for (; i < mtype.fieldsArray.length; ++i) {
816
834
  var pfield = mtype._fieldsArray[i];
817
835
  if (pfield.map)
818
836
  hasMapField = true;
819
- if (!pfield.repeated && !pfield.map && !pfield.hasPresence)
820
- hasImplicitPresenceField = true;
837
+ if (pfield.resolvedType instanceof Enum || !pfield.repeated && !pfield.map && !pfield.hasPresence)
838
+ needsValueVar = true;
821
839
  }
822
840
  var gen = util.codegen(["r", "l", "z", "q", "g"])
823
841
  ("if(!(r instanceof Reader))")
@@ -825,7 +843,7 @@ function decoder(mtype) {
825
843
  ("if(q===undefined)q=0")
826
844
  ("if(q>Reader.recursionLimit)")
827
845
  ("throw Error(\"max depth exceeded\")")
828
- ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
846
+ ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : needsValueVar ? ",v" : ""))
829
847
  ("while(r.pos<c){")
830
848
  ("var s=r.pos")
831
849
  ("var t=r.tag()")
@@ -837,18 +855,21 @@ function decoder(mtype) {
837
855
  ("var u=t&7")
838
856
  ("switch(t>>>=3){");
839
857
  for (i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
840
- var field = mtype._fieldsArray[i].resolve(),
841
- type = field.resolvedType instanceof Enum ? "int32" : field.type,
842
- ref = "m" + util.safeProp(field.name);
858
+ var field = mtype._fieldsArray[i].resolve(),
859
+ type = field.resolvedType instanceof Enum ? "int32" : field.type,
860
+ ref = "m" + util.safeProp(field.name),
861
+ closed = field.resolvedType instanceof Enum && field.resolvedType._features.enum_type === "CLOSED";
843
862
 
844
863
  // Map fields
845
864
  if (field.map) {
846
865
  gen
847
866
  ("case %i:{", field.id)
848
867
  ("if(u!==2)")
849
- ("break")
868
+ ("break");
869
+ if (!closed) gen
850
870
  ("if(%s===util.emptyObject)", ref)
851
- ("%s={}", ref)
871
+ ("%s={}", ref);
872
+ gen
852
873
  ("var c2=r.uint32()+r.pos");
853
874
 
854
875
  if (types.defaults[field.keyType] !== undefined) gen
@@ -888,6 +909,15 @@ function decoder(mtype) {
888
909
  ("r.skipType(u,q,t2)")
889
910
  ("}");
890
911
 
912
+ if (closed) { gen
913
+ ("if(types[%i].valuesById[v]===undefined){", i);
914
+ genPreserveUnknown(gen, "r.raw(s,r.pos)")
915
+ ("continue")
916
+ ("}")
917
+ ("if(%s===util.emptyObject)", ref)
918
+ ("%s={}", ref);
919
+ }
920
+
891
921
  var val = types.basic[type] === undefined ? "v||new types[" + i + "].ctor" : "v";
892
922
  if (types.long[field.keyType] !== undefined) gen
893
923
  ("%s[typeof k===\"object\"?util.longToHash(k):k]=%s", ref, val);
@@ -905,20 +935,39 @@ function decoder(mtype) {
905
935
  ("{");
906
936
 
907
937
  // Packable (always check for forward and backward compatiblity)
908
- if (types.packed[type] !== undefined) gen
909
- ("if(u===2){")
938
+ if (types.packed[type] !== undefined) {
939
+ gen
940
+ ("if(u===2){");
941
+ if (!closed) gen
910
942
  ("if(!(%s&&%s.length))", ref, ref)
911
- ("%s=[]", ref)
912
- ("var c2=r.uint32()+r.pos")
943
+ ("%s=[]", ref);
944
+ gen
945
+ ("var c2=r.uint32()+r.pos");
946
+ if (closed) {
947
+ gen
948
+ ("while(r.pos<c2){")
949
+ ("s=r.pos")
950
+ ("v=r.%s()", type)
951
+ ("if(types[%i].valuesById[v]!==undefined){", i)
952
+ ("if(!(%s&&%s.length))", ref, ref)
953
+ ("%s=[]", ref)
954
+ ("%s.push(v)", ref)
955
+ ("}else");
956
+ genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
957
+ ("}");
958
+ } else gen
913
959
  ("while(r.pos<c2)")
914
- ("%s.push(r.%s())", ref, type)
960
+ ("%s.push(r.%s())", ref, type);
961
+ gen
915
962
  ("continue")
916
963
  ("}");
964
+ }
917
965
 
918
966
  // Non-packed
919
967
  gen
920
968
  ("if(u!==%i)", types.basic[type] === undefined ? field.delimited ? 3 : 2 : types.basic[type])
921
- ("break")
969
+ ("break");
970
+ if (!closed) gen
922
971
  ("if(!(%s&&%s.length))", ref, ref)
923
972
  ("%s=[]", ref);
924
973
  if (types.basic[type] === undefined) {
@@ -926,6 +975,14 @@ function decoder(mtype) {
926
975
  ("%s.push(types[%i].decode(r,undefined,%i,q+1))", ref, i, field.id * 8 + 4);
927
976
  else gen
928
977
  ("%s.push(types[%i].decode(r,r.uint32(),undefined,q+1))", ref, i);
978
+ } else if (closed) { gen
979
+ ("v=r.%s()", type)
980
+ ("if(types[%i].valuesById[v]!==undefined){", i)
981
+ ("if(!(%s&&%s.length))", ref, ref)
982
+ ("%s=[]", ref)
983
+ ("%s.push(v)", ref)
984
+ ("}else");
985
+ genPreserveUnknown(gen, "r.raw(s,r.pos)");
929
986
  } else gen
930
987
  ("%s.push(r.%s())", ref, type === "string" ? stringMethod(field) : type);
931
988
 
@@ -944,33 +1001,55 @@ function decoder(mtype) {
944
1001
  gen
945
1002
  ("case %i:{", field.id)
946
1003
  ("if(u!==%i)", types.basic[type])
947
- ("break")
1004
+ ("break");
1005
+ if (closed) { gen
1006
+ ("v=r.%s()", type)
1007
+ ("if(types[%i].valuesById[v]!==undefined){", i)
1008
+ ("%s=v", ref);
1009
+ if (field.partOf) gen
1010
+ ("m%s=%j", util.safeProp(field.partOf.name), field.name);
1011
+ gen
1012
+ ("}else");
1013
+ genPreserveUnknown(gen, "r.raw(s,r.pos)");
1014
+ } else gen
948
1015
  ("%s=r.%s()", ref, type === "string" ? stringMethod(field) : type);
949
1016
  } else {
950
1017
  gen
951
1018
  ("case %i:{", field.id)
952
1019
  ("if(u!==%i)", types.basic[type])
953
1020
  ("break");
954
- if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
955
- // TODO: Protoc rejects open enums whose first value is not zero.
956
- // We should do the same, but for v8 this would be a regression.
957
- ("if((v=r.%s())!==%j)", type, field.typeDefault);
958
- else if (type === "string") gen
959
- ("if((v=r.%s()).length)", stringMethod(field));
960
- else if (type === "bytes") gen
961
- ("if((v=r.%s()).length)", type);
962
- else if (types.long[type] !== undefined) gen
963
- ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
964
- else if (type === "double" || type === "float") gen
965
- ("if((v=r.%s())!==0)", type);
966
- else gen
967
- ("if(v=r.%s())", type);
968
- gen
969
- ("%s=v", ref)
970
- ("else")
971
- ("delete %s", ref); // rare/odd case: later default clears earlier non-default
1021
+ if (closed) { gen
1022
+ ("v=r.%s()", type)
1023
+ ("if(types[%i].valuesById[v]!==undefined){", i)
1024
+ ("if(v!==%j)", field.typeDefault)
1025
+ ("%s=v", ref)
1026
+ ("else")
1027
+ ("delete %s", ref)
1028
+ ("}else{");
1029
+ genPreserveUnknown(gen, "r.raw(s,r.pos)")
1030
+ ("}");
1031
+ } else {
1032
+ if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
1033
+ // TODO: Protoc rejects open enums whose first value is not zero.
1034
+ // We should do the same, but for v8 this would be a regression.
1035
+ ("if((v=r.%s())!==%j)", type, field.typeDefault);
1036
+ else if (type === "string") gen
1037
+ ("if((v=r.%s()).length)", stringMethod(field));
1038
+ else if (type === "bytes") gen
1039
+ ("if((v=r.%s()).length)", type);
1040
+ else if (types.long[type] !== undefined) gen
1041
+ ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
1042
+ else if (type === "double" || type === "float") gen
1043
+ ("if(!Object.is(v=r.%s(),0))", type);
1044
+ else gen
1045
+ ("if(v=r.%s())", type);
1046
+ gen
1047
+ ("%s=v", ref)
1048
+ ("else")
1049
+ ("delete %s", ref); // rare/odd case: later default clears earlier non-default
1050
+ }
972
1051
  }
973
- if (field.partOf) gen
1052
+ if (field.partOf && !closed) gen
974
1053
  ("m%s=%j", util.safeProp(field.partOf.name), field.name);
975
1054
  gen
976
1055
  ("continue")
@@ -980,11 +1059,8 @@ function decoder(mtype) {
980
1059
  ("}");
981
1060
  // Unknown fields
982
1061
  gen
983
- ("r.skipType(%s,q,t)", i ? "u" : "t&7")
984
- ("if(!r.discardUnknown){")
985
- ("util.makeProp(m,\"$unknowns\",false);")
986
- ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
987
- ("}")
1062
+ ("r.skipType(%s,q,t)", i ? "u" : "t&7");
1063
+ genPreserveUnknown(gen, "r.raw(s,r.pos)")
988
1064
  ("}")
989
1065
  ("if(z!==undefined)")
990
1066
  ("throw Error(\"missing end group\")");
@@ -1096,8 +1172,23 @@ function encoder(mtype) {
1096
1172
 
1097
1173
  // Non-repeated
1098
1174
  } else {
1099
- if (!field.required) gen
1175
+ if (!field.required)
1176
+ if (field.hasPresence || !(field.resolvedType instanceof Enum || types.basic[type] !== undefined)) gen
1100
1177
  ("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
1178
+ else if (field.resolvedType instanceof Enum) gen
1179
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==%j)", ref, field.name, ref, field.typeDefault);
1180
+ else if (type === "bool") gen
1181
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==false)", ref, field.name, ref);
1182
+ else if (type === "string") gen
1183
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==\"\")", ref, field.name, ref);
1184
+ else if (type === "bytes") gen
1185
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s.length)", ref, field.name, ref);
1186
+ else if (type === "double" || type === "float") gen
1187
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&!Object.is(%s,0))", ref, field.name, ref);
1188
+ else if (types.long[type] !== undefined) gen
1189
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&(typeof %s===\"object\"?%s.low||%s.high:%s!==0))", ref, field.name, ref, ref, ref, ref);
1190
+ else gen
1191
+ ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)&&%s!==0)", ref, field.name, ref);
1101
1192
 
1102
1193
  if (wireType === undefined)
1103
1194
  genTypePartial(gen, field, index, ref);
@@ -1121,7 +1212,15 @@ module.exports = Enum;
1121
1212
 
1122
1213
  // extends ReflectionObject
1123
1214
  var ReflectionObject = require(15);
1124
- ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
1215
+ Enum.prototype = Object.create(ReflectionObject.prototype, {
1216
+ constructor: {
1217
+ value: Enum,
1218
+ writable: true,
1219
+ enumerable: false,
1220
+ configurable: true
1221
+ }
1222
+ });
1223
+ Enum.className = "Enum";
1125
1224
 
1126
1225
  var Namespace = require(14),
1127
1226
  util = require(28);
@@ -1148,7 +1247,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1148
1247
  * Enum values by id.
1149
1248
  * @type {Object.<number,string>}
1150
1249
  */
1151
- this.valuesById = {};
1250
+ this.valuesById = Object.create(null);
1152
1251
 
1153
1252
  /**
1154
1253
  * Enum values by name.
@@ -1354,7 +1453,15 @@ module.exports = Field;
1354
1453
 
1355
1454
  // extends ReflectionObject
1356
1455
  var ReflectionObject = require(15);
1357
- ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
1456
+ Field.prototype = Object.create(ReflectionObject.prototype, {
1457
+ constructor: {
1458
+ value: Field,
1459
+ writable: true,
1460
+ enumerable: false,
1461
+ configurable: true
1462
+ }
1463
+ });
1464
+ Field.className = "Field";
1358
1465
 
1359
1466
  var Enum = require(6),
1360
1467
  types = require(27),
@@ -2010,7 +2117,15 @@ module.exports = MapField;
2010
2117
 
2011
2118
  // extends Field
2012
2119
  var Field = require(7);
2013
- ((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
2120
+ MapField.prototype = Object.create(Field.prototype, {
2121
+ constructor: {
2122
+ value: MapField,
2123
+ writable: true,
2124
+ enumerable: false,
2125
+ configurable: true
2126
+ }
2127
+ });
2128
+ MapField.className = "MapField";
2014
2129
 
2015
2130
  var types = require(27),
2016
2131
  util = require(28);
@@ -2287,7 +2402,15 @@ module.exports = Method;
2287
2402
 
2288
2403
  // extends ReflectionObject
2289
2404
  var ReflectionObject = require(15);
2290
- ((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
2405
+ Method.prototype = Object.create(ReflectionObject.prototype, {
2406
+ constructor: {
2407
+ value: Method,
2408
+ writable: true,
2409
+ enumerable: false,
2410
+ configurable: true
2411
+ }
2412
+ });
2413
+ Method.className = "Method";
2291
2414
 
2292
2415
  var util = require(28);
2293
2416
 
@@ -2464,7 +2587,15 @@ module.exports = Namespace;
2464
2587
 
2465
2588
  // extends ReflectionObject
2466
2589
  var ReflectionObject = require(15);
2467
- ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
2590
+ Namespace.prototype = Object.create(ReflectionObject.prototype, {
2591
+ constructor: {
2592
+ value: Namespace,
2593
+ writable: true,
2594
+ enumerable: false,
2595
+ configurable: true
2596
+ }
2597
+ });
2598
+ Namespace.className = "Namespace";
2468
2599
 
2469
2600
  var Field = require(7),
2470
2601
  util = require(28),
@@ -3299,7 +3430,7 @@ ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProt
3299
3430
  * @returns {*} Option value or `undefined` if not set
3300
3431
  */
3301
3432
  ReflectionObject.prototype.getOption = function getOption(name) {
3302
- if (this.options)
3433
+ if (this.options && Object.prototype.hasOwnProperty.call(this.options, name))
3303
3434
  return this.options[name];
3304
3435
  return undefined;
3305
3436
  };
@@ -3318,9 +3449,12 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
3318
3449
  this.options = {};
3319
3450
  if (/^features\./.test(name)) {
3320
3451
  util.setProperty(this.options, name, value, ifNotSet);
3321
- } else if (!ifNotSet || this.options[name] === undefined) {
3322
- if (this.getOption(name) !== value) this.resolved = false;
3323
- this.options[name] = value;
3452
+ } else {
3453
+ var prev = this.getOption(name);
3454
+ if (!ifNotSet || prev === undefined) {
3455
+ if (prev !== value) this.resolved = false;
3456
+ this.options[name] = value;
3457
+ }
3324
3458
  }
3325
3459
 
3326
3460
  return this;
@@ -3382,15 +3516,22 @@ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
3382
3516
 
3383
3517
  /**
3384
3518
  * Converts this instance to its string representation.
3519
+ * @name ReflectionObject#toString
3520
+ * @function
3385
3521
  * @returns {string} Class name[, space, full name]
3386
3522
  */
3387
- ReflectionObject.prototype.toString = function toString() {
3388
- var className = this.constructor.className,
3389
- fullName = this.fullName;
3390
- if (fullName.length)
3391
- return className + " " + fullName;
3392
- return className;
3393
- };
3523
+ Object.defineProperty(ReflectionObject.prototype, "toString", {
3524
+ value: function toString() {
3525
+ var className = this.constructor.className,
3526
+ fullName = this.fullName;
3527
+ if (fullName.length)
3528
+ return className + " " + fullName;
3529
+ return className;
3530
+ },
3531
+ writable: true,
3532
+ enumerable: false,
3533
+ configurable: true
3534
+ });
3394
3535
 
3395
3536
  /**
3396
3537
  * Converts the edition this object is pinned to for JSON format.
@@ -3416,7 +3557,15 @@ module.exports = OneOf;
3416
3557
 
3417
3558
  // extends ReflectionObject
3418
3559
  var ReflectionObject = require(15);
3419
- ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
3560
+ OneOf.prototype = Object.create(ReflectionObject.prototype, {
3561
+ constructor: {
3562
+ value: OneOf,
3563
+ writable: true,
3564
+ enumerable: false,
3565
+ configurable: true
3566
+ }
3567
+ });
3568
+ OneOf.className = "OneOf";
3420
3569
 
3421
3570
  var Field = require(7),
3422
3571
  util = require(28);
@@ -4459,7 +4608,9 @@ function parse(source, root, options) {
4459
4608
  setOption(parent, name + "." + token, value);
4460
4609
  }
4461
4610
 
4462
- var prevValue = objectResult[propName];
4611
+ var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
4612
+ ? objectResult[propName]
4613
+ : undefined;
4463
4614
 
4464
4615
  if (prevValue)
4465
4616
  value = [].concat(prevValue).concat(value);
@@ -5273,7 +5424,14 @@ module.exports = BufferReader;
5273
5424
 
5274
5425
  // extends Reader
5275
5426
  var Reader = require(18);
5276
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
5427
+ BufferReader.prototype = Object.create(Reader.prototype, {
5428
+ constructor: {
5429
+ value: BufferReader,
5430
+ writable: true,
5431
+ enumerable: false,
5432
+ configurable: true
5433
+ }
5434
+ });
5277
5435
 
5278
5436
  var util = require(37);
5279
5437
 
@@ -5347,7 +5505,15 @@ module.exports = Root;
5347
5505
 
5348
5506
  // extends Namespace
5349
5507
  var Namespace = require(14);
5350
- ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
5508
+ Root.prototype = Object.create(Namespace.prototype, {
5509
+ constructor: {
5510
+ value: Root,
5511
+ writable: true,
5512
+ enumerable: false,
5513
+ configurable: true
5514
+ }
5515
+ });
5516
+ Root.className = "Root";
5351
5517
 
5352
5518
  var Field = require(7),
5353
5519
  Enum = require(6),
@@ -5824,7 +5990,14 @@ module.exports = Service;
5824
5990
  var util = require(37);
5825
5991
 
5826
5992
  // Extends EventEmitter
5827
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
5993
+ Service.prototype = Object.create(util.EventEmitter.prototype, {
5994
+ constructor: {
5995
+ value: Service,
5996
+ writable: true,
5997
+ enumerable: false,
5998
+ configurable: true
5999
+ }
6000
+ });
5828
6001
 
5829
6002
  /**
5830
6003
  * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
@@ -5973,7 +6146,15 @@ module.exports = Service;
5973
6146
 
5974
6147
  // extends Namespace
5975
6148
  var Namespace = require(14);
5976
- ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
6149
+ Service.prototype = Object.create(Namespace.prototype, {
6150
+ constructor: {
6151
+ value: Service,
6152
+ writable: true,
6153
+ enumerable: false,
6154
+ configurable: true
6155
+ }
6156
+ });
6157
+ Service.className = "Service";
5977
6158
 
5978
6159
  var Method = require(13),
5979
6160
  util = require(28),
@@ -6596,7 +6777,15 @@ module.exports = Type;
6596
6777
 
6597
6778
  // extends Namespace
6598
6779
  var Namespace = require(14);
6599
- ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
6780
+ Type.prototype = Object.create(Namespace.prototype, {
6781
+ constructor: {
6782
+ value: Type,
6783
+ writable: true,
6784
+ enumerable: false,
6785
+ configurable: true
6786
+ }
6787
+ });
6788
+ Type.className = "Type";
6600
6789
 
6601
6790
  var Enum = require(6),
6602
6791
  OneOf = require(16),
@@ -6761,7 +6950,13 @@ Object.defineProperties(Type.prototype, {
6761
6950
  // Ensure proper prototype
6762
6951
  var prototype = ctor.prototype;
6763
6952
  if (!(prototype instanceof Message)) {
6764
- (ctor.prototype = new Message()).constructor = ctor;
6953
+ ctor.prototype = new Message();
6954
+ Object.defineProperty(ctor.prototype, "constructor", {
6955
+ value: ctor,
6956
+ writable: true,
6957
+ enumerable: false,
6958
+ configurable: true
6959
+ });
6765
6960
  util.merge(ctor.prototype, prototype);
6766
6961
  }
6767
6962
 
@@ -7996,7 +8191,12 @@ function codegen(functionParams, functionName) {
7996
8191
  return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
7997
8192
  }
7998
8193
 
7999
- Codegen.toString = toString;
8194
+ Object.defineProperty(Codegen, "toString", {
8195
+ value: toString,
8196
+ writable: true,
8197
+ enumerable: true,
8198
+ configurable: true
8199
+ });
8000
8200
  return Codegen;
8001
8201
  }
8002
8202
 
@@ -8783,6 +8983,7 @@ LongBits.prototype.length = function length() {
8783
8983
 
8784
8984
  },{"37":37}],37:[function(require,module,exports){
8785
8985
  "use strict";
8986
+ /* global globalThis */
8786
8987
  var util = exports;
8787
8988
 
8788
8989
  // used to return a Promise where callback is omitted
@@ -8837,6 +9038,7 @@ util.isNode = Boolean(typeof global !== "undefined"
8837
9038
  util.global = util.isNode && global
8838
9039
  || typeof window !== "undefined" && window
8839
9040
  || typeof self !== "undefined" && self
9041
+ || typeof globalThis !== "undefined" && globalThis
8840
9042
  || this; // eslint-disable-line no-invalid-this
8841
9043
 
8842
9044
  /**
@@ -8951,6 +9153,28 @@ util.newBuffer = function newBuffer(sizeOrArray) {
8951
9153
  : new Uint8Array(sizeOrArray);
8952
9154
  };
8953
9155
 
9156
+ /**
9157
+ * Prepends a raw field tag to raw field data.
9158
+ * @param {number} id Field id
9159
+ * @param {number} wireType Wire type
9160
+ * @param {Uint8Array} data Raw field data
9161
+ * @returns {Uint8Array|Buffer} Raw field bytes
9162
+ * @ignore
9163
+ */
9164
+ util.rawField = function rawField(id, wireType, data) {
9165
+ var out = [],
9166
+ tag = id << 3 | wireType;
9167
+ tag >>>= 0;
9168
+ while (tag > 127) {
9169
+ out.push(tag & 127 | 128);
9170
+ tag >>>= 7;
9171
+ }
9172
+ out.push(tag);
9173
+ for (var i = 0; i < data.length; ++i)
9174
+ out.push(data[i]);
9175
+ return util.newBuffer(out);
9176
+ };
9177
+
8954
9178
  /**
8955
9179
  * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
8956
9180
  * @type {Constructor<Uint8Array>}
@@ -9064,7 +9288,7 @@ function merge(dst) { // used by converters
9064
9288
  if (!src)
9065
9289
  continue;
9066
9290
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
9067
- if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
9291
+ if (!isUnsafeProperty(keys[i]) && (!ifNotSet || !Object.prototype.hasOwnProperty.call(dst, keys[i]) || dst[keys[i]] === undefined))
9068
9292
  dst[keys[i]] = src[keys[i]];
9069
9293
  }
9070
9294
  return dst;
@@ -9671,16 +9895,21 @@ function invalid(field, expected) {
9671
9895
  */
9672
9896
  function genVerifyValue(gen, field, fieldIndex, ref) {
9673
9897
  /* eslint-disable no-unexpected-multiline */
9674
- if (field.resolvedType) {
9675
- if (field.resolvedType instanceof Enum) { gen
9676
- ("switch(%s){", ref)
9677
- ("default:")
9898
+ var resolvedType = field.resolvedType;
9899
+ if (resolvedType) {
9900
+ if (resolvedType instanceof Enum) {
9901
+ if (resolvedType._features.enum_type === "CLOSED") { gen
9902
+ ("switch(%s){", ref)
9903
+ ("default:")
9904
+ ("return%j", invalid(field, "enum value"));
9905
+ for (var keys = Object.keys(resolvedType.values), j = 0; j < keys.length; ++j) gen
9906
+ ("case %i:", resolvedType.values[keys[j]]);
9907
+ gen
9908
+ ("break")
9909
+ ("}");
9910
+ } else gen
9911
+ ("if(typeof %s!==\"number\"||(%s|0)!==%s)", ref, ref, ref)
9678
9912
  ("return%j", invalid(field, "enum value"));
9679
- for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
9680
- ("case %i:", field.resolvedType.values[keys[j]]);
9681
- gen
9682
- ("break")
9683
- ("}");
9684
9913
  } else {
9685
9914
  gen
9686
9915
  ("{")
@@ -10442,7 +10671,14 @@ module.exports = BufferWriter;
10442
10671
 
10443
10672
  // extends Writer
10444
10673
  var Writer = require(44);
10445
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
10674
+ BufferWriter.prototype = Object.create(Writer.prototype, {
10675
+ constructor: {
10676
+ value: BufferWriter,
10677
+ writable: true,
10678
+ enumerable: false,
10679
+ configurable: true
10680
+ }
10681
+ });
10446
10682
 
10447
10683
  var util = require(37);
10448
10684