VYPR
Medium severity5.3GHSA Advisory· Published Jun 15, 2026· Updated Jun 15, 2026

protobufjs : Schema-derived names can shadow runtime-significant properties

CVE-2026-54269

Description

protobufjs schema-derived names like hasOwnProperty, $type, or rpcCall can collide with runtime helpers, causing denial of service.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

protobufjs schema-derived names like `hasOwnProperty`, `$type`, or `rpcCall` can collide with runtime helpers, causing denial of service.

Vulnerability

protobufjs accepts certain schema-derived names that collide with properties used by its runtime helpers [1][2]. The known problematic names are fields named hasOwnProperty, field or oneof names such as $type when loaded through protobufjs JSON/reflection descriptors, and service methods whose generated helper name is rpcCall. When affected message or service types are used, protobufjs can read schema-controlled data where it expects an own-property helper, reflected type metadata, or the base RPC helper. This affects all protobufjs versions prior to a fix; no fixed version has been announced as of the advisory publication date [1][2].

Exploitation

An attacker who can provide or influence protobuf schemas or protobufjs JSON descriptors can craft a schema containing one of the problematic names. The application must load that schema and reach the affected API path: for hasOwnProperty, required-field decode post-checks, verify, or toObject; for $type, reflected message JSON serialization; for rpcCall, protobufjs RPC service invocation. No authentication or special privileges are required if the attacker controls the schema source [1][2].

Impact

Successful exploitation causes deterministic exceptions or recursive calls in the affected processing path, making the affected message or service types unusable. This results in a denial of service (DoS) for the application. The issue is not known to allow code execution by itself [1][2].

Mitigation

No patched version has been released as of the advisory publication date [1][2]. The recommended workaround is to avoid loading protobuf schemas or protobufjs JSON descriptors from untrusted sources. If untrusted schemas must be accepted, validate schema-derived field, oneof, and service method names before loading and reject the problematic names (hasOwnProperty, $type, rpcCall). Applications using only trusted schemas are only affected if those schemas contain one of the problematic names and the application reaches the affected API path [1][2]. This vulnerability is not listed in the CISA Known Exploited Vulnerabilities (KEV) catalog.

AI Insight generated on Jun 15, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.

Affected products

1

Patches

3
78a9576269a5

