protobufjs 8.6.4 → 8.6.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.
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.6 (c) 2016, daniel wirtz
3
+ * compiled sat, 04 jul 2026 01:09:57 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);
@@ -4385,6 +4534,9 @@ function parse(source, root, options) {
4385
4534
  }
4386
4535
 
4387
4536
  while (token !== "=") {
4537
+ if (token === null) {
4538
+ throw illegal(token, "end of input");
4539
+ }
4388
4540
  if (token === "(") {
4389
4541
  var parensValue = next();
4390
4542
  skip(")");
@@ -4459,7 +4611,9 @@ function parse(source, root, options) {
4459
4611
  setOption(parent, name + "." + token, value);
4460
4612
  }
4461
4613
 
4462
- var prevValue = objectResult[propName];
4614
+ var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
4615
+ ? objectResult[propName]
4616
+ : undefined;
4463
4617
 
4464
4618
  if (prevValue)
4465
4619
  value = [].concat(prevValue).concat(value);
@@ -5273,7 +5427,14 @@ module.exports = BufferReader;
5273
5427
 
5274
5428
  // extends Reader
5275
5429
  var Reader = require(18);
5276
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
5430
+ BufferReader.prototype = Object.create(Reader.prototype, {
5431
+ constructor: {
5432
+ value: BufferReader,
5433
+ writable: true,
5434
+ enumerable: false,
5435
+ configurable: true
5436
+ }
5437
+ });
5277
5438
 
5278
5439
  var util = require(37);
5279
5440
 
@@ -5347,7 +5508,15 @@ module.exports = Root;
5347
5508
 
5348
5509
  // extends Namespace
5349
5510
  var Namespace = require(14);
5350
- ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
5511
+ Root.prototype = Object.create(Namespace.prototype, {
5512
+ constructor: {
5513
+ value: Root,
5514
+ writable: true,
5515
+ enumerable: false,
5516
+ configurable: true
5517
+ }
5518
+ });
5519
+ Root.className = "Root";
5351
5520
 
5352
5521
  var Field = require(7),
5353
5522
  Enum = require(6),
@@ -5824,7 +5993,14 @@ module.exports = Service;
5824
5993
  var util = require(37);
5825
5994
 
5826
5995
  // Extends EventEmitter
5827
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
5996
+ Service.prototype = Object.create(util.EventEmitter.prototype, {
5997
+ constructor: {
5998
+ value: Service,
5999
+ writable: true,
6000
+ enumerable: false,
6001
+ configurable: true
6002
+ }
6003
+ });
5828
6004
 
5829
6005
  /**
5830
6006
  * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
@@ -5973,7 +6149,15 @@ module.exports = Service;
5973
6149
 
5974
6150
  // extends Namespace
5975
6151
  var Namespace = require(14);
5976
- ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
6152
+ Service.prototype = Object.create(Namespace.prototype, {
6153
+ constructor: {
6154
+ value: Service,
6155
+ writable: true,
6156
+ enumerable: false,
6157
+ configurable: true
6158
+ }
6159
+ });
6160
+ Service.className = "Service";
5977
6161
 
5978
6162
  var Method = require(13),
5979
6163
  util = require(28),
@@ -6596,7 +6780,15 @@ module.exports = Type;
6596
6780
 
6597
6781
  // extends Namespace
6598
6782
  var Namespace = require(14);
6599
- ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
6783
+ Type.prototype = Object.create(Namespace.prototype, {
6784
+ constructor: {
6785
+ value: Type,
6786
+ writable: true,
6787
+ enumerable: false,
6788
+ configurable: true
6789
+ }
6790
+ });
6791
+ Type.className = "Type";
6600
6792
 
6601
6793
  var Enum = require(6),
6602
6794
  OneOf = require(16),
@@ -6761,7 +6953,13 @@ Object.defineProperties(Type.prototype, {
6761
6953
  // Ensure proper prototype
6762
6954
  var prototype = ctor.prototype;
6763
6955
  if (!(prototype instanceof Message)) {
6764
- (ctor.prototype = new Message()).constructor = ctor;
6956
+ ctor.prototype = new Message();
6957
+ Object.defineProperty(ctor.prototype, "constructor", {
6958
+ value: ctor,
6959
+ writable: true,
6960
+ enumerable: false,
6961
+ configurable: true
6962
+ });
6765
6963
  util.merge(ctor.prototype, prototype);
6766
6964
  }
6767
6965
 
@@ -7996,7 +8194,12 @@ function codegen(functionParams, functionName) {
7996
8194
  return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
7997
8195
  }
7998
8196
 
7999
- Codegen.toString = toString;
8197
+ Object.defineProperty(Codegen, "toString", {
8198
+ value: toString,
8199
+ writable: true,
8200
+ enumerable: true,
8201
+ configurable: true
8202
+ });
8000
8203
  return Codegen;
8001
8204
  }
8002
8205
 
@@ -8783,6 +8986,7 @@ LongBits.prototype.length = function length() {
8783
8986
 
8784
8987
  },{"37":37}],37:[function(require,module,exports){
8785
8988
  "use strict";
8989
+ /* global globalThis */
8786
8990
  var util = exports;
8787
8991
 
8788
8992
  // used to return a Promise where callback is omitted
@@ -8837,6 +9041,7 @@ util.isNode = Boolean(typeof global !== "undefined"
8837
9041
  util.global = util.isNode && global
8838
9042
  || typeof window !== "undefined" && window
8839
9043
  || typeof self !== "undefined" && self
9044
+ || typeof globalThis !== "undefined" && globalThis
8840
9045
  || this; // eslint-disable-line no-invalid-this
8841
9046
 
8842
9047
  /**
@@ -8951,6 +9156,28 @@ util.newBuffer = function newBuffer(sizeOrArray) {
8951
9156
  : new Uint8Array(sizeOrArray);
8952
9157
  };
8953
9158
 
9159
+ /**
9160
+ * Prepends a raw field tag to raw field data.
9161
+ * @param {number} id Field id
9162
+ * @param {number} wireType Wire type
9163
+ * @param {Uint8Array} data Raw field data
9164
+ * @returns {Uint8Array|Buffer} Raw field bytes
9165
+ * @ignore
9166
+ */
9167
+ util.rawField = function rawField(id, wireType, data) {
9168
+ var out = [],
9169
+ tag = id << 3 | wireType;
9170
+ tag >>>= 0;
9171
+ while (tag > 127) {
9172
+ out.push(tag & 127 | 128);
9173
+ tag >>>= 7;
9174
+ }
9175
+ out.push(tag);
9176
+ for (var i = 0; i < data.length; ++i)
9177
+ out.push(data[i]);
9178
+ return util.newBuffer(out);
9179
+ };
9180
+
8954
9181
  /**
8955
9182
  * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
8956
9183
  * @type {Constructor<Uint8Array>}
@@ -9064,7 +9291,7 @@ function merge(dst) { // used by converters
9064
9291
  if (!src)
9065
9292
  continue;
9066
9293
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
9067
- if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
9294
+ if (!isUnsafeProperty(keys[i]) && (!ifNotSet || !Object.prototype.hasOwnProperty.call(dst, keys[i]) || dst[keys[i]] === undefined))
9068
9295
  dst[keys[i]] = src[keys[i]];
9069
9296
  }
9070
9297
  return dst;
@@ -9671,16 +9898,21 @@ function invalid(field, expected) {
9671
9898
  */
9672
9899
  function genVerifyValue(gen, field, fieldIndex, ref) {
9673
9900
  /* eslint-disable no-unexpected-multiline */
9674
- if (field.resolvedType) {
9675
- if (field.resolvedType instanceof Enum) { gen
9676
- ("switch(%s){", ref)
9677
- ("default:")
9901
+ var resolvedType = field.resolvedType;
9902
+ if (resolvedType) {
9903
+ if (resolvedType instanceof Enum) {
9904
+ if (resolvedType._features.enum_type === "CLOSED") { gen
9905
+ ("switch(%s){", ref)
9906
+ ("default:")
9907
+ ("return%j", invalid(field, "enum value"));
9908
+ for (var keys = Object.keys(resolvedType.values), j = 0; j < keys.length; ++j) gen
9909
+ ("case %i:", resolvedType.values[keys[j]]);
9910
+ gen
9911
+ ("break")
9912
+ ("}");
9913
+ } else gen
9914
+ ("if(typeof %s!==\"number\"||(%s|0)!==%s)", ref, ref, ref)
9678
9915
  ("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
9916
  } else {
9685
9917
  gen
9686
9918
  ("{")
@@ -9879,7 +10111,7 @@ wrappers[".google.protobuf.Any"] = {
9879
10111
  if (object && object["@type"]) {
9880
10112
  // Only use fully qualified type name after the last '/'
9881
10113
  var name = object["@type"].substring(object["@type"].lastIndexOf("/") + 1);
9882
- var type = this.lookup(name);
10114
+ var type = this.lookup(name, [ this.constructor ]);
9883
10115
  /* istanbul ignore else */
9884
10116
  if (type) {
9885
10117
  // type_url does not accept leading "."
@@ -9915,7 +10147,7 @@ wrappers[".google.protobuf.Any"] = {
9915
10147
  name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
9916
10148
  // Separate the prefix used
9917
10149
  prefix = message.type_url.substring(0, message.type_url.lastIndexOf("/") + 1);
9918
- var type = this.lookup(name);
10150
+ var type = this.lookup(name, [ this.constructor ]);
9919
10151
  /* istanbul ignore else */
9920
10152
  if (type)
9921
10153
  message = type.decode(message.value, undefined, undefined, depth + 1);
@@ -10442,7 +10674,14 @@ module.exports = BufferWriter;
10442
10674
 
10443
10675
  // extends Writer
10444
10676
  var Writer = require(44);
10445
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
10677
+ BufferWriter.prototype = Object.create(Writer.prototype, {
10678
+ constructor: {
10679
+ value: BufferWriter,
10680
+ writable: true,
10681
+ enumerable: false,
10682
+ configurable: true
10683
+ }
10684
+ });
10446
10685
 
10447
10686
  var util = require(37);
10448
10687