protobufjs 8.2.0 → 8.2.1

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.2.0 (c) 2016, daniel wirtz
3
- * compiled sat, 09 may 2026 19:37:43 utc
2
+ * protobuf.js v8.2.1 (c) 2016, daniel wirtz
3
+ * compiled wed, 13 may 2026 10:17:57 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -550,15 +550,15 @@ converter.fromObject = function fromObject(mtype) {
550
550
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
551
551
  var fields = mtype.fieldsArray;
552
552
  var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
553
- ("if(d instanceof this.ctor)")
553
+ ("if(d instanceof C)")
554
554
  ("return d")
555
555
  ("if(q===undefined)q=0")
556
556
  ("if(q>util.recursionLimit)")
557
557
  ("throw Error(\"max depth exceeded\")");
558
558
  if (!fields.length) return gen
559
- ("return new this.ctor");
559
+ ("return new C");
560
560
  gen
561
- ("var m=new this.ctor");
561
+ ("var m=new C");
562
562
  for (var i = 0; i < fields.length; ++i) {
563
563
  var field = fields[i].resolve(),
564
564
  prop = util.safeProp(field.name),
@@ -814,7 +814,7 @@ function decoder(mtype) {
814
814
  ("if(q===undefined)q=0")
815
815
  ("if(q>Reader.recursionLimit)")
816
816
  ("throw Error(\"max depth exceeded\")")
817
- ("var c=l===undefined?r.len:r.pos+l,m=g||new this.ctor" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
817
+ ("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
818
818
  ("while(r.pos<c){")
819
819
  ("var s=r.pos")
820
820
  ("var t=r.tag()")
@@ -938,7 +938,11 @@ function decoder(mtype) {
938
938
  ("case %i:{", field.id)
939
939
  ("if(u!==%i)", types.basic[type])
940
940
  ("break");
941
- if (type === "string" || type === "bytes") gen
941
+ if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
942
+ // TODO: Protoc rejects open enums whose first value is not zero.
943
+ // We should do the same, but for v8 this would be a regression.
944
+ ("if((v=r.%s())!==%j)", type, field.typeDefault);
945
+ else if (type === "string" || type === "bytes") gen
942
946
  ("if((v=r.%s()).length)", type);
943
947
  else if (types.long[type] !== undefined) gen
944
948
  ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
@@ -2406,7 +2410,10 @@ var Type, // cyclic
2406
2410
  * @throws {TypeError} If arguments are invalid
2407
2411
  */
2408
2412
  Namespace.fromJSON = function fromJSON(name, json, depth) {
2409
- depth = util.checkDepth(depth);
2413
+ if (depth === undefined)
2414
+ depth = 0;
2415
+ if (depth > util.recursionLimit)
2416
+ throw Error("max depth exceeded");
2410
2417
  return new Namespace(name, json.options).addJSON(json.nested, depth);
2411
2418
  };
2412
2419
 
@@ -2569,7 +2576,10 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
2569
2576
  * @returns {Namespace} `this`
2570
2577
  */
2571
2578
  Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
2572
- depth = util.checkDepth(depth);
2579
+ if (depth === undefined)
2580
+ depth = 0;
2581
+ if (depth > util.recursionLimit)
2582
+ throw Error("max depth exceeded");
2573
2583
  var ns = this;
2574
2584
  /* istanbul ignore else */
2575
2585
  if (nestedJson) {
@@ -2709,6 +2719,8 @@ Namespace.prototype.define = function define(path, json) {
2709
2719
  throw TypeError("illegal path");
2710
2720
  if (path && path.length && path[0] === "")
2711
2721
  throw Error("path must be relative");
2722
+ if (path.length > util.recursionLimit)
2723
+ throw Error("max depth exceeded");
2712
2724
 
2713
2725
  var ptr = this;
2714
2726
  while (path.length > 0) {
@@ -3854,7 +3866,9 @@ function parse(source, root, options) {
3854
3866
 
3855
3867
 
3856
3868
  function parseCommon(parent, token, depth) {
3857
- depth = util.checkDepth(depth);
3869
+ if (depth === undefined)
3870
+ depth = 0;
3871
+ // depth is checked by dispatched functions
3858
3872
  switch (token) {
3859
3873
 
3860
3874
  case "option":
@@ -3920,7 +3934,10 @@ function parse(source, root, options) {
3920
3934
  }
3921
3935
 
3922
3936
  function parseType(parent, token, depth) {
3923
- depth = util.checkDepth(depth);
3937
+ if (depth === undefined)
3938
+ depth = 0;
3939
+ if (depth > util.nestingLimit)
3940
+ throw Error("max depth exceeded");
3924
3941
 
3925
3942
  /* istanbul ignore if */
3926
3943
  if (!nameRe.test(token = next()))
@@ -4049,7 +4066,10 @@ function parse(source, root, options) {
4049
4066
  }
4050
4067
 
4051
4068
  function parseGroup(parent, rule, extend, depth) {
4052
- depth = util.checkDepth(depth);
4069
+ if (depth === undefined)
4070
+ depth = 0;
4071
+ if (depth > util.nestingLimit)
4072
+ throw Error("max depth exceeded");
4053
4073
  if (edition >= 2023) {
4054
4074
  throw illegal("group");
4055
4075
  }
@@ -4296,7 +4316,10 @@ function parse(source, root, options) {
4296
4316
  }
4297
4317
 
4298
4318
  function parseOptionValue(parent, name, depth) {
4299
- depth = util.checkDepth(depth);
4319
+ if (depth === undefined)
4320
+ depth = 0;
4321
+ if (depth > util.recursionLimit)
4322
+ throw Error("max depth exceeded");
4300
4323
  // { a: "foo" b { c: "bar" } }
4301
4324
  if (skip("{", true)) {
4302
4325
  var objectResult = {};
@@ -4387,7 +4410,10 @@ function parse(source, root, options) {
4387
4410
  }
4388
4411
 
4389
4412
  function parseService(parent, token, depth) {
4390
- depth = util.checkDepth(depth);
4413
+ if (depth === undefined)
4414
+ depth = 0;
4415
+ if (depth > util.recursionLimit)
4416
+ throw Error("max depth exceeded");
4391
4417
 
4392
4418
  /* istanbul ignore if */
4393
4419
  if (!nameRe.test(token = next()))
@@ -5247,7 +5273,10 @@ function Root(options) {
5247
5273
  * @returns {Root} Root namespace
5248
5274
  */
5249
5275
  Root.fromJSON = function fromJSON(json, root, depth) {
5250
- depth = util.checkDepth(depth);
5276
+ if (depth === undefined)
5277
+ depth = 0;
5278
+ if (depth > util.recursionLimit)
5279
+ throw Error("max depth exceeded");
5251
5280
  if (!root)
5252
5281
  root = new Root();
5253
5282
  if (json.options)
@@ -5852,7 +5881,10 @@ function Service(name, options) {
5852
5881
  * @throws {TypeError} If arguments are invalid
5853
5882
  */
5854
5883
  Service.fromJSON = function fromJSON(name, json, depth) {
5855
- depth = util.checkDepth(depth);
5884
+ if (depth === undefined)
5885
+ depth = 0;
5886
+ if (depth > util.recursionLimit)
5887
+ throw Error("max depth exceeded");
5856
5888
  var service = new Service(name, json.options);
5857
5889
  /* istanbul ignore else */
5858
5890
  if (json.methods)
@@ -6590,6 +6622,8 @@ Object.defineProperties(Type.prototype, {
6590
6622
  util.merge(ctor, Message, true);
6591
6623
 
6592
6624
  this._ctor = ctor;
6625
+ delete this.decode;
6626
+ delete this.fromObject;
6593
6627
 
6594
6628
  // Messages have non-enumerable default values on their prototype
6595
6629
  var i = 0;
@@ -6658,7 +6692,10 @@ function clearCache(type) {
6658
6692
  * @returns {Type} Created message type
6659
6693
  */
6660
6694
  Type.fromJSON = function fromJSON(name, json, depth) {
6661
- depth = util.checkDepth(depth);
6695
+ if (depth === undefined)
6696
+ depth = 0;
6697
+ if (depth > util.nestingLimit)
6698
+ throw Error("max depth exceeded");
6662
6699
  var type = new Type(name, json.options);
6663
6700
  type.extensions = json.extensions;
6664
6701
  type.reserved = json.reserved;
@@ -6898,7 +6935,8 @@ Type.prototype.setup = function setup() {
6898
6935
  this.decode = decoder(this)({
6899
6936
  Reader : Reader,
6900
6937
  types : types,
6901
- util : util
6938
+ util : util,
6939
+ C : this.ctor
6902
6940
  });
6903
6941
  this.verify = verifier(this)({
6904
6942
  types : types,
@@ -6906,7 +6944,8 @@ Type.prototype.setup = function setup() {
6906
6944
  });
6907
6945
  this.fromObject = converter.fromObject(this)({
6908
6946
  types : types,
6909
- util : util
6947
+ util : util,
6948
+ C : this.ctor
6910
6949
  });
6911
6950
  this.toObject = converter.toObject(this)({
6912
6951
  types : types,
@@ -7281,20 +7320,6 @@ var reservedRe = util.patterns.reservedRe,
7281
7320
  */
7282
7321
  util.fs = require(35);
7283
7322
 
7284
- /**
7285
- * Checks a recursion depth.
7286
- * @param {number|undefined} depth Depth of recursion
7287
- * @returns {number} Depth of recursion
7288
- * @throws {Error} If depth exceeds util.recursionLimit
7289
- */
7290
- util.checkDepth = function checkDepth(depth) {
7291
- if (depth === undefined)
7292
- depth = 0;
7293
- if (depth > util.recursionLimit)
7294
- throw Error("max depth exceeded");
7295
- return depth;
7296
- };
7297
-
7298
7323
  /**
7299
7324
  * Converts an object's values to an array.
7300
7325
  * @param {Object.<string,*>} object Object to convert
@@ -7471,6 +7496,8 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
7471
7496
  throw TypeError("path must be specified");
7472
7497
 
7473
7498
  path = path.split(".");
7499
+ if (path.length > util.recursionLimit)
7500
+ throw Error("max depth exceeded");
7474
7501
  return setProp(dst, path, value);
7475
7502
  };
7476
7503
 
@@ -8872,12 +8899,19 @@ function merge(dst, src, ifNotSet) { // used by converters
8872
8899
 
8873
8900
  util.merge = merge;
8874
8901
 
8902
+ /**
8903
+ * Schema declaration nesting limit.
8904
+ * @memberof util
8905
+ * @type {number}
8906
+ */
8907
+ util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
8908
+
8875
8909
  /**
8876
8910
  * Recursion limit.
8877
8911
  * @memberof util
8878
8912
  * @type {number}
8879
8913
  */
8880
- util.recursionLimit = 100;
8914
+ util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
8881
8915
 
8882
8916
  /**
8883
8917
  * Makes a property safe for assignment as an own property.
@@ -9259,19 +9293,7 @@ utf8.length = function utf8_length(string) {
9259
9293
  return len;
9260
9294
  };
9261
9295
 
9262
- /**
9263
- * Reads UTF8 bytes as a string.
9264
- * @param {Uint8Array} buffer Source buffer
9265
- * @param {number} start Source start
9266
- * @param {number} end Source end
9267
- * @returns {string} String read
9268
- */
9269
- utf8.read = function utf8_read(buffer, start, end) {
9270
- if (end - start < 1) {
9271
- return "";
9272
- }
9273
-
9274
- var str = "";
9296
+ function utf8_read_js(buffer, start, end, str) {
9275
9297
  for (var i = start; i < end;) {
9276
9298
  var t = buffer[i++];
9277
9299
  if (t <= 0x7F) {
@@ -9293,6 +9315,44 @@ utf8.read = function utf8_read(buffer, start, end) {
9293
9315
  }
9294
9316
  }
9295
9317
  }
9318
+ return str;
9319
+ }
9320
+
9321
+ /**
9322
+ * Reads UTF8 bytes as a string.
9323
+ * @param {Uint8Array} buffer Source buffer
9324
+ * @param {number} start Source start
9325
+ * @param {number} end Source end
9326
+ * @returns {string} String read
9327
+ */
9328
+ utf8.read = function utf8_read_ascii(buffer, start, end) {
9329
+ if (end - start < 1)
9330
+ return "";
9331
+
9332
+ var str = "",
9333
+ i = start,
9334
+ c1, c2, c3, c4, c5, c6, c7, c8;
9335
+
9336
+ for (; i + 7 < end; i += 8) {
9337
+ c1 = buffer[i];
9338
+ c2 = buffer[i + 1];
9339
+ c3 = buffer[i + 2];
9340
+ c4 = buffer[i + 3];
9341
+ c5 = buffer[i + 4];
9342
+ c6 = buffer[i + 5];
9343
+ c7 = buffer[i + 6];
9344
+ c8 = buffer[i + 7];
9345
+ if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
9346
+ return utf8_read_js(buffer, i, end, str);
9347
+ str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
9348
+ }
9349
+
9350
+ for (; i < end; ++i) {
9351
+ c1 = buffer[i];
9352
+ if (c1 & 0x80)
9353
+ return utf8_read_js(buffer, i, end, str);
9354
+ str += String.fromCharCode(c1);
9355
+ }
9296
9356
 
9297
9357
  return str;
9298
9358
  };
@@ -9794,6 +9854,11 @@ function writeByte(val, buf, pos) {
9794
9854
  buf[pos] = val & 255;
9795
9855
  }
9796
9856
 
9857
+ function writeStringAscii(val, buf, pos) {
9858
+ for (var i = 0; i < val.length;)
9859
+ buf[pos++] = val.charCodeAt(i++);
9860
+ }
9861
+
9797
9862
  function writeVarint32(val, buf, pos) {
9798
9863
  while (val > 127) {
9799
9864
  buf[pos++] = val & 127 | 128;
@@ -10022,7 +10087,7 @@ Writer.prototype.raw = function write_raw(value) {
10022
10087
  Writer.prototype.string = function write_string(value) {
10023
10088
  var len = utf8.length(value);
10024
10089
  return len
10025
- ? this.uint32(len)._push(utf8.write, len, value)
10090
+ ? this.uint32(len)._push(len === value.length ? writeStringAscii : utf8.write, len, value)
10026
10091
  : this._push(writeByte, 1, 0);
10027
10092
  };
10028
10093
 
@@ -10177,6 +10242,11 @@ BufferWriter.prototype.raw = function write_raw_buffer(value) {
10177
10242
  return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
10178
10243
  };
10179
10244
 
10245
+ function writeStringBufferAscii(val, buf, pos) {
10246
+ for (var i = 0; i < val.length;)
10247
+ buf[pos++] = val.charCodeAt(i++);
10248
+ }
10249
+
10180
10250
  function writeStringBuffer(val, buf, pos) {
10181
10251
  if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
10182
10252
  util.utf8.write(val, buf, pos);
@@ -10193,7 +10263,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
10193
10263
  var len = util.Buffer.byteLength(value);
10194
10264
  this.uint32(len);
10195
10265
  if (len)
10196
- this._push(writeStringBuffer, len, value);
10266
+ this._push(len === value.length && len < 40 ? writeStringBufferAscii : writeStringBuffer, len, value);
10197
10267
  return this;
10198
10268
  };
10199
10269