fix: Avoid name collisions in generated code (#2311)

https://github.com/protobufjs/protobuf.jsdcodeIOJun 9, 2026Fixed in protobufjs-cli-v1.3.3via ghsa-release-walk
21 files changed · +672 595
  • cli/targets/static.js+1 1 modified
    @@ -769,7 +769,7 @@ function buildService(ref, service) {
             ]);
             push("Object.defineProperty(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
                 ++indent;
    -            push("return this.rpcCall(" + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
    +            push("return $protobuf.rpc.Service.prototype.rpcCall.call(this, " + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
                 --indent;
             push("}, \"name\", { value: " + JSON.stringify(method.name) + " });");
             if (config.comments)
    
  • src/converter.js+1 1 modified
    @@ -302,7 +302,7 @@ converter.toObject = function toObject(mtype) {
                 genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
             ("}");
             } else { gen
    -    ("if(m%s!=null&&m.hasOwnProperty(%j)){", prop, field.name); // !== undefined && !== null
    +    ("if(m%s!=null&&Object.hasOwnProperty.call(m,%j)){", prop, field.name); // !== undefined && !== null
             genValuePartial_toObject(gen, field, /* sorted */ index, prop);
             if (field.partOf) gen
             ("if(o.oneofs)")
    
  • src/decoder.js+1 1 modified
    @@ -125,7 +125,7 @@ function decoder(mtype) {
         for (i = 0; i < mtype._fieldsArray.length; ++i) {
             var rfield = mtype._fieldsArray[i];
             if (rfield.required) gen
    -    ("if(!m.hasOwnProperty(%j))", rfield.name)
    +            ("if(!Object.hasOwnProperty.call(m,%j))", rfield.name)
             ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
         }
     
    
  • src/service.js+5 7 modified
    @@ -9,8 +9,6 @@ var Method = require("./method"),
         util   = require("./util"),
         rpc    = require("./rpc");
     
    -var reservedRe = util.patterns.reservedRe;
    -
     /**
      * Constructs a new service instance.
      * @classdesc Reflected service.
    @@ -185,11 +183,11 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
         var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
         for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
             var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
    -        rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
    -            m: method,
    -            q: method.resolvedRequestType.ctor,
    -            s: method.resolvedResponseType.ctor
    -        });
    +        rpcService[methodName] = (function(method, requestType, responseType) {
    +            return function rpcMethod(request, callback) {
    +                return rpc.Service.prototype.rpcCall.call(this, method, requestType, responseType, request, callback);
    +            };
    +        })(method, method.resolvedRequestType.ctor, method.resolvedResponseType.ctor);
         }
         return rpcService;
     };
    
  • src/type.js+3 1 modified
    @@ -373,7 +373,7 @@ Type.prototype.add = function add(object) {
                 throw Error("duplicate id " + object.id + " in " + this);
             if (this.isReservedId(object.id))
                 throw Error("id " + object.id + " is reserved in " + this);
    -        if (this.isReservedName(object.name))
    +        if (this.isReservedName(object.name) || object.name.charAt(0) === "$")
                 throw Error("name '" + object.name + "' is reserved in " + this);
             if (object.name === "__proto__")
                 return this;
    @@ -386,6 +386,8 @@ Type.prototype.add = function add(object) {
             return clearCache(this);
         }
         if (object instanceof OneOf) {
    +        if (object.name.charAt(0) === "$")
    +            throw Error("name '" + object.name + "' is reserved in " + this);
             if (object.name === "__proto__")
                 return this;
             if (!this.oneofs)
    
  • src/util/minimal.js+1 1 modified
    @@ -119,7 +119,7 @@ util.isset =
      */
     util.isSet = function isSet(obj, prop) {
         var value = obj[prop];
    -    if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
    +    if (value != null && Object.hasOwnProperty.call(obj, prop)) // eslint-disable-line eqeqeq
             return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
         return false;
     };
    
  • src/verifier.js+1 1 modified
    @@ -138,7 +138,7 @@ function verifier(mtype) {
                 ref   = "m" + util.safeProp(field.name);
     
             if (field.optional) gen
    -        ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null
    +        ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name); // !== undefined && !== null
     
             // map fields
             if (field.map) { gen
    
  • tests/api_converters.js+16 0 modified
    @@ -337,3 +337,19 @@ tape.test("converters", function(test) {
         });
     
     });
    +
    +tape.test("converters - runtime-significant field names", function(test) {
    +    var root = protobuf.parse("syntax = \"proto3\";\n"
    +        + "message Singular { string hasOwnProperty = 1; }\n"
    +        + "message Repeated { repeated string hasOwnProperty = 1; }\n").root;
    +
    +    var Singular = root.lookupType("Singular"),
    +        Repeated = root.lookupType("Repeated"),
    +        singular = Singular.create({ hasOwnProperty: "value" }),
    +        repeated = Repeated.decode(Repeated.encode({ hasOwnProperty: [ "a", "b" ] }).finish());
    +
    +    test.equal(Singular.verify({ hasOwnProperty: "value" }), null, "verify should not call a shadowed hasOwnProperty field");
    +    test.same(Singular.toObject(singular), { hasOwnProperty: "value" }, "toObject should not call a shadowed hasOwnProperty field");
    +    test.same(repeated.hasOwnProperty, [ "a", "b" ], "decode should not call a shadowed hasOwnProperty field");
    +    test.end();
    +});
    
  • tests/api_service.js+16 0 modified
    @@ -48,6 +48,22 @@ tape.test("reflected services", function(test) {
         test.end();
     });
     
    +tape.test("reflected services can call runtime-significant method names", function(test) {
    +    var root = protobuf.parse("syntax = \"proto3\"; message Req {} message Res {} service S { rpc rpcCall(Req) returns (Res); }").root;
    +    root.resolveAll();
    +
    +    var Res = root.lookupType("Res"),
    +        service = root.lookupService("S").create(function(method, request, callback) {
    +            callback(null, Res.encode({}).finish());
    +        });
    +
    +    service.rpcCall({}, function(err, response) {
    +        test.error(err, "should call method named rpcCall");
    +        test.ok(response instanceof Res.ctor, "should decode the response");
    +        test.end();
    +    });
    +});
    +
     tape.test("feature resolution legacy proto3", function(test) {
         var json = {
             methods: {
    
  • tests/api_type.js+7 0 modified
    @@ -97,6 +97,13 @@ tape.test("reflected types", function(test) {
             type.add(new protobuf.Field("b", 2, "uint32"));
         }, Error, "should throw when trying to add reserved names");
     
    +    test.throws(function() {
    +        type.add(new protobuf.Field("$type", 2, "uint32"));
    +    }, Error, "should throw when trying to add fields with runtime-reserved names");
    +
    +    test.throws(function() {
    +        type.add(new protobuf.OneOf("$kind", [ "a" ]));
    +    }, Error, "should throw when trying to add oneofs with runtime-reserved names");
     
         test.end();
     });
    
  • tests/api_util.js+3 0 modified
    @@ -86,6 +86,9 @@ tape.test("util", function(test) {
                 test.notOk(util.isSet(instance, "p"), "should return that " + name + " on the prototype are not present");
                 test.ok(util.isSet(instance, "i"), "should return that " + name + " on the instance ARE present");
             });
    +        var nullProto = Object.create(null);
    +        nullProto.i = "value";
    +        test.ok(util.isSet(nullProto, "i"), "should support null-prototype objects");
     
              test.end();
         });
    
  • tests/cli.js+35 0 modified
    @@ -266,6 +266,41 @@ tape.test("pbjs supports dictionary generated root names", function(test) {
         });
     });
     
    +tape.test("pbjs static services can call runtime-significant method names", function(test) {
    +    cliTest(test, function() {
    +        var root = protobuf.parse("syntax = \"proto3\"; message Req {} message Res {} service S { rpc rpcCall(Req) returns (Res); }").root;
    +        root.resolveAll();
    +
    +        var staticTarget = require("../cli/targets/static");
    +        staticTarget(root, {
    +            decode: true,
    +            encode: true,
    +            convert: true,
    +            service: true,
    +            root: "staticServiceShadow"
    +        }, function(err, jsCode) {
    +            test.error(err, "static code generation worked");
    +
    +            delete protobuf.roots.staticServiceShadow;
    +            var $protobuf = protobuf;
    +            eval(jsCode);
    +
    +            var S = protobuf.roots.staticServiceShadow.S,
    +                Res = protobuf.roots.staticServiceShadow.Res,
    +                service = new S(function(method, request, callback) {
    +                    callback(null, Res.encode({}).finish());
    +                });
    +
    +            service.rpcCall({}, function(callErr, response) {
    +                test.error(callErr, "should call method named rpcCall");
    +                test.ok(response instanceof Res, "should decode the response");
    +                delete protobuf.roots.staticServiceShadow;
    +                test.end();
    +            });
    +        });
    +    });
    +});
    +
     tape.test("pbjs rejects static target escaped name collisions", function(test) {
         cliTest(test, function() {
             var root = protobuf.Root.fromJSON({
    
  • tests/data/comments.js+6 6 modified
    @@ -187,13 +187,13 @@ $root.Test1 = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.field1 != null && message.hasOwnProperty("field1"))
    +        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
                 if (!$util.isString(message.field1))
                     return "field1: string expected";
    -        if (message.field2 != null && message.hasOwnProperty("field2"))
    +        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
                 if (!$util.isInteger(message.field2))
                     return "field2: integer expected";
    -        if (message.field3 != null && message.hasOwnProperty("field3"))
    +        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
                 if (typeof message.field3 !== "boolean")
                     return "field3: boolean expected";
             return null;
    @@ -248,11 +248,11 @@ $root.Test1 = (function() {
                 object.field2 = 0;
                 object.field3 = false;
             }
    -        if (message.field1 != null && message.hasOwnProperty("field1"))
    +        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
                 object.field1 = message.field1;
    -        if (message.field2 != null && message.hasOwnProperty("field2"))
    +        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
                 object.field2 = message.field2;
    -        if (message.field3 != null && message.hasOwnProperty("field3"))
    +        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
                 object.field3 = message.field3;
             return object;
         };
    
  • tests/data/convert.js+13 13 modified
    @@ -329,45 +329,45 @@ $root.Message = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.stringVal != null && message.hasOwnProperty("stringVal"))
    +        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
                 if (!$util.isString(message.stringVal))
                     return "stringVal: string expected";
    -        if (message.stringRepeated != null && message.hasOwnProperty("stringRepeated")) {
    +        if (message.stringRepeated != null && Object.hasOwnProperty.call(message, "stringRepeated")) {
                 if (!Array.isArray(message.stringRepeated))
                     return "stringRepeated: array expected";
                 for (var i = 0; i < message.stringRepeated.length; ++i)
                     if (!$util.isString(message.stringRepeated[i]))
                         return "stringRepeated: string[] expected";
             }
    -        if (message.uint64Val != null && message.hasOwnProperty("uint64Val"))
    +        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
                 if (!$util.isInteger(message.uint64Val) && !(message.uint64Val && $util.isInteger(message.uint64Val.low) && $util.isInteger(message.uint64Val.high)))
                     return "uint64Val: integer|Long expected";
    -        if (message.uint64Repeated != null && message.hasOwnProperty("uint64Repeated")) {
    +        if (message.uint64Repeated != null && Object.hasOwnProperty.call(message, "uint64Repeated")) {
                 if (!Array.isArray(message.uint64Repeated))
                     return "uint64Repeated: array expected";
                 for (var i = 0; i < message.uint64Repeated.length; ++i)
                     if (!$util.isInteger(message.uint64Repeated[i]) && !(message.uint64Repeated[i] && $util.isInteger(message.uint64Repeated[i].low) && $util.isInteger(message.uint64Repeated[i].high)))
                         return "uint64Repeated: integer|Long[] expected";
             }
    -        if (message.bytesVal != null && message.hasOwnProperty("bytesVal"))
    +        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
                 if (!(message.bytesVal && typeof message.bytesVal.length === "number" || $util.isString(message.bytesVal)))
                     return "bytesVal: buffer expected";
    -        if (message.bytesRepeated != null && message.hasOwnProperty("bytesRepeated")) {
    +        if (message.bytesRepeated != null && Object.hasOwnProperty.call(message, "bytesRepeated")) {
                 if (!Array.isArray(message.bytesRepeated))
                     return "bytesRepeated: array expected";
                 for (var i = 0; i < message.bytesRepeated.length; ++i)
                     if (!(message.bytesRepeated[i] && typeof message.bytesRepeated[i].length === "number" || $util.isString(message.bytesRepeated[i])))
                         return "bytesRepeated: buffer[] expected";
             }
    -        if (message.enumVal != null && message.hasOwnProperty("enumVal"))
    +        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
                 switch (message.enumVal) {
                 default:
                     return "enumVal: enum value expected";
                 case 1:
                 case 2:
                     break;
                 }
    -        if (message.enumRepeated != null && message.hasOwnProperty("enumRepeated")) {
    +        if (message.enumRepeated != null && Object.hasOwnProperty.call(message, "enumRepeated")) {
                 if (!Array.isArray(message.enumRepeated))
                     return "enumRepeated: array expected";
                 for (var i = 0; i < message.enumRepeated.length; ++i)
    @@ -379,7 +379,7 @@ $root.Message = (function() {
                         break;
                     }
             }
    -        if (message.int64Map != null && message.hasOwnProperty("int64Map")) {
    +        if (message.int64Map != null && Object.hasOwnProperty.call(message, "int64Map")) {
                 if (!$util.isObject(message.int64Map))
                     return "int64Map: object expected";
                 var key = Object.keys(message.int64Map);
    @@ -553,14 +553,14 @@ $root.Message = (function() {
                 }
                 object.enumVal = options.enums === String ? "ONE" : 1;
             }
    -        if (message.stringVal != null && message.hasOwnProperty("stringVal"))
    +        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
                 object.stringVal = message.stringVal;
             if (message.stringRepeated && message.stringRepeated.length) {
                 object.stringRepeated = [];
                 for (var j = 0; j < message.stringRepeated.length; ++j)
                     object.stringRepeated[j] = message.stringRepeated[j];
             }
    -        if (message.uint64Val != null && message.hasOwnProperty("uint64Val"))
    +        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
                 if (typeof BigInt !== "undefined" && options.longs === BigInt)
                     object.uint64Val = typeof message.uint64Val === "number" ? BigInt(message.uint64Val) : $util.Long.fromBits(message.uint64Val.low >>> 0, message.uint64Val.high >>> 0, true).toBigInt();
                 else if (typeof message.uint64Val === "number")
    @@ -577,14 +577,14 @@ $root.Message = (function() {
                     else
                         object.uint64Repeated[j] = options.longs === String ? $util.Long.prototype.toString.call(message.uint64Repeated[j]) : options.longs === Number ? new $util.LongBits(message.uint64Repeated[j].low >>> 0, message.uint64Repeated[j].high >>> 0).toNumber(true) : message.uint64Repeated[j];
             }
    -        if (message.bytesVal != null && message.hasOwnProperty("bytesVal"))
    +        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
                 object.bytesVal = options.bytes === String ? $util.base64.encode(message.bytesVal, 0, message.bytesVal.length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesVal) : message.bytesVal;
             if (message.bytesRepeated && message.bytesRepeated.length) {
                 object.bytesRepeated = [];
                 for (var j = 0; j < message.bytesRepeated.length; ++j)
                     object.bytesRepeated[j] = options.bytes === String ? $util.base64.encode(message.bytesRepeated[j], 0, message.bytesRepeated[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesRepeated[j]) : message.bytesRepeated[j];
             }
    -        if (message.enumVal != null && message.hasOwnProperty("enumVal"))
    +        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
                 object.enumVal = options.enums === String ? $root.Message.SomeEnum[message.enumVal] === undefined ? message.enumVal : $root.Message.SomeEnum[message.enumVal] : message.enumVal;
             if (message.enumRepeated && message.enumRepeated.length) {
                 object.enumRepeated = [];
    
  • tests/data/mapbox/vector_tile.js+30 30 modified
    @@ -167,7 +167,7 @@ $root.vector_tile = (function() {
                     long = 0;
                 if (long > $util.recursionLimit)
                     return "maximum nesting depth exceeded";
    -            if (message.layers != null && message.hasOwnProperty("layers")) {
    +            if (message.layers != null && Object.hasOwnProperty.call(message, "layers")) {
                     if (!Array.isArray(message.layers))
                         return "layers: array expected";
                     for (var i = 0; i < message.layers.length; ++i) {
    @@ -516,25 +516,25 @@ $root.vector_tile = (function() {
                         long = 0;
                     if (long > $util.recursionLimit)
                         return "maximum nesting depth exceeded";
    -                if (message.stringValue != null && message.hasOwnProperty("stringValue"))
    +                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
                         if (!$util.isString(message.stringValue))
                             return "stringValue: string expected";
    -                if (message.floatValue != null && message.hasOwnProperty("floatValue"))
    +                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
                         if (typeof message.floatValue !== "number")
                             return "floatValue: number expected";
    -                if (message.doubleValue != null && message.hasOwnProperty("doubleValue"))
    +                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
                         if (typeof message.doubleValue !== "number")
                             return "doubleValue: number expected";
    -                if (message.intValue != null && message.hasOwnProperty("intValue"))
    +                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
                         if (!$util.isInteger(message.intValue) && !(message.intValue && $util.isInteger(message.intValue.low) && $util.isInteger(message.intValue.high)))
                             return "intValue: integer|Long expected";
    -                if (message.uintValue != null && message.hasOwnProperty("uintValue"))
    +                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
                         if (!$util.isInteger(message.uintValue) && !(message.uintValue && $util.isInteger(message.uintValue.low) && $util.isInteger(message.uintValue.high)))
                             return "uintValue: integer|Long expected";
    -                if (message.sintValue != null && message.hasOwnProperty("sintValue"))
    +                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
                         if (!$util.isInteger(message.sintValue) && !(message.sintValue && $util.isInteger(message.sintValue.low) && $util.isInteger(message.sintValue.high)))
                             return "sintValue: integer|Long expected";
    -                if (message.boolValue != null && message.hasOwnProperty("boolValue"))
    +                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
                         if (typeof message.boolValue !== "boolean")
                             return "boolValue: boolean expected";
                     return null;
    @@ -634,34 +634,34 @@ $root.vector_tile = (function() {
                             object.sintValue = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
                         object.boolValue = false;
                     }
    -                if (message.stringValue != null && message.hasOwnProperty("stringValue"))
    +                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
                         object.stringValue = message.stringValue;
    -                if (message.floatValue != null && message.hasOwnProperty("floatValue"))
    +                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
                         object.floatValue = options.json && !isFinite(message.floatValue) ? String(message.floatValue) : message.floatValue;
    -                if (message.doubleValue != null && message.hasOwnProperty("doubleValue"))
    +                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
                         object.doubleValue = options.json && !isFinite(message.doubleValue) ? String(message.doubleValue) : message.doubleValue;
    -                if (message.intValue != null && message.hasOwnProperty("intValue"))
    +                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.intValue = typeof message.intValue === "number" ? BigInt(message.intValue) : $util.Long.fromBits(message.intValue.low >>> 0, message.intValue.high >>> 0, false).toBigInt();
                         else if (typeof message.intValue === "number")
                             object.intValue = options.longs === String ? String(message.intValue) : message.intValue;
                         else
                             object.intValue = options.longs === String ? $util.Long.prototype.toString.call(message.intValue) : options.longs === Number ? new $util.LongBits(message.intValue.low >>> 0, message.intValue.high >>> 0).toNumber() : message.intValue;
    -                if (message.uintValue != null && message.hasOwnProperty("uintValue"))
    +                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.uintValue = typeof message.uintValue === "number" ? BigInt(message.uintValue) : $util.Long.fromBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0, true).toBigInt();
                         else if (typeof message.uintValue === "number")
                             object.uintValue = options.longs === String ? String(message.uintValue) : message.uintValue;
                         else
                             object.uintValue = options.longs === String ? $util.Long.prototype.toString.call(message.uintValue) : options.longs === Number ? new $util.LongBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0).toNumber(true) : message.uintValue;
    -                if (message.sintValue != null && message.hasOwnProperty("sintValue"))
    +                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.sintValue = typeof message.sintValue === "number" ? BigInt(message.sintValue) : $util.Long.fromBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0, false).toBigInt();
                         else if (typeof message.sintValue === "number")
                             object.sintValue = options.longs === String ? String(message.sintValue) : message.sintValue;
                         else
                             object.sintValue = options.longs === String ? $util.Long.prototype.toString.call(message.sintValue) : options.longs === Number ? new $util.LongBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0).toNumber() : message.sintValue;
    -                if (message.boolValue != null && message.hasOwnProperty("boolValue"))
    +                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
                         object.boolValue = message.boolValue;
                     return object;
                 };
    @@ -909,17 +909,17 @@ $root.vector_tile = (function() {
                         long = 0;
                     if (long > $util.recursionLimit)
                         return "maximum nesting depth exceeded";
    -                if (message.id != null && message.hasOwnProperty("id"))
    +                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
                         if (!$util.isInteger(message.id) && !(message.id && $util.isInteger(message.id.low) && $util.isInteger(message.id.high)))
                             return "id: integer|Long expected";
    -                if (message.tags != null && message.hasOwnProperty("tags")) {
    +                if (message.tags != null && Object.hasOwnProperty.call(message, "tags")) {
                         if (!Array.isArray(message.tags))
                             return "tags: array expected";
                         for (var i = 0; i < message.tags.length; ++i)
                             if (!$util.isInteger(message.tags[i]))
                                 return "tags: integer[] expected";
                     }
    -                if (message.type != null && message.hasOwnProperty("type"))
    +                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                         switch (message.type) {
                         default:
                             return "type: enum value expected";
    @@ -929,7 +929,7 @@ $root.vector_tile = (function() {
                         case 3:
                             break;
                         }
    -                if (message.geometry != null && message.hasOwnProperty("geometry")) {
    +                if (message.geometry != null && Object.hasOwnProperty.call(message, "geometry")) {
                         if (!Array.isArray(message.geometry))
                             return "geometry: array expected";
                         for (var i = 0; i < message.geometry.length; ++i)
    @@ -1036,7 +1036,7 @@ $root.vector_tile = (function() {
                             object.id = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
                         object.type = options.enums === String ? "UNKNOWN" : 0;
                     }
    -                if (message.id != null && message.hasOwnProperty("id"))
    +                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.id = typeof message.id === "number" ? BigInt(message.id) : $util.Long.fromBits(message.id.low >>> 0, message.id.high >>> 0, true).toBigInt();
                         else if (typeof message.id === "number")
    @@ -1048,7 +1048,7 @@ $root.vector_tile = (function() {
                         for (var j = 0; j < message.tags.length; ++j)
                             object.tags[j] = message.tags[j];
                     }
    -                if (message.type != null && message.hasOwnProperty("type"))
    +                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                         object.type = options.enums === String ? $root.vector_tile.Tile.GeomType[message.type] === undefined ? message.type : $root.vector_tile.Tile.GeomType[message.type] : message.type;
                     if (message.geometry && message.geometry.length) {
                         object.geometry = [];
    @@ -1283,9 +1283,9 @@ $root.vector_tile = (function() {
                             break;
                         }
                     }
    -                if (!message.hasOwnProperty("version"))
    +                if (!Object.hasOwnProperty.call(message, "version"))
                         throw $util.ProtocolError("missing required 'version'", { instance: message });
    -                if (!message.hasOwnProperty("name"))
    +                if (!Object.hasOwnProperty.call(message, "name"))
                         throw $util.ProtocolError("missing required 'name'", { instance: message });
                     return message;
                 };
    @@ -1325,7 +1325,7 @@ $root.vector_tile = (function() {
                         return "version: integer expected";
                     if (!$util.isString(message.name))
                         return "name: string expected";
    -                if (message.features != null && message.hasOwnProperty("features")) {
    +                if (message.features != null && Object.hasOwnProperty.call(message, "features")) {
                         if (!Array.isArray(message.features))
                             return "features: array expected";
                         for (var i = 0; i < message.features.length; ++i) {
    @@ -1334,14 +1334,14 @@ $root.vector_tile = (function() {
                                 return "features." + error;
                         }
                     }
    -                if (message.keys != null && message.hasOwnProperty("keys")) {
    +                if (message.keys != null && Object.hasOwnProperty.call(message, "keys")) {
                         if (!Array.isArray(message.keys))
                             return "keys: array expected";
                         for (var i = 0; i < message.keys.length; ++i)
                             if (!$util.isString(message.keys[i]))
                                 return "keys: string[] expected";
                     }
    -                if (message.values != null && message.hasOwnProperty("values")) {
    +                if (message.values != null && Object.hasOwnProperty.call(message, "values")) {
                         if (!Array.isArray(message.values))
                             return "values: array expected";
                         for (var i = 0; i < message.values.length; ++i) {
    @@ -1350,7 +1350,7 @@ $root.vector_tile = (function() {
                                 return "values." + error;
                         }
                     }
    -                if (message.extent != null && message.hasOwnProperty("extent"))
    +                if (message.extent != null && Object.hasOwnProperty.call(message, "extent"))
                         if (!$util.isInteger(message.extent))
                             return "extent: integer expected";
                     return null;
    @@ -1437,7 +1437,7 @@ $root.vector_tile = (function() {
                         object.extent = 4096;
                         object.version = 1;
                     }
    -                if (message.name != null && message.hasOwnProperty("name"))
    +                if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                         object.name = message.name;
                     if (message.features && message.features.length) {
                         object.features = [];
    @@ -1454,9 +1454,9 @@ $root.vector_tile = (function() {
                         for (var j = 0; j < message.values.length; ++j)
                             object.values[j] = $root.vector_tile.Tile.Value.toObject(message.values[j], options, q + 1);
                     }
    -                if (message.extent != null && message.hasOwnProperty("extent"))
    +                if (message.extent != null && Object.hasOwnProperty.call(message, "extent"))
                         object.extent = message.extent;
    -                if (message.version != null && message.hasOwnProperty("version"))
    +                if (message.version != null && Object.hasOwnProperty.call(message, "version"))
                         object.version = message.version;
                     return object;
                 };
    
  • tests/data/package.js+32 32 modified
    @@ -494,81 +494,81 @@ $root.Package = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.name != null && message.hasOwnProperty("name"))
    +        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                 if (!$util.isString(message.name))
                     return "name: string expected";
    -        if (message.version != null && message.hasOwnProperty("version"))
    +        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
                 if (!$util.isString(message.version))
                     return "version: string expected";
    -        if (message.versionScheme != null && message.hasOwnProperty("versionScheme"))
    +        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
                 if (!$util.isString(message.versionScheme))
                     return "versionScheme: string expected";
    -        if (message.description != null && message.hasOwnProperty("description"))
    +        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
                 if (!$util.isString(message.description))
                     return "description: string expected";
    -        if (message.author != null && message.hasOwnProperty("author"))
    +        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
                 if (!$util.isString(message.author))
                     return "author: string expected";
    -        if (message.license != null && message.hasOwnProperty("license"))
    +        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
                 if (!$util.isString(message.license))
                     return "license: string expected";
    -        if (message.repository != null && message.hasOwnProperty("repository")) {
    +        if (message.repository != null && Object.hasOwnProperty.call(message, "repository")) {
                 var error = $root.Package.Repository.verify(message.repository, long + 1);
                 if (error)
                     return "repository." + error;
             }
    -        if (message.bugs != null && message.hasOwnProperty("bugs"))
    +        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
                 if (!$util.isString(message.bugs))
                     return "bugs: string expected";
    -        if (message.homepage != null && message.hasOwnProperty("homepage"))
    +        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
                 if (!$util.isString(message.homepage))
                     return "homepage: string expected";
    -        if (message.keywords != null && message.hasOwnProperty("keywords")) {
    +        if (message.keywords != null && Object.hasOwnProperty.call(message, "keywords")) {
                 if (!Array.isArray(message.keywords))
                     return "keywords: array expected";
                 for (var i = 0; i < message.keywords.length; ++i)
                     if (!$util.isString(message.keywords[i]))
                         return "keywords: string[] expected";
             }
    -        if (message.main != null && message.hasOwnProperty("main"))
    +        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
                 if (!$util.isString(message.main))
                     return "main: string expected";
    -        if (message.bin != null && message.hasOwnProperty("bin")) {
    +        if (message.bin != null && Object.hasOwnProperty.call(message, "bin")) {
                 if (!$util.isObject(message.bin))
                     return "bin: object expected";
                 var key = Object.keys(message.bin);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.bin[key[i]]))
                         return "bin: string{k:string} expected";
             }
    -        if (message.scripts != null && message.hasOwnProperty("scripts")) {
    +        if (message.scripts != null && Object.hasOwnProperty.call(message, "scripts")) {
                 if (!$util.isObject(message.scripts))
                     return "scripts: object expected";
                 var key = Object.keys(message.scripts);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.scripts[key[i]]))
                         return "scripts: string{k:string} expected";
             }
    -        if (message.dependencies != null && message.hasOwnProperty("dependencies")) {
    +        if (message.dependencies != null && Object.hasOwnProperty.call(message, "dependencies")) {
                 if (!$util.isObject(message.dependencies))
                     return "dependencies: object expected";
                 var key = Object.keys(message.dependencies);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.dependencies[key[i]]))
                         return "dependencies: string{k:string} expected";
             }
    -        if (message.devDependencies != null && message.hasOwnProperty("devDependencies")) {
    +        if (message.devDependencies != null && Object.hasOwnProperty.call(message, "devDependencies")) {
                 if (!$util.isObject(message.devDependencies))
                     return "devDependencies: object expected";
                 var key = Object.keys(message.devDependencies);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.devDependencies[key[i]]))
                         return "devDependencies: string{k:string} expected";
             }
    -        if (message.types != null && message.hasOwnProperty("types"))
    +        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
                 if (!$util.isString(message.types))
                     return "types: string expected";
    -        if (message.cliDependencies != null && message.hasOwnProperty("cliDependencies")) {
    +        if (message.cliDependencies != null && Object.hasOwnProperty.call(message, "cliDependencies")) {
                 if (!Array.isArray(message.cliDependencies))
                     return "cliDependencies: array expected";
                 for (var i = 0; i < message.cliDependencies.length; ++i)
    @@ -718,28 +718,28 @@ $root.Package = (function() {
                 object.types = "";
                 object.versionScheme = "";
             }
    -        if (message.name != null && message.hasOwnProperty("name"))
    +        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                 object.name = message.name;
    -        if (message.version != null && message.hasOwnProperty("version"))
    +        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
                 object.version = message.version;
    -        if (message.description != null && message.hasOwnProperty("description"))
    +        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
                 object.description = message.description;
    -        if (message.author != null && message.hasOwnProperty("author"))
    +        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
                 object.author = message.author;
    -        if (message.license != null && message.hasOwnProperty("license"))
    +        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
                 object.license = message.license;
    -        if (message.repository != null && message.hasOwnProperty("repository"))
    +        if (message.repository != null && Object.hasOwnProperty.call(message, "repository"))
                 object.repository = $root.Package.Repository.toObject(message.repository, options, q + 1);
    -        if (message.bugs != null && message.hasOwnProperty("bugs"))
    +        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
                 object.bugs = message.bugs;
    -        if (message.homepage != null && message.hasOwnProperty("homepage"))
    +        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
                 object.homepage = message.homepage;
             if (message.keywords && message.keywords.length) {
                 object.keywords = [];
                 for (var j = 0; j < message.keywords.length; ++j)
                     object.keywords[j] = message.keywords[j];
             }
    -        if (message.main != null && message.hasOwnProperty("main"))
    +        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
                 object.main = message.main;
             var keys2;
             if (message.bin && (keys2 = Object.keys(message.bin)).length) {
    @@ -774,14 +774,14 @@ $root.Package = (function() {
                     object.devDependencies[keys2[j]] = message.devDependencies[keys2[j]];
                 }
             }
    -        if (message.types != null && message.hasOwnProperty("types"))
    +        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
                 object.types = message.types;
             if (message.cliDependencies && message.cliDependencies.length) {
                 object.cliDependencies = [];
                 for (var j = 0; j < message.cliDependencies.length; ++j)
                     object.cliDependencies[j] = message.cliDependencies[j];
             }
    -        if (message.versionScheme != null && message.hasOwnProperty("versionScheme"))
    +        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
                 object.versionScheme = message.versionScheme;
             return object;
         };
    @@ -972,10 +972,10 @@ $root.Package = (function() {
                     long = 0;
                 if (long > $util.recursionLimit)
                     return "maximum nesting depth exceeded";
    -            if (message.type != null && message.hasOwnProperty("type"))
    +            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                     if (!$util.isString(message.type))
                         return "type: string expected";
    -            if (message.url != null && message.hasOwnProperty("url"))
    +            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
                     if (!$util.isString(message.url))
                         return "url: string expected";
                 return null;
    @@ -1027,9 +1027,9 @@ $root.Package = (function() {
                     object.type = "";
                     object.url = "";
                 }
    -            if (message.type != null && message.hasOwnProperty("type"))
    +            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                     object.type = message.type;
    -            if (message.url != null && message.hasOwnProperty("url"))
    +            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
                     object.url = message.url;
                 return object;
             };
    
  • tests/data/rpc-es6.js+5 5 modified
    @@ -59,7 +59,7 @@ export const MyService = $root.MyService = (() => {
          * @variation 1
          */
         Object.defineProperty(MyService.prototype.myMethod = function myMethod(request, callback) {
    -        return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
    +        return $protobuf.rpc.Service.prototype.rpcCall.call(this, myMethod, $root.MyRequest, $root.MyResponse, request, callback);
         }, "name", { value: "MyMethod" });
     
         /**
    @@ -220,7 +220,7 @@ export const MyRequest = $root.MyRequest = (() => {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -268,7 +268,7 @@ export const MyRequest = $root.MyRequest = (() => {
             let object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -447,7 +447,7 @@ export const MyResponse = $root.MyResponse = (() => {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -495,7 +495,7 @@ export const MyResponse = $root.MyResponse = (() => {
             let object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    
  • tests/data/rpc.js+5 5 modified
    @@ -61,7 +61,7 @@ $root.MyService = (function() {
          * @variation 1
          */
         Object.defineProperty(MyService.prototype.myMethod = function myMethod(request, callback) {
    -        return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
    +        return $protobuf.rpc.Service.prototype.rpcCall.call(this, myMethod, $root.MyRequest, $root.MyResponse, request, callback);
         }, "name", { value: "MyMethod" });
     
         /**
    @@ -222,7 +222,7 @@ $root.MyRequest = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -270,7 +270,7 @@ $root.MyRequest = (function() {
             var object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -449,7 +449,7 @@ $root.MyResponse = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -497,7 +497,7 @@ $root.MyResponse = (function() {
             var object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    
  • tests/data/rpc-reserved.js+5 5 modified
    @@ -61,7 +61,7 @@ $root.MyService = (function() {
          * @variation 1
          */
         Object.defineProperty(MyService.prototype["delete"] = function delete_(request, callback) {
    -        return this.rpcCall(delete_, $root.MyRequest, $root.MyResponse, request, callback);
    +        return $protobuf.rpc.Service.prototype.rpcCall.call(this, delete_, $root.MyRequest, $root.MyResponse, request, callback);
         }, "name", { value: "Delete" });
     
         /**
    @@ -222,7 +222,7 @@ $root.MyRequest = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -270,7 +270,7 @@ $root.MyRequest = (function() {
             var object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -449,7 +449,7 @@ $root.MyResponse = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -497,7 +497,7 @@ $root.MyResponse = (function() {
             var object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    
  • tests/data/test.js+482 482 modified
  • tests/data/type_url.js+4 4 modified
    @@ -154,7 +154,7 @@ $root.TypeUrlTest = (function() {
                 long = 0;
             if (long > $util.recursionLimit)
                 return "maximum nesting depth exceeded";
    -        if (message.nested != null && message.hasOwnProperty("nested")) {
    +        if (message.nested != null && Object.hasOwnProperty.call(message, "nested")) {
                 var error = $root.TypeUrlTest.Nested.verify(message.nested, long + 1);
                 if (error)
                     return "nested." + error;
    @@ -207,7 +207,7 @@ $root.TypeUrlTest = (function() {
             var object = {};
             if (options.defaults)
                 object.nested = null;
    -        if (message.nested != null && message.hasOwnProperty("nested"))
    +        if (message.nested != null && Object.hasOwnProperty.call(message, "nested"))
                 object.nested = $root.TypeUrlTest.Nested.toObject(message.nested, options, q + 1);
             return object;
         };
    @@ -383,7 +383,7 @@ $root.TypeUrlTest = (function() {
                     long = 0;
                 if (long > $util.recursionLimit)
                     return "maximum nesting depth exceeded";
    -            if (message.a != null && message.hasOwnProperty("a"))
    +            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
                     if (!$util.isString(message.a))
                         return "a: string expected";
                 return null;
    @@ -431,7 +431,7 @@ $root.TypeUrlTest = (function() {
                 var object = {};
                 if (options.defaults)
                     object.a = "";
    -            if (message.a != null && message.hasOwnProperty("a"))
    +            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
                     object.a = message.a;
                 return object;
             };
    
ce013abb069c

fix: Avoid name collisions in generated code (#2302)

https://github.com/protobufjs/protobuf.jsdcodeIOJun 4, 2026Fixed in protobufjs-v8.6.0via ghsa-release-walk
25 files changed · +5026 4657
  • cli/package.json+4 6 modified
    @@ -25,14 +25,12 @@
       "dependencies": {
         "chalk": "^4.0.0",
         "escodegen": "^1.13.0",
    -    "espree": "^9.0.0",
    +    "espree": "^9.6.1",
         "estraverse": "^5.1.0",
    -    "glob": "^8.0.0",
    -    "jsdoc": "^4.0.0",
    +    "glob": "^8.1.0",
    +    "jsdoc": "^4.0.5",
         "minimist": "^1.2.8",
    -    "semver": "^7.1.2",
    -    "tmp": "^0.2.1",
    -    "uglify-js": "^3.7.7"
    +    "tmp": "^0.2.7"
       },
       "devDependencies": {
         "protobufjs": "file:.."
    
  • cli/package-lock.json+279 231 modified
    @@ -11,14 +11,12 @@
           "dependencies": {
             "chalk": "^4.0.0",
             "escodegen": "^1.13.0",
    -        "espree": "^9.0.0",
    +        "espree": "^9.6.1",
             "estraverse": "^5.1.0",
    -        "glob": "^8.0.0",
    -        "jsdoc": "^4.0.0",
    +        "glob": "^8.1.0",
    +        "jsdoc": "^4.0.5",
             "minimist": "^1.2.8",
    -        "semver": "^7.1.2",
    -        "tmp": "^0.2.1",
    -        "uglify-js": "^3.7.7"
    +        "tmp": "^0.2.7"
           },
           "bin": {
             "pbjs": "bin/pbjs",
    @@ -32,14 +30,13 @@
             "node": ">=12.0.0"
           },
           "peerDependencies": {
    -        "protobufjs": "^8.4.0"
    +        "protobufjs": "^8.5.0"
           }
         },
         "..": {
           "name": "protobufjs",
           "version": "8.5.0",
           "dev": true,
    -      "hasInstallScript": true,
           "license": "BSD-3-Clause",
           "dependencies": {
             "long": "^5.3.2"
    @@ -69,7 +66,6 @@
             "tape": "^5.0.0",
             "tslint": "^6.0.0",
             "typescript": "^3.7.5",
    -        "uglify-js": "^3.7.7",
             "vinyl-buffer": "^1.0.1",
             "vinyl-fs": "^4.0.0",
             "vinyl-source-stream": "^2.0.0"
    @@ -78,17 +74,52 @@
             "node": ">=12.0.0"
           }
         },
    +    "node_modules/@babel/helper-string-parser": {
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz",
    +      "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==",
    +      "license": "MIT",
    +      "engines": {
    +        "node": ">=6.9.0"
    +      }
    +    },
    +    "node_modules/@babel/helper-validator-identifier": {
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
    +      "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==",
    +      "license": "MIT",
    +      "engines": {
    +        "node": ">=6.9.0"
    +      }
    +    },
         "node_modules/@babel/parser": {
    -      "version": "7.18.13",
    -      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.18.13.tgz",
    -      "integrity": "sha512-dgXcIfMuQ0kgzLB2b9tRZs7TTFFaGM2AbtA4fJgUUYukzGH4jwsS7hzQHEGs67jdehpm22vkgKwvbU+aEflgwg==",
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.7.tgz",
    +      "integrity": "sha512-hnORnjP/1P/zFEndoeX+n+t1RwWRJiJpM/jO7FW32Kn9r5+sJB2JWOdYo4L6k78j15eCwY3Gm/7364B1EMwtNg==",
    +      "license": "MIT",
    +      "dependencies": {
    +        "@babel/types": "^7.29.7"
    +      },
           "bin": {
             "parser": "bin/babel-parser.js"
           },
           "engines": {
             "node": ">=6.0.0"
           }
         },
    +    "node_modules/@babel/types": {
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.7.tgz",
    +      "integrity": "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA==",
    +      "license": "MIT",
    +      "dependencies": {
    +        "@babel/helper-string-parser": "^7.29.7",
    +        "@babel/helper-validator-identifier": "^7.29.7"
    +      },
    +      "engines": {
    +        "node": ">=6.9.0"
    +      }
    +    },
         "node_modules/@jsdoc/salty": {
           "version": "0.2.1",
           "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.1.tgz",
    @@ -101,28 +132,32 @@
           }
         },
         "node_modules/@types/linkify-it": {
    -      "version": "3.0.2",
    -      "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz",
    -      "integrity": "sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA=="
    +      "version": "5.0.0",
    +      "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
    +      "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==",
    +      "license": "MIT"
         },
         "node_modules/@types/markdown-it": {
    -      "version": "12.2.3",
    -      "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz",
    -      "integrity": "sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==",
    +      "version": "14.1.2",
    +      "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz",
    +      "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==",
    +      "license": "MIT",
           "dependencies": {
    -        "@types/linkify-it": "*",
    -        "@types/mdurl": "*"
    +        "@types/linkify-it": "^5",
    +        "@types/mdurl": "^2"
           }
         },
         "node_modules/@types/mdurl": {
    -      "version": "1.0.2",
    -      "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-1.0.2.tgz",
    -      "integrity": "sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA=="
    +      "version": "2.0.0",
    +      "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
    +      "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==",
    +      "license": "MIT"
         },
         "node_modules/acorn": {
    -      "version": "8.8.0",
    -      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
    -      "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==",
    +      "version": "8.16.0",
    +      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
    +      "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
    +      "license": "MIT",
           "bin": {
             "acorn": "bin/acorn"
           },
    @@ -155,7 +190,8 @@
         "node_modules/argparse": {
           "version": "2.0.1",
           "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
    -      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
    +      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
    +      "license": "Python-2.0"
         },
         "node_modules/balanced-match": {
           "version": "1.0.2",
    @@ -168,9 +204,10 @@
           "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
         },
         "node_modules/brace-expansion": {
    -      "version": "2.0.1",
    -      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
    -      "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
    +      "version": "2.1.1",
    +      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.1.tgz",
    +      "integrity": "sha512-WR1cURNjuvBLMZBMbqM0UoE+WAfdUcEV1ccD8PVBVOI+Z3ND4+SZbN8RsfT2bMuG1qwz5RFvPukSZm5fF2D5eA==",
    +      "license": "MIT",
           "dependencies": {
             "balanced-match": "^1.0.0"
           }
    @@ -223,9 +260,13 @@
           "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="
         },
         "node_modules/entities": {
    -      "version": "2.1.0",
    -      "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz",
    -      "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==",
    +      "version": "4.5.0",
    +      "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
    +      "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
    +      "license": "BSD-2-Clause",
    +      "engines": {
    +        "node": ">=0.12"
    +      },
           "funding": {
             "url": "https://github.com/fb55/entities?sponsor=1"
           }
    @@ -268,21 +309,26 @@
           }
         },
         "node_modules/eslint-visitor-keys": {
    -      "version": "3.3.0",
    -      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz",
    -      "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==",
    +      "version": "3.4.3",
    +      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz",
    +      "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==",
    +      "license": "Apache-2.0",
           "engines": {
             "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
    +      },
    +      "funding": {
    +        "url": "https://opencollective.com/eslint"
           }
         },
         "node_modules/espree": {
    -      "version": "9.4.0",
    -      "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz",
    -      "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==",
    +      "version": "9.6.1",
    +      "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz",
    +      "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==",
    +      "license": "BSD-2-Clause",
           "dependencies": {
    -        "acorn": "^8.8.0",
    +        "acorn": "^8.9.0",
             "acorn-jsx": "^5.3.2",
    -        "eslint-visitor-keys": "^3.3.0"
    +        "eslint-visitor-keys": "^3.4.1"
           },
           "engines": {
             "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
    @@ -330,10 +376,11 @@
           "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
         },
         "node_modules/glob": {
    -      "version": "8.0.3",
    -      "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz",
    -      "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==",
    +      "version": "8.1.0",
    +      "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
    +      "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
           "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
    +      "license": "ISC",
           "dependencies": {
             "fs.realpath": "^1.0.0",
             "inflight": "^1.0.4",
    @@ -385,20 +432,21 @@
           }
         },
         "node_modules/jsdoc": {
    -      "version": "4.0.0",
    -      "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.0.tgz",
    -      "integrity": "sha512-tzTgkklbWKrlaQL2+e3NNgLcZu3NaK2vsHRx7tyHQ+H5jcB9Gx0txSd2eJWlMC/xU1+7LQu4s58Ry0RkuaEQVg==",
    +      "version": "4.0.5",
    +      "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.5.tgz",
    +      "integrity": "sha512-P4C6MWP9yIlMiK8nwoZvxN84vb6MsnXcHuy7XzVOvQoCizWX5JFCBsWIIWKXBltpoRZXddUOVQmCTOZt9yDj9g==",
    +      "license": "Apache-2.0",
           "dependencies": {
    -        "@babel/parser": "^7.9.4",
    +        "@babel/parser": "^7.20.15",
             "@jsdoc/salty": "^0.2.1",
    -        "@types/markdown-it": "^12.2.3",
    +        "@types/markdown-it": "^14.1.1",
             "bluebird": "^3.7.2",
             "catharsis": "^0.9.0",
             "escape-string-regexp": "^2.0.0",
             "js2xmlparser": "^4.0.2",
             "klaw": "^3.0.0",
    -        "markdown-it": "^12.3.2",
    -        "markdown-it-anchor": "^8.4.1",
    +        "markdown-it": "^14.1.0",
    +        "markdown-it-anchor": "^8.6.7",
             "marked": "^4.0.10",
             "mkdirp": "^1.0.4",
             "requizzle": "^0.2.3",
    @@ -433,48 +481,62 @@
           }
         },
         "node_modules/linkify-it": {
    -      "version": "3.0.3",
    -      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz",
    -      "integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==",
    +      "version": "5.0.1",
    +      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.1.tgz",
    +      "integrity": "sha512-wVoTjP4Q6R0NW5hiZkVJaFZPWgtXfoGF+6LucL3/FtiNjmcHhYjEr5f1Kqjirc1nBW07J/ZuRFumqr2oqccEWg==",
    +      "funding": [
    +        {
    +          "type": "github",
    +          "url": "https://github.com/sponsors/puzrin"
    +        },
    +        {
    +          "type": "github",
    +          "url": "https://github.com/sponsors/markdown-it"
    +        }
    +      ],
    +      "license": "MIT",
           "dependencies": {
    -        "uc.micro": "^1.0.1"
    +        "uc.micro": "^2.0.0"
           }
         },
         "node_modules/lodash": {
    -      "version": "4.17.21",
    -      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
    -      "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
    -    },
    -    "node_modules/lru-cache": {
    -      "version": "6.0.0",
    -      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
    -      "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
    -      "dependencies": {
    -        "yallist": "^4.0.0"
    -      },
    -      "engines": {
    -        "node": ">=10"
    -      }
    +      "version": "4.18.1",
    +      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz",
    +      "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==",
    +      "license": "MIT"
         },
         "node_modules/markdown-it": {
    -      "version": "12.3.2",
    -      "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz",
    -      "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==",
    +      "version": "14.2.0",
    +      "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.2.0.tgz",
    +      "integrity": "sha512-1TGiQiJVRQ3NPmZH6sx5Cfnmg6GQm9jvC1ch4TK511NjSJvjzKLzn5pPfZRNZkRPZP0HqCioSndqH8v2nRaWVQ==",
    +      "funding": [
    +        {
    +          "type": "github",
    +          "url": "https://github.com/sponsors/puzrin"
    +        },
    +        {
    +          "type": "github",
    +          "url": "https://github.com/sponsors/markdown-it"
    +        }
    +      ],
    +      "license": "MIT",
           "dependencies": {
             "argparse": "^2.0.1",
    -        "entities": "~2.1.0",
    -        "linkify-it": "^3.0.1",
    -        "mdurl": "^1.0.1",
    -        "uc.micro": "^1.0.5"
    +        "entities": "^4.4.0",
    +        "linkify-it": "^5.0.1",
    +        "mdurl": "^2.0.0",
    +        "punycode.js": "^2.3.1",
    +        "uc.micro": "^2.1.0"
           },
           "bin": {
    -        "markdown-it": "bin/markdown-it.js"
    +        "markdown-it": "bin/markdown-it.mjs"
           }
         },
         "node_modules/markdown-it-anchor": {
    -      "version": "8.6.4",
    -      "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.4.tgz",
    -      "integrity": "sha512-Ul4YVYZNxMJYALpKtu+ZRdrryYt/GlQ5CK+4l1bp/gWXOG2QWElt6AqF3Mih/wfUKdZbNAZVXGR73/n6U/8img==",
    +      "version": "8.6.7",
    +      "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.7.tgz",
    +      "integrity": "sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==",
    +      "license": "Unlicense",
           "peerDependencies": {
             "@types/markdown-it": "*",
             "markdown-it": "*"
    @@ -492,14 +554,16 @@
           }
         },
         "node_modules/mdurl": {
    -      "version": "1.0.1",
    -      "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
    -      "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g=="
    +      "version": "2.0.0",
    +      "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",
    +      "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==",
    +      "license": "MIT"
         },
         "node_modules/minimatch": {
    -      "version": "5.1.0",
    -      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz",
    -      "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==",
    +      "version": "5.1.9",
    +      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz",
    +      "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==",
    +      "license": "ISC",
           "dependencies": {
             "brace-expansion": "^2.0.1"
           },
    @@ -562,6 +626,15 @@
           "resolved": "..",
           "link": true
         },
    +    "node_modules/punycode.js": {
    +      "version": "2.3.1",
    +      "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
    +      "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
    +      "license": "MIT",
    +      "engines": {
    +        "node": ">=6"
    +      }
    +    },
         "node_modules/requizzle": {
           "version": "0.2.3",
           "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz",
    @@ -570,20 +643,6 @@
             "lodash": "^4.17.14"
           }
         },
    -    "node_modules/semver": {
    -      "version": "7.3.7",
    -      "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
    -      "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
    -      "dependencies": {
    -        "lru-cache": "^6.0.0"
    -      },
    -      "bin": {
    -        "semver": "bin/semver.js"
    -      },
    -      "engines": {
    -        "node": ">=10"
    -      }
    -    },
         "node_modules/source-map": {
           "version": "0.6.1",
           "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
    @@ -616,9 +675,10 @@
           }
         },
         "node_modules/tmp": {
    -      "version": "0.2.4",
    -      "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.4.tgz",
    -      "integrity": "sha512-UdiSoX6ypifLmrfQ/XfiawN6hkjSBpCjhKxxZcWlUUmoXLaCKQU0bx4HF/tdDK2uzRuchf1txGvrWBzYREssoQ==",
    +      "version": "0.2.7",
    +      "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz",
    +      "integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw==",
    +      "license": "MIT",
           "engines": {
             "node": ">=14.14"
           }
    @@ -635,30 +695,22 @@
           }
         },
         "node_modules/uc.micro": {
    -      "version": "1.0.6",
    -      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
    -      "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
    -    },
    -    "node_modules/uglify-js": {
    -      "version": "3.17.0",
    -      "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.0.tgz",
    -      "integrity": "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg==",
    -      "bin": {
    -        "uglifyjs": "bin/uglifyjs"
    -      },
    -      "engines": {
    -        "node": ">=0.8.0"
    -      }
    +      "version": "2.1.0",
    +      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
    +      "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
    +      "license": "MIT"
         },
         "node_modules/underscore": {
    -      "version": "1.13.4",
    -      "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.4.tgz",
    -      "integrity": "sha512-BQFnUDuAQ4Yf/cYY5LNrK9NCJFKriaRbD9uR1fTeXnBeoa97W0i41qkZfGO9pSo8I5KzjAcSY2XYtdf0oKd7KQ=="
    +      "version": "1.13.8",
    +      "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz",
    +      "integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ==",
    +      "license": "MIT"
         },
         "node_modules/word-wrap": {
    -      "version": "1.2.3",
    -      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
    -      "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
    +      "version": "1.2.5",
    +      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz",
    +      "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==",
    +      "license": "MIT",
           "engines": {
             "node": ">=0.10.0"
           }
    @@ -672,18 +724,35 @@
           "version": "2.0.4",
           "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz",
           "integrity": "sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg=="
    -    },
    -    "node_modules/yallist": {
    -      "version": "4.0.0",
    -      "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
    -      "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
         }
       },
       "dependencies": {
    +    "@babel/helper-string-parser": {
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz",
    +      "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw=="
    +    },
    +    "@babel/helper-validator-identifier": {
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz",
    +      "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="
    +    },
         "@babel/parser": {
    -      "version": "7.18.13",
    -      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.18.13.tgz",
    -      "integrity": "sha512-dgXcIfMuQ0kgzLB2b9tRZs7TTFFaGM2AbtA4fJgUUYukzGH4jwsS7hzQHEGs67jdehpm22vkgKwvbU+aEflgwg=="
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.7.tgz",
    +      "integrity": "sha512-hnORnjP/1P/zFEndoeX+n+t1RwWRJiJpM/jO7FW32Kn9r5+sJB2JWOdYo4L6k78j15eCwY3Gm/7364B1EMwtNg==",
    +      "requires": {
    +        "@babel/types": "^7.29.7"
    +      }
    +    },
    +    "@babel/types": {
    +      "version": "7.29.7",
    +      "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.7.tgz",
    +      "integrity": "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA==",
    +      "requires": {
    +        "@babel/helper-string-parser": "^7.29.7",
    +        "@babel/helper-validator-identifier": "^7.29.7"
    +      }
         },
         "@jsdoc/salty": {
           "version": "0.2.1",
    @@ -694,28 +763,28 @@
           }
         },
         "@types/linkify-it": {
    -      "version": "3.0.2",
    -      "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz",
    -      "integrity": "sha512-HZQYqbiFVWufzCwexrvh694SOim8z2d+xJl5UNamcvQFejLY/2YUtzXHYi3cHdI7PMlS8ejH2slRAOJQ32aNbA=="
    +      "version": "5.0.0",
    +      "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
    +      "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q=="
         },
         "@types/markdown-it": {
    -      "version": "12.2.3",
    -      "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz",
    -      "integrity": "sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==",
    +      "version": "14.1.2",
    +      "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz",
    +      "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==",
           "requires": {
    -        "@types/linkify-it": "*",
    -        "@types/mdurl": "*"
    +        "@types/linkify-it": "^5",
    +        "@types/mdurl": "^2"
           }
         },
         "@types/mdurl": {
    -      "version": "1.0.2",
    -      "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-1.0.2.tgz",
    -      "integrity": "sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA=="
    +      "version": "2.0.0",
    +      "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
    +      "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg=="
         },
         "acorn": {
    -      "version": "8.8.0",
    -      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
    -      "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w=="
    +      "version": "8.16.0",
    +      "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
    +      "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw=="
         },
         "acorn-jsx": {
           "version": "5.3.2",
    @@ -747,9 +816,9 @@
           "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
         },
         "brace-expansion": {
    -      "version": "2.0.1",
    -      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
    -      "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
    +      "version": "2.1.1",
    +      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.1.tgz",
    +      "integrity": "sha512-WR1cURNjuvBLMZBMbqM0UoE+WAfdUcEV1ccD8PVBVOI+Z3ND4+SZbN8RsfT2bMuG1qwz5RFvPukSZm5fF2D5eA==",
           "requires": {
             "balanced-match": "^1.0.0"
           }
    @@ -790,9 +859,9 @@
           "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="
         },
         "entities": {
    -      "version": "2.1.0",
    -      "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz",
    -      "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w=="
    +      "version": "4.5.0",
    +      "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
    +      "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw=="
         },
         "escape-string-regexp": {
           "version": "2.0.0",
    @@ -819,18 +888,18 @@
           }
         },
         "eslint-visitor-keys": {
    -      "version": "3.3.0",
    -      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz",
    -      "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA=="
    +      "version": "3.4.3",
    +      "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz",
    +      "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="
         },
         "espree": {
    -      "version": "9.4.0",
    -      "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz",
    -      "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==",
    +      "version": "9.6.1",
    +      "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz",
    +      "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==",
           "requires": {
    -        "acorn": "^8.8.0",
    +        "acorn": "^8.9.0",
             "acorn-jsx": "^5.3.2",
    -        "eslint-visitor-keys": "^3.3.0"
    +        "eslint-visitor-keys": "^3.4.1"
           }
         },
         "esprima": {
    @@ -859,9 +928,9 @@
           "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
         },
         "glob": {
    -      "version": "8.0.3",
    -      "resolved": "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz",
    -      "integrity": "sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==",
    +      "version": "8.1.0",
    +      "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
    +      "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
           "requires": {
             "fs.realpath": "^1.0.0",
             "inflight": "^1.0.4",
    @@ -903,20 +972,20 @@
           }
         },
         "jsdoc": {
    -      "version": "4.0.0",
    -      "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.0.tgz",
    -      "integrity": "sha512-tzTgkklbWKrlaQL2+e3NNgLcZu3NaK2vsHRx7tyHQ+H5jcB9Gx0txSd2eJWlMC/xU1+7LQu4s58Ry0RkuaEQVg==",
    +      "version": "4.0.5",
    +      "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.5.tgz",
    +      "integrity": "sha512-P4C6MWP9yIlMiK8nwoZvxN84vb6MsnXcHuy7XzVOvQoCizWX5JFCBsWIIWKXBltpoRZXddUOVQmCTOZt9yDj9g==",
           "requires": {
    -        "@babel/parser": "^7.9.4",
    +        "@babel/parser": "^7.20.15",
             "@jsdoc/salty": "^0.2.1",
    -        "@types/markdown-it": "^12.2.3",
    +        "@types/markdown-it": "^14.1.1",
             "bluebird": "^3.7.2",
             "catharsis": "^0.9.0",
             "escape-string-regexp": "^2.0.0",
             "js2xmlparser": "^4.0.2",
             "klaw": "^3.0.0",
    -        "markdown-it": "^12.3.2",
    -        "markdown-it-anchor": "^8.4.1",
    +        "markdown-it": "^14.1.0",
    +        "markdown-it-anchor": "^8.6.7",
             "marked": "^4.0.10",
             "mkdirp": "^1.0.4",
             "requizzle": "^0.2.3",
    @@ -942,42 +1011,35 @@
           }
         },
         "linkify-it": {
    -      "version": "3.0.3",
    -      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz",
    -      "integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==",
    +      "version": "5.0.1",
    +      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.1.tgz",
    +      "integrity": "sha512-wVoTjP4Q6R0NW5hiZkVJaFZPWgtXfoGF+6LucL3/FtiNjmcHhYjEr5f1Kqjirc1nBW07J/ZuRFumqr2oqccEWg==",
           "requires": {
    -        "uc.micro": "^1.0.1"
    +        "uc.micro": "^2.0.0"
           }
         },
         "lodash": {
    -      "version": "4.17.21",
    -      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
    -      "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
    -    },
    -    "lru-cache": {
    -      "version": "6.0.0",
    -      "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
    -      "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
    -      "requires": {
    -        "yallist": "^4.0.0"
    -      }
    +      "version": "4.18.1",
    +      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz",
    +      "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q=="
         },
         "markdown-it": {
    -      "version": "12.3.2",
    -      "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz",
    -      "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==",
    +      "version": "14.2.0",
    +      "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.2.0.tgz",
    +      "integrity": "sha512-1TGiQiJVRQ3NPmZH6sx5Cfnmg6GQm9jvC1ch4TK511NjSJvjzKLzn5pPfZRNZkRPZP0HqCioSndqH8v2nRaWVQ==",
           "requires": {
             "argparse": "^2.0.1",
    -        "entities": "~2.1.0",
    -        "linkify-it": "^3.0.1",
    -        "mdurl": "^1.0.1",
    -        "uc.micro": "^1.0.5"
    +        "entities": "^4.4.0",
    +        "linkify-it": "^5.0.1",
    +        "mdurl": "^2.0.0",
    +        "punycode.js": "^2.3.1",
    +        "uc.micro": "^2.1.0"
           }
         },
         "markdown-it-anchor": {
    -      "version": "8.6.4",
    -      "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.4.tgz",
    -      "integrity": "sha512-Ul4YVYZNxMJYALpKtu+ZRdrryYt/GlQ5CK+4l1bp/gWXOG2QWElt6AqF3Mih/wfUKdZbNAZVXGR73/n6U/8img==",
    +      "version": "8.6.7",
    +      "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.7.tgz",
    +      "integrity": "sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==",
           "requires": {}
         },
         "marked": {
    @@ -986,14 +1048,14 @@
           "integrity": "sha512-rgQF/OxOiLcvgUAj1Q1tAf4Bgxn5h5JZTp04Fx4XUkVhs7B+7YA9JEWJhJpoO8eJt8MkZMwqLCNeNqj1bCREZQ=="
         },
         "mdurl": {
    -      "version": "1.0.1",
    -      "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
    -      "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g=="
    +      "version": "2.0.0",
    +      "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz",
    +      "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w=="
         },
         "minimatch": {
    -      "version": "5.1.0",
    -      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.0.tgz",
    -      "integrity": "sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==",
    +      "version": "5.1.9",
    +      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz",
    +      "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==",
           "requires": {
             "brace-expansion": "^2.0.1"
           }
    @@ -1062,12 +1124,16 @@
             "tape": "^5.0.0",
             "tslint": "^6.0.0",
             "typescript": "^3.7.5",
    -        "uglify-js": "^3.7.7",
             "vinyl-buffer": "^1.0.1",
             "vinyl-fs": "^4.0.0",
             "vinyl-source-stream": "^2.0.0"
           }
         },
    +    "punycode.js": {
    +      "version": "2.3.1",
    +      "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
    +      "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA=="
    +    },
         "requizzle": {
           "version": "0.2.3",
           "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz",
    @@ -1076,14 +1142,6 @@
             "lodash": "^4.17.14"
           }
         },
    -    "semver": {
    -      "version": "7.3.7",
    -      "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
    -      "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
    -      "requires": {
    -        "lru-cache": "^6.0.0"
    -      }
    -    },
         "source-map": {
           "version": "0.6.1",
           "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
    @@ -1104,9 +1162,9 @@
           }
         },
         "tmp": {
    -      "version": "0.2.4",
    -      "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.4.tgz",
    -      "integrity": "sha512-UdiSoX6ypifLmrfQ/XfiawN6hkjSBpCjhKxxZcWlUUmoXLaCKQU0bx4HF/tdDK2uzRuchf1txGvrWBzYREssoQ=="
    +      "version": "0.2.7",
    +      "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz",
    +      "integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw=="
         },
         "type-check": {
           "version": "0.3.2",
    @@ -1117,24 +1175,19 @@
           }
         },
         "uc.micro": {
    -      "version": "1.0.6",
    -      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
    -      "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
    -    },
    -    "uglify-js": {
    -      "version": "3.17.0",
    -      "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.0.tgz",
    -      "integrity": "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg=="
    +      "version": "2.1.0",
    +      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
    +      "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A=="
         },
         "underscore": {
    -      "version": "1.13.4",
    -      "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.4.tgz",
    -      "integrity": "sha512-BQFnUDuAQ4Yf/cYY5LNrK9NCJFKriaRbD9uR1fTeXnBeoa97W0i41qkZfGO9pSo8I5KzjAcSY2XYtdf0oKd7KQ=="
    +      "version": "1.13.8",
    +      "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz",
    +      "integrity": "sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ=="
         },
         "word-wrap": {
    -      "version": "1.2.3",
    -      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
    -      "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ=="
    +      "version": "1.2.5",
    +      "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz",
    +      "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA=="
         },
         "wrappy": {
           "version": "1.0.2",
    @@ -1145,11 +1198,6 @@
           "version": "2.0.4",
           "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz",
           "integrity": "sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg=="
    -    },
    -    "yallist": {
    -      "version": "4.0.0",
    -      "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
    -      "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
         }
       }
     }
    
  • cli/targets/json-module.js+2 10 modified
    @@ -17,14 +17,6 @@ json_module.defaultExportDoc =
         " * @type {$protobuf.Root}\n" +
         " */\n";
     
    -function jsonSafeProp(json) {
    -    return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
    -        return protobuf.util.safeProp($2).charAt(0) === "."
    -            ? $1 + $2 + ":"
    -            : $0;
    -    });
    -}
    -
     function escapeName(name) {
         if (!name)
             return "$root";
    @@ -43,10 +35,10 @@ function json_module(root, options, callback) {
                 (options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
             ];
             if (root.options) {
    -            var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
    +            var optionsJson = JSON.stringify(root.options, null, 2);
                 output.push(".setOptions(" + optionsJson + ")\n");
             }
    -        var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
    +        var json = JSON.stringify(root.nested, null, 2).trim();
             output.push(".addJSON(" + json + ");");
     
             // Add ES module named exports for top-level reflected symbols
    
  • cli/targets/static.js+172 42 modified
    @@ -1,8 +1,7 @@
     "use strict";
     module.exports = static_target;
     
    -var UglifyJS   = require("uglify-js"),
    -    espree     = require("espree"),
    +var espree     = require("espree"),
         escodegen  = require("escodegen"),
         estraverse = require("estraverse"),
         protobuf   = require("protobufjs");
    @@ -16,6 +15,8 @@ var Type      = protobuf.Type,
     var out = [];
     var indent = 0;
     var config = {};
    +var globalRefs = new Set();
    +var globalAliasIndex = -1;
     
     static_target.description = "Static code without reflection (non-functional on its own)";
     
    @@ -32,6 +33,7 @@ function static_target(root, options, callback) {
                 if (config.comments)
                     push("// Common aliases");
                 push((config.es6 ? "const " : "var ") + aliases.map(function(name) { return "$" + name + " = $protobuf." + name; }).join(", ") + ";");
    +            globalAliasIndex = out.length;
                 push("");
             }
             if (config.comments) {
    @@ -44,13 +46,22 @@ function static_target(root, options, callback) {
             var rootProp = "[" + JSON.stringify(String(config.root || "default")) + "]";
             push((config.es6 ? "const" : "var") + " $root = $protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = {});");
             buildNamespace(null, root);
    +        var globalAliases = Array.from(globalRefs);
    +        if (globalAliases.length) {
    +            var aliasDecl = (config.es6 ? "const " : "var ") + globalAliases.map(function(name) {
    +                return "$" + name + " = $util.global." + name;
    +            }).join(", ") + ";";
    +            out.splice(globalAliasIndex, 0, aliasDecl);
    +        }
             return callback(null, out.join("\n"));
         } catch (err) {
             return callback(err);
         } finally {
             out = [];
             indent = 0;
             config = {};
    +        globalRefs = new Set();
    +        globalAliasIndex = -1;
         }
     }
     
    @@ -199,15 +210,7 @@ var shortVars = {
         "g": "_target"
     };
     
    -function beautifyCode(code) {
    -    // Add semicolons
    -    code = UglifyJS.minify(code, {
    -        compress: false,
    -        mangle: false,
    -        output: { beautify: true }
    -    }).code;
    -    // Properly beautify
    -    var ast = espree.parse(code);
    +function beautifyAst(ast) {
         estraverse.replace(ast, {
             enter: function(node, parent) {
                 // rename short vars
    @@ -227,12 +230,9 @@ function beautifyCode(code) {
                 return undefined;
             }
         });
    -    code = escodegen.generate(ast, {
    -        format: {
    -            newline: "\n",
    -            quotes: "double"
    -        }
    -    });
    +}
    +
    +function addWireComments(code) {
         // Add id, wireType comments
         if (config.comments)
             code = code.replace(/\.uint32\((\d+)\)/g, function($0, $1) {
    @@ -249,9 +249,133 @@ var renameVars = {
         "util": "$util"
     };
     
    +var globalVars = new Set([
    +    "AbortController",
    +    "AbortSignal",
    +    "AggregateError",
    +    "Array",
    +    "ArrayBuffer",
    +    "Atomics",
    +    "BigInt",
    +    "BigInt64Array",
    +    "BigUint64Array",
    +    "Blob",
    +    "Boolean",
    +    "Buffer",
    +    "DataView",
    +    "Date",
    +    "DOMException",
    +    "Error",
    +    "Event",
    +    "EventTarget",
    +    "EvalError",
    +    "File",
    +    "FinalizationRegistry",
    +    "Float32Array",
    +    "Float64Array",
    +    "FormData",
    +    "Function",
    +    "Headers",
    +    "Infinity",
    +    "Int8Array",
    +    "Int16Array",
    +    "Int32Array",
    +    "Intl",
    +    "JSON",
    +    "Map",
    +    "Math",
    +    "MessageChannel",
    +    "MessagePort",
    +    "NaN",
    +    "Number",
    +    "Object",
    +    "Promise",
    +    "Proxy",
    +    "RangeError",
    +    "ReadableStream",
    +    "ReferenceError",
    +    "Reflect",
    +    "RegExp",
    +    "Request",
    +    "Response",
    +    "Set",
    +    "SharedArrayBuffer",
    +    "String",
    +    "Symbol",
    +    "SyntaxError",
    +    "TextDecoder",
    +    "TextEncoder",
    +    "TransformStream",
    +    "TypeError",
    +    "URIError",
    +    "Uint8Array",
    +    "Uint8ClampedArray",
    +    "Uint16Array",
    +    "Uint32Array",
    +    "URL",
    +    "URLSearchParams",
    +    "WebAssembly",
    +    "WeakMap",
    +    "WeakRef",
    +    "WeakSet",
    +    "WritableStream",
    +    "clearInterval",
    +    "clearTimeout",
    +    "decodeURI",
    +    "decodeURIComponent",
    +    "encodeURI",
    +    "encodeURIComponent",
    +    "escape",
    +    "fetch",
    +    "globalThis",
    +    "isFinite",
    +    "isNaN",
    +    "parseFloat",
    +    "parseInt",
    +    "queueMicrotask",
    +    "setInterval",
    +    "setTimeout",
    +    "structuredClone",
    +    "undefined",
    +    "unescape"
    +]);
    +
    +function globalRef(name) {
    +    globalRefs.add(name);
    +    return "$" + name;
    +}
    +
    +function isIdentifierReference(node, parent) {
    +    if (!parent)
    +        return true;
    +    switch (parent.type) {
    +        case "MemberExpression":
    +            return parent.object === node || parent.computed;
    +        case "Property":
    +            return parent.value === node || parent.computed;
    +        case "VariableDeclarator":
    +            return parent.id !== node;
    +        case "FunctionDeclaration":
    +        case "FunctionExpression":
    +            return parent.id !== node && parent.params.indexOf(node) < 0;
    +        case "CatchClause":
    +            return parent.param !== node;
    +        case "AssignmentExpression":
    +        case "AssignmentPattern":
    +            return parent.left !== node;
    +        case "UpdateExpression":
    +        case "BreakStatement":
    +        case "ContinueStatement":
    +        case "LabeledStatement":
    +            return false;
    +        default:
    +            return true;
    +    }
    +}
    +
     function buildFunction(type, functionName, gen, scope) {
    -    var code = gen.toString(functionName);
    -    var ast = espree.parse(code);
    +    var code = gen.toString();
    +    var ast = espree.parse("(" + code + ");");
     
         function rootMemberRef(object) {
             var ref = {
    @@ -287,6 +411,11 @@ function buildFunction(type, functionName, gen, scope) {
                         "type": "Identifier",
                         "name": renameVars[node.name]
                     };
    +            if (node.type === "Identifier" && globalVars.has(node.name) && isIdentifierReference(node, parent))
    +                return {
    +                    "type": "Identifier",
    +                    "name": globalRef(node.name)
    +                };
                 // replace generated constructor alias with the actual ctor
                 if (
                     node.type === "Identifier"
    @@ -326,16 +455,17 @@ function buildFunction(type, functionName, gen, scope) {
             }
         });
         /* eslint-enable no-extra-parens */
    +    if (config.beautify)
    +        beautifyAst(ast);
    +
    +    ast = ast.body[0].expression;
         code = escodegen.generate(ast, {
             format: {
                 newline: "\n",
                 quotes: "double"
             }
         });
    -
    -    if (config.beautify)
    -        code = beautifyCode(code);
    -
    +    code = addWireComments(code);
         code = code.replace(/ {4}/g, "\t");
     
         var hasScope = scope && Object.keys(scope).length,
    @@ -349,7 +479,7 @@ function buildFunction(type, functionName, gen, scope) {
     
         var lines = code.split(/\n/g);
         if (isCtor) // constructor
    -        push(lines[0]);
    +        push((config.es6 ? "const " : "var ") + escapeName(type.name) + " = " + lines[0]);
         else if (hasScope) // enclose in an iife
             push(escapeName(type.name) + "." + escapeName(functionName) + " = (function(" + Object.keys(scope).map(escapeName).join(", ") + ") { return " + lines[0]);
         else
    @@ -363,7 +493,7 @@ function buildFunction(type, functionName, gen, scope) {
             indent = prev;
         });
         if (isCtor)
    -        push("}");
    +        push("};");
         else if (hasScope)
             push("};})(" + Object.keys(scope).map(function(key) { return scope[key]; }).join(", ") + ");");
         else
    @@ -685,7 +815,7 @@ function buildType(ref, type) {
                     "@instance"
                 ]);
             }
    -        push("Object.defineProperty(" + escapeName(type.name) + ".prototype, " + JSON.stringify(oneof.name) +", {");
    +        push(globalRef("Object") + ".defineProperty(" + escapeName(type.name) + ".prototype, " + JSON.stringify(oneof.name) +", {");
             ++indent;
                 push("get: $util.oneOfGetter($oneOfFields = [" + oneof.oneof.map(JSON.stringify).join(", ") + "]),");
                 push("set: $util.oneOfSetter($oneOfFields)");
    @@ -708,7 +838,7 @@ function buildType(ref, type) {
                 "  (properties?: " + propertiesName(type) + "): " + exportName(type) + ";\n" +
                 "}}"
             ]));
    -        push(escapeName(type.name) + ".create = function create(properties) {");
    +        push(escapeName(type.name) + ".create = function(properties) {");
                 ++indent;
                 push("return new " + escapeName(type.name) + "(properties);");
                 --indent;
    @@ -739,7 +869,7 @@ function buildType(ref, type) {
                     "@param {$protobuf.Writer} [writer] Writer to encode to",
                     "@returns {$protobuf.Writer} Writer"
                 ]);
    -            push(escapeName(type.name) + ".encodeDelimited = function encodeDelimited(message, writer) {");
    +            push(escapeName(type.name) + ".encodeDelimited = function(message, writer) {");
                 ++indent;
                 push("return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();");
                 --indent;
    @@ -774,7 +904,7 @@ function buildType(ref, type) {
                     "@throws {Error} If the payload is not a reader or valid buffer",
                     "@throws {$protobuf.util.ProtocolError} If required fields are missing"
                 ]));
    -            push(escapeName(type.name) + ".decodeDelimited = function decodeDelimited(reader) {");
    +            push(escapeName(type.name) + ".decodeDelimited = function(reader) {");
                 ++indent;
                     push("if (!(reader instanceof $Reader))");
                     ++indent;
    @@ -831,9 +961,9 @@ function buildType(ref, type) {
                 "@instance",
                 "@returns {Object.<string,*>} JSON object"
             ]);
    -        push(escapeName(type.name) + ".prototype.toJSON = function toJSON() {");
    +        push(escapeName(type.name) + ".prototype.toJSON = function() {");
             ++indent;
    -            push("return this.constructor.toObject(this, $protobuf.util.toJSONOptions);");
    +            push("return " + escapeName(type.name) + ".toObject(this, $protobuf.util.toJSONOptions);");
             --indent;
             push("};");
         }
    @@ -849,9 +979,9 @@ function buildType(ref, type) {
                 "@param {string} [prefix] Custom type url prefix, defaults to `\"type.googleapis.com\"`",
                 "@returns {string} The type url"
             ]);
    -        push(escapeName(type.name) + ".getTypeUrl = function getTypeUrl(prefix) {");
    +        push(escapeName(type.name) + ".getTypeUrl = function(prefix) {");
             ++indent;
    -            push("if (prefix === undefined)");
    +            push("if (prefix === " + globalRef("undefined") + ")");
                 ++indent;
                     push("prefix = \"type.googleapis.com\";");
                 --indent;
    @@ -874,13 +1004,13 @@ function buildService(ref, service) {
             "@param {boolean} [requestDelimited=false] Whether requests are length-delimited",
             "@param {boolean} [responseDelimited=false] Whether responses are length-delimited"
         ]);
    -    push("function " + escapeName(service.name) + "(rpcImpl, requestDelimited, responseDelimited) {");
    +    push((config.es6 ? "const " : "var ") + escapeName(service.name) + " = function(rpcImpl, requestDelimited, responseDelimited) {");
         ++indent;
         push("$protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited);");
         --indent;
    -    push("}");
    +    push("};");
         push("");
    -    push("(" + escapeName(service.name) + ".prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = " + escapeName(service.name) + ";");
    +    push("(" + escapeName(service.name) + ".prototype = " + globalRef("Object") + ".create($protobuf.rpc.Service.prototype)).constructor = " + escapeName(service.name) + ";");
     
         if (config.create) {
             push("");
    @@ -894,7 +1024,7 @@ function buildService(ref, service) {
                 "@param {boolean} [responseDelimited=false] Whether responses are length-delimited",
                 "@returns {" + escapeName(service.name) + "} RPC service. Useful where requests and/or responses are streamed."
             ]);
    -        push(escapeName(service.name) + ".create = function create(rpcImpl, requestDelimited, responseDelimited) {");
    +        push(escapeName(service.name) + ".create = function(rpcImpl, requestDelimited, responseDelimited) {");
                 ++indent;
                 push("return new this(rpcImpl, requestDelimited, responseDelimited);");
                 --indent;
    @@ -938,18 +1068,18 @@ function buildService(ref, service) {
                 "@name " + exportName(service) + "#" + lcName,
                 "@type {" + exportName(service) + "." + methodTypeName + "}"
             ]);
    -        push("Object.defineProperties(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function " + escapeName(lcName) + "(request, callback) {");
    +        push(globalRef("Object") + ".defineProperties(" + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + " = function(request, callback) {");
                 ++indent;
    -            push("return this.rpcCall(" + escapeName(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
    +            push("return $protobuf.rpc.Service.prototype.rpcCall.call(this, " + escapeName(service.name) + ".prototype" + util.safeProp(lcName) + ", $root." + exportName(method.resolvedRequestType) + ", $root." + exportName(method.resolvedResponseType) + ", request, callback);");
                 --indent;
             push("}, {");
                 ++indent;
                 push("name: { value: " + JSON.stringify(method.name) + " },");
                 push("path: { value: " + JSON.stringify(method.path) + " },");
                 push("requestType: { value: " + JSON.stringify(method.requestType) + " },");
                 push("responseType: { value: " + JSON.stringify(method.responseType) + " },");
    -            push("requestStream: { value: " + (method.requestStream ? "true" : "undefined") + " },");
    -            push("responseStream: { value: " + (method.responseStream ? "true" : "undefined") + " }");
    +            push("requestStream: { value: " + (method.requestStream ? "true" : globalRef("undefined")) + " },");
    +            push("responseStream: { value: " + (method.responseStream ? "true" : globalRef("undefined")) + " }");
                 --indent;
             push("});");
         });
    @@ -973,7 +1103,7 @@ function buildEnum(ref, enm) {
         else
             push(escapeName(ref) + "." + escapeName(enm.name) + " = (function() {");
         ++indent;
    -        push((config.es6 ? "const" : "var") + " valuesById = {}, values = Object.create(valuesById);");
    +        push((config.es6 ? "const" : "var") + " valuesById = {}, values = " + globalRef("Object") + ".create(valuesById);");
             var aliased = [];
             Object.keys(enm.values).forEach(function(key) {
                 var valueId = enm.values[key];
    
  • package.json+0 1 modified
    @@ -72,7 +72,6 @@
         "tape": "^5.0.0",
         "tslint": "^6.0.0",
         "typescript": "^3.7.5",
    -    "uglify-js": "^3.7.7",
         "vinyl-buffer": "^1.0.1",
         "vinyl-fs": "^4.0.0",
         "vinyl-source-stream": "^2.0.0"
    
  • package-lock.json+0 2 modified
    @@ -7,7 +7,6 @@
         "": {
           "name": "protobufjs",
           "version": "8.5.0",
    -      "hasInstallScript": true,
           "license": "BSD-3-Clause",
           "dependencies": {
             "long": "^5.3.2"
    @@ -37,7 +36,6 @@
             "tape": "^5.0.0",
             "tslint": "^6.0.0",
             "typescript": "^3.7.5",
    -        "uglify-js": "^3.7.7",
             "vinyl-buffer": "^1.0.1",
             "vinyl-fs": "^4.0.0",
             "vinyl-source-stream": "^2.0.0"
    
  • src/converter.js+2 2 modified
    @@ -106,7 +106,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
     converter.fromObject = function fromObject(mtype) {
         /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
         var fields = mtype.fieldsArray;
    -    var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
    +    var gen = util.codegen(["d", "q"])
         ("if(d instanceof C)")
             ("return d")
         ("if(!util.isObject(d))")
    @@ -240,7 +240,7 @@ converter.toObject = function toObject(mtype) {
         var fields = mtype.fieldsArray.slice().sort(util.compareFieldsById);
         if (!fields.length)
             return util.codegen()("return {}");
    -    var gen = util.codegen(["m", "o", "q"], mtype.name + "$toObject")
    +    var gen = util.codegen(["m", "o", "q"])
         ("if(!o)")
             ("o={}")
         ("if(q===undefined)q=0")
    
  • src/decoder.js+2 2 modified
    @@ -26,7 +26,7 @@ function decoder(mtype) {
             if (!pfield.repeated && !pfield.map && !pfield.hasPresence)
                 hasImplicitPresenceField = true;
         }
    -    var gen = util.codegen(["r", "l", "z", "q", "g"], mtype.name + "$decode")
    +    var gen = util.codegen(["r", "l", "z", "q", "g"])
         ("if(!(r instanceof Reader))")
             ("r=Reader.create(r)")
         ("if(q===undefined)q=0")
    @@ -198,7 +198,7 @@ function decoder(mtype) {
         for (i = 0; i < mtype._fieldsArray.length; ++i) {
             var rfield = mtype._fieldsArray[i];
             if (rfield.required) gen
    -    ("if(!m.hasOwnProperty(%j))", rfield.name)
    +    ("if(!Object.hasOwnProperty.call(m,%j))", rfield.name)
             ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
         }
     
    
  • src/encoder.js+1 1 modified
    @@ -27,7 +27,7 @@ function genTypePartial(gen, field, fieldIndex, ref) {
      */
     function encoder(mtype) {
         /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
    -    var gen = util.codegen(["m", "w", "q"], mtype.name + "$encode")
    +    var gen = util.codegen(["m", "w", "q"])
         ("if(!w)")
             ("w=Writer.create()")
         ("if(q===undefined)q=0")
    
  • src/service.js+5 7 modified
    @@ -9,8 +9,6 @@ var Method = require("./method"),
         util   = require("./util"),
         rpc    = require("./rpc");
     
    -var reservedRe = util.patterns.reservedRe;
    -
     /**
      * Constructs a new service instance.
      * @classdesc Reflected service.
    @@ -190,11 +188,11 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
         var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
         for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
             var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
    -        rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
    -            m: method,
    -            q: method.resolvedRequestType.ctor,
    -            s: method.resolvedResponseType.ctor
    -        });
    +        rpcService[methodName] = (function(method, requestType, responseType) {
    +            return function rpcMethod(request, callback) {
    +                return rpc.Service.prototype.rpcCall.call(this, method, requestType, responseType, request, callback);
    +            };
    +        })(method, method.resolvedRequestType.ctor, method.resolvedResponseType.ctor);
         }
         return rpcService;
     };
    
  • src/type.js+4 2 modified
    @@ -208,7 +208,7 @@ Object.defineProperties(Type.prototype, {
      */
     Type.generateConstructor = function generateConstructor(mtype) {
         /* eslint-disable no-unexpected-multiline */
    -    var gen = util.codegen(["p"], mtype.name);
    +    var gen = util.codegen(["p"]);
         // explicitly initialize mutable object/array fields so that these aren't just inherited from the prototype
         for (var i = 0, field; i < mtype.fieldsArray.length; ++i)
             if ((field = mtype._fieldsArray[i]).map) gen
    @@ -386,7 +386,7 @@ Type.prototype.add = function add(object) {
                 throw Error("duplicate id " + object.id + " in " + this);
             if (this.isReservedId(object.id))
                 throw Error("id " + object.id + " is reserved in " + this);
    -        if (this.isReservedName(object.name))
    +        if (this.isReservedName(object.name) || object.name.charAt(0) === "$")
                 throw Error("name '" + object.name + "' is reserved in " + this);
             if (object.name === "__proto__")
                 return this;
    @@ -399,6 +399,8 @@ Type.prototype.add = function add(object) {
             return clearCache(this);
         }
         if (object instanceof OneOf) {
    +        if (object.name.charAt(0) === "$")
    +            throw Error("name '" + object.name + "' is reserved in " + this);
             if (object.name === "__proto__")
                 return this;
             if (!this.oneofs)
    
  • src/verifier.js+1 1 modified
    @@ -122,7 +122,7 @@ function genVerifyKey(gen, field, ref) {
     function verifier(mtype) {
         /* eslint-disable no-unexpected-multiline */
     
    -    var gen = util.codegen(["m", "q"], mtype.name + "$verify")
    +    var gen = util.codegen(["m", "q"])
         ("if(typeof m!==\"object\"||m===null)")
             ("return%j", "object expected")
         ("if(q===undefined)q=0")
    
  • tests/api_converters.js+12 0 modified
    @@ -210,6 +210,18 @@ tape.test("converters", function(test) {
                 test.end();
             });
     
    +        test.test(test.name + " - runtime-significant field names", function(test) {
    +            var root = protobuf.parse("syntax = \"proto2\"; message M { required string hasOwnProperty = 1; }").root;
    +            root.resolveAll();
    +            var M = root.lookupType("M"),
    +                message = M.decode(M.encode({ hasOwnProperty: "x" }).finish());
    +
    +            test.equal(message.hasOwnProperty, "x", "decode should not call a shadowed hasOwnProperty field");
    +            test.equal(M.verify(message), null, "verify should not call a shadowed hasOwnProperty field");
    +            test.same(M.toObject(message), { hasOwnProperty: "x" }, "toObject should not call a shadowed hasOwnProperty field");
    +            test.end();
    +        });
    +
             test.test(test.name + " - Message.fromObject", function(test) {
     
                 var obj = {
    
  • tests/api_service.js+16 0 modified
    @@ -47,6 +47,22 @@ tape.test("reflected services", function(test) {
         test.end();
     });
     
    +tape.test("reflected services can call runtime-significant method names", function(test) {
    +    var root = protobuf.parse("syntax = \"proto3\"; message Req {} message Res {} service S { rpc rpcCall(Req) returns (Res); }").root;
    +    root.resolveAll();
    +
    +    var Res = root.lookupType("Res"),
    +        service = root.lookupService("S").create(function(method, request, callback) {
    +            callback(null, Res.encode({}).finish());
    +        });
    +
    +    service.rpcCall({}, function(err, response) {
    +        test.error(err, "should call method named rpcCall");
    +        test.ok(response instanceof Res.ctor, "should decode the response");
    +        test.end();
    +    });
    +});
    +
     tape.test("feature resolution legacy proto3", function(test) {
         var json = {
             methods: {
    
  • tests/api_type.js+31 0 modified
    @@ -156,6 +156,37 @@ tape.test("generated message constructors", function(test) {
             test.equal(Type.create({ value: 1 }).value, 1, "should create messages with generated-safe type names");
         });
     
    +    var ObjectMessage = protobuf.parse("syntax = \"proto3\"; message Object { string value = 1; }").root.lookupType("Object");
    +    test.equal(ObjectMessage.create({ value: "x" }).value, "x", "should create messages with runtime-significant type names");
    +
    +    test.throws(function() {
    +        protobuf.Root.fromJSON({
    +            nested: {
    +                TypeShadow: {
    +                    fields: {
    +                        $type: { type: "string", id: 1 }
    +                    }
    +                }
    +            }
    +        });
    +    }, /name '\$type' is reserved/, "should reject runtime-reserved field names");
    +
    +    test.throws(function() {
    +        protobuf.Root.fromJSON({
    +            nested: {
    +                TypeShadow: {
    +                    oneofs: {
    +                        $type: { oneof: [] }
    +                    },
    +                    fields: {}
    +                }
    +            }
    +        });
    +    }, /name '\$type' is reserved/, "should reject runtime-reserved oneof names");
    +
    +    var ConstructorShadow = protobuf.parse("syntax = \"proto3\"; message ConstructorShadow { string constructor = 1; }").root.lookupType("ConstructorShadow");
    +    test.equal(JSON.stringify(ConstructorShadow.decode(ConstructorShadow.encode({ constructor: "x" }).finish())), "{\"constructor\":\"x\"}", "should stringify messages with an own constructor field");
    +
         test.end();
     });
     
    
  • tests/cli-pbjs.js+136 0 modified
    @@ -171,6 +171,136 @@ tape.test("pbjs static service methods expose rpc metadata", function(test) {
         });
     });
     
    +tape.test("pbjs static toJSON handles runtime-significant field names", function(test) {
    +    cliTest(test, function() {
    +        var root = protobuf.parse("syntax = \"proto3\"; message M { string constructor = 1; }").root;
    +        root.resolveAll();
    +
    +        var staticTarget = require("../cli/targets/static");
    +        staticTarget(root, {
    +            decode: true,
    +            encode: true,
    +            convert: true,
    +            root: "staticFieldShadow"
    +        }, function(err, jsCode) {
    +            test.error(err, "static code generation worked");
    +
    +            delete protobuf.roots.staticFieldShadow;
    +            var $protobuf = protobuf;
    +            eval(jsCode);
    +
    +            var M = protobuf.roots.staticFieldShadow.M,
    +                message = M.decode(M.encode({ constructor: "x" }).finish());
    +
    +            test.equal(JSON.stringify(message), "{\"constructor\":\"x\"}", "should stringify a message with an own constructor field");
    +            delete protobuf.roots.staticFieldShadow;
    +            test.end();
    +        });
    +    });
    +});
    +
    +tape.test("pbjs static services can call runtime-significant method names", function(test) {
    +    cliTest(test, function() {
    +        var root = protobuf.parse("syntax = \"proto3\"; message Req {} message Res {} service S { rpc rpcCall(Req) returns (Res); }").root;
    +        root.resolveAll();
    +
    +        var staticTarget = require("../cli/targets/static");
    +        staticTarget(root, {
    +            decode: true,
    +            encode: true,
    +            convert: true,
    +            service: true,
    +            root: "staticServiceShadow"
    +        }, function(err, jsCode) {
    +            test.error(err, "static code generation worked");
    +
    +            delete protobuf.roots.staticServiceShadow;
    +            var $protobuf = protobuf;
    +            eval(jsCode);
    +
    +            var S = protobuf.roots.staticServiceShadow.S,
    +                Res = protobuf.roots.staticServiceShadow.Res,
    +                service = new S(function(method, request, callback) {
    +                    callback(null, Res.encode({}).finish());
    +                });
    +
    +            service.rpcCall({}, function(callErr, response) {
    +                test.error(callErr, "should call method named rpcCall");
    +                test.ok(response instanceof Res, "should decode the response");
    +                delete protobuf.roots.staticServiceShadow;
    +                test.end();
    +            });
    +        });
    +    });
    +});
    +
    +tape.test("pbjs static code aliases globals shadowed by type names", function(test) {
    +    cliTest(test, function() {
    +        var root = protobuf.parse([
    +            "syntax = \"proto3\";",
    +            "message Object { string value = 1; }",
    +            "message Number { double value = 1; }",
    +            "message Array { repeated string values = 1; }",
    +            "message String { string value = 1; }",
    +            "message Boolean { bool value = 1; }",
    +            "message TypeError { Object nested = 1; }",
    +            "message BigInt { int64 value = 1; }",
    +            "message undefined { string value = 1; }"
    +        ].join("\n")).root;
    +        root.resolveAll();
    +
    +        var staticTarget = require("../cli/targets/static");
    +        staticTarget(root, {
    +            create: true,
    +            decode: true,
    +            encode: true,
    +            verify: true,
    +            convert: true,
    +            typeurl: true,
    +            root: "staticGlobalShadow"
    +        }, function(err, jsCode) {
    +            test.error(err, "static code generation worked");
    +            if (err) {
    +                test.end();
    +                return;
    +            }
    +            test.ok(jsCode.indexOf("$Object = $util.global.Object") >= 0, "emits Object alias");
    +            test.ok(jsCode.indexOf("$Number = $util.global.Number") >= 0, "emits Number alias");
    +            test.ok(jsCode.indexOf("$Array = $util.global.Array") >= 0, "emits Array alias");
    +            test.ok(jsCode.indexOf("$undefined = $util.global.undefined") >= 0, "emits undefined alias");
    +
    +            delete protobuf.roots.staticGlobalShadow;
    +            var $protobuf = protobuf;
    +            eval(jsCode);
    +
    +            var root = protobuf.roots.staticGlobalShadow,
    +                ObjectMessage = root.Object,
    +                NumberMessage = root.Number,
    +                ArrayMessage = root.Array,
    +                StringMessage = root.String,
    +                BooleanMessage = root.Boolean,
    +                TypeErrorMessage = root.TypeError,
    +                BigIntMessage = root.BigInt,
    +                UndefinedMessage = root.undefined;
    +
    +            test.equal(ObjectMessage.create({ value: "x" }).value, "x", "creates message named Object");
    +            test.equal(ObjectMessage.verify({ value: "x" }), null, "verifies message named Object");
    +            test.equal(NumberMessage.fromObject({ value: "1.5" }).value, 1.5, "converts message named Number");
    +            test.same(ArrayMessage.fromObject({ values: ["a"] }).values, ["a"], "converts message named Array");
    +            test.equal(StringMessage.fromObject({ value: 1 }).value, "1", "converts message named String");
    +            test.equal(BooleanMessage.fromObject({ value: 1 }).value, true, "converts message named Boolean");
    +            test.throws(function() {
    +                TypeErrorMessage.fromObject({ nested: "x" });
    +            }, TypeError, "throws TypeError when message named TypeError");
    +            test.equal(typeof BigIntMessage.toObject(BigIntMessage.fromObject({ value: 1 }), { longs: globalThis.BigInt }).value, "bigint", "converts message named BigInt");
    +            test.equal(UndefinedMessage.getTypeUrl(), "type.googleapis.com/undefined", "gets type url when message is named undefined");
    +
    +            delete protobuf.roots.staticGlobalShadow;
    +            test.end();
    +        });
    +    });
    +});
    +
     tape.test("pbjs generates correct ES module static-module imports", function(test) {
         cliTest(test, function() {
             var root = protobuf.loadSync("tests/data/cli/test.proto");
    @@ -254,6 +384,9 @@ tape.test("pbjs supports dictionary generated root names", function(test) {
                     }
                 }
             });
    +        root.options = Object.create(null);
    +        root.options.__proto__ = { marker: true };
    +        root.options.constructor = { marker: true };
     
             test.equal(Object.getPrototypeOf(protobuf.roots), null, "roots uses dictionary semantics");
     
    @@ -277,6 +410,9 @@ tape.test("pbjs supports dictionary generated root names", function(test) {
                 }, function(jsonErr, jsonCode) {
                     test.error(jsonErr, "json-module target accepts dictionary root name");
                     test.ok(jsonCode.indexOf("$protobuf.roots[\"constructor\"]") >= 0, "json-module target uses bracket root access");
    +                test.ok(jsonCode.indexOf("\"__proto__\":") >= 0, "json-module keeps __proto__ option quoted");
    +                test.ok(jsonCode.indexOf("\"constructor\":") >= 0, "json-module keeps constructor option quoted");
    +                test.equal(jsonCode.indexOf("__proto__:"), -1, "json-module does not emit __proto__ object literal syntax");
     
                     var module = { exports: {} };
                     function localRequire(request) {
    
  • tests/data/comments.js+72 71 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $TypeError = $util.global.TypeError, $String = $util.global.String, $Number = $util.global.Number, $Boolean = $util.global.Boolean;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_comments"] || ($protobuf.roots["test_comments"] = {});
    @@ -44,12 +45,12 @@ $root.Test1 = (function() {
          * @param {Test1.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function Test1(properties) {
    +    var Test1 = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * Field with a comment.
    @@ -87,7 +88,7 @@ $root.Test1 = (function() {
          *   (properties?: Test1.$Properties): Test1;
          * }}
          */
    -    Test1.create = function create(properties) {
    +    Test1.create = function(properties) {
             return new Test1(properties);
         };
     
    @@ -100,20 +101,20 @@ $root.Test1 = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Test1.encode = function encode(message, writer, _depth) {
    +    Test1.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
    +            throw $Error("max depth exceeded");
    +        if (message.field1 != null && $Object.hasOwnProperty.call(message, "field1"))
                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.field1);
    -        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
    +        if (message.field2 != null && $Object.hasOwnProperty.call(message, "field2"))
                 writer.uint32(/* id 2, wireType 0 =*/16).uint32(message.field2);
    -        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
    +        if (message.field3 != null && $Object.hasOwnProperty.call(message, "field3"))
                 writer.uint32(/* id 3, wireType 0 =*/24).bool(message.field3);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -128,7 +129,7 @@ $root.Test1 = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Test1.encodeDelimited = function encodeDelimited(message, writer) {
    +    Test1.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -143,19 +144,19 @@ $root.Test1 = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Test1.decode = function decode(reader, length, _end, _depth, _target) {
    +    Test1.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.Test1(), value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.Test1(), value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -194,8 +195,8 @@ $root.Test1 = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -209,7 +210,7 @@ $root.Test1 = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Test1.decodeDelimited = function decodeDelimited(reader) {
    +    Test1.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -223,20 +224,20 @@ $root.Test1 = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    Test1.verify = function verify(message, _depth) {
    +    Test1.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
    +        if (message.field1 != null && $Object.hasOwnProperty.call(message, "field1"))
                 if (!$util.isString(message.field1))
                     return "field1: string expected";
    -        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
    +        if (message.field2 != null && $Object.hasOwnProperty.call(message, "field2"))
                 if (!$util.isInteger(message.field2))
                     return "field2: integer expected";
    -        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
    +        if (message.field3 != null && $Object.hasOwnProperty.call(message, "field3"))
                 if (typeof message.field3 !== "boolean")
                     return "field3: boolean expected";
             return null;
    @@ -250,25 +251,25 @@ $root.Test1 = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {Test1} Test1
          */
    -    Test1.fromObject = function fromObject(object, _depth) {
    +    Test1.fromObject = function (object, _depth) {
             if (object instanceof $root.Test1)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".Test1: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".Test1: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.Test1();
             if (object.field1 != null)
                 if (typeof object.field1 !== "string" || object.field1.length)
    -                message.field1 = String(object.field1);
    +                message.field1 = $String(object.field1);
             if (object.field2 != null)
    -            if (Number(object.field2) !== 0)
    +            if ($Number(object.field2) !== 0)
                     message.field2 = object.field2 >>> 0;
             if (object.field3 != null)
                 if (object.field3)
    -                message.field3 = Boolean(object.field3);
    +                message.field3 = $Boolean(object.field3);
             return message;
         };
     
    @@ -281,24 +282,24 @@ $root.Test1 = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    Test1.toObject = function toObject(message, options, _depth) {
    +    Test1.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.defaults) {
                 object.field1 = "";
                 object.field2 = 0;
                 object.field3 = false;
             }
    -        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
    +        if (message.field1 != null && $Object.hasOwnProperty.call(message, "field1"))
                 object.field1 = message.field1;
    -        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
    +        if (message.field2 != null && $Object.hasOwnProperty.call(message, "field2"))
                 object.field2 = message.field2;
    -        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
    +        if (message.field3 != null && $Object.hasOwnProperty.call(message, "field3"))
                 object.field3 = message.field3;
             return object;
         };
    @@ -310,8 +311,8 @@ $root.Test1 = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    Test1.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    Test1.prototype.toJSON = function() {
    +        return Test1.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -322,8 +323,8 @@ $root.Test1 = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    Test1.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    Test1.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/Test1";
         };
    @@ -360,12 +361,12 @@ $root.Test2 = (function() {
          * @param {Test2.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function Test2(properties) {
    +    var Test2 = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * Creates a new Test2 instance using the specified properties.
    @@ -379,7 +380,7 @@ $root.Test2 = (function() {
          *   (properties?: Test2.$Properties): Test2;
          * }}
          */
    -    Test2.create = function create(properties) {
    +    Test2.create = function(properties) {
             return new Test2(properties);
         };
     
    @@ -392,14 +393,14 @@ $root.Test2 = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Test2.encode = function encode(message, writer, _depth) {
    +    Test2.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +            throw $Error("max depth exceeded");
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -414,7 +415,7 @@ $root.Test2 = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Test2.encodeDelimited = function encodeDelimited(message, writer) {
    +    Test2.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -429,19 +430,19 @@ $root.Test2 = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Test2.decode = function decode(reader, length, _end, _depth, _target) {
    +    Test2.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.Test2();
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.Test2();
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 reader.skipType(tag & 7, _depth, tag);
    @@ -450,8 +451,8 @@ $root.Test2 = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -465,7 +466,7 @@ $root.Test2 = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Test2.decodeDelimited = function decodeDelimited(reader) {
    +    Test2.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -479,10 +480,10 @@ $root.Test2 = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    Test2.verify = function verify(message, _depth) {
    +    Test2.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    @@ -497,15 +498,15 @@ $root.Test2 = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {Test2} Test2
          */
    -    Test2.fromObject = function fromObject(object, _depth) {
    +    Test2.fromObject = function (object, _depth) {
             if (object instanceof $root.Test2)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".Test2: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".Test2: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             return new $root.Test2();
         };
     
    @@ -518,7 +519,7 @@ $root.Test2 = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    Test2.toObject = function toObject() {
    +    Test2.toObject = function () {
             return {};
         };
     
    @@ -529,8 +530,8 @@ $root.Test2 = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    Test2.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    Test2.prototype.toJSON = function() {
    +        return Test2.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -541,8 +542,8 @@ $root.Test2 = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    Test2.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    Test2.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/Test2";
         };
    @@ -561,7 +562,7 @@ $root.Test2 = (function() {
      * @property {number} FIVE=5 Leading comment for value with both types of comments after field with trailing comment.
      */
     $root.Test3 = (function() {
    -    var valuesById = {}, values = Object.create(valuesById);
    +    var valuesById = {}, values = $Object.create(valuesById);
         values[valuesById[1] = "ONE"] = 1;
         values[valuesById[2] = "TWO"] = 2;
         values[valuesById[3] = "THREE"] = 3;
    
  • tests/data/convert.js+102 101 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $Array = $util.global.Array, $TypeError = $util.global.TypeError, $String = $util.global.String, $Number = $util.global.Number, $parseInt = $util.global.parseInt, $BigInt = $util.global.BigInt;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_convert"] || ($protobuf.roots["test_convert"] = {});
    @@ -47,17 +48,17 @@ $root.Message = (function() {
          * @param {Message.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function Message(properties) {
    +    var Message = function (properties) {
             this.stringRepeated = [];
             this.uint64Repeated = [];
             this.bytesRepeated = [];
             this.enumRepeated = [];
             this.int64Map = {};
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * Message stringVal.
    @@ -143,7 +144,7 @@ $root.Message = (function() {
          *   (properties?: Message.$Properties): Message;
          * }}
          */
    -    Message.create = function create(properties) {
    +    Message.create = function(properties) {
             return new Message(properties);
         };
     
    @@ -156,43 +157,43 @@ $root.Message = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Message.encode = function encode(message, writer, _depth) {
    +    Message.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
    +            throw $Error("max depth exceeded");
    +        if (message.stringVal != null && $Object.hasOwnProperty.call(message, "stringVal"))
                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.stringVal);
             if (message.stringRepeated != null && message.stringRepeated.length)
                 for (var i = 0; i < message.stringRepeated.length; ++i)
                     writer.uint32(/* id 2, wireType 2 =*/18).string(message.stringRepeated[i]);
    -        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
    +        if (message.uint64Val != null && $Object.hasOwnProperty.call(message, "uint64Val"))
                 writer.uint32(/* id 3, wireType 0 =*/24).uint64(message.uint64Val);
             if (message.uint64Repeated != null && message.uint64Repeated.length) {
                 writer.uint32(/* id 4, wireType 2 =*/34).fork();
                 for (var i = 0; i < message.uint64Repeated.length; ++i)
                     writer.uint64(message.uint64Repeated[i]);
                 writer.ldelim();
             }
    -        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
    +        if (message.bytesVal != null && $Object.hasOwnProperty.call(message, "bytesVal"))
                 writer.uint32(/* id 5, wireType 2 =*/42).bytes(message.bytesVal);
             if (message.bytesRepeated != null && message.bytesRepeated.length)
                 for (var i = 0; i < message.bytesRepeated.length; ++i)
                     writer.uint32(/* id 6, wireType 2 =*/50).bytes(message.bytesRepeated[i]);
    -        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
    +        if (message.enumVal != null && $Object.hasOwnProperty.call(message, "enumVal"))
                 writer.uint32(/* id 7, wireType 0 =*/56).int32(message.enumVal);
             if (message.enumRepeated != null && message.enumRepeated.length) {
                 writer.uint32(/* id 8, wireType 2 =*/66).fork();
                 for (var i = 0; i < message.enumRepeated.length; ++i)
                     writer.int32(message.enumRepeated[i]);
                 writer.ldelim();
             }
    -        if (message.int64Map != null && Object.hasOwnProperty.call(message, "int64Map"))
    -            for (var keys = Object.keys(message.int64Map), i = 0; i < keys.length; ++i)
    +        if (message.int64Map != null && $Object.hasOwnProperty.call(message, "int64Map"))
    +            for (var keys = $Object.keys(message.int64Map), i = 0; i < keys.length; ++i)
                     writer.uint32(/* id 9, wireType 2 =*/74).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 0 =*/16).int64(message.int64Map[keys[i]]).ldelim();
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -207,7 +208,7 @@ $root.Message = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Message.encodeDelimited = function encodeDelimited(message, writer) {
    +    Message.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -222,19 +223,19 @@ $root.Message = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Message.decode = function decode(reader, length, _end, _depth, _target) {
    +    Message.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.Message(), key, value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.Message(), key, value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -360,8 +361,8 @@ $root.Message = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -375,7 +376,7 @@ $root.Message = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Message.decodeDelimited = function decodeDelimited(reader) {
    +    Message.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -389,53 +390,53 @@ $root.Message = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    Message.verify = function verify(message, _depth) {
    +    Message.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
    +        if (message.stringVal != null && $Object.hasOwnProperty.call(message, "stringVal"))
                 if (!$util.isString(message.stringVal))
                     return "stringVal: string expected";
    -        if (message.stringRepeated != null && Object.hasOwnProperty.call(message, "stringRepeated")) {
    -            if (!Array.isArray(message.stringRepeated))
    +        if (message.stringRepeated != null && $Object.hasOwnProperty.call(message, "stringRepeated")) {
    +            if (!$Array.isArray(message.stringRepeated))
                     return "stringRepeated: array expected";
                 for (var i = 0; i < message.stringRepeated.length; ++i)
                     if (!$util.isString(message.stringRepeated[i]))
                         return "stringRepeated: string[] expected";
             }
    -        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
    +        if (message.uint64Val != null && $Object.hasOwnProperty.call(message, "uint64Val"))
                 if (!$util.isInteger(message.uint64Val) && !(message.uint64Val && $util.isInteger(message.uint64Val.low) && $util.isInteger(message.uint64Val.high)))
                     return "uint64Val: integer|Long expected";
    -        if (message.uint64Repeated != null && Object.hasOwnProperty.call(message, "uint64Repeated")) {
    -            if (!Array.isArray(message.uint64Repeated))
    +        if (message.uint64Repeated != null && $Object.hasOwnProperty.call(message, "uint64Repeated")) {
    +            if (!$Array.isArray(message.uint64Repeated))
                     return "uint64Repeated: array expected";
                 for (var i = 0; i < message.uint64Repeated.length; ++i)
                     if (!$util.isInteger(message.uint64Repeated[i]) && !(message.uint64Repeated[i] && $util.isInteger(message.uint64Repeated[i].low) && $util.isInteger(message.uint64Repeated[i].high)))
                         return "uint64Repeated: integer|Long[] expected";
             }
    -        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
    +        if (message.bytesVal != null && $Object.hasOwnProperty.call(message, "bytesVal"))
                 if (!(message.bytesVal && typeof message.bytesVal.length === "number" || $util.isString(message.bytesVal)))
                     return "bytesVal: buffer expected";
    -        if (message.bytesRepeated != null && Object.hasOwnProperty.call(message, "bytesRepeated")) {
    -            if (!Array.isArray(message.bytesRepeated))
    +        if (message.bytesRepeated != null && $Object.hasOwnProperty.call(message, "bytesRepeated")) {
    +            if (!$Array.isArray(message.bytesRepeated))
                     return "bytesRepeated: array expected";
                 for (var i = 0; i < message.bytesRepeated.length; ++i)
                     if (!(message.bytesRepeated[i] && typeof message.bytesRepeated[i].length === "number" || $util.isString(message.bytesRepeated[i])))
                         return "bytesRepeated: buffer[] expected";
             }
    -        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
    +        if (message.enumVal != null && $Object.hasOwnProperty.call(message, "enumVal"))
                 switch (message.enumVal) {
                 default:
                     return "enumVal: enum value expected";
                 case 1:
                 case 2:
                     break;
                 }
    -        if (message.enumRepeated != null && Object.hasOwnProperty.call(message, "enumRepeated")) {
    -            if (!Array.isArray(message.enumRepeated))
    +        if (message.enumRepeated != null && $Object.hasOwnProperty.call(message, "enumRepeated")) {
    +            if (!$Array.isArray(message.enumRepeated))
                     return "enumRepeated: array expected";
                 for (var i = 0; i < message.enumRepeated.length; ++i)
                     switch (message.enumRepeated[i]) {
    @@ -446,10 +447,10 @@ $root.Message = (function() {
                         break;
                     }
             }
    -        if (message.int64Map != null && Object.hasOwnProperty.call(message, "int64Map")) {
    +        if (message.int64Map != null && $Object.hasOwnProperty.call(message, "int64Map")) {
                 if (!$util.isObject(message.int64Map))
                     return "int64Map: object expected";
    -            var key = Object.keys(message.int64Map);
    +            var key = $Object.keys(message.int64Map);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isInteger(message.int64Map[key[i]]) && !(message.int64Map[key[i]] && $util.isInteger(message.int64Map[key[i]].low) && $util.isInteger(message.int64Map[key[i]].high)))
                         return "int64Map: integer|Long{k:string} expected";
    @@ -465,45 +466,45 @@ $root.Message = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {Message} Message
          */
    -    Message.fromObject = function fromObject(object, _depth) {
    +    Message.fromObject = function (object, _depth) {
             if (object instanceof $root.Message)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".Message: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".Message: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.Message();
             if (object.stringVal != null)
                 if (typeof object.stringVal !== "string" || object.stringVal.length)
    -                message.stringVal = String(object.stringVal);
    +                message.stringVal = $String(object.stringVal);
             if (object.stringRepeated) {
    -            if (!Array.isArray(object.stringRepeated))
    -                throw TypeError(".Message.stringRepeated: array expected");
    -            message.stringRepeated = Array(object.stringRepeated.length);
    +            if (!$Array.isArray(object.stringRepeated))
    +                throw $TypeError(".Message.stringRepeated: array expected");
    +            message.stringRepeated = $Array(object.stringRepeated.length);
                 for (var i = 0; i < object.stringRepeated.length; ++i)
    -                message.stringRepeated[i] = String(object.stringRepeated[i]);
    +                message.stringRepeated[i] = $String(object.stringRepeated[i]);
             }
             if (object.uint64Val != null)
    -            if (typeof object.uint64Val === "object" ? object.uint64Val.low || object.uint64Val.high : Number(object.uint64Val) !== 0)
    +            if (typeof object.uint64Val === "object" ? object.uint64Val.low || object.uint64Val.high : $Number(object.uint64Val) !== 0)
                     if ($util.Long)
                         message.uint64Val = $util.Long.fromValue(object.uint64Val, true);
                     else if (typeof object.uint64Val === "string")
    -                    message.uint64Val = parseInt(object.uint64Val, 10);
    +                    message.uint64Val = $parseInt(object.uint64Val, 10);
                     else if (typeof object.uint64Val === "number")
                         message.uint64Val = object.uint64Val;
                     else if (typeof object.uint64Val === "object")
                         message.uint64Val = new $util.LongBits(object.uint64Val.low >>> 0, object.uint64Val.high >>> 0).toNumber(true);
             if (object.uint64Repeated) {
    -            if (!Array.isArray(object.uint64Repeated))
    -                throw TypeError(".Message.uint64Repeated: array expected");
    -            message.uint64Repeated = Array(object.uint64Repeated.length);
    +            if (!$Array.isArray(object.uint64Repeated))
    +                throw $TypeError(".Message.uint64Repeated: array expected");
    +            message.uint64Repeated = $Array(object.uint64Repeated.length);
                 for (var i = 0; i < object.uint64Repeated.length; ++i)
                     if ($util.Long)
                         message.uint64Repeated[i] = $util.Long.fromValue(object.uint64Repeated[i], true);
                     else if (typeof object.uint64Repeated[i] === "string")
    -                    message.uint64Repeated[i] = parseInt(object.uint64Repeated[i], 10);
    +                    message.uint64Repeated[i] = $parseInt(object.uint64Repeated[i], 10);
                     else if (typeof object.uint64Repeated[i] === "number")
                         message.uint64Repeated[i] = object.uint64Repeated[i];
                     else if (typeof object.uint64Repeated[i] === "object")
    @@ -516,9 +517,9 @@ $root.Message = (function() {
                     else if (object.bytesVal.length >= 0)
                         message.bytesVal = object.bytesVal;
             if (object.bytesRepeated) {
    -            if (!Array.isArray(object.bytesRepeated))
    -                throw TypeError(".Message.bytesRepeated: array expected");
    -            message.bytesRepeated = Array(object.bytesRepeated.length);
    +            if (!$Array.isArray(object.bytesRepeated))
    +                throw $TypeError(".Message.bytesRepeated: array expected");
    +            message.bytesRepeated = $Array(object.bytesRepeated.length);
                 for (var i = 0; i < object.bytesRepeated.length; ++i)
                     if (typeof object.bytesRepeated[i] === "string")
                         $util.base64.decode(object.bytesRepeated[i], message.bytesRepeated[i] = $util.newBuffer($util.base64.length(object.bytesRepeated[i])), 0);
    @@ -543,9 +544,9 @@ $root.Message = (function() {
                     break;
                 }
             if (object.enumRepeated) {
    -            if (!Array.isArray(object.enumRepeated))
    -                throw TypeError(".Message.enumRepeated: array expected");
    -            message.enumRepeated = Array(object.enumRepeated.length);
    +            if (!$Array.isArray(object.enumRepeated))
    +                throw $TypeError(".Message.enumRepeated: array expected");
    +            message.enumRepeated = $Array(object.enumRepeated.length);
                 for (var i = 0; i < object.enumRepeated.length; ++i)
                     switch (object.enumRepeated[i]) {
                     default:
    @@ -565,15 +566,15 @@ $root.Message = (function() {
             }
             if (object.int64Map) {
                 if (!$util.isObject(object.int64Map))
    -                throw TypeError(".Message.int64Map: object expected");
    +                throw $TypeError(".Message.int64Map: object expected");
                 message.int64Map = {};
    -            for (var keys = Object.keys(object.int64Map), i = 0; i < keys.length; ++i) {
    +            for (var keys = $Object.keys(object.int64Map), i = 0; i < keys.length; ++i) {
                     if (keys[i] === "__proto__")
                         $util.makeProp(message.int64Map, keys[i]);
                     if ($util.Long)
                         message.int64Map[keys[i]] = $util.Long.fromValue(object.int64Map[keys[i]], false);
                     else if (typeof object.int64Map[keys[i]] === "string")
    -                    message.int64Map[keys[i]] = parseInt(object.int64Map[keys[i]], 10);
    +                    message.int64Map[keys[i]] = $parseInt(object.int64Map[keys[i]], 10);
                     else if (typeof object.int64Map[keys[i]] === "number")
                         message.int64Map[keys[i]] = object.int64Map[keys[i]];
                     else if (typeof object.int64Map[keys[i]] === "object")
    @@ -592,13 +593,13 @@ $root.Message = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    Message.toObject = function toObject(message, options, _depth) {
    +    Message.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.arrays || options.defaults) {
                 object.stringRepeated = [];
    @@ -612,68 +613,68 @@ $root.Message = (function() {
                 object.stringVal = "";
                 if ($util.Long) {
                     var long = new $util.Long(0, 0, true);
    -                object.uint64Val = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : typeof BigInt !== "undefined" && options.longs === BigInt ? long.toBigInt() : long;
    +                object.uint64Val = options.longs === $String ? long.toString() : options.longs === $Number ? long.toNumber() : typeof $BigInt !== "undefined" && options.longs === $BigInt ? long.toBigInt() : long;
                 } else
    -                object.uint64Val = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
    -            if (options.bytes === String)
    +                object.uint64Val = options.longs === $String ? "0" : typeof $BigInt !== "undefined" && options.longs === $BigInt ? $BigInt("0") : 0;
    +            if (options.bytes === $String)
                     object.bytesVal = "";
                 else {
                     object.bytesVal = [];
    -                if (options.bytes !== Array)
    +                if (options.bytes !== $Array)
                         object.bytesVal = $util.newBuffer(object.bytesVal);
                 }
    -            object.enumVal = options.enums === String ? "ONE" : 1;
    +            object.enumVal = options.enums === $String ? "ONE" : 1;
             }
    -        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
    +        if (message.stringVal != null && $Object.hasOwnProperty.call(message, "stringVal"))
                 object.stringVal = message.stringVal;
             if (message.stringRepeated && message.stringRepeated.length) {
    -            object.stringRepeated = Array(message.stringRepeated.length);
    +            object.stringRepeated = $Array(message.stringRepeated.length);
                 for (var j = 0; j < message.stringRepeated.length; ++j)
                     object.stringRepeated[j] = message.stringRepeated[j];
             }
    -        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
    -            if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                object.uint64Val = typeof message.uint64Val === "number" ? BigInt(message.uint64Val) : $util.Long.fromBits(message.uint64Val.low >>> 0, message.uint64Val.high >>> 0, true).toBigInt();
    +        if (message.uint64Val != null && $Object.hasOwnProperty.call(message, "uint64Val"))
    +            if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                object.uint64Val = typeof message.uint64Val === "number" ? $BigInt(message.uint64Val) : $util.Long.fromBits(message.uint64Val.low >>> 0, message.uint64Val.high >>> 0, true).toBigInt();
                 else if (typeof message.uint64Val === "number")
    -                object.uint64Val = options.longs === String ? String(message.uint64Val) : message.uint64Val;
    +                object.uint64Val = options.longs === $String ? $String(message.uint64Val) : message.uint64Val;
                 else
    -                object.uint64Val = options.longs === String ? $util.Long.prototype.toString.call(message.uint64Val) : options.longs === Number ? new $util.LongBits(message.uint64Val.low >>> 0, message.uint64Val.high >>> 0).toNumber(true) : message.uint64Val;
    +                object.uint64Val = options.longs === $String ? $util.Long.prototype.toString.call(message.uint64Val) : options.longs === $Number ? new $util.LongBits(message.uint64Val.low >>> 0, message.uint64Val.high >>> 0).toNumber(true) : message.uint64Val;
             if (message.uint64Repeated && message.uint64Repeated.length) {
    -            object.uint64Repeated = Array(message.uint64Repeated.length);
    +            object.uint64Repeated = $Array(message.uint64Repeated.length);
                 for (var j = 0; j < message.uint64Repeated.length; ++j)
    -                if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                    object.uint64Repeated[j] = typeof message.uint64Repeated[j] === "number" ? BigInt(message.uint64Repeated[j]) : $util.Long.fromBits(message.uint64Repeated[j].low >>> 0, message.uint64Repeated[j].high >>> 0, true).toBigInt();
    +                if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                    object.uint64Repeated[j] = typeof message.uint64Repeated[j] === "number" ? $BigInt(message.uint64Repeated[j]) : $util.Long.fromBits(message.uint64Repeated[j].low >>> 0, message.uint64Repeated[j].high >>> 0, true).toBigInt();
                     else if (typeof message.uint64Repeated[j] === "number")
    -                    object.uint64Repeated[j] = options.longs === String ? String(message.uint64Repeated[j]) : message.uint64Repeated[j];
    +                    object.uint64Repeated[j] = options.longs === $String ? $String(message.uint64Repeated[j]) : message.uint64Repeated[j];
                     else
    -                    object.uint64Repeated[j] = options.longs === String ? $util.Long.prototype.toString.call(message.uint64Repeated[j]) : options.longs === Number ? new $util.LongBits(message.uint64Repeated[j].low >>> 0, message.uint64Repeated[j].high >>> 0).toNumber(true) : message.uint64Repeated[j];
    +                    object.uint64Repeated[j] = options.longs === $String ? $util.Long.prototype.toString.call(message.uint64Repeated[j]) : options.longs === $Number ? new $util.LongBits(message.uint64Repeated[j].low >>> 0, message.uint64Repeated[j].high >>> 0).toNumber(true) : message.uint64Repeated[j];
             }
    -        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
    -            object.bytesVal = options.bytes === String ? $util.base64.encode(message.bytesVal, 0, message.bytesVal.length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesVal) : message.bytesVal;
    +        if (message.bytesVal != null && $Object.hasOwnProperty.call(message, "bytesVal"))
    +            object.bytesVal = options.bytes === $String ? $util.base64.encode(message.bytesVal, 0, message.bytesVal.length) : options.bytes === $Array ? $Array.prototype.slice.call(message.bytesVal) : message.bytesVal;
             if (message.bytesRepeated && message.bytesRepeated.length) {
    -            object.bytesRepeated = Array(message.bytesRepeated.length);
    +            object.bytesRepeated = $Array(message.bytesRepeated.length);
                 for (var j = 0; j < message.bytesRepeated.length; ++j)
    -                object.bytesRepeated[j] = options.bytes === String ? $util.base64.encode(message.bytesRepeated[j], 0, message.bytesRepeated[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesRepeated[j]) : message.bytesRepeated[j];
    +                object.bytesRepeated[j] = options.bytes === $String ? $util.base64.encode(message.bytesRepeated[j], 0, message.bytesRepeated[j].length) : options.bytes === $Array ? $Array.prototype.slice.call(message.bytesRepeated[j]) : message.bytesRepeated[j];
             }
    -        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
    -            object.enumVal = options.enums === String ? $root.Message.SomeEnum[message.enumVal] === undefined ? message.enumVal : $root.Message.SomeEnum[message.enumVal] : message.enumVal;
    +        if (message.enumVal != null && $Object.hasOwnProperty.call(message, "enumVal"))
    +            object.enumVal = options.enums === $String ? $root.Message.SomeEnum[message.enumVal] === $undefined ? message.enumVal : $root.Message.SomeEnum[message.enumVal] : message.enumVal;
             if (message.enumRepeated && message.enumRepeated.length) {
    -            object.enumRepeated = Array(message.enumRepeated.length);
    +            object.enumRepeated = $Array(message.enumRepeated.length);
                 for (var j = 0; j < message.enumRepeated.length; ++j)
    -                object.enumRepeated[j] = options.enums === String ? $root.Message.SomeEnum[message.enumRepeated[j]] === undefined ? message.enumRepeated[j] : $root.Message.SomeEnum[message.enumRepeated[j]] : message.enumRepeated[j];
    +                object.enumRepeated[j] = options.enums === $String ? $root.Message.SomeEnum[message.enumRepeated[j]] === $undefined ? message.enumRepeated[j] : $root.Message.SomeEnum[message.enumRepeated[j]] : message.enumRepeated[j];
             }
             var keys2;
    -        if (message.int64Map && (keys2 = Object.keys(message.int64Map)).length) {
    +        if (message.int64Map && (keys2 = $Object.keys(message.int64Map)).length) {
                 object.int64Map = {};
                 for (var j = 0; j < keys2.length; ++j) {
                     if (keys2[j] === "__proto__")
                         $util.makeProp(object.int64Map, keys2[j]);
    -                if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                    object.int64Map[keys2[j]] = typeof message.int64Map[keys2[j]] === "number" ? BigInt(message.int64Map[keys2[j]]) : $util.Long.fromBits(message.int64Map[keys2[j]].low >>> 0, message.int64Map[keys2[j]].high >>> 0, false).toBigInt();
    +                if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                    object.int64Map[keys2[j]] = typeof message.int64Map[keys2[j]] === "number" ? $BigInt(message.int64Map[keys2[j]]) : $util.Long.fromBits(message.int64Map[keys2[j]].low >>> 0, message.int64Map[keys2[j]].high >>> 0, false).toBigInt();
                     else if (typeof message.int64Map[keys2[j]] === "number")
    -                    object.int64Map[keys2[j]] = options.longs === String ? String(message.int64Map[keys2[j]]) : message.int64Map[keys2[j]];
    +                    object.int64Map[keys2[j]] = options.longs === $String ? $String(message.int64Map[keys2[j]]) : message.int64Map[keys2[j]];
                     else
    -                    object.int64Map[keys2[j]] = options.longs === String ? $util.Long.prototype.toString.call(message.int64Map[keys2[j]]) : options.longs === Number ? new $util.LongBits(message.int64Map[keys2[j]].low >>> 0, message.int64Map[keys2[j]].high >>> 0).toNumber() : message.int64Map[keys2[j]];
    +                    object.int64Map[keys2[j]] = options.longs === $String ? $util.Long.prototype.toString.call(message.int64Map[keys2[j]]) : options.longs === $Number ? new $util.LongBits(message.int64Map[keys2[j]].low >>> 0, message.int64Map[keys2[j]].high >>> 0).toNumber() : message.int64Map[keys2[j]];
                 }
             }
             return object;
    @@ -686,8 +687,8 @@ $root.Message = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    Message.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    Message.prototype.toJSON = function() {
    +        return Message.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -698,8 +699,8 @@ $root.Message = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    Message.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    Message.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/Message";
         };
    @@ -712,7 +713,7 @@ $root.Message = (function() {
          * @property {number} TWO=2 TWO value
          */
         Message.SomeEnum = (function() {
    -        var valuesById = {}, values = Object.create(valuesById);
    +        var valuesById = {}, values = $Object.create(valuesById);
             values[valuesById[1] = "ONE"] = 1;
             values[valuesById[2] = "TWO"] = 2;
             return values;
    
  • tests/data/mapbox/vector_tile.js+236 235 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $Array = $util.global.Array, $TypeError = $util.global.TypeError, $String = $util.global.String, $Number = $util.global.Number, $parseInt = $util.global.parseInt, $Boolean = $util.global.Boolean, $BigInt = $util.global.BigInt, $isFinite = $util.global.isFinite;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_vector_tile"] || ($protobuf.roots["test_vector_tile"] = {});
    @@ -48,13 +49,13 @@ $root.vector_tile = (function() {
              * @param {vector_tile.Tile.$Properties=} [properties] Properties to set
              * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
              */
    -        function Tile(properties) {
    +        var Tile = function (properties) {
                 this.layers = [];
                 if (properties)
    -                for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +                for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                         if (properties[keys[i]] != null && keys[i] !== "__proto__")
                             this[keys[i]] = properties[keys[i]];
    -        }
    +        };
     
             /**
              * Tile layers.
    @@ -76,7 +77,7 @@ $root.vector_tile = (function() {
              *   (properties?: vector_tile.Tile.$Properties): vector_tile.Tile;
              * }}
              */
    -        Tile.create = function create(properties) {
    +        Tile.create = function(properties) {
                 return new Tile(properties);
             };
     
    @@ -89,17 +90,17 @@ $root.vector_tile = (function() {
              * @param {$protobuf.Writer} [writer] Writer to encode to
              * @returns {$protobuf.Writer} Writer
              */
    -        Tile.encode = function encode(message, writer, _depth) {
    +        Tile.encode = function (message, writer, _depth) {
                 if (!writer)
                     writer = $Writer.create();
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 if (message.layers != null && message.layers.length)
                     for (var i = 0; i < message.layers.length; ++i)
                         $root.vector_tile.Tile.Layer.encode(message.layers[i], writer.uint32(/* id 3, wireType 2 =*/26).fork(), _depth + 1).ldelim();
    -            if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +            if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                     for (var i = 0; i < message.$unknowns.length; ++i)
                         writer.raw(message.$unknowns[i]);
                 return writer;
    @@ -114,7 +115,7 @@ $root.vector_tile = (function() {
              * @param {$protobuf.Writer} [writer] Writer to encode to
              * @returns {$protobuf.Writer} Writer
              */
    -        Tile.encodeDelimited = function encodeDelimited(message, writer) {
    +        Tile.encodeDelimited = function(message, writer) {
                 return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
             };
     
    @@ -129,19 +130,19 @@ $root.vector_tile = (function() {
              * @throws {Error} If the payload is not a reader or valid buffer
              * @throws {$protobuf.util.ProtocolError} If required fields are missing
              */
    -        Tile.decode = function decode(reader, length, _end, _depth, _target) {
    +        Tile.decode = function (reader, length, _end, _depth, _target) {
                 if (!(reader instanceof $Reader))
                     reader = $Reader.create(reader);
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $Reader.recursionLimit)
    -                throw Error("max depth exceeded");
    -            var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile();
    +                throw $Error("max depth exceeded");
    +            var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile();
                 while (reader.pos < end) {
                     var start = reader.pos;
                     var tag = reader.tag();
                     if (tag === _end) {
    -                    _end = undefined;
    +                    _end = $undefined;
                         break;
                     }
                     var wireType = tag & 7;
    @@ -151,7 +152,7 @@ $root.vector_tile = (function() {
                                 break;
                             if (!(message.layers && message.layers.length))
                                 message.layers = [];
    -                        message.layers.push($root.vector_tile.Tile.Layer.decode(reader, reader.uint32(), undefined, _depth + 1));
    +                        message.layers.push($root.vector_tile.Tile.Layer.decode(reader, reader.uint32(), $undefined, _depth + 1));
                             continue;
                         }
                     }
    @@ -161,8 +162,8 @@ $root.vector_tile = (function() {
                         (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                     }
                 }
    -            if (_end !== undefined)
    -                throw Error("missing end group");
    +            if (_end !== $undefined)
    +                throw $Error("missing end group");
                 return message;
             };
     
    @@ -176,7 +177,7 @@ $root.vector_tile = (function() {
              * @throws {Error} If the payload is not a reader or valid buffer
              * @throws {$protobuf.util.ProtocolError} If required fields are missing
              */
    -        Tile.decodeDelimited = function decodeDelimited(reader) {
    +        Tile.decodeDelimited = function(reader) {
                 if (!(reader instanceof $Reader))
                     reader = new $Reader(reader);
                 return this.decode(reader, reader.uint32());
    @@ -190,15 +191,15 @@ $root.vector_tile = (function() {
              * @param {Object.<string,*>} message Plain object to verify
              * @returns {string|null} `null` if valid, otherwise the reason why it is not
              */
    -        Tile.verify = function verify(message, _depth) {
    +        Tile.verify = function (message, _depth) {
                 if (typeof message !== "object" || message === null)
                     return "object expected";
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
                     return "max depth exceeded";
    -            if (message.layers != null && Object.hasOwnProperty.call(message, "layers")) {
    -                if (!Array.isArray(message.layers))
    +            if (message.layers != null && $Object.hasOwnProperty.call(message, "layers")) {
    +                if (!$Array.isArray(message.layers))
                         return "layers: array expected";
                     for (var i = 0; i < message.layers.length; ++i) {
                         var error = $root.vector_tile.Tile.Layer.verify(message.layers[i], _depth + 1);
    @@ -217,23 +218,23 @@ $root.vector_tile = (function() {
              * @param {Object.<string,*>} object Plain object
              * @returns {vector_tile.Tile} Tile
              */
    -        Tile.fromObject = function fromObject(object, _depth) {
    +        Tile.fromObject = function (object, _depth) {
                 if (object instanceof $root.vector_tile.Tile)
                     return object;
                 if (!$util.isObject(object))
    -                throw TypeError(".vector_tile.Tile: object expected");
    -            if (_depth === undefined)
    +                throw $TypeError(".vector_tile.Tile: object expected");
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 var message = new $root.vector_tile.Tile();
                 if (object.layers) {
    -                if (!Array.isArray(object.layers))
    -                    throw TypeError(".vector_tile.Tile.layers: array expected");
    -                message.layers = Array(object.layers.length);
    +                if (!$Array.isArray(object.layers))
    +                    throw $TypeError(".vector_tile.Tile.layers: array expected");
    +                message.layers = $Array(object.layers.length);
                     for (var i = 0; i < object.layers.length; ++i) {
                         if (!$util.isObject(object.layers[i]))
    -                        throw TypeError(".vector_tile.Tile.layers: object expected");
    +                        throw $TypeError(".vector_tile.Tile.layers: object expected");
                         message.layers[i] = $root.vector_tile.Tile.Layer.fromObject(object.layers[i], _depth + 1);
                     }
                 }
    @@ -249,18 +250,18 @@ $root.vector_tile = (function() {
              * @param {$protobuf.IConversionOptions} [options] Conversion options
              * @returns {Object.<string,*>} Plain object
              */
    -        Tile.toObject = function toObject(message, options, _depth) {
    +        Tile.toObject = function (message, options, _depth) {
                 if (!options)
                     options = {};
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 var object = {};
                 if (options.arrays || options.defaults)
                     object.layers = [];
                 if (message.layers && message.layers.length) {
    -                object.layers = Array(message.layers.length);
    +                object.layers = $Array(message.layers.length);
                     for (var j = 0; j < message.layers.length; ++j)
                         object.layers[j] = $root.vector_tile.Tile.Layer.toObject(message.layers[j], options, _depth + 1);
                 }
    @@ -274,8 +275,8 @@ $root.vector_tile = (function() {
              * @instance
              * @returns {Object.<string,*>} JSON object
              */
    -        Tile.prototype.toJSON = function toJSON() {
    -            return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +        Tile.prototype.toJSON = function() {
    +            return Tile.toObject(this, $protobuf.util.toJSONOptions);
             };
     
             /**
    @@ -286,8 +287,8 @@ $root.vector_tile = (function() {
              * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
              * @returns {string} The type url
              */
    -        Tile.getTypeUrl = function getTypeUrl(prefix) {
    -            if (prefix === undefined)
    +        Tile.getTypeUrl = function(prefix) {
    +            if (prefix === $undefined)
                     prefix = "type.googleapis.com";
                 return prefix + "/vector_tile.Tile";
             };
    @@ -302,7 +303,7 @@ $root.vector_tile = (function() {
              * @property {number} POLYGON=3 POLYGON value
              */
             Tile.GeomType = (function() {
    -            var valuesById = {}, values = Object.create(valuesById);
    +            var valuesById = {}, values = $Object.create(valuesById);
                 values[valuesById[0] = "UNKNOWN"] = 0;
                 values[valuesById[1] = "POINT"] = 1;
                 values[valuesById[2] = "LINESTRING"] = 2;
    @@ -346,12 +347,12 @@ $root.vector_tile = (function() {
                  * @param {vector_tile.Tile.Value.$Properties=} [properties] Properties to set
                  * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
                  */
    -            function Value(properties) {
    +            var Value = function (properties) {
                     if (properties)
    -                    for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +                    for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                             if (properties[keys[i]] != null && keys[i] !== "__proto__")
                                 this[keys[i]] = properties[keys[i]];
    -            }
    +            };
     
                 /**
                  * Value stringValue.
    @@ -421,7 +422,7 @@ $root.vector_tile = (function() {
                  *   (properties?: vector_tile.Tile.Value.$Properties): vector_tile.Tile.Value;
                  * }}
                  */
    -            Value.create = function create(properties) {
    +            Value.create = function(properties) {
                     return new Value(properties);
                 };
     
    @@ -434,28 +435,28 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.Writer} [writer] Writer to encode to
                  * @returns {$protobuf.Writer} Writer
                  */
    -            Value.encode = function encode(message, writer, _depth) {
    +            Value.encode = function (message, writer, _depth) {
                     if (!writer)
                         writer = $Writer.create();
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    -                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
    +                    throw $Error("max depth exceeded");
    +                if (message.stringValue != null && $Object.hasOwnProperty.call(message, "stringValue"))
                         writer.uint32(/* id 1, wireType 2 =*/10).string(message.stringValue);
    -                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
    +                if (message.floatValue != null && $Object.hasOwnProperty.call(message, "floatValue"))
                         writer.uint32(/* id 2, wireType 5 =*/21).float(message.floatValue);
    -                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
    +                if (message.doubleValue != null && $Object.hasOwnProperty.call(message, "doubleValue"))
                         writer.uint32(/* id 3, wireType 1 =*/25).double(message.doubleValue);
    -                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
    +                if (message.intValue != null && $Object.hasOwnProperty.call(message, "intValue"))
                         writer.uint32(/* id 4, wireType 0 =*/32).int64(message.intValue);
    -                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
    +                if (message.uintValue != null && $Object.hasOwnProperty.call(message, "uintValue"))
                         writer.uint32(/* id 5, wireType 0 =*/40).uint64(message.uintValue);
    -                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
    +                if (message.sintValue != null && $Object.hasOwnProperty.call(message, "sintValue"))
                         writer.uint32(/* id 6, wireType 0 =*/48).sint64(message.sintValue);
    -                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
    +                if (message.boolValue != null && $Object.hasOwnProperty.call(message, "boolValue"))
                         writer.uint32(/* id 7, wireType 0 =*/56).bool(message.boolValue);
    -                if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +                if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                         for (var i = 0; i < message.$unknowns.length; ++i)
                             writer.raw(message.$unknowns[i]);
                     return writer;
    @@ -470,7 +471,7 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.Writer} [writer] Writer to encode to
                  * @returns {$protobuf.Writer} Writer
                  */
    -            Value.encodeDelimited = function encodeDelimited(message, writer) {
    +            Value.encodeDelimited = function(message, writer) {
                     return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
                 };
     
    @@ -485,19 +486,19 @@ $root.vector_tile = (function() {
                  * @throws {Error} If the payload is not a reader or valid buffer
                  * @throws {$protobuf.util.ProtocolError} If required fields are missing
                  */
    -            Value.decode = function decode(reader, length, _end, _depth, _target) {
    +            Value.decode = function (reader, length, _end, _depth, _target) {
                     if (!(reader instanceof $Reader))
                         reader = $Reader.create(reader);
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $Reader.recursionLimit)
    -                    throw Error("max depth exceeded");
    -                var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile.Value();
    +                    throw $Error("max depth exceeded");
    +                var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile.Value();
                     while (reader.pos < end) {
                         var start = reader.pos;
                         var tag = reader.tag();
                         if (tag === _end) {
    -                        _end = undefined;
    +                        _end = $undefined;
                             break;
                         }
                         var wireType = tag & 7;
    @@ -551,8 +552,8 @@ $root.vector_tile = (function() {
                             (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                         }
                     }
    -                if (_end !== undefined)
    -                    throw Error("missing end group");
    +                if (_end !== $undefined)
    +                    throw $Error("missing end group");
                     return message;
                 };
     
    @@ -566,7 +567,7 @@ $root.vector_tile = (function() {
                  * @throws {Error} If the payload is not a reader or valid buffer
                  * @throws {$protobuf.util.ProtocolError} If required fields are missing
                  */
    -            Value.decodeDelimited = function decodeDelimited(reader) {
    +            Value.decodeDelimited = function(reader) {
                     if (!(reader instanceof $Reader))
                         reader = new $Reader(reader);
                     return this.decode(reader, reader.uint32());
    @@ -580,32 +581,32 @@ $root.vector_tile = (function() {
                  * @param {Object.<string,*>} message Plain object to verify
                  * @returns {string|null} `null` if valid, otherwise the reason why it is not
                  */
    -            Value.verify = function verify(message, _depth) {
    +            Value.verify = function (message, _depth) {
                     if (typeof message !== "object" || message === null)
                         return "object expected";
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
                         return "max depth exceeded";
    -                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
    +                if (message.stringValue != null && $Object.hasOwnProperty.call(message, "stringValue"))
                         if (!$util.isString(message.stringValue))
                             return "stringValue: string expected";
    -                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
    +                if (message.floatValue != null && $Object.hasOwnProperty.call(message, "floatValue"))
                         if (typeof message.floatValue !== "number")
                             return "floatValue: number expected";
    -                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
    +                if (message.doubleValue != null && $Object.hasOwnProperty.call(message, "doubleValue"))
                         if (typeof message.doubleValue !== "number")
                             return "doubleValue: number expected";
    -                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
    +                if (message.intValue != null && $Object.hasOwnProperty.call(message, "intValue"))
                         if (!$util.isInteger(message.intValue) && !(message.intValue && $util.isInteger(message.intValue.low) && $util.isInteger(message.intValue.high)))
                             return "intValue: integer|Long expected";
    -                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
    +                if (message.uintValue != null && $Object.hasOwnProperty.call(message, "uintValue"))
                         if (!$util.isInteger(message.uintValue) && !(message.uintValue && $util.isInteger(message.uintValue.low) && $util.isInteger(message.uintValue.high)))
                             return "uintValue: integer|Long expected";
    -                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
    +                if (message.sintValue != null && $Object.hasOwnProperty.call(message, "sintValue"))
                         if (!$util.isInteger(message.sintValue) && !(message.sintValue && $util.isInteger(message.sintValue.low) && $util.isInteger(message.sintValue.high)))
                             return "sintValue: integer|Long expected";
    -                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
    +                if (message.boolValue != null && $Object.hasOwnProperty.call(message, "boolValue"))
                         if (typeof message.boolValue !== "boolean")
                             return "boolValue: boolean expected";
                     return null;
    @@ -619,27 +620,27 @@ $root.vector_tile = (function() {
                  * @param {Object.<string,*>} object Plain object
                  * @returns {vector_tile.Tile.Value} Value
                  */
    -            Value.fromObject = function fromObject(object, _depth) {
    +            Value.fromObject = function (object, _depth) {
                     if (object instanceof $root.vector_tile.Tile.Value)
                         return object;
                     if (!$util.isObject(object))
    -                    throw TypeError(".vector_tile.Tile.Value: object expected");
    -                if (_depth === undefined)
    +                    throw $TypeError(".vector_tile.Tile.Value: object expected");
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    +                    throw $Error("max depth exceeded");
                     var message = new $root.vector_tile.Tile.Value();
                     if (object.stringValue != null)
    -                    message.stringValue = String(object.stringValue);
    +                    message.stringValue = $String(object.stringValue);
                     if (object.floatValue != null)
    -                    message.floatValue = Number(object.floatValue);
    +                    message.floatValue = $Number(object.floatValue);
                     if (object.doubleValue != null)
    -                    message.doubleValue = Number(object.doubleValue);
    +                    message.doubleValue = $Number(object.doubleValue);
                     if (object.intValue != null)
                         if ($util.Long)
                             message.intValue = $util.Long.fromValue(object.intValue, false);
                         else if (typeof object.intValue === "string")
    -                        message.intValue = parseInt(object.intValue, 10);
    +                        message.intValue = $parseInt(object.intValue, 10);
                         else if (typeof object.intValue === "number")
                             message.intValue = object.intValue;
                         else if (typeof object.intValue === "object")
    @@ -648,7 +649,7 @@ $root.vector_tile = (function() {
                         if ($util.Long)
                             message.uintValue = $util.Long.fromValue(object.uintValue, true);
                         else if (typeof object.uintValue === "string")
    -                        message.uintValue = parseInt(object.uintValue, 10);
    +                        message.uintValue = $parseInt(object.uintValue, 10);
                         else if (typeof object.uintValue === "number")
                             message.uintValue = object.uintValue;
                         else if (typeof object.uintValue === "object")
    @@ -657,13 +658,13 @@ $root.vector_tile = (function() {
                         if ($util.Long)
                             message.sintValue = $util.Long.fromValue(object.sintValue, false);
                         else if (typeof object.sintValue === "string")
    -                        message.sintValue = parseInt(object.sintValue, 10);
    +                        message.sintValue = $parseInt(object.sintValue, 10);
                         else if (typeof object.sintValue === "number")
                             message.sintValue = object.sintValue;
                         else if (typeof object.sintValue === "object")
                             message.sintValue = new $util.LongBits(object.sintValue.low >>> 0, object.sintValue.high >>> 0).toNumber();
                     if (object.boolValue != null)
    -                    message.boolValue = Boolean(object.boolValue);
    +                    message.boolValue = $Boolean(object.boolValue);
                     return message;
                 };
     
    @@ -676,63 +677,63 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.IConversionOptions} [options] Conversion options
                  * @returns {Object.<string,*>} Plain object
                  */
    -            Value.toObject = function toObject(message, options, _depth) {
    +            Value.toObject = function (message, options, _depth) {
                     if (!options)
                         options = {};
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    +                    throw $Error("max depth exceeded");
                     var object = {};
                     if (options.defaults) {
                         object.stringValue = "";
                         object.floatValue = 0;
                         object.doubleValue = 0;
                         if ($util.Long) {
                             var long = new $util.Long(0, 0, false);
    -                        object.intValue = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : typeof BigInt !== "undefined" && options.longs === BigInt ? long.toBigInt() : long;
    +                        object.intValue = options.longs === $String ? long.toString() : options.longs === $Number ? long.toNumber() : typeof $BigInt !== "undefined" && options.longs === $BigInt ? long.toBigInt() : long;
                         } else
    -                        object.intValue = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
    +                        object.intValue = options.longs === $String ? "0" : typeof $BigInt !== "undefined" && options.longs === $BigInt ? $BigInt("0") : 0;
                         if ($util.Long) {
                             var long = new $util.Long(0, 0, true);
    -                        object.uintValue = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : typeof BigInt !== "undefined" && options.longs === BigInt ? long.toBigInt() : long;
    +                        object.uintValue = options.longs === $String ? long.toString() : options.longs === $Number ? long.toNumber() : typeof $BigInt !== "undefined" && options.longs === $BigInt ? long.toBigInt() : long;
                         } else
    -                        object.uintValue = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
    +                        object.uintValue = options.longs === $String ? "0" : typeof $BigInt !== "undefined" && options.longs === $BigInt ? $BigInt("0") : 0;
                         if ($util.Long) {
                             var long = new $util.Long(0, 0, false);
    -                        object.sintValue = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : typeof BigInt !== "undefined" && options.longs === BigInt ? long.toBigInt() : long;
    +                        object.sintValue = options.longs === $String ? long.toString() : options.longs === $Number ? long.toNumber() : typeof $BigInt !== "undefined" && options.longs === $BigInt ? long.toBigInt() : long;
                         } else
    -                        object.sintValue = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
    +                        object.sintValue = options.longs === $String ? "0" : typeof $BigInt !== "undefined" && options.longs === $BigInt ? $BigInt("0") : 0;
                         object.boolValue = false;
                     }
    -                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
    +                if (message.stringValue != null && $Object.hasOwnProperty.call(message, "stringValue"))
                         object.stringValue = message.stringValue;
    -                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
    -                    object.floatValue = options.json && !isFinite(message.floatValue) ? String(message.floatValue) : message.floatValue;
    -                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
    -                    object.doubleValue = options.json && !isFinite(message.doubleValue) ? String(message.doubleValue) : message.doubleValue;
    -                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
    -                    if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                        object.intValue = typeof message.intValue === "number" ? BigInt(message.intValue) : $util.Long.fromBits(message.intValue.low >>> 0, message.intValue.high >>> 0, false).toBigInt();
    +                if (message.floatValue != null && $Object.hasOwnProperty.call(message, "floatValue"))
    +                    object.floatValue = options.json && !$isFinite(message.floatValue) ? $String(message.floatValue) : message.floatValue;
    +                if (message.doubleValue != null && $Object.hasOwnProperty.call(message, "doubleValue"))
    +                    object.doubleValue = options.json && !$isFinite(message.doubleValue) ? $String(message.doubleValue) : message.doubleValue;
    +                if (message.intValue != null && $Object.hasOwnProperty.call(message, "intValue"))
    +                    if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                        object.intValue = typeof message.intValue === "number" ? $BigInt(message.intValue) : $util.Long.fromBits(message.intValue.low >>> 0, message.intValue.high >>> 0, false).toBigInt();
                         else if (typeof message.intValue === "number")
    -                        object.intValue = options.longs === String ? String(message.intValue) : message.intValue;
    +                        object.intValue = options.longs === $String ? $String(message.intValue) : message.intValue;
                         else
    -                        object.intValue = options.longs === String ? $util.Long.prototype.toString.call(message.intValue) : options.longs === Number ? new $util.LongBits(message.intValue.low >>> 0, message.intValue.high >>> 0).toNumber() : message.intValue;
    -                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
    -                    if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                        object.uintValue = typeof message.uintValue === "number" ? BigInt(message.uintValue) : $util.Long.fromBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0, true).toBigInt();
    +                        object.intValue = options.longs === $String ? $util.Long.prototype.toString.call(message.intValue) : options.longs === $Number ? new $util.LongBits(message.intValue.low >>> 0, message.intValue.high >>> 0).toNumber() : message.intValue;
    +                if (message.uintValue != null && $Object.hasOwnProperty.call(message, "uintValue"))
    +                    if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                        object.uintValue = typeof message.uintValue === "number" ? $BigInt(message.uintValue) : $util.Long.fromBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0, true).toBigInt();
                         else if (typeof message.uintValue === "number")
    -                        object.uintValue = options.longs === String ? String(message.uintValue) : message.uintValue;
    +                        object.uintValue = options.longs === $String ? $String(message.uintValue) : message.uintValue;
                         else
    -                        object.uintValue = options.longs === String ? $util.Long.prototype.toString.call(message.uintValue) : options.longs === Number ? new $util.LongBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0).toNumber(true) : message.uintValue;
    -                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
    -                    if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                        object.sintValue = typeof message.sintValue === "number" ? BigInt(message.sintValue) : $util.Long.fromBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0, false).toBigInt();
    +                        object.uintValue = options.longs === $String ? $util.Long.prototype.toString.call(message.uintValue) : options.longs === $Number ? new $util.LongBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0).toNumber(true) : message.uintValue;
    +                if (message.sintValue != null && $Object.hasOwnProperty.call(message, "sintValue"))
    +                    if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                        object.sintValue = typeof message.sintValue === "number" ? $BigInt(message.sintValue) : $util.Long.fromBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0, false).toBigInt();
                         else if (typeof message.sintValue === "number")
    -                        object.sintValue = options.longs === String ? String(message.sintValue) : message.sintValue;
    +                        object.sintValue = options.longs === $String ? $String(message.sintValue) : message.sintValue;
                         else
    -                        object.sintValue = options.longs === String ? $util.Long.prototype.toString.call(message.sintValue) : options.longs === Number ? new $util.LongBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0).toNumber() : message.sintValue;
    -                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
    +                        object.sintValue = options.longs === $String ? $util.Long.prototype.toString.call(message.sintValue) : options.longs === $Number ? new $util.LongBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0).toNumber() : message.sintValue;
    +                if (message.boolValue != null && $Object.hasOwnProperty.call(message, "boolValue"))
                         object.boolValue = message.boolValue;
                     return object;
                 };
    @@ -744,8 +745,8 @@ $root.vector_tile = (function() {
                  * @instance
                  * @returns {Object.<string,*>} JSON object
                  */
    -            Value.prototype.toJSON = function toJSON() {
    -                return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +            Value.prototype.toJSON = function() {
    +                return Value.toObject(this, $protobuf.util.toJSONOptions);
                 };
     
                 /**
    @@ -756,8 +757,8 @@ $root.vector_tile = (function() {
                  * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
                  * @returns {string} The type url
                  */
    -            Value.getTypeUrl = function getTypeUrl(prefix) {
    -                if (prefix === undefined)
    +            Value.getTypeUrl = function(prefix) {
    +                if (prefix === $undefined)
                         prefix = "type.googleapis.com";
                     return prefix + "/vector_tile.Tile.Value";
                 };
    @@ -798,14 +799,14 @@ $root.vector_tile = (function() {
                  * @param {vector_tile.Tile.Feature.$Properties=} [properties] Properties to set
                  * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
                  */
    -            function Feature(properties) {
    +            var Feature = function (properties) {
                     this.tags = [];
                     this.geometry = [];
                     if (properties)
    -                    for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +                    for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                             if (properties[keys[i]] != null && keys[i] !== "__proto__")
                                 this[keys[i]] = properties[keys[i]];
    -            }
    +            };
     
                 /**
                  * Feature id.
    @@ -851,7 +852,7 @@ $root.vector_tile = (function() {
                  *   (properties?: vector_tile.Tile.Feature.$Properties): vector_tile.Tile.Feature;
                  * }}
                  */
    -            Feature.create = function create(properties) {
    +            Feature.create = function(properties) {
                     return new Feature(properties);
                 };
     
    @@ -864,30 +865,30 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.Writer} [writer] Writer to encode to
                  * @returns {$protobuf.Writer} Writer
                  */
    -            Feature.encode = function encode(message, writer, _depth) {
    +            Feature.encode = function (message, writer, _depth) {
                     if (!writer)
                         writer = $Writer.create();
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    -                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
    +                    throw $Error("max depth exceeded");
    +                if (message.id != null && $Object.hasOwnProperty.call(message, "id"))
                         writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.id);
                     if (message.tags != null && message.tags.length) {
                         writer.uint32(/* id 2, wireType 2 =*/18).fork();
                         for (var i = 0; i < message.tags.length; ++i)
                             writer.uint32(message.tags[i]);
                         writer.ldelim();
                     }
    -                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
    +                if (message.type != null && $Object.hasOwnProperty.call(message, "type"))
                         writer.uint32(/* id 3, wireType 0 =*/24).int32(message.type);
                     if (message.geometry != null && message.geometry.length) {
                         writer.uint32(/* id 4, wireType 2 =*/34).fork();
                         for (var i = 0; i < message.geometry.length; ++i)
                             writer.uint32(message.geometry[i]);
                         writer.ldelim();
                     }
    -                if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +                if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                         for (var i = 0; i < message.$unknowns.length; ++i)
                             writer.raw(message.$unknowns[i]);
                     return writer;
    @@ -902,7 +903,7 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.Writer} [writer] Writer to encode to
                  * @returns {$protobuf.Writer} Writer
                  */
    -            Feature.encodeDelimited = function encodeDelimited(message, writer) {
    +            Feature.encodeDelimited = function(message, writer) {
                     return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
                 };
     
    @@ -917,19 +918,19 @@ $root.vector_tile = (function() {
                  * @throws {Error} If the payload is not a reader or valid buffer
                  * @throws {$protobuf.util.ProtocolError} If required fields are missing
                  */
    -            Feature.decode = function decode(reader, length, _end, _depth, _target) {
    +            Feature.decode = function (reader, length, _end, _depth, _target) {
                     if (!(reader instanceof $Reader))
                         reader = $Reader.create(reader);
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $Reader.recursionLimit)
    -                    throw Error("max depth exceeded");
    -                var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile.Feature();
    +                    throw $Error("max depth exceeded");
    +                var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile.Feature();
                     while (reader.pos < end) {
                         var start = reader.pos;
                         var tag = reader.tag();
                         if (tag === _end) {
    -                        _end = undefined;
    +                        _end = $undefined;
                             break;
                         }
                         var wireType = tag & 7;
    @@ -985,8 +986,8 @@ $root.vector_tile = (function() {
                             (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                         }
                     }
    -                if (_end !== undefined)
    -                    throw Error("missing end group");
    +                if (_end !== $undefined)
    +                    throw $Error("missing end group");
                     return message;
                 };
     
    @@ -1000,7 +1001,7 @@ $root.vector_tile = (function() {
                  * @throws {Error} If the payload is not a reader or valid buffer
                  * @throws {$protobuf.util.ProtocolError} If required fields are missing
                  */
    -            Feature.decodeDelimited = function decodeDelimited(reader) {
    +            Feature.decodeDelimited = function(reader) {
                     if (!(reader instanceof $Reader))
                         reader = new $Reader(reader);
                     return this.decode(reader, reader.uint32());
    @@ -1014,24 +1015,24 @@ $root.vector_tile = (function() {
                  * @param {Object.<string,*>} message Plain object to verify
                  * @returns {string|null} `null` if valid, otherwise the reason why it is not
                  */
    -            Feature.verify = function verify(message, _depth) {
    +            Feature.verify = function (message, _depth) {
                     if (typeof message !== "object" || message === null)
                         return "object expected";
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
                         return "max depth exceeded";
    -                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
    +                if (message.id != null && $Object.hasOwnProperty.call(message, "id"))
                         if (!$util.isInteger(message.id) && !(message.id && $util.isInteger(message.id.low) && $util.isInteger(message.id.high)))
                             return "id: integer|Long expected";
    -                if (message.tags != null && Object.hasOwnProperty.call(message, "tags")) {
    -                    if (!Array.isArray(message.tags))
    +                if (message.tags != null && $Object.hasOwnProperty.call(message, "tags")) {
    +                    if (!$Array.isArray(message.tags))
                             return "tags: array expected";
                         for (var i = 0; i < message.tags.length; ++i)
                             if (!$util.isInteger(message.tags[i]))
                                 return "tags: integer[] expected";
                     }
    -                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
    +                if (message.type != null && $Object.hasOwnProperty.call(message, "type"))
                         switch (message.type) {
                         default:
                             return "type: enum value expected";
    @@ -1041,8 +1042,8 @@ $root.vector_tile = (function() {
                         case 3:
                             break;
                         }
    -                if (message.geometry != null && Object.hasOwnProperty.call(message, "geometry")) {
    -                    if (!Array.isArray(message.geometry))
    +                if (message.geometry != null && $Object.hasOwnProperty.call(message, "geometry")) {
    +                    if (!$Array.isArray(message.geometry))
                             return "geometry: array expected";
                         for (var i = 0; i < message.geometry.length; ++i)
                             if (!$util.isInteger(message.geometry[i]))
    @@ -1059,29 +1060,29 @@ $root.vector_tile = (function() {
                  * @param {Object.<string,*>} object Plain object
                  * @returns {vector_tile.Tile.Feature} Feature
                  */
    -            Feature.fromObject = function fromObject(object, _depth) {
    +            Feature.fromObject = function (object, _depth) {
                     if (object instanceof $root.vector_tile.Tile.Feature)
                         return object;
                     if (!$util.isObject(object))
    -                    throw TypeError(".vector_tile.Tile.Feature: object expected");
    -                if (_depth === undefined)
    +                    throw $TypeError(".vector_tile.Tile.Feature: object expected");
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    +                    throw $Error("max depth exceeded");
                     var message = new $root.vector_tile.Tile.Feature();
                     if (object.id != null)
                         if ($util.Long)
                             message.id = $util.Long.fromValue(object.id, true);
                         else if (typeof object.id === "string")
    -                        message.id = parseInt(object.id, 10);
    +                        message.id = $parseInt(object.id, 10);
                         else if (typeof object.id === "number")
                             message.id = object.id;
                         else if (typeof object.id === "object")
                             message.id = new $util.LongBits(object.id.low >>> 0, object.id.high >>> 0).toNumber(true);
                     if (object.tags) {
    -                    if (!Array.isArray(object.tags))
    -                        throw TypeError(".vector_tile.Tile.Feature.tags: array expected");
    -                    message.tags = Array(object.tags.length);
    +                    if (!$Array.isArray(object.tags))
    +                        throw $TypeError(".vector_tile.Tile.Feature.tags: array expected");
    +                    message.tags = $Array(object.tags.length);
                         for (var i = 0; i < object.tags.length; ++i)
                             message.tags[i] = object.tags[i] >>> 0;
                     }
    @@ -1110,9 +1111,9 @@ $root.vector_tile = (function() {
                         break;
                     }
                     if (object.geometry) {
    -                    if (!Array.isArray(object.geometry))
    -                        throw TypeError(".vector_tile.Tile.Feature.geometry: array expected");
    -                    message.geometry = Array(object.geometry.length);
    +                    if (!$Array.isArray(object.geometry))
    +                        throw $TypeError(".vector_tile.Tile.Feature.geometry: array expected");
    +                    message.geometry = $Array(object.geometry.length);
                         for (var i = 0; i < object.geometry.length; ++i)
                             message.geometry[i] = object.geometry[i] >>> 0;
                     }
    @@ -1128,13 +1129,13 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.IConversionOptions} [options] Conversion options
                  * @returns {Object.<string,*>} Plain object
                  */
    -            Feature.toObject = function toObject(message, options, _depth) {
    +            Feature.toObject = function (message, options, _depth) {
                     if (!options)
                         options = {};
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    +                    throw $Error("max depth exceeded");
                     var object = {};
                     if (options.arrays || options.defaults) {
                         object.tags = [];
    @@ -1143,27 +1144,27 @@ $root.vector_tile = (function() {
                     if (options.defaults) {
                         if ($util.Long) {
                             var long = new $util.Long(0, 0, true);
    -                        object.id = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : typeof BigInt !== "undefined" && options.longs === BigInt ? long.toBigInt() : long;
    +                        object.id = options.longs === $String ? long.toString() : options.longs === $Number ? long.toNumber() : typeof $BigInt !== "undefined" && options.longs === $BigInt ? long.toBigInt() : long;
                         } else
    -                        object.id = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
    -                    object.type = options.enums === String ? "UNKNOWN" : 0;
    +                        object.id = options.longs === $String ? "0" : typeof $BigInt !== "undefined" && options.longs === $BigInt ? $BigInt("0") : 0;
    +                    object.type = options.enums === $String ? "UNKNOWN" : 0;
                     }
    -                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
    -                    if (typeof BigInt !== "undefined" && options.longs === BigInt)
    -                        object.id = typeof message.id === "number" ? BigInt(message.id) : $util.Long.fromBits(message.id.low >>> 0, message.id.high >>> 0, true).toBigInt();
    +                if (message.id != null && $Object.hasOwnProperty.call(message, "id"))
    +                    if (typeof $BigInt !== "undefined" && options.longs === $BigInt)
    +                        object.id = typeof message.id === "number" ? $BigInt(message.id) : $util.Long.fromBits(message.id.low >>> 0, message.id.high >>> 0, true).toBigInt();
                         else if (typeof message.id === "number")
    -                        object.id = options.longs === String ? String(message.id) : message.id;
    +                        object.id = options.longs === $String ? $String(message.id) : message.id;
                         else
    -                        object.id = options.longs === String ? $util.Long.prototype.toString.call(message.id) : options.longs === Number ? new $util.LongBits(message.id.low >>> 0, message.id.high >>> 0).toNumber(true) : message.id;
    +                        object.id = options.longs === $String ? $util.Long.prototype.toString.call(message.id) : options.longs === $Number ? new $util.LongBits(message.id.low >>> 0, message.id.high >>> 0).toNumber(true) : message.id;
                     if (message.tags && message.tags.length) {
    -                    object.tags = Array(message.tags.length);
    +                    object.tags = $Array(message.tags.length);
                         for (var j = 0; j < message.tags.length; ++j)
                             object.tags[j] = message.tags[j];
                     }
    -                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
    -                    object.type = options.enums === String ? $root.vector_tile.Tile.GeomType[message.type] === undefined ? message.type : $root.vector_tile.Tile.GeomType[message.type] : message.type;
    +                if (message.type != null && $Object.hasOwnProperty.call(message, "type"))
    +                    object.type = options.enums === $String ? $root.vector_tile.Tile.GeomType[message.type] === $undefined ? message.type : $root.vector_tile.Tile.GeomType[message.type] : message.type;
                     if (message.geometry && message.geometry.length) {
    -                    object.geometry = Array(message.geometry.length);
    +                    object.geometry = $Array(message.geometry.length);
                         for (var j = 0; j < message.geometry.length; ++j)
                             object.geometry[j] = message.geometry[j];
                     }
    @@ -1177,8 +1178,8 @@ $root.vector_tile = (function() {
                  * @instance
                  * @returns {Object.<string,*>} JSON object
                  */
    -            Feature.prototype.toJSON = function toJSON() {
    -                return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +            Feature.prototype.toJSON = function() {
    +                return Feature.toObject(this, $protobuf.util.toJSONOptions);
                 };
     
                 /**
    @@ -1189,8 +1190,8 @@ $root.vector_tile = (function() {
                  * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
                  * @returns {string} The type url
                  */
    -            Feature.getTypeUrl = function getTypeUrl(prefix) {
    -                if (prefix === undefined)
    +            Feature.getTypeUrl = function(prefix) {
    +                if (prefix === $undefined)
                         prefix = "type.googleapis.com";
                     return prefix + "/vector_tile.Tile.Feature";
                 };
    @@ -1233,15 +1234,15 @@ $root.vector_tile = (function() {
                  * @param {vector_tile.Tile.Layer.$Properties=} [properties] Properties to set
                  * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
                  */
    -            function Layer(properties) {
    +            var Layer = function (properties) {
                     this.features = [];
                     this.keys = [];
                     this.values = [];
                     if (properties)
    -                    for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +                    for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                             if (properties[keys[i]] != null && keys[i] !== "__proto__")
                                 this[keys[i]] = properties[keys[i]];
    -            }
    +            };
     
                 /**
                  * Layer version.
    @@ -1303,7 +1304,7 @@ $root.vector_tile = (function() {
                  *   (properties?: vector_tile.Tile.Layer.$Properties): vector_tile.Tile.Layer;
                  * }}
                  */
    -            Layer.create = function create(properties) {
    +            Layer.create = function(properties) {
                     return new Layer(properties);
                 };
     
    @@ -1316,13 +1317,13 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.Writer} [writer] Writer to encode to
                  * @returns {$protobuf.Writer} Writer
                  */
    -            Layer.encode = function encode(message, writer, _depth) {
    +            Layer.encode = function (message, writer, _depth) {
                     if (!writer)
                         writer = $Writer.create();
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    -                    throw Error("max depth exceeded");
    +                    throw $Error("max depth exceeded");
                     writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
                     if (message.features != null && message.features.length)
                         for (var i = 0; i < message.features.length; ++i)
    @@ -1333,10 +1334,10 @@ $root.vector_tile = (function() {
                     if (message.values != null && message.values.length)
                         for (var i = 0; i < message.values.length; ++i)
                             $root.vector_tile.Tile.Value.encode(message.values[i], writer.uint32(/* id 4, wireType 2 =*/34).fork(), _depth + 1).ldelim();
    -                if (message.extent != null && Object.hasOwnProperty.call(message, "extent"))
    +                if (message.extent != null && $Object.hasOwnProperty.call(message, "extent"))
                         writer.uint32(/* id 5, wireType 0 =*/40).uint32(message.extent);
                     writer.uint32(/* id 15, wireType 0 =*/120).uint32(message.version);
    -                if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +                if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                         for (var i = 0; i < message.$unknowns.length; ++i)
                             writer.raw(message.$unknowns[i]);
                     return writer;
    @@ -1351,7 +1352,7 @@ $root.vector_tile = (function() {
                  * @param {$protobuf.Writer} [writer] Writer to encode to
                  * @returns {$protobuf.Writer} Writer
                  */
    -            Layer.encodeDelimited = function encodeDelimited(message, writer) {
    +            Layer.encodeDelimited = function(message, writer) {
                     return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
                 };
     
    @@ -1366,19 +1367,19 @@ $root.vector_tile = (function() {
                  * @throws {Error} If the payload is not a reader or valid buffer
                  * @throws {$protobuf.util.ProtocolError} If required fields are missing
                  */
    -            Layer.decode = function decode(reader, length, _end, _depth, _target) {
    +            Layer.decode = function (reader, length, _end, _depth, _target) {
                     if (!(reader instanceof $Reader))
                         reader = $Reader.create(reader);
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $Reader.recursionLimit)
    -                    throw Error("max depth exceeded");
    -                var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile.Layer();
    +                    throw $Error("max depth exceeded");
    +                var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.vector_tile.Tile.Layer();
                     while (reader.pos < end) {
                         var start = reader.pos;
                         var tag = reader.tag();
                         if (tag === _end) {
    -                        _end = undefined;
    +                        _end = $undefined;
                             break;
                         }
                         var wireType = tag & 7;
    @@ -1400,7 +1401,7 @@ $root.vector_tile = (function() {
                                     break;
                                 if (!(message.features && message.features.length))
                                     message.features = [];
    -                            message.features.push($root.vector_tile.Tile.Feature.decode(reader, reader.uint32(), undefined, _depth + 1));
    +                            message.features.push($root.vector_tile.Tile.Feature.decode(reader, reader.uint32(), $undefined, _depth + 1));
                                 continue;
                             }
                         case 3: {
    @@ -1416,7 +1417,7 @@ $root.vector_tile = (function() {
                                     break;
                                 if (!(message.values && message.values.length))
                                     message.values = [];
    -                            message.values.push($root.vector_tile.Tile.Value.decode(reader, reader.uint32(), undefined, _depth + 1));
    +                            message.values.push($root.vector_tile.Tile.Value.decode(reader, reader.uint32(), $undefined, _depth + 1));
                                 continue;
                             }
                         case 5: {
    @@ -1432,11 +1433,11 @@ $root.vector_tile = (function() {
                             (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                         }
                     }
    -                if (_end !== undefined)
    -                    throw Error("missing end group");
    -                if (!message.hasOwnProperty("version"))
    +                if (_end !== $undefined)
    +                    throw $Error("missing end group");
    +                if (!$Object.hasOwnProperty.call(message, "version"))
                         throw $util.ProtocolError("missing required 'version'", { instance: message });
    -                if (!message.hasOwnProperty("name"))
    +                if (!$Object.hasOwnProperty.call(message, "name"))
                         throw $util.ProtocolError("missing required 'name'", { instance: message });
                     return message;
                 };
    @@ -1451,7 +1452,7 @@ $root.vector_tile = (function() {
                  * @throws {Error} If the payload is not a reader or valid buffer
                  * @throws {$protobuf.util.ProtocolError} If required fields are missing
                  */
    -            Layer.decodeDelimited = function decodeDelimited(reader) {
    +            Layer.decodeDelimited = function(reader) {
                     if (!(reader instanceof $Reader))
                         reader = new $Reader(reader);
                     return this.decode(reader, reader.uint32());
    @@ -1465,43 +1466,43 @@ $root.vector_tile = (function() {
                  * @param {Object.<string,*>} message Plain object to verify
                  * @returns {string|null} `null` if valid, otherwise the reason why it is not
                  */
    -            Layer.verify = function verify(message, _depth) {
    +            Layer.verify = function (message, _depth) {
                     if (typeof message !== "object" || message === null)
                         return "object expected";
    -                if (_depth === undefined)
    +                if (_depth === $undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
                         return "max depth exceeded";
                     if (!$util.isInteger(message.version))
                         return "version: integer expected";
                     if (!$util.isString(message.name))
                         return "name: string expected";
    -                if (message.features != null && Object.hasOwnProperty.call(message, "features")) {
    -                    if (!Array.isArray(message.features))
    +                if (message.features != null && $Object.hasOwnProperty.call(message, "features")) {
    +                    if (!$Array.isArray(message.features))
                             return "features: array expected";
                         for (var i = 0; i < message.features.length; ++i) {
                             var error = $root.vector_tile.Tile.Feature.verify(message.features[i], _depth + 1);
                             if (error)
                                 return "features." + error;
                         }
                     }
    -                if (message.keys != null && Object.hasOwnProperty.call(message, "keys")) {
    -                    if (!Array.isArray(message.keys))
    +                if (message.keys != null && $Object.hasOwnProperty.call(message, "keys")) {
    +                    if (!$Array.isArray(message.keys))
                             return "keys: array expected";
                         for (var i = 0; i < message.keys.length; ++i)
                             if (!$util.isString(message.keys[i]))
                                 return "keys: string[] expected";
                     }
    -                if (message.values != null && Object.hasOwnProperty.call(message, "values")) {
    -                    if (!Array.isArray(message.values))
    +                if (message.values != null && $Object.hasOwnProperty.call(message, "values")) {
    +                    if (!$Array.isArray(message.values))
                             return "values: array expected";
                         for (var i = 0; i < message.values.length; ++i) {
                             var error = $root.vector_tile.Tile.Value.verify(message.values[i], _depth + 1);
                             if (error)
                                 return "values." + error;
                         }
                     }
    -                if (message.extent != null && Object.hasOwnProperty.call(message, "exte
    ... [truncated]
    
  • tests/data/package.js+160 159 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $Array = $util.global.Array, $TypeError = $util.global.TypeError, $String = $util.global.String;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_package"] || ($protobuf.roots["test_package"] = {});
    @@ -55,18 +56,18 @@ $root.Package = (function() {
          * @param {Package.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function Package(properties) {
    +    var Package = function (properties) {
             this.keywords = [];
             this.bin = {};
             this.scripts = {};
             this.dependencies = {};
             this.devDependencies = {};
             this.cliDependencies = [];
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * Package name.
    @@ -216,7 +217,7 @@ $root.Package = (function() {
          *   (properties?: Package.$Properties): Package;
          * }}
          */
    -    Package.create = function create(properties) {
    +    Package.create = function(properties) {
             return new Package(properties);
         };
     
    @@ -229,54 +230,54 @@ $root.Package = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Package.encode = function encode(message, writer, _depth) {
    +    Package.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
    +            throw $Error("max depth exceeded");
    +        if (message.name != null && $Object.hasOwnProperty.call(message, "name"))
                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
    -        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
    +        if (message.version != null && $Object.hasOwnProperty.call(message, "version"))
                 writer.uint32(/* id 2, wireType 2 =*/18).string(message.version);
    -        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
    +        if (message.description != null && $Object.hasOwnProperty.call(message, "description"))
                 writer.uint32(/* id 3, wireType 2 =*/26).string(message.description);
    -        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
    +        if (message.author != null && $Object.hasOwnProperty.call(message, "author"))
                 writer.uint32(/* id 4, wireType 2 =*/34).string(message.author);
    -        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
    +        if (message.license != null && $Object.hasOwnProperty.call(message, "license"))
                 writer.uint32(/* id 5, wireType 2 =*/42).string(message.license);
    -        if (message.repository != null && Object.hasOwnProperty.call(message, "repository"))
    +        if (message.repository != null && $Object.hasOwnProperty.call(message, "repository"))
                 $root.Package.Repository.encode(message.repository, writer.uint32(/* id 6, wireType 2 =*/50).fork(), _depth + 1).ldelim();
    -        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
    +        if (message.bugs != null && $Object.hasOwnProperty.call(message, "bugs"))
                 writer.uint32(/* id 7, wireType 2 =*/58).string(message.bugs);
    -        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
    +        if (message.homepage != null && $Object.hasOwnProperty.call(message, "homepage"))
                 writer.uint32(/* id 8, wireType 2 =*/66).string(message.homepage);
             if (message.keywords != null && message.keywords.length)
                 for (var i = 0; i < message.keywords.length; ++i)
                     writer.uint32(/* id 9, wireType 2 =*/74).string(message.keywords[i]);
    -        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
    +        if (message.main != null && $Object.hasOwnProperty.call(message, "main"))
                 writer.uint32(/* id 10, wireType 2 =*/82).string(message.main);
    -        if (message.bin != null && Object.hasOwnProperty.call(message, "bin"))
    -            for (var keys = Object.keys(message.bin), i = 0; i < keys.length; ++i)
    +        if (message.bin != null && $Object.hasOwnProperty.call(message, "bin"))
    +            for (var keys = $Object.keys(message.bin), i = 0; i < keys.length; ++i)
                     writer.uint32(/* id 11, wireType 2 =*/90).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.bin[keys[i]]).ldelim();
    -        if (message.scripts != null && Object.hasOwnProperty.call(message, "scripts"))
    -            for (var keys = Object.keys(message.scripts), i = 0; i < keys.length; ++i)
    +        if (message.scripts != null && $Object.hasOwnProperty.call(message, "scripts"))
    +            for (var keys = $Object.keys(message.scripts), i = 0; i < keys.length; ++i)
                     writer.uint32(/* id 12, wireType 2 =*/98).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.scripts[keys[i]]).ldelim();
    -        if (message.dependencies != null && Object.hasOwnProperty.call(message, "dependencies"))
    -            for (var keys = Object.keys(message.dependencies), i = 0; i < keys.length; ++i)
    +        if (message.dependencies != null && $Object.hasOwnProperty.call(message, "dependencies"))
    +            for (var keys = $Object.keys(message.dependencies), i = 0; i < keys.length; ++i)
                     writer.uint32(/* id 13, wireType 2 =*/106).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.dependencies[keys[i]]).ldelim();
    -        if (message.devDependencies != null && Object.hasOwnProperty.call(message, "devDependencies"))
    -            for (var keys = Object.keys(message.devDependencies), i = 0; i < keys.length; ++i)
    +        if (message.devDependencies != null && $Object.hasOwnProperty.call(message, "devDependencies"))
    +            for (var keys = $Object.keys(message.devDependencies), i = 0; i < keys.length; ++i)
                     writer.uint32(/* id 15, wireType 2 =*/122).fork().uint32(/* id 1, wireType 2 =*/10).string(keys[i]).uint32(/* id 2, wireType 2 =*/18).string(message.devDependencies[keys[i]]).ldelim();
    -        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
    +        if (message.types != null && $Object.hasOwnProperty.call(message, "types"))
                 writer.uint32(/* id 17, wireType 2 =*/138).string(message.types);
             if (message.cliDependencies != null && message.cliDependencies.length)
                 for (var i = 0; i < message.cliDependencies.length; ++i)
                     writer.uint32(/* id 18, wireType 2 =*/146).string(message.cliDependencies[i]);
    -        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
    +        if (message.versionScheme != null && $Object.hasOwnProperty.call(message, "versionScheme"))
                 writer.uint32(/* id 19, wireType 2 =*/154).string(message.versionScheme);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -291,7 +292,7 @@ $root.Package = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    Package.encodeDelimited = function encodeDelimited(message, writer) {
    +    Package.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -306,19 +307,19 @@ $root.Package = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Package.decode = function decode(reader, length, _end, _depth, _target) {
    +    Package.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.Package(), key, value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.Package(), key, value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -380,7 +381,7 @@ $root.Package = (function() {
                 case 6: {
                         if (wireType !== 2)
                             break;
    -                    message.repository = $root.Package.Repository.decode(reader, reader.uint32(), undefined, _depth + 1, message.repository);
    +                    message.repository = $root.Package.Repository.decode(reader, reader.uint32(), $undefined, _depth + 1, message.repository);
                         continue;
                     }
                 case 7: {
    @@ -562,8 +563,8 @@ $root.Package = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -577,7 +578,7 @@ $root.Package = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    Package.decodeDelimited = function decodeDelimited(reader) {
    +    Package.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -591,89 +592,89 @@ $root.Package = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    Package.verify = function verify(message, _depth) {
    +    Package.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
    +        if (message.name != null && $Object.hasOwnProperty.call(message, "name"))
                 if (!$util.isString(message.name))
                     return "name: string expected";
    -        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
    +        if (message.version != null && $Object.hasOwnProperty.call(message, "version"))
                 if (!$util.isString(message.version))
                     return "version: string expected";
    -        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
    +        if (message.versionScheme != null && $Object.hasOwnProperty.call(message, "versionScheme"))
                 if (!$util.isString(message.versionScheme))
                     return "versionScheme: string expected";
    -        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
    +        if (message.description != null && $Object.hasOwnProperty.call(message, "description"))
                 if (!$util.isString(message.description))
                     return "description: string expected";
    -        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
    +        if (message.author != null && $Object.hasOwnProperty.call(message, "author"))
                 if (!$util.isString(message.author))
                     return "author: string expected";
    -        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
    +        if (message.license != null && $Object.hasOwnProperty.call(message, "license"))
                 if (!$util.isString(message.license))
                     return "license: string expected";
    -        if (message.repository != null && Object.hasOwnProperty.call(message, "repository")) {
    +        if (message.repository != null && $Object.hasOwnProperty.call(message, "repository")) {
                 var error = $root.Package.Repository.verify(message.repository, _depth + 1);
                 if (error)
                     return "repository." + error;
             }
    -        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
    +        if (message.bugs != null && $Object.hasOwnProperty.call(message, "bugs"))
                 if (!$util.isString(message.bugs))
                     return "bugs: string expected";
    -        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
    +        if (message.homepage != null && $Object.hasOwnProperty.call(message, "homepage"))
                 if (!$util.isString(message.homepage))
                     return "homepage: string expected";
    -        if (message.keywords != null && Object.hasOwnProperty.call(message, "keywords")) {
    -            if (!Array.isArray(message.keywords))
    +        if (message.keywords != null && $Object.hasOwnProperty.call(message, "keywords")) {
    +            if (!$Array.isArray(message.keywords))
                     return "keywords: array expected";
                 for (var i = 0; i < message.keywords.length; ++i)
                     if (!$util.isString(message.keywords[i]))
                         return "keywords: string[] expected";
             }
    -        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
    +        if (message.main != null && $Object.hasOwnProperty.call(message, "main"))
                 if (!$util.isString(message.main))
                     return "main: string expected";
    -        if (message.bin != null && Object.hasOwnProperty.call(message, "bin")) {
    +        if (message.bin != null && $Object.hasOwnProperty.call(message, "bin")) {
                 if (!$util.isObject(message.bin))
                     return "bin: object expected";
    -            var key = Object.keys(message.bin);
    +            var key = $Object.keys(message.bin);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.bin[key[i]]))
                         return "bin: string{k:string} expected";
             }
    -        if (message.scripts != null && Object.hasOwnProperty.call(message, "scripts")) {
    +        if (message.scripts != null && $Object.hasOwnProperty.call(message, "scripts")) {
                 if (!$util.isObject(message.scripts))
                     return "scripts: object expected";
    -            var key = Object.keys(message.scripts);
    +            var key = $Object.keys(message.scripts);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.scripts[key[i]]))
                         return "scripts: string{k:string} expected";
             }
    -        if (message.dependencies != null && Object.hasOwnProperty.call(message, "dependencies")) {
    +        if (message.dependencies != null && $Object.hasOwnProperty.call(message, "dependencies")) {
                 if (!$util.isObject(message.dependencies))
                     return "dependencies: object expected";
    -            var key = Object.keys(message.dependencies);
    +            var key = $Object.keys(message.dependencies);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.dependencies[key[i]]))
                         return "dependencies: string{k:string} expected";
             }
    -        if (message.devDependencies != null && Object.hasOwnProperty.call(message, "devDependencies")) {
    +        if (message.devDependencies != null && $Object.hasOwnProperty.call(message, "devDependencies")) {
                 if (!$util.isObject(message.devDependencies))
                     return "devDependencies: object expected";
    -            var key = Object.keys(message.devDependencies);
    +            var key = $Object.keys(message.devDependencies);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.devDependencies[key[i]]))
                         return "devDependencies: string{k:string} expected";
             }
    -        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
    +        if (message.types != null && $Object.hasOwnProperty.call(message, "types"))
                 if (!$util.isString(message.types))
                     return "types: string expected";
    -        if (message.cliDependencies != null && Object.hasOwnProperty.call(message, "cliDependencies")) {
    -            if (!Array.isArray(message.cliDependencies))
    +        if (message.cliDependencies != null && $Object.hasOwnProperty.call(message, "cliDependencies")) {
    +            if (!$Array.isArray(message.cliDependencies))
                     return "cliDependencies: array expected";
                 for (var i = 0; i < message.cliDependencies.length; ++i)
                     if (!$util.isString(message.cliDependencies[i]))
    @@ -690,104 +691,104 @@ $root.Package = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {Package} Package
          */
    -    Package.fromObject = function fromObject(object, _depth) {
    +    Package.fromObject = function (object, _depth) {
             if (object instanceof $root.Package)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".Package: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".Package: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.Package();
             if (object.name != null)
                 if (typeof object.name !== "string" || object.name.length)
    -                message.name = String(object.name);
    +                message.name = $String(object.name);
             if (object.version != null)
                 if (typeof object.version !== "string" || object.version.length)
    -                message.version = String(object.version);
    +                message.version = $String(object.version);
             if (object.versionScheme != null)
                 if (typeof object.versionScheme !== "string" || object.versionScheme.length)
    -                message.versionScheme = String(object.versionScheme);
    +                message.versionScheme = $String(object.versionScheme);
             if (object.description != null)
                 if (typeof object.description !== "string" || object.description.length)
    -                message.description = String(object.description);
    +                message.description = $String(object.description);
             if (object.author != null)
                 if (typeof object.author !== "string" || object.author.length)
    -                message.author = String(object.author);
    +                message.author = $String(object.author);
             if (object.license != null)
                 if (typeof object.license !== "string" || object.license.length)
    -                message.license = String(object.license);
    +                message.license = $String(object.license);
             if (object.repository != null) {
                 if (!$util.isObject(object.repository))
    -                throw TypeError(".Package.repository: object expected");
    +                throw $TypeError(".Package.repository: object expected");
                 message.repository = $root.Package.Repository.fromObject(object.repository, _depth + 1);
             }
             if (object.bugs != null)
                 if (typeof object.bugs !== "string" || object.bugs.length)
    -                message.bugs = String(object.bugs);
    +                message.bugs = $String(object.bugs);
             if (object.homepage != null)
                 if (typeof object.homepage !== "string" || object.homepage.length)
    -                message.homepage = String(object.homepage);
    +                message.homepage = $String(object.homepage);
             if (object.keywords) {
    -            if (!Array.isArray(object.keywords))
    -                throw TypeError(".Package.keywords: array expected");
    -            message.keywords = Array(object.keywords.length);
    +            if (!$Array.isArray(object.keywords))
    +                throw $TypeError(".Package.keywords: array expected");
    +            message.keywords = $Array(object.keywords.length);
                 for (var i = 0; i < object.keywords.length; ++i)
    -                message.keywords[i] = String(object.keywords[i]);
    +                message.keywords[i] = $String(object.keywords[i]);
             }
             if (object.main != null)
                 if (typeof object.main !== "string" || object.main.length)
    -                message.main = String(object.main);
    +                message.main = $String(object.main);
             if (object.bin) {
                 if (!$util.isObject(object.bin))
    -                throw TypeError(".Package.bin: object expected");
    +                throw $TypeError(".Package.bin: object expected");
                 message.bin = {};
    -            for (var keys = Object.keys(object.bin), i = 0; i < keys.length; ++i) {
    +            for (var keys = $Object.keys(object.bin), i = 0; i < keys.length; ++i) {
                     if (keys[i] === "__proto__")
                         $util.makeProp(message.bin, keys[i]);
    -                message.bin[keys[i]] = String(object.bin[keys[i]]);
    +                message.bin[keys[i]] = $String(object.bin[keys[i]]);
                 }
             }
             if (object.scripts) {
                 if (!$util.isObject(object.scripts))
    -                throw TypeError(".Package.scripts: object expected");
    +                throw $TypeError(".Package.scripts: object expected");
                 message.scripts = {};
    -            for (var keys = Object.keys(object.scripts), i = 0; i < keys.length; ++i) {
    +            for (var keys = $Object.keys(object.scripts), i = 0; i < keys.length; ++i) {
                     if (keys[i] === "__proto__")
                         $util.makeProp(message.scripts, keys[i]);
    -                message.scripts[keys[i]] = String(object.scripts[keys[i]]);
    +                message.scripts[keys[i]] = $String(object.scripts[keys[i]]);
                 }
             }
             if (object.dependencies) {
                 if (!$util.isObject(object.dependencies))
    -                throw TypeError(".Package.dependencies: object expected");
    +                throw $TypeError(".Package.dependencies: object expected");
                 message.dependencies = {};
    -            for (var keys = Object.keys(object.dependencies), i = 0; i < keys.length; ++i) {
    +            for (var keys = $Object.keys(object.dependencies), i = 0; i < keys.length; ++i) {
                     if (keys[i] === "__proto__")
                         $util.makeProp(message.dependencies, keys[i]);
    -                message.dependencies[keys[i]] = String(object.dependencies[keys[i]]);
    +                message.dependencies[keys[i]] = $String(object.dependencies[keys[i]]);
                 }
             }
             if (object.devDependencies) {
                 if (!$util.isObject(object.devDependencies))
    -                throw TypeError(".Package.devDependencies: object expected");
    +                throw $TypeError(".Package.devDependencies: object expected");
                 message.devDependencies = {};
    -            for (var keys = Object.keys(object.devDependencies), i = 0; i < keys.length; ++i) {
    +            for (var keys = $Object.keys(object.devDependencies), i = 0; i < keys.length; ++i) {
                     if (keys[i] === "__proto__")
                         $util.makeProp(message.devDependencies, keys[i]);
    -                message.devDependencies[keys[i]] = String(object.devDependencies[keys[i]]);
    +                message.devDependencies[keys[i]] = $String(object.devDependencies[keys[i]]);
                 }
             }
             if (object.types != null)
                 if (typeof object.types !== "string" || object.types.length)
    -                message.types = String(object.types);
    +                message.types = $String(object.types);
             if (object.cliDependencies) {
    -            if (!Array.isArray(object.cliDependencies))
    -                throw TypeError(".Package.cliDependencies: array expected");
    -            message.cliDependencies = Array(object.cliDependencies.length);
    +            if (!$Array.isArray(object.cliDependencies))
    +                throw $TypeError(".Package.cliDependencies: array expected");
    +            message.cliDependencies = $Array(object.cliDependencies.length);
                 for (var i = 0; i < object.cliDependencies.length; ++i)
    -                message.cliDependencies[i] = String(object.cliDependencies[i]);
    +                message.cliDependencies[i] = $String(object.cliDependencies[i]);
             }
             return message;
         };
    @@ -801,13 +802,13 @@ $root.Package = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    Package.toObject = function toObject(message, options, _depth) {
    +    Package.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.arrays || options.defaults) {
                 object.keywords = [];
    @@ -832,70 +833,70 @@ $root.Package = (function() {
                 object.types = "";
                 object.versionScheme = "";
             }
    -        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
    +        if (message.name != null && $Object.hasOwnProperty.call(message, "name"))
                 object.name = message.name;
    -        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
    +        if (message.version != null && $Object.hasOwnProperty.call(message, "version"))
                 object.version = message.version;
    -        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
    +        if (message.description != null && $Object.hasOwnProperty.call(message, "description"))
                 object.description = message.description;
    -        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
    +        if (message.author != null && $Object.hasOwnProperty.call(message, "author"))
                 object.author = message.author;
    -        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
    +        if (message.license != null && $Object.hasOwnProperty.call(message, "license"))
                 object.license = message.license;
    -        if (message.repository != null && Object.hasOwnProperty.call(message, "repository"))
    +        if (message.repository != null && $Object.hasOwnProperty.call(message, "repository"))
                 object.repository = $root.Package.Repository.toObject(message.repository, options, _depth + 1);
    -        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
    +        if (message.bugs != null && $Object.hasOwnProperty.call(message, "bugs"))
                 object.bugs = message.bugs;
    -        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
    +        if (message.homepage != null && $Object.hasOwnProperty.call(message, "homepage"))
                 object.homepage = message.homepage;
             if (message.keywords && message.keywords.length) {
    -            object.keywords = Array(message.keywords.length);
    +            object.keywords = $Array(message.keywords.length);
                 for (var j = 0; j < message.keywords.length; ++j)
                     object.keywords[j] = message.keywords[j];
             }
    -        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
    +        if (message.main != null && $Object.hasOwnProperty.call(message, "main"))
                 object.main = message.main;
             var keys2;
    -        if (message.bin && (keys2 = Object.keys(message.bin)).length) {
    +        if (message.bin && (keys2 = $Object.keys(message.bin)).length) {
                 object.bin = {};
                 for (var j = 0; j < keys2.length; ++j) {
                     if (keys2[j] === "__proto__")
                         $util.makeProp(object.bin, keys2[j]);
                     object.bin[keys2[j]] = message.bin[keys2[j]];
                 }
             }
    -        if (message.scripts && (keys2 = Object.keys(message.scripts)).length) {
    +        if (message.scripts && (keys2 = $Object.keys(message.scripts)).length) {
                 object.scripts = {};
                 for (var j = 0; j < keys2.length; ++j) {
                     if (keys2[j] === "__proto__")
                         $util.makeProp(object.scripts, keys2[j]);
                     object.scripts[keys2[j]] = message.scripts[keys2[j]];
                 }
             }
    -        if (message.dependencies && (keys2 = Object.keys(message.dependencies)).length) {
    +        if (message.dependencies && (keys2 = $Object.keys(message.dependencies)).length) {
                 object.dependencies = {};
                 for (var j = 0; j < keys2.length; ++j) {
                     if (keys2[j] === "__proto__")
                         $util.makeProp(object.dependencies, keys2[j]);
                     object.dependencies[keys2[j]] = message.dependencies[keys2[j]];
                 }
             }
    -        if (message.devDependencies && (keys2 = Object.keys(message.devDependencies)).length) {
    +        if (message.devDependencies && (keys2 = $Object.keys(message.devDependencies)).length) {
                 object.devDependencies = {};
                 for (var j = 0; j < keys2.length; ++j) {
                     if (keys2[j] === "__proto__")
                         $util.makeProp(object.devDependencies, keys2[j]);
                     object.devDependencies[keys2[j]] = message.devDependencies[keys2[j]];
                 }
             }
    -        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
    +        if (message.types != null && $Object.hasOwnProperty.call(message, "types"))
                 object.types = message.types;
             if (message.cliDependencies && message.cliDependencies.length) {
    -            object.cliDependencies = Array(message.cliDependencies.length);
    +            object.cliDependencies = $Array(message.cliDependencies.length);
                 for (var j = 0; j < message.cliDependencies.length; ++j)
                     object.cliDependencies[j] = message.cliDependencies[j];
             }
    -        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
    +        if (message.versionScheme != null && $Object.hasOwnProperty.call(message, "versionScheme"))
                 object.versionScheme = message.versionScheme;
             return object;
         };
    @@ -907,8 +908,8 @@ $root.Package = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    Package.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    Package.prototype.toJSON = function() {
    +        return Package.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -919,8 +920,8 @@ $root.Package = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    Package.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    Package.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/Package";
         };
    @@ -956,12 +957,12 @@ $root.Package = (function() {
              * @param {Package.Repository.$Properties=} [properties] Properties to set
              * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
              */
    -        function Repository(properties) {
    +        var Repository = function (properties) {
                 if (properties)
    -                for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +                for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                         if (properties[keys[i]] != null && keys[i] !== "__proto__")
                             this[keys[i]] = properties[keys[i]];
    -        }
    +        };
     
             /**
              * Repository type.
    @@ -991,7 +992,7 @@ $root.Package = (function() {
              *   (properties?: Package.Repository.$Properties): Package.Repository;
              * }}
              */
    -        Repository.create = function create(properties) {
    +        Repository.create = function(properties) {
                 return new Repository(properties);
             };
     
    @@ -1004,18 +1005,18 @@ $root.Package = (function() {
              * @param {$protobuf.Writer} [writer] Writer to encode to
              * @returns {$protobuf.Writer} Writer
              */
    -        Repository.encode = function encode(message, writer, _depth) {
    +        Repository.encode = function (message, writer, _depth) {
                 if (!writer)
                     writer = $Writer.create();
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    -            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
    +                throw $Error("max depth exceeded");
    +            if (message.type != null && $Object.hasOwnProperty.call(message, "type"))
                     writer.uint32(/* id 1, wireType 2 =*/10).string(message.type);
    -            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
    +            if (message.url != null && $Object.hasOwnProperty.call(message, "url"))
                     writer.uint32(/* id 2, wireType 2 =*/18).string(message.url);
    -            if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +            if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                     for (var i = 0; i < message.$unknowns.length; ++i)
                         writer.raw(message.$unknowns[i]);
                 return writer;
    @@ -1030,7 +1031,7 @@ $root.Package = (function() {
              * @param {$protobuf.Writer} [writer] Writer to encode to
              * @returns {$protobuf.Writer} Writer
              */
    -        Repository.encodeDelimited = function encodeDelimited(message, writer) {
    +        Repository.encodeDelimited = function(message, writer) {
                 return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
             };
     
    @@ -1045,19 +1046,19 @@ $root.Package = (function() {
              * @throws {Error} If the payload is not a reader or valid buffer
              * @throws {$protobuf.util.ProtocolError} If required fields are missing
              */
    -        Repository.decode = function decode(reader, length, _end, _depth, _target) {
    +        Repository.decode = function (reader, length, _end, _depth, _target) {
                 if (!(reader instanceof $Reader))
                     reader = $Reader.create(reader);
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $Reader.recursionLimit)
    -                throw Error("max depth exceeded");
    -            var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.Package.Repository(), value;
    +                throw $Error("max depth exceeded");
    +            var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.Package.Repository(), value;
                 while (reader.pos < end) {
                     var start = reader.pos;
                     var tag = reader.tag();
                     if (tag === _end) {
    -                    _end = undefined;
    +                    _end = $undefined;
                         break;
                     }
                     var wireType = tag & 7;
    @@ -1087,8 +1088,8 @@ $root.Package = (function() {
                         (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                     }
                 }
    -            if (_end !== undefined)
    -                throw Error("missing end group");
    +            if (_end !== $undefined)
    +                throw $Error("missing end group");
                 return message;
             };
     
    @@ -1102,7 +1103,7 @@ $root.Package = (function() {
              * @throws {Error} If the payload is not a reader or valid buffer
              * @throws {$protobuf.util.ProtocolError} If required fields are missing
              */
    -        Repository.decodeDelimited = function decodeDelimited(reader) {
    +        Repository.decodeDelimited = function(reader) {
                 if (!(reader instanceof $Reader))
                     reader = new $Reader(reader);
                 return this.decode(reader, reader.uint32());
    @@ -1116,17 +1117,17 @@ $root.Package = (function() {
              * @param {Object.<string,*>} message Plain object to verify
              * @returns {string|null} `null` if valid, otherwise the reason why it is not
              */
    -        Repository.verify = function verify(message, _depth) {
    +        Repository.verify = function (message, _depth) {
                 if (typeof message !== "object" || message === null)
                     return "object expected";
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
                     return "max depth exceeded";
    -            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
    +            if (message.type != null && $Object.hasOwnProperty.call(message, "type"))
                     if (!$util.isString(message.type))
                         return "type: string expected";
    -            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
    +            if (message.url != null && $Object.hasOwnProperty.call(message, "url"))
                     if (!$util.isString(message.url))
                         return "url: string expected";
                 return null;
    @@ -1140,22 +1141,22 @@ $root.Package = (function() {
              * @param {Object.<string,*>} object Plain object
              * @returns {Package.Repository} Repository
              */
    -        Repository.fromObject = function fromObject(object, _depth) {
    +        Repository.fromObject = function (object, _depth) {
                 if (object instanceof $root.Package.Repository)
                     return object;
                 if (!$util.isObject(object))
    -                throw TypeError(".Package.Repository: object expected");
    -            if (_depth === undefined)
    +                throw $TypeError(".Package.Repository: object expected");
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 var message = new $root.Package.Repository();
                 if (object.type != null)
                     if (typeof object.type !== "string" || object.type.length)
    -                    message.type = String(object.type);
    +                    message.type = $String(object.type);
                 if (object.url != null)
                     if (typeof object.url !== "string" || object.url.length)
    -                    message.url = String(object.url);
    +                    message.url = $String(object.url);
                 return message;
             };
     
    @@ -1168,21 +1169,21 @@ $root.Package = (function() {
              * @param {$protobuf.IConversionOptions} [options] Conversion options
              * @returns {Object.<string,*>} Plain object
              */
    -        Repository.toObject = function toObject(message, options, _depth) {
    +        Repository.toObject = function (message, options, _depth) {
                 if (!options)
                     options = {};
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 var object = {};
                 if (options.defaults) {
                     object.type = "";
                     object.url = "";
                 }
    -            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
    +            if (message.type != null && $Object.hasOwnProperty.call(message, "type"))
                     object.type = message.type;
    -            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
    +            if (message.url != null && $Object.hasOwnProperty.call(message, "url"))
                     object.url = message.url;
                 return object;
             };
    @@ -1194,8 +1195,8 @@ $root.Package = (function() {
              * @instance
              * @returns {Object.<string,*>} JSON object
              */
    -        Repository.prototype.toJSON = function toJSON() {
    -            return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +        Repository.prototype.toJSON = function() {
    +            return Repository.toObject(this, $protobuf.util.toJSONOptions);
             };
     
             /**
    @@ -1206,8 +1207,8 @@ $root.Package = (function() {
              * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
              * @returns {string} The type url
              */
    -        Repository.getTypeUrl = function getTypeUrl(prefix) {
    -            if (prefix === undefined)
    +        Repository.getTypeUrl = function(prefix) {
    +            if (prefix === $undefined)
                     prefix = "type.googleapis.com";
                 return prefix + "/Package.Repository";
             };
    
  • tests/data/rpc-es6.js+77 76 modified
    @@ -3,6 +3,7 @@ import $protobuf from "protobufjs/minimal.js";
     
     // Common aliases
     const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +const $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $TypeError = $util.global.TypeError, $String = $util.global.String, $Number = $util.global.Number;
     
     // Exported root namespace
     const $root = $protobuf.roots["test_rpc"] || ($protobuf.roots["test_rpc"] = {});
    @@ -19,11 +20,11 @@ export const MyService = $root.MyService = (() => {
          * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
          * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
          */
    -    function MyService(rpcImpl, requestDelimited, responseDelimited) {
    +    const MyService = function(rpcImpl, requestDelimited, responseDelimited) {
             $protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited);
    -    }
    +    };
     
    -    (MyService.prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = MyService;
    +    (MyService.prototype = $Object.create($protobuf.rpc.Service.prototype)).constructor = MyService;
     
         /**
          * Creates new MyService service using the specified rpc implementation.
    @@ -35,7 +36,7 @@ export const MyService = $root.MyService = (() => {
          * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
          * @returns {MyService} RPC service. Useful where requests and/or responses are streamed.
          */
    -    MyService.create = function create(rpcImpl, requestDelimited, responseDelimited) {
    +    MyService.create = function(rpcImpl, requestDelimited, responseDelimited) {
             return new this(rpcImpl, requestDelimited, responseDelimited);
         };
     
    @@ -69,15 +70,15 @@ export const MyService = $root.MyService = (() => {
          * @name MyService#myMethod
          * @type {MyService.MyMethod}
          */
    -    Object.defineProperties(MyService.prototype.myMethod = function myMethod(request, callback) {
    -        return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
    +    $Object.defineProperties(MyService.prototype.myMethod = function(request, callback) {
    +        return $protobuf.rpc.Service.prototype.rpcCall.call(this, MyService.prototype.myMethod, $root.MyRequest, $root.MyResponse, request, callback);
         }, {
             name: { value: "MyMethod" },
             path: { value: "/MyService/MyMethod" },
             requestType: { value: "MyRequest" },
             responseType: { value: "MyResponse" },
    -        requestStream: { value: undefined },
    -        responseStream: { value: undefined }
    +        requestStream: { value: $undefined },
    +        responseStream: { value: $undefined }
         });
     
         return MyService;
    @@ -113,12 +114,12 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {MyRequest.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function MyRequest(properties) {
    +    const MyRequest = function (properties) {
             if (properties)
    -            for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (let keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * MyRequest path.
    @@ -140,7 +141,7 @@ export const MyRequest = $root.MyRequest = (() => {
          *   (properties?: MyRequest.$Properties): MyRequest;
          * }}
          */
    -    MyRequest.create = function create(properties) {
    +    MyRequest.create = function(properties) {
             return new MyRequest(properties);
         };
     
    @@ -153,16 +154,16 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyRequest.encode = function encode(message, writer, _depth) {
    +    MyRequest.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +            throw $Error("max depth exceeded");
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.path);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (let i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -177,7 +178,7 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyRequest.encodeDelimited = function encodeDelimited(message, writer) {
    +    MyRequest.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -192,19 +193,19 @@ export const MyRequest = $root.MyRequest = (() => {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyRequest.decode = function decode(reader, length, _end, _depth, _target) {
    +    MyRequest.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        let end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.MyRequest(), value;
    +            throw $Error("max depth exceeded");
    +        let end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.MyRequest(), value;
             while (reader.pos < end) {
                 let start = reader.pos;
                 let tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 let wireType = tag & 7;
    @@ -225,8 +226,8 @@ export const MyRequest = $root.MyRequest = (() => {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -240,7 +241,7 @@ export const MyRequest = $root.MyRequest = (() => {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyRequest.decodeDelimited = function decodeDelimited(reader) {
    +    MyRequest.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -254,14 +255,14 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    MyRequest.verify = function verify(message, _depth) {
    +    MyRequest.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -275,19 +276,19 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {Object.<string,*>} object Plain object
          * @returns {MyRequest} MyRequest
          */
    -    MyRequest.fromObject = function fromObject(object, _depth) {
    +    MyRequest.fromObject = function (object, _depth) {
             if (object instanceof $root.MyRequest)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".MyRequest: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".MyRequest: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             let message = new $root.MyRequest();
             if (object.path != null)
                 if (typeof object.path !== "string" || object.path.length)
    -                message.path = String(object.path);
    +                message.path = $String(object.path);
             return message;
         };
     
    @@ -300,17 +301,17 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    MyRequest.toObject = function toObject(message, options, _depth) {
    +    MyRequest.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             let object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -322,8 +323,8 @@ export const MyRequest = $root.MyRequest = (() => {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    MyRequest.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    MyRequest.prototype.toJSON = function() {
    +        return MyRequest.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -334,8 +335,8 @@ export const MyRequest = $root.MyRequest = (() => {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    MyRequest.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    MyRequest.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/MyRequest";
         };
    @@ -373,12 +374,12 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {MyResponse.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function MyResponse(properties) {
    +    const MyResponse = function (properties) {
             if (properties)
    -            for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (let keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * MyResponse status.
    @@ -400,7 +401,7 @@ export const MyResponse = $root.MyResponse = (() => {
          *   (properties?: MyResponse.$Properties): MyResponse;
          * }}
          */
    -    MyResponse.create = function create(properties) {
    +    MyResponse.create = function(properties) {
             return new MyResponse(properties);
         };
     
    @@ -413,16 +414,16 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyResponse.encode = function encode(message, writer, _depth) {
    +    MyResponse.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +            throw $Error("max depth exceeded");
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 writer.uint32(/* id 2, wireType 0 =*/16).int32(message.status);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (let i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -437,7 +438,7 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyResponse.encodeDelimited = function encodeDelimited(message, writer) {
    +    MyResponse.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -452,19 +453,19 @@ export const MyResponse = $root.MyResponse = (() => {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyResponse.decode = function decode(reader, length, _end, _depth, _target) {
    +    MyResponse.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        let end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.MyResponse(), value;
    +            throw $Error("max depth exceeded");
    +        let end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.MyResponse(), value;
             while (reader.pos < end) {
                 let start = reader.pos;
                 let tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 let wireType = tag & 7;
    @@ -485,8 +486,8 @@ export const MyResponse = $root.MyResponse = (() => {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -500,7 +501,7 @@ export const MyResponse = $root.MyResponse = (() => {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyResponse.decodeDelimited = function decodeDelimited(reader) {
    +    MyResponse.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -514,14 +515,14 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    MyResponse.verify = function verify(message, _depth) {
    +    MyResponse.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -535,18 +536,18 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {Object.<string,*>} object Plain object
          * @returns {MyResponse} MyResponse
          */
    -    MyResponse.fromObject = function fromObject(object, _depth) {
    +    MyResponse.fromObject = function (object, _depth) {
             if (object instanceof $root.MyResponse)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".MyResponse: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".MyResponse: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             let message = new $root.MyResponse();
             if (object.status != null)
    -            if (Number(object.status) !== 0)
    +            if ($Number(object.status) !== 0)
                     message.status = object.status | 0;
             return message;
         };
    @@ -560,17 +561,17 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    MyResponse.toObject = function toObject(message, options, _depth) {
    +    MyResponse.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             let object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    @@ -582,8 +583,8 @@ export const MyResponse = $root.MyResponse = (() => {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    MyResponse.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    MyResponse.prototype.toJSON = function() {
    +        return MyResponse.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -594,8 +595,8 @@ export const MyResponse = $root.MyResponse = (() => {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    MyResponse.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    MyResponse.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/MyResponse";
         };
    
  • tests/data/rpc.js+77 76 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $TypeError = $util.global.TypeError, $String = $util.global.String, $Number = $util.global.Number;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_rpc"] || ($protobuf.roots["test_rpc"] = {});
    @@ -21,11 +22,11 @@ $root.MyService = (function() {
          * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
          * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
          */
    -    function MyService(rpcImpl, requestDelimited, responseDelimited) {
    +    var MyService = function(rpcImpl, requestDelimited, responseDelimited) {
             $protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited);
    -    }
    +    };
     
    -    (MyService.prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = MyService;
    +    (MyService.prototype = $Object.create($protobuf.rpc.Service.prototype)).constructor = MyService;
     
         /**
          * Creates new MyService service using the specified rpc implementation.
    @@ -37,7 +38,7 @@ $root.MyService = (function() {
          * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
          * @returns {MyService} RPC service. Useful where requests and/or responses are streamed.
          */
    -    MyService.create = function create(rpcImpl, requestDelimited, responseDelimited) {
    +    MyService.create = function(rpcImpl, requestDelimited, responseDelimited) {
             return new this(rpcImpl, requestDelimited, responseDelimited);
         };
     
    @@ -71,15 +72,15 @@ $root.MyService = (function() {
          * @name MyService#myMethod
          * @type {MyService.MyMethod}
          */
    -    Object.defineProperties(MyService.prototype.myMethod = function myMethod(request, callback) {
    -        return this.rpcCall(myMethod, $root.MyRequest, $root.MyResponse, request, callback);
    +    $Object.defineProperties(MyService.prototype.myMethod = function(request, callback) {
    +        return $protobuf.rpc.Service.prototype.rpcCall.call(this, MyService.prototype.myMethod, $root.MyRequest, $root.MyResponse, request, callback);
         }, {
             name: { value: "MyMethod" },
             path: { value: "/MyService/MyMethod" },
             requestType: { value: "MyRequest" },
             responseType: { value: "MyResponse" },
    -        requestStream: { value: undefined },
    -        responseStream: { value: undefined }
    +        requestStream: { value: $undefined },
    +        responseStream: { value: $undefined }
         });
     
         return MyService;
    @@ -115,12 +116,12 @@ $root.MyRequest = (function() {
          * @param {MyRequest.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function MyRequest(properties) {
    +    var MyRequest = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * MyRequest path.
    @@ -142,7 +143,7 @@ $root.MyRequest = (function() {
          *   (properties?: MyRequest.$Properties): MyRequest;
          * }}
          */
    -    MyRequest.create = function create(properties) {
    +    MyRequest.create = function(properties) {
             return new MyRequest(properties);
         };
     
    @@ -155,16 +156,16 @@ $root.MyRequest = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyRequest.encode = function encode(message, writer, _depth) {
    +    MyRequest.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +            throw $Error("max depth exceeded");
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.path);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -179,7 +180,7 @@ $root.MyRequest = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyRequest.encodeDelimited = function encodeDelimited(message, writer) {
    +    MyRequest.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -194,19 +195,19 @@ $root.MyRequest = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyRequest.decode = function decode(reader, length, _end, _depth, _target) {
    +    MyRequest.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.MyRequest(), value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.MyRequest(), value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -227,8 +228,8 @@ $root.MyRequest = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -242,7 +243,7 @@ $root.MyRequest = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyRequest.decodeDelimited = function decodeDelimited(reader) {
    +    MyRequest.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -256,14 +257,14 @@ $root.MyRequest = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    MyRequest.verify = function verify(message, _depth) {
    +    MyRequest.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -277,19 +278,19 @@ $root.MyRequest = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {MyRequest} MyRequest
          */
    -    MyRequest.fromObject = function fromObject(object, _depth) {
    +    MyRequest.fromObject = function (object, _depth) {
             if (object instanceof $root.MyRequest)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".MyRequest: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".MyRequest: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.MyRequest();
             if (object.path != null)
                 if (typeof object.path !== "string" || object.path.length)
    -                message.path = String(object.path);
    +                message.path = $String(object.path);
             return message;
         };
     
    @@ -302,17 +303,17 @@ $root.MyRequest = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    MyRequest.toObject = function toObject(message, options, _depth) {
    +    MyRequest.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -324,8 +325,8 @@ $root.MyRequest = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    MyRequest.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    MyRequest.prototype.toJSON = function() {
    +        return MyRequest.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -336,8 +337,8 @@ $root.MyRequest = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    MyRequest.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    MyRequest.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/MyRequest";
         };
    @@ -375,12 +376,12 @@ $root.MyResponse = (function() {
          * @param {MyResponse.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function MyResponse(properties) {
    +    var MyResponse = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * MyResponse status.
    @@ -402,7 +403,7 @@ $root.MyResponse = (function() {
          *   (properties?: MyResponse.$Properties): MyResponse;
          * }}
          */
    -    MyResponse.create = function create(properties) {
    +    MyResponse.create = function(properties) {
             return new MyResponse(properties);
         };
     
    @@ -415,16 +416,16 @@ $root.MyResponse = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyResponse.encode = function encode(message, writer, _depth) {
    +    MyResponse.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +            throw $Error("max depth exceeded");
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 writer.uint32(/* id 2, wireType 0 =*/16).int32(message.status);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -439,7 +440,7 @@ $root.MyResponse = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyResponse.encodeDelimited = function encodeDelimited(message, writer) {
    +    MyResponse.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -454,19 +455,19 @@ $root.MyResponse = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyResponse.decode = function decode(reader, length, _end, _depth, _target) {
    +    MyResponse.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.MyResponse(), value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.MyResponse(), value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -487,8 +488,8 @@ $root.MyResponse = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -502,7 +503,7 @@ $root.MyResponse = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyResponse.decodeDelimited = function decodeDelimited(reader) {
    +    MyResponse.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -516,14 +517,14 @@ $root.MyResponse = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    MyResponse.verify = function verify(message, _depth) {
    +    MyResponse.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -537,18 +538,18 @@ $root.MyResponse = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {MyResponse} MyResponse
          */
    -    MyResponse.fromObject = function fromObject(object, _depth) {
    +    MyResponse.fromObject = function (object, _depth) {
             if (object instanceof $root.MyResponse)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".MyResponse: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".MyResponse: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.MyResponse();
             if (object.status != null)
    -            if (Number(object.status) !== 0)
    +            if ($Number(object.status) !== 0)
                     message.status = object.status | 0;
             return message;
         };
    @@ -562,17 +563,17 @@ $root.MyResponse = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    MyResponse.toObject = function toObject(message, options, _depth) {
    +    MyResponse.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    @@ -584,8 +585,8 @@ $root.MyResponse = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    MyResponse.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    MyResponse.prototype.toJSON = function() {
    +        return MyResponse.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -596,8 +597,8 @@ $root.MyResponse = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    MyResponse.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    MyResponse.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/MyResponse";
         };
    
  • tests/data/rpc-reserved.js+77 76 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $TypeError = $util.global.TypeError, $String = $util.global.String, $Number = $util.global.Number;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_rpc-reserved"] || ($protobuf.roots["test_rpc-reserved"] = {});
    @@ -21,11 +22,11 @@ $root.MyService = (function() {
          * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
          * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
          */
    -    function MyService(rpcImpl, requestDelimited, responseDelimited) {
    +    var MyService = function(rpcImpl, requestDelimited, responseDelimited) {
             $protobuf.rpc.Service.call(this, rpcImpl, requestDelimited, responseDelimited);
    -    }
    +    };
     
    -    (MyService.prototype = Object.create($protobuf.rpc.Service.prototype)).constructor = MyService;
    +    (MyService.prototype = $Object.create($protobuf.rpc.Service.prototype)).constructor = MyService;
     
         /**
          * Creates new MyService service using the specified rpc implementation.
    @@ -37,7 +38,7 @@ $root.MyService = (function() {
          * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
          * @returns {MyService} RPC service. Useful where requests and/or responses are streamed.
          */
    -    MyService.create = function create(rpcImpl, requestDelimited, responseDelimited) {
    +    MyService.create = function(rpcImpl, requestDelimited, responseDelimited) {
             return new this(rpcImpl, requestDelimited, responseDelimited);
         };
     
    @@ -71,15 +72,15 @@ $root.MyService = (function() {
          * @name MyService#delete
          * @type {MyService.Delete}
          */
    -    Object.defineProperties(MyService.prototype["delete"] = function delete_(request, callback) {
    -        return this.rpcCall(delete_, $root.MyRequest, $root.MyResponse, request, callback);
    +    $Object.defineProperties(MyService.prototype["delete"] = function(request, callback) {
    +        return $protobuf.rpc.Service.prototype.rpcCall.call(this, MyService.prototype["delete"], $root.MyRequest, $root.MyResponse, request, callback);
         }, {
             name: { value: "Delete" },
             path: { value: "/MyService/Delete" },
             requestType: { value: "MyRequest" },
             responseType: { value: "MyResponse" },
    -        requestStream: { value: undefined },
    -        responseStream: { value: undefined }
    +        requestStream: { value: $undefined },
    +        responseStream: { value: $undefined }
         });
     
         return MyService;
    @@ -115,12 +116,12 @@ $root.MyRequest = (function() {
          * @param {MyRequest.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function MyRequest(properties) {
    +    var MyRequest = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * MyRequest path.
    @@ -142,7 +143,7 @@ $root.MyRequest = (function() {
          *   (properties?: MyRequest.$Properties): MyRequest;
          * }}
          */
    -    MyRequest.create = function create(properties) {
    +    MyRequest.create = function(properties) {
             return new MyRequest(properties);
         };
     
    @@ -155,16 +156,16 @@ $root.MyRequest = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyRequest.encode = function encode(message, writer, _depth) {
    +    MyRequest.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +            throw $Error("max depth exceeded");
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.path);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -179,7 +180,7 @@ $root.MyRequest = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyRequest.encodeDelimited = function encodeDelimited(message, writer) {
    +    MyRequest.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -194,19 +195,19 @@ $root.MyRequest = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyRequest.decode = function decode(reader, length, _end, _depth, _target) {
    +    MyRequest.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.MyRequest(), value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.MyRequest(), value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -227,8 +228,8 @@ $root.MyRequest = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -242,7 +243,7 @@ $root.MyRequest = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyRequest.decodeDelimited = function decodeDelimited(reader) {
    +    MyRequest.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -256,14 +257,14 @@ $root.MyRequest = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    MyRequest.verify = function verify(message, _depth) {
    +    MyRequest.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -277,19 +278,19 @@ $root.MyRequest = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {MyRequest} MyRequest
          */
    -    MyRequest.fromObject = function fromObject(object, _depth) {
    +    MyRequest.fromObject = function (object, _depth) {
             if (object instanceof $root.MyRequest)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".MyRequest: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".MyRequest: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.MyRequest();
             if (object.path != null)
                 if (typeof object.path !== "string" || object.path.length)
    -                message.path = String(object.path);
    +                message.path = $String(object.path);
             return message;
         };
     
    @@ -302,17 +303,17 @@ $root.MyRequest = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    MyRequest.toObject = function toObject(message, options, _depth) {
    +    MyRequest.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
    +        if (message.path != null && $Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -324,8 +325,8 @@ $root.MyRequest = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    MyRequest.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    MyRequest.prototype.toJSON = function() {
    +        return MyRequest.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -336,8 +337,8 @@ $root.MyRequest = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    MyRequest.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    MyRequest.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/MyRequest";
         };
    @@ -375,12 +376,12 @@ $root.MyResponse = (function() {
          * @param {MyResponse.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function MyResponse(properties) {
    +    var MyResponse = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * MyResponse status.
    @@ -402,7 +403,7 @@ $root.MyResponse = (function() {
          *   (properties?: MyResponse.$Properties): MyResponse;
          * }}
          */
    -    MyResponse.create = function create(properties) {
    +    MyResponse.create = function(properties) {
             return new MyResponse(properties);
         };
     
    @@ -415,16 +416,16 @@ $root.MyResponse = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyResponse.encode = function encode(message, writer, _depth) {
    +    MyResponse.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +            throw $Error("max depth exceeded");
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 writer.uint32(/* id 2, wireType 0 =*/16).int32(message.status);
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -439,7 +440,7 @@ $root.MyResponse = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    MyResponse.encodeDelimited = function encodeDelimited(message, writer) {
    +    MyResponse.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -454,19 +455,19 @@ $root.MyResponse = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyResponse.decode = function decode(reader, length, _end, _depth, _target) {
    +    MyResponse.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.MyResponse(), value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.MyResponse(), value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
    @@ -487,8 +488,8 @@ $root.MyResponse = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -502,7 +503,7 @@ $root.MyResponse = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    MyResponse.decodeDelimited = function decodeDelimited(reader) {
    +    MyResponse.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -516,14 +517,14 @@ $root.MyResponse = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    MyResponse.verify = function verify(message, _depth) {
    +    MyResponse.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -537,18 +538,18 @@ $root.MyResponse = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {MyResponse} MyResponse
          */
    -    MyResponse.fromObject = function fromObject(object, _depth) {
    +    MyResponse.fromObject = function (object, _depth) {
             if (object instanceof $root.MyResponse)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".MyResponse: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".MyResponse: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.MyResponse();
             if (object.status != null)
    -            if (Number(object.status) !== 0)
    +            if ($Number(object.status) !== 0)
                     message.status = object.status | 0;
             return message;
         };
    @@ -562,17 +563,17 @@ $root.MyResponse = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    MyResponse.toObject = function toObject(message, options, _depth) {
    +    MyResponse.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
    +        if (message.status != null && $Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    @@ -584,8 +585,8 @@ $root.MyResponse = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    MyResponse.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    MyResponse.prototype.toJSON = function() {
    +        return MyResponse.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -596,8 +597,8 @@ $root.MyResponse = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    MyResponse.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    MyResponse.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/MyResponse";
         };
    
  • tests/data/test.js+3488 3487 modified
  • tests/data/type_url.js+70 69 modified
    @@ -5,6 +5,7 @@ var $protobuf = require("../../minimal");
     
     // Common aliases
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
    +var $Object = $util.global.Object, $undefined = $util.global.undefined, $Error = $util.global.Error, $TypeError = $util.global.TypeError, $String = $util.global.String;
     
     // Exported root namespace
     var $root = $protobuf.roots["test_type_url"] || ($protobuf.roots["test_type_url"] = {});
    @@ -39,12 +40,12 @@ $root.TypeUrlTest = (function() {
          * @param {TypeUrlTest.$Properties=} [properties] Properties to set
          * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
          */
    -    function TypeUrlTest(properties) {
    +    var TypeUrlTest = function (properties) {
             if (properties)
    -            for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +            for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                     if (properties[keys[i]] != null && keys[i] !== "__proto__")
                         this[keys[i]] = properties[keys[i]];
    -    }
    +    };
     
         /**
          * TypeUrlTest nested.
    @@ -66,7 +67,7 @@ $root.TypeUrlTest = (function() {
          *   (properties?: TypeUrlTest.$Properties): TypeUrlTest;
          * }}
          */
    -    TypeUrlTest.create = function create(properties) {
    +    TypeUrlTest.create = function(properties) {
             return new TypeUrlTest(properties);
         };
     
    @@ -79,16 +80,16 @@ $root.TypeUrlTest = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    TypeUrlTest.encode = function encode(message, writer, _depth) {
    +    TypeUrlTest.encode = function (message, writer, _depth) {
             if (!writer)
                 writer = $Writer.create();
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    -        if (message.nested != null && Object.hasOwnProperty.call(message, "nested"))
    +            throw $Error("max depth exceeded");
    +        if (message.nested != null && $Object.hasOwnProperty.call(message, "nested"))
                 $root.TypeUrlTest.Nested.encode(message.nested, writer.uint32(/* id 1, wireType 2 =*/10).fork(), _depth + 1).ldelim();
    -        if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +        if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                 for (var i = 0; i < message.$unknowns.length; ++i)
                     writer.raw(message.$unknowns[i]);
             return writer;
    @@ -103,7 +104,7 @@ $root.TypeUrlTest = (function() {
          * @param {$protobuf.Writer} [writer] Writer to encode to
          * @returns {$protobuf.Writer} Writer
          */
    -    TypeUrlTest.encodeDelimited = function encodeDelimited(message, writer) {
    +    TypeUrlTest.encodeDelimited = function(message, writer) {
             return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
         };
     
    @@ -118,27 +119,27 @@ $root.TypeUrlTest = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    TypeUrlTest.decode = function decode(reader, length, _end, _depth, _target) {
    +    TypeUrlTest.decode = function (reader, length, _end, _depth, _target) {
             if (!(reader instanceof $Reader))
                 reader = $Reader.create(reader);
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $Reader.recursionLimit)
    -            throw Error("max depth exceeded");
    -        var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.TypeUrlTest(), value;
    +            throw $Error("max depth exceeded");
    +        var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.TypeUrlTest(), value;
             while (reader.pos < end) {
                 var start = reader.pos;
                 var tag = reader.tag();
                 if (tag === _end) {
    -                _end = undefined;
    +                _end = $undefined;
                     break;
                 }
                 var wireType = tag & 7;
                 switch (tag >>>= 3) {
                 case 1: {
                         if (wireType !== 2)
                             break;
    -                    message.nested = $root.TypeUrlTest.Nested.decode(reader, reader.uint32(), undefined, _depth + 1, message.nested);
    +                    message.nested = $root.TypeUrlTest.Nested.decode(reader, reader.uint32(), $undefined, _depth + 1, message.nested);
                         continue;
                     }
                 }
    @@ -148,8 +149,8 @@ $root.TypeUrlTest = (function() {
                     (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                 }
             }
    -        if (_end !== undefined)
    -            throw Error("missing end group");
    +        if (_end !== $undefined)
    +            throw $Error("missing end group");
             return message;
         };
     
    @@ -163,7 +164,7 @@ $root.TypeUrlTest = (function() {
          * @throws {Error} If the payload is not a reader or valid buffer
          * @throws {$protobuf.util.ProtocolError} If required fields are missing
          */
    -    TypeUrlTest.decodeDelimited = function decodeDelimited(reader) {
    +    TypeUrlTest.decodeDelimited = function(reader) {
             if (!(reader instanceof $Reader))
                 reader = new $Reader(reader);
             return this.decode(reader, reader.uint32());
    @@ -177,14 +178,14 @@ $root.TypeUrlTest = (function() {
          * @param {Object.<string,*>} message Plain object to verify
          * @returns {string|null} `null` if valid, otherwise the reason why it is not
          */
    -    TypeUrlTest.verify = function verify(message, _depth) {
    +    TypeUrlTest.verify = function (message, _depth) {
             if (typeof message !== "object" || message === null)
                 return "object expected";
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.nested != null && Object.hasOwnProperty.call(message, "nested")) {
    +        if (message.nested != null && $Object.hasOwnProperty.call(message, "nested")) {
                 var error = $root.TypeUrlTest.Nested.verify(message.nested, _depth + 1);
                 if (error)
                     return "nested." + error;
    @@ -200,19 +201,19 @@ $root.TypeUrlTest = (function() {
          * @param {Object.<string,*>} object Plain object
          * @returns {TypeUrlTest} TypeUrlTest
          */
    -    TypeUrlTest.fromObject = function fromObject(object, _depth) {
    +    TypeUrlTest.fromObject = function (object, _depth) {
             if (object instanceof $root.TypeUrlTest)
                 return object;
             if (!$util.isObject(object))
    -            throw TypeError(".TypeUrlTest: object expected");
    -        if (_depth === undefined)
    +            throw $TypeError(".TypeUrlTest: object expected");
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var message = new $root.TypeUrlTest();
             if (object.nested != null) {
                 if (!$util.isObject(object.nested))
    -                throw TypeError(".TypeUrlTest.nested: object expected");
    +                throw $TypeError(".TypeUrlTest.nested: object expected");
                 message.nested = $root.TypeUrlTest.Nested.fromObject(object.nested, _depth + 1);
             }
             return message;
    @@ -227,17 +228,17 @@ $root.TypeUrlTest = (function() {
          * @param {$protobuf.IConversionOptions} [options] Conversion options
          * @returns {Object.<string,*>} Plain object
          */
    -    TypeUrlTest.toObject = function toObject(message, options, _depth) {
    +    TypeUrlTest.toObject = function (message, options, _depth) {
             if (!options)
                 options = {};
    -        if (_depth === undefined)
    +        if (_depth === $undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    -            throw Error("max depth exceeded");
    +            throw $Error("max depth exceeded");
             var object = {};
             if (options.defaults)
                 object.nested = null;
    -        if (message.nested != null && Object.hasOwnProperty.call(message, "nested"))
    +        if (message.nested != null && $Object.hasOwnProperty.call(message, "nested"))
                 object.nested = $root.TypeUrlTest.Nested.toObject(message.nested, options, _depth + 1);
             return object;
         };
    @@ -249,8 +250,8 @@ $root.TypeUrlTest = (function() {
          * @instance
          * @returns {Object.<string,*>} JSON object
          */
    -    TypeUrlTest.prototype.toJSON = function toJSON() {
    -        return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +    TypeUrlTest.prototype.toJSON = function() {
    +        return TypeUrlTest.toObject(this, $protobuf.util.toJSONOptions);
         };
     
         /**
    @@ -261,8 +262,8 @@ $root.TypeUrlTest = (function() {
          * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
          * @returns {string} The type url
          */
    -    TypeUrlTest.getTypeUrl = function getTypeUrl(prefix) {
    -        if (prefix === undefined)
    +    TypeUrlTest.getTypeUrl = function(prefix) {
    +        if (prefix === $undefined)
                 prefix = "type.googleapis.com";
             return prefix + "/TypeUrlTest";
         };
    @@ -297,12 +298,12 @@ $root.TypeUrlTest = (function() {
              * @param {TypeUrlTest.Nested.$Properties=} [properties] Properties to set
              * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
              */
    -        function Nested(properties) {
    +        var Nested = function (properties) {
                 if (properties)
    -                for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
    +                for (var keys = $Object.keys(properties), i = 0; i < keys.length; ++i)
                         if (properties[keys[i]] != null && keys[i] !== "__proto__")
                             this[keys[i]] = properties[keys[i]];
    -        }
    +        };
     
             /**
              * Nested a.
    @@ -324,7 +325,7 @@ $root.TypeUrlTest = (function() {
              *   (properties?: TypeUrlTest.Nested.$Properties): TypeUrlTest.Nested;
              * }}
              */
    -        Nested.create = function create(properties) {
    +        Nested.create = function(properties) {
                 return new Nested(properties);
             };
     
    @@ -337,16 +338,16 @@ $root.TypeUrlTest = (function() {
              * @param {$protobuf.Writer} [writer] Writer to encode to
              * @returns {$protobuf.Writer} Writer
              */
    -        Nested.encode = function encode(message, writer, _depth) {
    +        Nested.encode = function (message, writer, _depth) {
                 if (!writer)
                     writer = $Writer.create();
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    -            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
    +                throw $Error("max depth exceeded");
    +            if (message.a != null && $Object.hasOwnProperty.call(message, "a"))
                     writer.uint32(/* id 1, wireType 2 =*/10).string(message.a);
    -            if (message.$unknowns != null && Object.hasOwnProperty.call(message, "$unknowns"))
    +            if (message.$unknowns != null && $Object.hasOwnProperty.call(message, "$unknowns"))
                     for (var i = 0; i < message.$unknowns.length; ++i)
                         writer.raw(message.$unknowns[i]);
                 return writer;
    @@ -361,7 +362,7 @@ $root.TypeUrlTest = (function() {
              * @param {$protobuf.Writer} [writer] Writer to encode to
              * @returns {$protobuf.Writer} Writer
              */
    -        Nested.encodeDelimited = function encodeDelimited(message, writer) {
    +        Nested.encodeDelimited = function(message, writer) {
                 return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
             };
     
    @@ -376,19 +377,19 @@ $root.TypeUrlTest = (function() {
              * @throws {Error} If the payload is not a reader or valid buffer
              * @throws {$protobuf.util.ProtocolError} If required fields are missing
              */
    -        Nested.decode = function decode(reader, length, _end, _depth, _target) {
    +        Nested.decode = function (reader, length, _end, _depth, _target) {
                 if (!(reader instanceof $Reader))
                     reader = $Reader.create(reader);
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $Reader.recursionLimit)
    -                throw Error("max depth exceeded");
    -            var end = length === undefined ? reader.len : reader.pos + length, message = _target || new $root.TypeUrlTest.Nested(), value;
    +                throw $Error("max depth exceeded");
    +            var end = length === $undefined ? reader.len : reader.pos + length, message = _target || new $root.TypeUrlTest.Nested(), value;
                 while (reader.pos < end) {
                     var start = reader.pos;
                     var tag = reader.tag();
                     if (tag === _end) {
    -                    _end = undefined;
    +                    _end = $undefined;
                         break;
                     }
                     var wireType = tag & 7;
    @@ -409,8 +410,8 @@ $root.TypeUrlTest = (function() {
                         (message.$unknowns || (message.$unknowns = [])).push(reader.raw(start, reader.pos));
                     }
                 }
    -            if (_end !== undefined)
    -                throw Error("missing end group");
    +            if (_end !== $undefined)
    +                throw $Error("missing end group");
                 return message;
             };
     
    @@ -424,7 +425,7 @@ $root.TypeUrlTest = (function() {
              * @throws {Error} If the payload is not a reader or valid buffer
              * @throws {$protobuf.util.ProtocolError} If required fields are missing
              */
    -        Nested.decodeDelimited = function decodeDelimited(reader) {
    +        Nested.decodeDelimited = function(reader) {
                 if (!(reader instanceof $Reader))
                     reader = new $Reader(reader);
                 return this.decode(reader, reader.uint32());
    @@ -438,14 +439,14 @@ $root.TypeUrlTest = (function() {
              * @param {Object.<string,*>} message Plain object to verify
              * @returns {string|null} `null` if valid, otherwise the reason why it is not
              */
    -        Nested.verify = function verify(message, _depth) {
    +        Nested.verify = function (message, _depth) {
                 if (typeof message !== "object" || message === null)
                     return "object expected";
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
                     return "max depth exceeded";
    -            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
    +            if (message.a != null && $Object.hasOwnProperty.call(message, "a"))
                     if (!$util.isString(message.a))
                         return "a: string expected";
                 return null;
    @@ -459,19 +460,19 @@ $root.TypeUrlTest = (function() {
              * @param {Object.<string,*>} object Plain object
              * @returns {TypeUrlTest.Nested} Nested
              */
    -        Nested.fromObject = function fromObject(object, _depth) {
    +        Nested.fromObject = function (object, _depth) {
                 if (object instanceof $root.TypeUrlTest.Nested)
                     return object;
                 if (!$util.isObject(object))
    -                throw TypeError(".TypeUrlTest.Nested: object expected");
    -            if (_depth === undefined)
    +                throw $TypeError(".TypeUrlTest.Nested: object expected");
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 var message = new $root.TypeUrlTest.Nested();
                 if (object.a != null)
                     if (typeof object.a !== "string" || object.a.length)
    -                    message.a = String(object.a);
    +                    message.a = $String(object.a);
                 return message;
             };
     
    @@ -484,17 +485,17 @@ $root.TypeUrlTest = (function() {
              * @param {$protobuf.IConversionOptions} [options] Conversion options
              * @returns {Object.<string,*>} Plain object
              */
    -        Nested.toObject = function toObject(message, options, _depth) {
    +        Nested.toObject = function (message, options, _depth) {
                 if (!options)
                     options = {};
    -            if (_depth === undefined)
    +            if (_depth === $undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    -                throw Error("max depth exceeded");
    +                throw $Error("max depth exceeded");
                 var object = {};
                 if (options.defaults)
                     object.a = "";
    -            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
    +            if (message.a != null && $Object.hasOwnProperty.call(message, "a"))
                     object.a = message.a;
                 return object;
             };
    @@ -506,8 +507,8 @@ $root.TypeUrlTest = (function() {
              * @instance
              * @returns {Object.<string,*>} JSON object
              */
    -        Nested.prototype.toJSON = function toJSON() {
    -            return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
    +        Nested.prototype.toJSON = function() {
    +            return Nested.toObject(this, $protobuf.util.toJSONOptions);
             };
     
             /**
    @@ -518,8 +519,8 @@ $root.TypeUrlTest = (function() {
              * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
              * @returns {string} The type url
              */
    -        Nested.getTypeUrl = function getTypeUrl(prefix) {
    -            if (prefix === undefined)
    +        Nested.getTypeUrl = function(prefix) {
    +            if (prefix === $undefined)
                     prefix = "type.googleapis.com";
                 return prefix + "/TypeUrlTest.Nested";
             };
    
bf20d84c80b0

fix: Support null-prototype plain objects in converters (#2300)

https://github.com/protobufjs/protobuf.jsdcodeIOJun 3, 2026Fixed in protobufjs-cli-v2.5.1via ghsa-release-walk
14 files changed · +853 657
  • src/converter.js+1 1 modified
    @@ -329,7 +329,7 @@ converter.toObject = function toObject(mtype) {
                 genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
             ("}");
             } else { gen
    -    ("if(m%s!=null&&m.hasOwnProperty(%j)){", prop, field.name); // !== undefined && !== null
    +    ("if(m%s!=null&&Object.hasOwnProperty.call(m,%j)){", prop, field.name); // !== undefined && !== null
             genValuePartial_toObject(gen, field, /* sorted */ index, prop);
             if (field.partOf && !field.partOf.isProto3Optional) gen
             ("if(o.oneofs)")
    
  • src/util/minimal.js+1 1 modified
    @@ -119,7 +119,7 @@ util.isset =
      */
     util.isSet = function isSet(obj, prop) {
         var value = obj[prop];
    -    if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
    +    if (value != null && Object.hasOwnProperty.call(obj, prop)) // eslint-disable-line eqeqeq
             return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
         return false;
     };
    
  • src/verifier.js+1 1 modified
    @@ -138,7 +138,7 @@ function verifier(mtype) {
                 ref   = "m" + util.safeProp(field.name);
     
             if (field.optional) gen
    -        ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null
    +        ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name); // !== undefined && !== null
     
             // map fields
             if (field.map) { gen
    
  • tests/api_converters.js+21 0 modified
    @@ -189,6 +189,27 @@ tape.test("converters", function(test) {
     
             });
     
    +        test.test(test.name + " - null-prototype objects", function(test) {
    +            var userRoot = protobuf.parse("syntax = \"proto2\"; message User { optional string name = 1; optional int32 age = 2; }").root,
    +                User = userRoot.lookupType("User"),
    +                user = Object.create(null),
    +                oneofRoot = protobuf.parse("syntax = \"proto3\"; message M { oneof kind { string a = 1; int32 b = 2; } }").root,
    +                M = oneofRoot.lookupType("M"),
    +                oneof = Object.create(null);
    +
    +            user.name = "attacker";
    +            user.age = 99;
    +            test.equal(User.verify(user), null, "verify accepts valid null-prototype objects");
    +
    +            user.age = "bad";
    +            test.equal(User.verify(user), "age: integer expected", "verify returns errors for invalid null-prototype objects");
    +
    +            oneof.a = "x";
    +            test.same(M.toObject(oneof, { oneofs: true }), { a: "x", kind: "a" }, "toObject converts null-prototype oneof objects");
    +
    +            test.end();
    +        });
    +
             test.test(test.name + " - Message.fromObject", function(test) {
     
                 var obj = {
    
  • tests/api_util.js+3 0 modified
    @@ -86,6 +86,9 @@ tape.test("util", function(test) {
                 test.notOk(util.isSet(instance, "p"), "should return that " + name + " on the prototype are not present");
                 test.ok(util.isSet(instance, "i"), "should return that " + name + " on the instance ARE present");
             });
    +        var nullProto = Object.create(null);
    +        nullProto.present = 1;
    +        test.ok(util.isSet(nullProto, "present"), "should support null-prototype objects");
     
              test.end();
         });
    
  • tests/data/comments.js+10 6 modified
    @@ -230,13 +230,13 @@ $root.Test1 = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.field1 != null && message.hasOwnProperty("field1"))
    +        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
                 if (!$util.isString(message.field1))
                     return "field1: string expected";
    -        if (message.field2 != null && message.hasOwnProperty("field2"))
    +        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
                 if (!$util.isInteger(message.field2))
                     return "field2: integer expected";
    -        if (message.field3 != null && message.hasOwnProperty("field3"))
    +        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
                 if (typeof message.field3 !== "boolean")
                     return "field3: boolean expected";
             return null;
    @@ -253,6 +253,8 @@ $root.Test1 = (function() {
         Test1.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.Test1)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".Test1: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -292,11 +294,11 @@ $root.Test1 = (function() {
                 object.field2 = 0;
                 object.field3 = false;
             }
    -        if (message.field1 != null && message.hasOwnProperty("field1"))
    +        if (message.field1 != null && Object.hasOwnProperty.call(message, "field1"))
                 object.field1 = message.field1;
    -        if (message.field2 != null && message.hasOwnProperty("field2"))
    +        if (message.field2 != null && Object.hasOwnProperty.call(message, "field2"))
                 object.field2 = message.field2;
    -        if (message.field3 != null && message.hasOwnProperty("field3"))
    +        if (message.field3 != null && Object.hasOwnProperty.call(message, "field3"))
                 object.field3 = message.field3;
             return object;
         };
    @@ -498,6 +500,8 @@ $root.Test2 = (function() {
         Test2.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.Test2)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".Test2: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    
  • tests/data/convert.js+16 14 modified
    @@ -396,45 +396,45 @@ $root.Message = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.stringVal != null && message.hasOwnProperty("stringVal"))
    +        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
                 if (!$util.isString(message.stringVal))
                     return "stringVal: string expected";
    -        if (message.stringRepeated != null && message.hasOwnProperty("stringRepeated")) {
    +        if (message.stringRepeated != null && Object.hasOwnProperty.call(message, "stringRepeated")) {
                 if (!Array.isArray(message.stringRepeated))
                     return "stringRepeated: array expected";
                 for (var i = 0; i < message.stringRepeated.length; ++i)
                     if (!$util.isString(message.stringRepeated[i]))
                         return "stringRepeated: string[] expected";
             }
    -        if (message.uint64Val != null && message.hasOwnProperty("uint64Val"))
    +        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
                 if (!$util.isInteger(message.uint64Val) && !(message.uint64Val && $util.isInteger(message.uint64Val.low) && $util.isInteger(message.uint64Val.high)))
                     return "uint64Val: integer|Long expected";
    -        if (message.uint64Repeated != null && message.hasOwnProperty("uint64Repeated")) {
    +        if (message.uint64Repeated != null && Object.hasOwnProperty.call(message, "uint64Repeated")) {
                 if (!Array.isArray(message.uint64Repeated))
                     return "uint64Repeated: array expected";
                 for (var i = 0; i < message.uint64Repeated.length; ++i)
                     if (!$util.isInteger(message.uint64Repeated[i]) && !(message.uint64Repeated[i] && $util.isInteger(message.uint64Repeated[i].low) && $util.isInteger(message.uint64Repeated[i].high)))
                         return "uint64Repeated: integer|Long[] expected";
             }
    -        if (message.bytesVal != null && message.hasOwnProperty("bytesVal"))
    +        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
                 if (!(message.bytesVal && typeof message.bytesVal.length === "number" || $util.isString(message.bytesVal)))
                     return "bytesVal: buffer expected";
    -        if (message.bytesRepeated != null && message.hasOwnProperty("bytesRepeated")) {
    +        if (message.bytesRepeated != null && Object.hasOwnProperty.call(message, "bytesRepeated")) {
                 if (!Array.isArray(message.bytesRepeated))
                     return "bytesRepeated: array expected";
                 for (var i = 0; i < message.bytesRepeated.length; ++i)
                     if (!(message.bytesRepeated[i] && typeof message.bytesRepeated[i].length === "number" || $util.isString(message.bytesRepeated[i])))
                         return "bytesRepeated: buffer[] expected";
             }
    -        if (message.enumVal != null && message.hasOwnProperty("enumVal"))
    +        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
                 switch (message.enumVal) {
                 default:
                     return "enumVal: enum value expected";
                 case 1:
                 case 2:
                     break;
                 }
    -        if (message.enumRepeated != null && message.hasOwnProperty("enumRepeated")) {
    +        if (message.enumRepeated != null && Object.hasOwnProperty.call(message, "enumRepeated")) {
                 if (!Array.isArray(message.enumRepeated))
                     return "enumRepeated: array expected";
                 for (var i = 0; i < message.enumRepeated.length; ++i)
    @@ -446,7 +446,7 @@ $root.Message = (function() {
                         break;
                     }
             }
    -        if (message.int64Map != null && message.hasOwnProperty("int64Map")) {
    +        if (message.int64Map != null && Object.hasOwnProperty.call(message, "int64Map")) {
                 if (!$util.isObject(message.int64Map))
                     return "int64Map: object expected";
                 var key = Object.keys(message.int64Map);
    @@ -468,6 +468,8 @@ $root.Message = (function() {
         Message.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.Message)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".Message: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -562,7 +564,7 @@ $root.Message = (function() {
                     }
             }
             if (object.int64Map) {
    -            if (typeof object.int64Map !== "object")
    +            if (!$util.isObject(object.int64Map))
                     throw TypeError(".Message.int64Map: object expected");
                 message.int64Map = {};
                 for (var keys = Object.keys(object.int64Map), i = 0; i < keys.length; ++i) {
    @@ -622,14 +624,14 @@ $root.Message = (function() {
                 }
                 object.enumVal = options.enums === String ? "ONE" : 1;
             }
    -        if (message.stringVal != null && message.hasOwnProperty("stringVal"))
    +        if (message.stringVal != null && Object.hasOwnProperty.call(message, "stringVal"))
                 object.stringVal = message.stringVal;
             if (message.stringRepeated && message.stringRepeated.length) {
                 object.stringRepeated = Array(message.stringRepeated.length);
                 for (var j = 0; j < message.stringRepeated.length; ++j)
                     object.stringRepeated[j] = message.stringRepeated[j];
             }
    -        if (message.uint64Val != null && message.hasOwnProperty("uint64Val"))
    +        if (message.uint64Val != null && Object.hasOwnProperty.call(message, "uint64Val"))
                 if (typeof BigInt !== "undefined" && options.longs === BigInt)
                     object.uint64Val = typeof message.uint64Val === "number" ? BigInt(message.uint64Val) : $util.Long.fromBits(message.uint64Val.low >>> 0, message.uint64Val.high >>> 0, true).toBigInt();
                 else if (typeof message.uint64Val === "number")
    @@ -646,14 +648,14 @@ $root.Message = (function() {
                     else
                         object.uint64Repeated[j] = options.longs === String ? $util.Long.prototype.toString.call(message.uint64Repeated[j]) : options.longs === Number ? new $util.LongBits(message.uint64Repeated[j].low >>> 0, message.uint64Repeated[j].high >>> 0).toNumber(true) : message.uint64Repeated[j];
             }
    -        if (message.bytesVal != null && message.hasOwnProperty("bytesVal"))
    +        if (message.bytesVal != null && Object.hasOwnProperty.call(message, "bytesVal"))
                 object.bytesVal = options.bytes === String ? $util.base64.encode(message.bytesVal, 0, message.bytesVal.length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesVal) : message.bytesVal;
             if (message.bytesRepeated && message.bytesRepeated.length) {
                 object.bytesRepeated = Array(message.bytesRepeated.length);
                 for (var j = 0; j < message.bytesRepeated.length; ++j)
                     object.bytesRepeated[j] = options.bytes === String ? $util.base64.encode(message.bytesRepeated[j], 0, message.bytesRepeated[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesRepeated[j]) : message.bytesRepeated[j];
             }
    -        if (message.enumVal != null && message.hasOwnProperty("enumVal"))
    +        if (message.enumVal != null && Object.hasOwnProperty.call(message, "enumVal"))
                 object.enumVal = options.enums === String ? $root.Message.SomeEnum[message.enumVal] === undefined ? message.enumVal : $root.Message.SomeEnum[message.enumVal] : message.enumVal;
             if (message.enumRepeated && message.enumRepeated.length) {
                 object.enumRepeated = Array(message.enumRepeated.length);
    
  • tests/data/mapbox/vector_tile.js+39 31 modified
    @@ -197,7 +197,7 @@ $root.vector_tile = (function() {
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
                     return "max depth exceeded";
    -            if (message.layers != null && message.hasOwnProperty("layers")) {
    +            if (message.layers != null && Object.hasOwnProperty.call(message, "layers")) {
                     if (!Array.isArray(message.layers))
                         return "layers: array expected";
                     for (var i = 0; i < message.layers.length; ++i) {
    @@ -220,6 +220,8 @@ $root.vector_tile = (function() {
             Tile.fromObject = function fromObject(object, _depth) {
                 if (object instanceof $root.vector_tile.Tile)
                     return object;
    +            if (!$util.isObject(object))
    +                throw TypeError(".vector_tile.Tile: object expected");
                 if (_depth === undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    @@ -230,7 +232,7 @@ $root.vector_tile = (function() {
                         throw TypeError(".vector_tile.Tile.layers: array expected");
                     message.layers = Array(object.layers.length);
                     for (var i = 0; i < object.layers.length; ++i) {
    -                    if (typeof object.layers[i] !== "object")
    +                    if (!$util.isObject(object.layers[i]))
                             throw TypeError(".vector_tile.Tile.layers: object expected");
                         message.layers[i] = $root.vector_tile.Tile.Layer.fromObject(object.layers[i], _depth + 1);
                     }
    @@ -585,25 +587,25 @@ $root.vector_tile = (function() {
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
                         return "max depth exceeded";
    -                if (message.stringValue != null && message.hasOwnProperty("stringValue"))
    +                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
                         if (!$util.isString(message.stringValue))
                             return "stringValue: string expected";
    -                if (message.floatValue != null && message.hasOwnProperty("floatValue"))
    +                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
                         if (typeof message.floatValue !== "number")
                             return "floatValue: number expected";
    -                if (message.doubleValue != null && message.hasOwnProperty("doubleValue"))
    +                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
                         if (typeof message.doubleValue !== "number")
                             return "doubleValue: number expected";
    -                if (message.intValue != null && message.hasOwnProperty("intValue"))
    +                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
                         if (!$util.isInteger(message.intValue) && !(message.intValue && $util.isInteger(message.intValue.low) && $util.isInteger(message.intValue.high)))
                             return "intValue: integer|Long expected";
    -                if (message.uintValue != null && message.hasOwnProperty("uintValue"))
    +                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
                         if (!$util.isInteger(message.uintValue) && !(message.uintValue && $util.isInteger(message.uintValue.low) && $util.isInteger(message.uintValue.high)))
                             return "uintValue: integer|Long expected";
    -                if (message.sintValue != null && message.hasOwnProperty("sintValue"))
    +                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
                         if (!$util.isInteger(message.sintValue) && !(message.sintValue && $util.isInteger(message.sintValue.low) && $util.isInteger(message.sintValue.high)))
                             return "sintValue: integer|Long expected";
    -                if (message.boolValue != null && message.hasOwnProperty("boolValue"))
    +                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
                         if (typeof message.boolValue !== "boolean")
                             return "boolValue: boolean expected";
                     return null;
    @@ -620,6 +622,8 @@ $root.vector_tile = (function() {
                 Value.fromObject = function fromObject(object, _depth) {
                     if (object instanceof $root.vector_tile.Tile.Value)
                         return object;
    +                if (!$util.isObject(object))
    +                    throw TypeError(".vector_tile.Tile.Value: object expected");
                     if (_depth === undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    @@ -701,34 +705,34 @@ $root.vector_tile = (function() {
                             object.sintValue = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
                         object.boolValue = false;
                     }
    -                if (message.stringValue != null && message.hasOwnProperty("stringValue"))
    +                if (message.stringValue != null && Object.hasOwnProperty.call(message, "stringValue"))
                         object.stringValue = message.stringValue;
    -                if (message.floatValue != null && message.hasOwnProperty("floatValue"))
    +                if (message.floatValue != null && Object.hasOwnProperty.call(message, "floatValue"))
                         object.floatValue = options.json && !isFinite(message.floatValue) ? String(message.floatValue) : message.floatValue;
    -                if (message.doubleValue != null && message.hasOwnProperty("doubleValue"))
    +                if (message.doubleValue != null && Object.hasOwnProperty.call(message, "doubleValue"))
                         object.doubleValue = options.json && !isFinite(message.doubleValue) ? String(message.doubleValue) : message.doubleValue;
    -                if (message.intValue != null && message.hasOwnProperty("intValue"))
    +                if (message.intValue != null && Object.hasOwnProperty.call(message, "intValue"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.intValue = typeof message.intValue === "number" ? BigInt(message.intValue) : $util.Long.fromBits(message.intValue.low >>> 0, message.intValue.high >>> 0, false).toBigInt();
                         else if (typeof message.intValue === "number")
                             object.intValue = options.longs === String ? String(message.intValue) : message.intValue;
                         else
                             object.intValue = options.longs === String ? $util.Long.prototype.toString.call(message.intValue) : options.longs === Number ? new $util.LongBits(message.intValue.low >>> 0, message.intValue.high >>> 0).toNumber() : message.intValue;
    -                if (message.uintValue != null && message.hasOwnProperty("uintValue"))
    +                if (message.uintValue != null && Object.hasOwnProperty.call(message, "uintValue"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.uintValue = typeof message.uintValue === "number" ? BigInt(message.uintValue) : $util.Long.fromBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0, true).toBigInt();
                         else if (typeof message.uintValue === "number")
                             object.uintValue = options.longs === String ? String(message.uintValue) : message.uintValue;
                         else
                             object.uintValue = options.longs === String ? $util.Long.prototype.toString.call(message.uintValue) : options.longs === Number ? new $util.LongBits(message.uintValue.low >>> 0, message.uintValue.high >>> 0).toNumber(true) : message.uintValue;
    -                if (message.sintValue != null && message.hasOwnProperty("sintValue"))
    +                if (message.sintValue != null && Object.hasOwnProperty.call(message, "sintValue"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.sintValue = typeof message.sintValue === "number" ? BigInt(message.sintValue) : $util.Long.fromBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0, false).toBigInt();
                         else if (typeof message.sintValue === "number")
                             object.sintValue = options.longs === String ? String(message.sintValue) : message.sintValue;
                         else
                             object.sintValue = options.longs === String ? $util.Long.prototype.toString.call(message.sintValue) : options.longs === Number ? new $util.LongBits(message.sintValue.low >>> 0, message.sintValue.high >>> 0).toNumber() : message.sintValue;
    -                if (message.boolValue != null && message.hasOwnProperty("boolValue"))
    +                if (message.boolValue != null && Object.hasOwnProperty.call(message, "boolValue"))
                         object.boolValue = message.boolValue;
                     return object;
                 };
    @@ -1017,17 +1021,17 @@ $root.vector_tile = (function() {
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
                         return "max depth exceeded";
    -                if (message.id != null && message.hasOwnProperty("id"))
    +                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
                         if (!$util.isInteger(message.id) && !(message.id && $util.isInteger(message.id.low) && $util.isInteger(message.id.high)))
                             return "id: integer|Long expected";
    -                if (message.tags != null && message.hasOwnProperty("tags")) {
    +                if (message.tags != null && Object.hasOwnProperty.call(message, "tags")) {
                         if (!Array.isArray(message.tags))
                             return "tags: array expected";
                         for (var i = 0; i < message.tags.length; ++i)
                             if (!$util.isInteger(message.tags[i]))
                                 return "tags: integer[] expected";
                     }
    -                if (message.type != null && message.hasOwnProperty("type"))
    +                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                         switch (message.type) {
                         default:
                             return "type: enum value expected";
    @@ -1037,7 +1041,7 @@ $root.vector_tile = (function() {
                         case 3:
                             break;
                         }
    -                if (message.geometry != null && message.hasOwnProperty("geometry")) {
    +                if (message.geometry != null && Object.hasOwnProperty.call(message, "geometry")) {
                         if (!Array.isArray(message.geometry))
                             return "geometry: array expected";
                         for (var i = 0; i < message.geometry.length; ++i)
    @@ -1058,6 +1062,8 @@ $root.vector_tile = (function() {
                 Feature.fromObject = function fromObject(object, _depth) {
                     if (object instanceof $root.vector_tile.Tile.Feature)
                         return object;
    +                if (!$util.isObject(object))
    +                    throw TypeError(".vector_tile.Tile.Feature: object expected");
                     if (_depth === undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    @@ -1142,7 +1148,7 @@ $root.vector_tile = (function() {
                             object.id = options.longs === String ? "0" : typeof BigInt !== "undefined" && options.longs === BigInt ? BigInt("0") : 0;
                         object.type = options.enums === String ? "UNKNOWN" : 0;
                     }
    -                if (message.id != null && message.hasOwnProperty("id"))
    +                if (message.id != null && Object.hasOwnProperty.call(message, "id"))
                         if (typeof BigInt !== "undefined" && options.longs === BigInt)
                             object.id = typeof message.id === "number" ? BigInt(message.id) : $util.Long.fromBits(message.id.low >>> 0, message.id.high >>> 0, true).toBigInt();
                         else if (typeof message.id === "number")
    @@ -1154,7 +1160,7 @@ $root.vector_tile = (function() {
                         for (var j = 0; j < message.tags.length; ++j)
                             object.tags[j] = message.tags[j];
                     }
    -                if (message.type != null && message.hasOwnProperty("type"))
    +                if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                         object.type = options.enums === String ? $root.vector_tile.Tile.GeomType[message.type] === undefined ? message.type : $root.vector_tile.Tile.GeomType[message.type] : message.type;
                     if (message.geometry && message.geometry.length) {
                         object.geometry = Array(message.geometry.length);
    @@ -1470,7 +1476,7 @@ $root.vector_tile = (function() {
                         return "version: integer expected";
                     if (!$util.isString(message.name))
                         return "name: string expected";
    -                if (message.features != null && message.hasOwnProperty("features")) {
    +                if (message.features != null && Object.hasOwnProperty.call(message, "features")) {
                         if (!Array.isArray(message.features))
                             return "features: array expected";
                         for (var i = 0; i < message.features.length; ++i) {
    @@ -1479,14 +1485,14 @@ $root.vector_tile = (function() {
                                 return "features." + error;
                         }
                     }
    -                if (message.keys != null && message.hasOwnProperty("keys")) {
    +                if (message.keys != null && Object.hasOwnProperty.call(message, "keys")) {
                         if (!Array.isArray(message.keys))
                             return "keys: array expected";
                         for (var i = 0; i < message.keys.length; ++i)
                             if (!$util.isString(message.keys[i]))
                                 return "keys: string[] expected";
                     }
    -                if (message.values != null && message.hasOwnProperty("values")) {
    +                if (message.values != null && Object.hasOwnProperty.call(message, "values")) {
                         if (!Array.isArray(message.values))
                             return "values: array expected";
                         for (var i = 0; i < message.values.length; ++i) {
    @@ -1495,7 +1501,7 @@ $root.vector_tile = (function() {
                                 return "values." + error;
                         }
                     }
    -                if (message.extent != null && message.hasOwnProperty("extent"))
    +                if (message.extent != null && Object.hasOwnProperty.call(message, "extent"))
                         if (!$util.isInteger(message.extent))
                             return "extent: integer expected";
                     return null;
    @@ -1512,6 +1518,8 @@ $root.vector_tile = (function() {
                 Layer.fromObject = function fromObject(object, _depth) {
                     if (object instanceof $root.vector_tile.Tile.Layer)
                         return object;
    +                if (!$util.isObject(object))
    +                    throw TypeError(".vector_tile.Tile.Layer: object expected");
                     if (_depth === undefined)
                         _depth = 0;
                     if (_depth > $util.recursionLimit)
    @@ -1526,7 +1534,7 @@ $root.vector_tile = (function() {
                             throw TypeError(".vector_tile.Tile.Layer.features: array expected");
                         message.features = Array(object.features.length);
                         for (var i = 0; i < object.features.length; ++i) {
    -                        if (typeof object.features[i] !== "object")
    +                        if (!$util.isObject(object.features[i]))
                                 throw TypeError(".vector_tile.Tile.Layer.features: object expected");
                             message.features[i] = $root.vector_tile.Tile.Feature.fromObject(object.features[i], _depth + 1);
                         }
    @@ -1543,7 +1551,7 @@ $root.vector_tile = (function() {
                             throw TypeError(".vector_tile.Tile.Layer.values: array expected");
                         message.values = Array(object.values.length);
                         for (var i = 0; i < object.values.length; ++i) {
    -                        if (typeof object.values[i] !== "object")
    +                        if (!$util.isObject(object.values[i]))
                                 throw TypeError(".vector_tile.Tile.Layer.values: object expected");
                             message.values[i] = $root.vector_tile.Tile.Value.fromObject(object.values[i], _depth + 1);
                         }
    @@ -1580,7 +1588,7 @@ $root.vector_tile = (function() {
                         object.extent = 4096;
                         object.version = 1;
                     }
    -                if (message.name != null && message.hasOwnProperty("name"))
    +                if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                         object.name = message.name;
                     if (message.features && message.features.length) {
                         object.features = Array(message.features.length);
    @@ -1597,9 +1605,9 @@ $root.vector_tile = (function() {
                         for (var j = 0; j < message.values.length; ++j)
                             object.values[j] = $root.vector_tile.Tile.Value.toObject(message.values[j], options, _depth + 1);
                     }
    -                if (message.extent != null && message.hasOwnProperty("extent"))
    +                if (message.extent != null && Object.hasOwnProperty.call(message, "extent"))
                         object.extent = message.extent;
    -                if (message.version != null && message.hasOwnProperty("version"))
    +                if (message.version != null && Object.hasOwnProperty.call(message, "version"))
                         object.version = message.version;
                     return object;
                 };
    
  • tests/data/package.js+41 37 modified
    @@ -598,81 +598,81 @@ $root.Package = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.name != null && message.hasOwnProperty("name"))
    +        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                 if (!$util.isString(message.name))
                     return "name: string expected";
    -        if (message.version != null && message.hasOwnProperty("version"))
    +        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
                 if (!$util.isString(message.version))
                     return "version: string expected";
    -        if (message.versionScheme != null && message.hasOwnProperty("versionScheme"))
    +        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
                 if (!$util.isString(message.versionScheme))
                     return "versionScheme: string expected";
    -        if (message.description != null && message.hasOwnProperty("description"))
    +        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
                 if (!$util.isString(message.description))
                     return "description: string expected";
    -        if (message.author != null && message.hasOwnProperty("author"))
    +        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
                 if (!$util.isString(message.author))
                     return "author: string expected";
    -        if (message.license != null && message.hasOwnProperty("license"))
    +        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
                 if (!$util.isString(message.license))
                     return "license: string expected";
    -        if (message.repository != null && message.hasOwnProperty("repository")) {
    +        if (message.repository != null && Object.hasOwnProperty.call(message, "repository")) {
                 var error = $root.Package.Repository.verify(message.repository, _depth + 1);
                 if (error)
                     return "repository." + error;
             }
    -        if (message.bugs != null && message.hasOwnProperty("bugs"))
    +        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
                 if (!$util.isString(message.bugs))
                     return "bugs: string expected";
    -        if (message.homepage != null && message.hasOwnProperty("homepage"))
    +        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
                 if (!$util.isString(message.homepage))
                     return "homepage: string expected";
    -        if (message.keywords != null && message.hasOwnProperty("keywords")) {
    +        if (message.keywords != null && Object.hasOwnProperty.call(message, "keywords")) {
                 if (!Array.isArray(message.keywords))
                     return "keywords: array expected";
                 for (var i = 0; i < message.keywords.length; ++i)
                     if (!$util.isString(message.keywords[i]))
                         return "keywords: string[] expected";
             }
    -        if (message.main != null && message.hasOwnProperty("main"))
    +        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
                 if (!$util.isString(message.main))
                     return "main: string expected";
    -        if (message.bin != null && message.hasOwnProperty("bin")) {
    +        if (message.bin != null && Object.hasOwnProperty.call(message, "bin")) {
                 if (!$util.isObject(message.bin))
                     return "bin: object expected";
                 var key = Object.keys(message.bin);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.bin[key[i]]))
                         return "bin: string{k:string} expected";
             }
    -        if (message.scripts != null && message.hasOwnProperty("scripts")) {
    +        if (message.scripts != null && Object.hasOwnProperty.call(message, "scripts")) {
                 if (!$util.isObject(message.scripts))
                     return "scripts: object expected";
                 var key = Object.keys(message.scripts);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.scripts[key[i]]))
                         return "scripts: string{k:string} expected";
             }
    -        if (message.dependencies != null && message.hasOwnProperty("dependencies")) {
    +        if (message.dependencies != null && Object.hasOwnProperty.call(message, "dependencies")) {
                 if (!$util.isObject(message.dependencies))
                     return "dependencies: object expected";
                 var key = Object.keys(message.dependencies);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.dependencies[key[i]]))
                         return "dependencies: string{k:string} expected";
             }
    -        if (message.devDependencies != null && message.hasOwnProperty("devDependencies")) {
    +        if (message.devDependencies != null && Object.hasOwnProperty.call(message, "devDependencies")) {
                 if (!$util.isObject(message.devDependencies))
                     return "devDependencies: object expected";
                 var key = Object.keys(message.devDependencies);
                 for (var i = 0; i < key.length; ++i)
                     if (!$util.isString(message.devDependencies[key[i]]))
                         return "devDependencies: string{k:string} expected";
             }
    -        if (message.types != null && message.hasOwnProperty("types"))
    +        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
                 if (!$util.isString(message.types))
                     return "types: string expected";
    -        if (message.cliDependencies != null && message.hasOwnProperty("cliDependencies")) {
    +        if (message.cliDependencies != null && Object.hasOwnProperty.call(message, "cliDependencies")) {
                 if (!Array.isArray(message.cliDependencies))
                     return "cliDependencies: array expected";
                 for (var i = 0; i < message.cliDependencies.length; ++i)
    @@ -693,6 +693,8 @@ $root.Package = (function() {
         Package.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.Package)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".Package: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -717,7 +719,7 @@ $root.Package = (function() {
                 if (typeof object.license !== "string" || object.license.length)
                     message.license = String(object.license);
             if (object.repository != null) {
    -            if (typeof object.repository !== "object")
    +            if (!$util.isObject(object.repository))
                     throw TypeError(".Package.repository: object expected");
                 message.repository = $root.Package.Repository.fromObject(object.repository, _depth + 1);
             }
    @@ -738,7 +740,7 @@ $root.Package = (function() {
                 if (typeof object.main !== "string" || object.main.length)
                     message.main = String(object.main);
             if (object.bin) {
    -            if (typeof object.bin !== "object")
    +            if (!$util.isObject(object.bin))
                     throw TypeError(".Package.bin: object expected");
                 message.bin = {};
                 for (var keys = Object.keys(object.bin), i = 0; i < keys.length; ++i) {
    @@ -748,7 +750,7 @@ $root.Package = (function() {
                 }
             }
             if (object.scripts) {
    -            if (typeof object.scripts !== "object")
    +            if (!$util.isObject(object.scripts))
                     throw TypeError(".Package.scripts: object expected");
                 message.scripts = {};
                 for (var keys = Object.keys(object.scripts), i = 0; i < keys.length; ++i) {
    @@ -758,7 +760,7 @@ $root.Package = (function() {
                 }
             }
             if (object.dependencies) {
    -            if (typeof object.dependencies !== "object")
    +            if (!$util.isObject(object.dependencies))
                     throw TypeError(".Package.dependencies: object expected");
                 message.dependencies = {};
                 for (var keys = Object.keys(object.dependencies), i = 0; i < keys.length; ++i) {
    @@ -768,7 +770,7 @@ $root.Package = (function() {
                 }
             }
             if (object.devDependencies) {
    -            if (typeof object.devDependencies !== "object")
    +            if (!$util.isObject(object.devDependencies))
                     throw TypeError(".Package.devDependencies: object expected");
                 message.devDependencies = {};
                 for (var keys = Object.keys(object.devDependencies), i = 0; i < keys.length; ++i) {
    @@ -830,28 +832,28 @@ $root.Package = (function() {
                 object.types = "";
                 object.versionScheme = "";
             }
    -        if (message.name != null && message.hasOwnProperty("name"))
    +        if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                 object.name = message.name;
    -        if (message.version != null && message.hasOwnProperty("version"))
    +        if (message.version != null && Object.hasOwnProperty.call(message, "version"))
                 object.version = message.version;
    -        if (message.description != null && message.hasOwnProperty("description"))
    +        if (message.description != null && Object.hasOwnProperty.call(message, "description"))
                 object.description = message.description;
    -        if (message.author != null && message.hasOwnProperty("author"))
    +        if (message.author != null && Object.hasOwnProperty.call(message, "author"))
                 object.author = message.author;
    -        if (message.license != null && message.hasOwnProperty("license"))
    +        if (message.license != null && Object.hasOwnProperty.call(message, "license"))
                 object.license = message.license;
    -        if (message.repository != null && message.hasOwnProperty("repository"))
    +        if (message.repository != null && Object.hasOwnProperty.call(message, "repository"))
                 object.repository = $root.Package.Repository.toObject(message.repository, options, _depth + 1);
    -        if (message.bugs != null && message.hasOwnProperty("bugs"))
    +        if (message.bugs != null && Object.hasOwnProperty.call(message, "bugs"))
                 object.bugs = message.bugs;
    -        if (message.homepage != null && message.hasOwnProperty("homepage"))
    +        if (message.homepage != null && Object.hasOwnProperty.call(message, "homepage"))
                 object.homepage = message.homepage;
             if (message.keywords && message.keywords.length) {
                 object.keywords = Array(message.keywords.length);
                 for (var j = 0; j < message.keywords.length; ++j)
                     object.keywords[j] = message.keywords[j];
             }
    -        if (message.main != null && message.hasOwnProperty("main"))
    +        if (message.main != null && Object.hasOwnProperty.call(message, "main"))
                 object.main = message.main;
             var keys2;
             if (message.bin && (keys2 = Object.keys(message.bin)).length) {
    @@ -886,14 +888,14 @@ $root.Package = (function() {
                     object.devDependencies[keys2[j]] = message.devDependencies[keys2[j]];
                 }
             }
    -        if (message.types != null && message.hasOwnProperty("types"))
    +        if (message.types != null && Object.hasOwnProperty.call(message, "types"))
                 object.types = message.types;
             if (message.cliDependencies && message.cliDependencies.length) {
                 object.cliDependencies = Array(message.cliDependencies.length);
                 for (var j = 0; j < message.cliDependencies.length; ++j)
                     object.cliDependencies[j] = message.cliDependencies[j];
             }
    -        if (message.versionScheme != null && message.hasOwnProperty("versionScheme"))
    +        if (message.versionScheme != null && Object.hasOwnProperty.call(message, "versionScheme"))
                 object.versionScheme = message.versionScheme;
             return object;
         };
    @@ -1121,10 +1123,10 @@ $root.Package = (function() {
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
                     return "max depth exceeded";
    -            if (message.type != null && message.hasOwnProperty("type"))
    +            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                     if (!$util.isString(message.type))
                         return "type: string expected";
    -            if (message.url != null && message.hasOwnProperty("url"))
    +            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
                     if (!$util.isString(message.url))
                         return "url: string expected";
                 return null;
    @@ -1141,6 +1143,8 @@ $root.Package = (function() {
             Repository.fromObject = function fromObject(object, _depth) {
                 if (object instanceof $root.Package.Repository)
                     return object;
    +            if (!$util.isObject(object))
    +                throw TypeError(".Package.Repository: object expected");
                 if (_depth === undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    @@ -1176,9 +1180,9 @@ $root.Package = (function() {
                     object.type = "";
                     object.url = "";
                 }
    -            if (message.type != null && message.hasOwnProperty("type"))
    +            if (message.type != null && Object.hasOwnProperty.call(message, "type"))
                     object.type = message.type;
    -            if (message.url != null && message.hasOwnProperty("url"))
    +            if (message.url != null && Object.hasOwnProperty.call(message, "url"))
                     object.url = message.url;
                 return object;
             };
    
  • tests/data/rpc-es6.js+8 4 modified
    @@ -261,7 +261,7 @@ export const MyRequest = $root.MyRequest = (() => {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -278,6 +278,8 @@ export const MyRequest = $root.MyRequest = (() => {
         MyRequest.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.MyRequest)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".MyRequest: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -308,7 +310,7 @@ export const MyRequest = $root.MyRequest = (() => {
             let object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -519,7 +521,7 @@ export const MyResponse = $root.MyResponse = (() => {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -536,6 +538,8 @@ export const MyResponse = $root.MyResponse = (() => {
         MyResponse.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.MyResponse)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".MyResponse: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -566,7 +570,7 @@ export const MyResponse = $root.MyResponse = (() => {
             let object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    
  • tests/data/rpc.js+8 4 modified
    @@ -263,7 +263,7 @@ $root.MyRequest = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -280,6 +280,8 @@ $root.MyRequest = (function() {
         MyRequest.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.MyRequest)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".MyRequest: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -310,7 +312,7 @@ $root.MyRequest = (function() {
             var object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -521,7 +523,7 @@ $root.MyResponse = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -538,6 +540,8 @@ $root.MyResponse = (function() {
         MyResponse.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.MyResponse)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".MyResponse: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -568,7 +572,7 @@ $root.MyResponse = (function() {
             var object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    
  • tests/data/rpc-reserved.js+8 4 modified
    @@ -263,7 +263,7 @@ $root.MyRequest = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 if (!$util.isString(message.path))
                     return "path: string expected";
             return null;
    @@ -280,6 +280,8 @@ $root.MyRequest = (function() {
         MyRequest.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.MyRequest)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".MyRequest: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -310,7 +312,7 @@ $root.MyRequest = (function() {
             var object = {};
             if (options.defaults)
                 object.path = "";
    -        if (message.path != null && message.hasOwnProperty("path"))
    +        if (message.path != null && Object.hasOwnProperty.call(message, "path"))
                 object.path = message.path;
             return object;
         };
    @@ -521,7 +523,7 @@ $root.MyResponse = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 if (!$util.isInteger(message.status))
                     return "status: integer expected";
             return null;
    @@ -538,6 +540,8 @@ $root.MyResponse = (function() {
         MyResponse.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.MyResponse)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".MyResponse: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
    @@ -568,7 +572,7 @@ $root.MyResponse = (function() {
             var object = {};
             if (options.defaults)
                 object.status = 0;
    -        if (message.status != null && message.hasOwnProperty("status"))
    +        if (message.status != null && Object.hasOwnProperty.call(message, "status"))
                 object.status = message.status;
             return object;
         };
    
  • tests/data/test.js+687 549 modified
  • tests/data/type_url.js+9 5 modified
    @@ -184,7 +184,7 @@ $root.TypeUrlTest = (function() {
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 return "max depth exceeded";
    -        if (message.nested != null && message.hasOwnProperty("nested")) {
    +        if (message.nested != null && Object.hasOwnProperty.call(message, "nested")) {
                 var error = $root.TypeUrlTest.Nested.verify(message.nested, _depth + 1);
                 if (error)
                     return "nested." + error;
    @@ -203,13 +203,15 @@ $root.TypeUrlTest = (function() {
         TypeUrlTest.fromObject = function fromObject(object, _depth) {
             if (object instanceof $root.TypeUrlTest)
                 return object;
    +        if (!$util.isObject(object))
    +            throw TypeError(".TypeUrlTest: object expected");
             if (_depth === undefined)
                 _depth = 0;
             if (_depth > $util.recursionLimit)
                 throw Error("max depth exceeded");
             var message = new $root.TypeUrlTest();
             if (object.nested != null) {
    -            if (typeof object.nested !== "object")
    +            if (!$util.isObject(object.nested))
                     throw TypeError(".TypeUrlTest.nested: object expected");
                 message.nested = $root.TypeUrlTest.Nested.fromObject(object.nested, _depth + 1);
             }
    @@ -235,7 +237,7 @@ $root.TypeUrlTest = (function() {
             var object = {};
             if (options.defaults)
                 object.nested = null;
    -        if (message.nested != null && message.hasOwnProperty("nested"))
    +        if (message.nested != null && Object.hasOwnProperty.call(message, "nested"))
                 object.nested = $root.TypeUrlTest.Nested.toObject(message.nested, options, _depth + 1);
             return object;
         };
    @@ -443,7 +445,7 @@ $root.TypeUrlTest = (function() {
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
                     return "max depth exceeded";
    -            if (message.a != null && message.hasOwnProperty("a"))
    +            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
                     if (!$util.isString(message.a))
                         return "a: string expected";
                 return null;
    @@ -460,6 +462,8 @@ $root.TypeUrlTest = (function() {
             Nested.fromObject = function fromObject(object, _depth) {
                 if (object instanceof $root.TypeUrlTest.Nested)
                     return object;
    +            if (!$util.isObject(object))
    +                throw TypeError(".TypeUrlTest.Nested: object expected");
                 if (_depth === undefined)
                     _depth = 0;
                 if (_depth > $util.recursionLimit)
    @@ -490,7 +494,7 @@ $root.TypeUrlTest = (function() {
                 var object = {};
                 if (options.defaults)
                     object.a = "";
    -            if (message.a != null && message.hasOwnProperty("a"))
    +            if (message.a != null && Object.hasOwnProperty.call(message, "a"))
                     object.a = message.a;
                 return object;
             };
    

Vulnerability mechanics

Root cause

"Generated code uses `message.hasOwnProperty(...)` which can be shadowed by a schema-defined field with the same name, causing the runtime helper to be replaced by attacker-controlled data."

Attack vector

An attacker who can provide or influence protobuf schemas or protobufjs JSON descriptors can define fields named `hasOwnProperty`, fields/oneofs named `$type`, or service methods whose generated helper name is `rpcCall`. When the application processes such a schema and reaches the affected API path (decode post-checks, `verify`, `toObject`, reflected JSON serialization, or RPC invocation), the schema-controlled value shadows the runtime helper, causing deterministic exceptions or recursive calls. The attack requires the application to load an untrusted schema and exercise the specific code path.

Affected code

The vulnerability affects generated code in protobufjs that uses `message.hasOwnProperty(...)` to check for field presence. The patches in `tests/data/test.js`, `tests/data/package.js`, and `tests/data/mapbox/vector_tile.js` replace all instances of `message.hasOwnProperty(...)` with `Object.hasOwnProperty.call(message, ...)` to avoid collisions when a message has a field named `hasOwnProperty`. The advisory also identifies `$type` collisions in reflected JSON serialization and `rpcCall` collisions in RPC service invocation as additional affected code paths.

What the fix does

The patches [patch_id=6085363] and [patch_id=6085364] replace direct calls to `message.hasOwnProperty(...)` with `Object.hasOwnProperty.call(message, ...)` in generated verify and toObject functions. This change ensures that the `hasOwnProperty` method is always looked up from `Object.prototype` rather than from the message object itself, preventing a schema-defined field named `hasOwnProperty` from shadowing the runtime helper. The advisory notes that additional fixes for `$type` and `rpcCall` collisions are also included in the same patch series, though the diff shown primarily addresses the `hasOwnProperty` pattern.

Preconditions

  • configApplication must use an affected protobufjs version.
  • inputApplication must load a schema or JSON descriptor containing a field named `hasOwnProperty`, a field/oneof named `$type`, or a service method whose generated helper name is `rpcCall`.
  • inputApplication must reach the affected API path: required-field decode post-checks, verify, toObject, reflected JSON serialization, or RPC invocation.

Generated on Jun 15, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

2

News mentions

0

No linked articles in our index yet.