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.
package/src/object.js CHANGED
@@ -270,7 +270,7 @@ ReflectionObject.prototype._inferLegacyProtoFeatures = function _inferLegacyProt
270
270
  * @returns {*} Option value or `undefined` if not set
271
271
  */
272
272
  ReflectionObject.prototype.getOption = function getOption(name) {
273
- if (this.options)
273
+ if (this.options && Object.prototype.hasOwnProperty.call(this.options, name))
274
274
  return this.options[name];
275
275
  return undefined;
276
276
  };
@@ -289,9 +289,12 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
289
289
  this.options = {};
290
290
  if (/^features\./.test(name)) {
291
291
  util.setProperty(this.options, name, value, ifNotSet);
292
- } else if (!ifNotSet || this.options[name] === undefined) {
293
- if (this.getOption(name) !== value) this.resolved = false;
294
- this.options[name] = value;
292
+ } else {
293
+ var prev = this.getOption(name);
294
+ if (!ifNotSet || prev === undefined) {
295
+ if (prev !== value) this.resolved = false;
296
+ this.options[name] = value;
297
+ }
295
298
  }
296
299
 
297
300
  return this;
@@ -353,15 +356,22 @@ ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
353
356
 
354
357
  /**
355
358
  * Converts this instance to its string representation.
359
+ * @name ReflectionObject#toString
360
+ * @function
356
361
  * @returns {string} Class name[, space, full name]
357
362
  */
358
- ReflectionObject.prototype.toString = function toString() {
359
- var className = this.constructor.className,
360
- fullName = this.fullName;
361
- if (fullName.length)
362
- return className + " " + fullName;
363
- return className;
364
- };
363
+ Object.defineProperty(ReflectionObject.prototype, "toString", {
364
+ value: function toString() {
365
+ var className = this.constructor.className,
366
+ fullName = this.fullName;
367
+ if (fullName.length)
368
+ return className + " " + fullName;
369
+ return className;
370
+ },
371
+ writable: true,
372
+ enumerable: false,
373
+ configurable: true
374
+ });
365
375
 
366
376
  /**
367
377
  * Converts the edition this object is pinned to for JSON format.
package/src/oneof.js CHANGED
@@ -3,7 +3,15 @@ module.exports = OneOf;
3
3
 
4
4
  // extends ReflectionObject
5
5
  var ReflectionObject = require("./object");
6
- ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
6
+ OneOf.prototype = Object.create(ReflectionObject.prototype, {
7
+ constructor: {
8
+ value: OneOf,
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ }
13
+ });
14
+ OneOf.className = "OneOf";
7
15
 
8
16
  var Field = require("./field"),
9
17
  util = require("./util");
package/src/parse.js CHANGED
@@ -819,7 +819,9 @@ function parse(source, root, options) {
819
819
  setOption(parent, name + "." + token, value);
820
820
  }
821
821
 
822
- var prevValue = objectResult[propName];
822
+ var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
823
+ ? objectResult[propName]
824
+ : undefined;
823
825
 
824
826
  if (prevValue)
825
827
  value = [].concat(prevValue).concat(value);
@@ -3,7 +3,14 @@ module.exports = BufferReader;
3
3
 
4
4
  // extends Reader
5
5
  var Reader = require("./reader");
6
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
6
+ BufferReader.prototype = Object.create(Reader.prototype, {
7
+ constructor: {
8
+ value: BufferReader,
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ }
13
+ });
7
14
 
8
15
  var util = require("./util/minimal");
9
16
 
package/src/root.js CHANGED
@@ -3,7 +3,15 @@ module.exports = Root;
3
3
 
4
4
  // extends Namespace
5
5
  var Namespace = require("./namespace");
6
- ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
6
+ Root.prototype = Object.create(Namespace.prototype, {
7
+ constructor: {
8
+ value: Root,
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ }
13
+ });
14
+ Root.className = "Root";
7
15
 
8
16
  var Field = require("./field"),
9
17
  Enum = require("./enum"),
@@ -4,7 +4,14 @@ module.exports = Service;
4
4
  var util = require("../util/minimal");
5
5
 
6
6
  // Extends EventEmitter
7
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
7
+ Service.prototype = Object.create(util.EventEmitter.prototype, {
8
+ constructor: {
9
+ value: Service,
10
+ writable: true,
11
+ enumerable: false,
12
+ configurable: true
13
+ }
14
+ });
8
15
 
9
16
  /**
10
17
  * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
package/src/service.js CHANGED
@@ -3,7 +3,15 @@ module.exports = Service;
3
3
 
4
4
  // extends Namespace
5
5
  var Namespace = require("./namespace");
6
- ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
6
+ Service.prototype = Object.create(Namespace.prototype, {
7
+ constructor: {
8
+ value: Service,
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ }
13
+ });
14
+ Service.className = "Service";
7
15
 
8
16
  var Method = require("./method"),
9
17
  util = require("./util"),
package/src/type.js CHANGED
@@ -3,7 +3,15 @@ module.exports = Type;
3
3
 
4
4
  // extends Namespace
5
5
  var Namespace = require("./namespace");
6
- ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
6
+ Type.prototype = Object.create(Namespace.prototype, {
7
+ constructor: {
8
+ value: Type,
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ }
13
+ });
14
+ Type.className = "Type";
7
15
 
8
16
  var Enum = require("./enum"),
9
17
  OneOf = require("./oneof"),
@@ -168,7 +176,13 @@ Object.defineProperties(Type.prototype, {
168
176
  // Ensure proper prototype
169
177
  var prototype = ctor.prototype;
170
178
  if (!(prototype instanceof Message)) {
171
- (ctor.prototype = new Message()).constructor = ctor;
179
+ ctor.prototype = new Message();
180
+ Object.defineProperty(ctor.prototype, "constructor", {
181
+ value: ctor,
182
+ writable: true,
183
+ enumerable: false,
184
+ configurable: true
185
+ });
172
186
  util.merge(ctor.prototype, prototype);
173
187
  }
174
188
 
@@ -81,7 +81,12 @@ function codegen(functionParams, functionName) {
81
81
  return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
82
82
  }
83
83
 
84
- Codegen.toString = toString;
84
+ Object.defineProperty(Codegen, "toString", {
85
+ value: toString,
86
+ writable: true,
87
+ enumerable: true,
88
+ configurable: true
89
+ });
85
90
  return Codegen;
86
91
  }
87
92
 
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ /* global globalThis */
2
3
  var util = exports;
3
4
 
4
5
  // used to return a Promise where callback is omitted
@@ -53,6 +54,7 @@ util.isNode = Boolean(typeof global !== "undefined"
53
54
  util.global = util.isNode && global
54
55
  || typeof window !== "undefined" && window
55
56
  || typeof self !== "undefined" && self
57
+ || typeof globalThis !== "undefined" && globalThis
56
58
  || this; // eslint-disable-line no-invalid-this
57
59
 
58
60
  /**
@@ -167,6 +169,28 @@ util.newBuffer = function newBuffer(sizeOrArray) {
167
169
  : new Uint8Array(sizeOrArray);
168
170
  };
169
171
 
172
+ /**
173
+ * Prepends a raw field tag to raw field data.
174
+ * @param {number} id Field id
175
+ * @param {number} wireType Wire type
176
+ * @param {Uint8Array} data Raw field data
177
+ * @returns {Uint8Array|Buffer} Raw field bytes
178
+ * @ignore
179
+ */
180
+ util.rawField = function rawField(id, wireType, data) {
181
+ var out = [],
182
+ tag = id << 3 | wireType;
183
+ tag >>>= 0;
184
+ while (tag > 127) {
185
+ out.push(tag & 127 | 128);
186
+ tag >>>= 7;
187
+ }
188
+ out.push(tag);
189
+ for (var i = 0; i < data.length; ++i)
190
+ out.push(data[i]);
191
+ return util.newBuffer(out);
192
+ };
193
+
170
194
  /**
171
195
  * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
172
196
  * @type {Constructor<Uint8Array>}
@@ -280,7 +304,7 @@ function merge(dst) { // used by converters
280
304
  if (!src)
281
305
  continue;
282
306
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
283
- if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
307
+ if (!isUnsafeProperty(keys[i]) && (!ifNotSet || !Object.prototype.hasOwnProperty.call(dst, keys[i]) || dst[keys[i]] === undefined))
284
308
  dst[keys[i]] = src[keys[i]];
285
309
  }
286
310
  return dst;
package/src/util/utf8.js CHANGED
@@ -7,7 +7,14 @@
7
7
  */
8
8
  var utf8 = exports,
9
9
  replacementChar = "\ufffd",
10
+ strictDecoder;
11
+
12
+ try {
10
13
  strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
14
+ } catch (err) {
15
+ // "fatal" option is not supported on Node.js compiled without ICU
16
+ strictDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
17
+ }
11
18
 
12
19
  /**
13
20
  * Calculates the UTF8 byte length of a string.
package/src/verifier.js CHANGED
@@ -19,16 +19,21 @@ function invalid(field, expected) {
19
19
  */
20
20
  function genVerifyValue(gen, field, fieldIndex, ref) {
21
21
  /* eslint-disable no-unexpected-multiline */
22
- if (field.resolvedType) {
23
- if (field.resolvedType instanceof Enum) { gen
24
- ("switch(%s){", ref)
25
- ("default:")
22
+ var resolvedType = field.resolvedType;
23
+ if (resolvedType) {
24
+ if (resolvedType instanceof Enum) {
25
+ if (resolvedType._features.enum_type === "CLOSED") { gen
26
+ ("switch(%s){", ref)
27
+ ("default:")
28
+ ("return%j", invalid(field, "enum value"));
29
+ for (var keys = Object.keys(resolvedType.values), j = 0; j < keys.length; ++j) gen
30
+ ("case %i:", resolvedType.values[keys[j]]);
31
+ gen
32
+ ("break")
33
+ ("}");
34
+ } else gen
35
+ ("if(typeof %s!==\"number\"||(%s|0)!==%s)", ref, ref, ref)
26
36
  ("return%j", invalid(field, "enum value"));
27
- for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
28
- ("case %i:", field.resolvedType.values[keys[j]]);
29
- gen
30
- ("break")
31
- ("}");
32
37
  } else {
33
38
  gen
34
39
  ("{")
@@ -3,7 +3,14 @@ module.exports = BufferWriter;
3
3
 
4
4
  // extends Writer
5
5
  var Writer = require("./writer");
6
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
6
+ BufferWriter.prototype = Object.create(Writer.prototype, {
7
+ constructor: {
8
+ value: BufferWriter,
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ }
13
+ });
7
14
 
8
15
  var util = require("./util/minimal");
9
16