protobufjs 7.5.5 → 7.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/light/protobuf.js +230 -108
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +90 -38
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +234 -111
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor/index.d.ts +4 -0
- package/ext/descriptor/index.js +35 -16
- package/index.d.ts +22 -4
- package/package.json +7 -4
- package/src/converter.js +14 -5
- package/src/decoder.js +17 -9
- package/src/enum.js +4 -1
- package/src/namespace.js +10 -6
- package/src/object.js +4 -0
- package/src/parse.js +4 -3
- package/src/reader.js +12 -2
- package/src/service.js +8 -4
- package/src/type.js +22 -12
- package/src/types.js +1 -1
- package/src/util/minimal.js +24 -1
- package/src/util/patterns.js +8 -0
- package/src/util.js +9 -9
- package/src/verifier.js +7 -4
- package/src/wrappers.js +4 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $protobuf from "../..";
|
|
2
|
+
import Long = require("long");
|
|
2
3
|
export const FileDescriptorSet: $protobuf.Type;
|
|
3
4
|
|
|
4
5
|
export const FileDescriptorProto: $protobuf.Type;
|
|
@@ -73,8 +74,11 @@ export interface IFileDescriptorProto {
|
|
|
73
74
|
options?: IFileOptions;
|
|
74
75
|
sourceCodeInfo?: any;
|
|
75
76
|
syntax?: string;
|
|
77
|
+
edition?: IEdition;
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
type IEdition = number;
|
|
81
|
+
|
|
78
82
|
export interface IFileOptions {
|
|
79
83
|
javaPackage?: string;
|
|
80
84
|
javaOuterClassname?: string;
|
package/ext/descriptor/index.js
CHANGED
|
@@ -10,7 +10,11 @@ var Namespace = $protobuf.Namespace,
|
|
|
10
10
|
MapField = $protobuf.MapField,
|
|
11
11
|
OneOf = $protobuf.OneOf,
|
|
12
12
|
Service = $protobuf.Service,
|
|
13
|
-
Method = $protobuf.Method
|
|
13
|
+
Method = $protobuf.Method,
|
|
14
|
+
patterns = $protobuf.util.patterns;
|
|
15
|
+
|
|
16
|
+
var numberRe = patterns.numberRe,
|
|
17
|
+
typeRefRe = patterns.typeRefRe;
|
|
14
18
|
|
|
15
19
|
// --- Root ---
|
|
16
20
|
|
|
@@ -393,9 +397,6 @@ Type.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
393
397
|
* @property {number} JS_NUMBER=2
|
|
394
398
|
*/
|
|
395
399
|
|
|
396
|
-
// copied here from parse.js
|
|
397
|
-
var numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
|
|
398
|
-
|
|
399
400
|
/**
|
|
400
401
|
* Creates a field from a descriptor.
|
|
401
402
|
*
|
|
@@ -416,10 +417,13 @@ Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
|
416
417
|
throw Error("missing field id");
|
|
417
418
|
|
|
418
419
|
// Rewire field type
|
|
419
|
-
var
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
var typeName = descriptor.typeName,
|
|
421
|
+
fieldType;
|
|
422
|
+
if (typeName != null && typeName !== "") {
|
|
423
|
+
if (typeof typeName !== "string" || !typeRefRe.test(typeName))
|
|
424
|
+
throw Error("illegal type name: " + typeName);
|
|
425
|
+
fieldType = typeName;
|
|
426
|
+
} else
|
|
423
427
|
fieldType = fromDescriptorType(descriptor.type);
|
|
424
428
|
|
|
425
429
|
// Rewire field rule
|
|
@@ -432,10 +436,12 @@ Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
|
432
436
|
default: throw Error("illegal label: " + descriptor.label);
|
|
433
437
|
}
|
|
434
438
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
+
var extendee = descriptor.extendee;
|
|
440
|
+
if (extendee != null && extendee !== "") {
|
|
441
|
+
if (typeof extendee !== "string" || !typeRefRe.test(extendee))
|
|
442
|
+
throw Error("illegal type name: " + extendee);
|
|
443
|
+
} else
|
|
444
|
+
extendee = undefined;
|
|
439
445
|
var field = new Field(
|
|
440
446
|
descriptor.name.length ? descriptor.name : "field" + descriptor.number,
|
|
441
447
|
descriptor.number,
|
|
@@ -518,10 +524,11 @@ Field.prototype.toDescriptor = function toDescriptor(edition) {
|
|
|
518
524
|
// Handle extension field
|
|
519
525
|
descriptor.extendee = this.extensionField ? this.extensionField.parent.fullName : this.extend;
|
|
520
526
|
|
|
521
|
-
// Handle part of oneof
|
|
522
|
-
if (this.partOf)
|
|
527
|
+
// Handle part of oneof (only meaningful for message types)
|
|
528
|
+
if (this.partOf && this.parent instanceof Type) {
|
|
523
529
|
if ((descriptor.oneofIndex = this.parent.oneofsArray.indexOf(this.partOf)) < 0)
|
|
524
530
|
throw Error("missing oneof");
|
|
531
|
+
}
|
|
525
532
|
|
|
526
533
|
if (this.options) {
|
|
527
534
|
descriptor.options = toDescriptorOptions(this.options, exports.FieldOptions);
|
|
@@ -762,12 +769,24 @@ Method.fromDescriptor = function fromDescriptor(descriptor) {
|
|
|
762
769
|
if (typeof descriptor.length === "number")
|
|
763
770
|
descriptor = exports.MethodDescriptorProto.decode(descriptor);
|
|
764
771
|
|
|
772
|
+
var inputType = descriptor.inputType,
|
|
773
|
+
outputType = descriptor.outputType;
|
|
774
|
+
|
|
775
|
+
if (inputType != null && inputType !== "") {
|
|
776
|
+
if (typeof inputType !== "string" || !typeRefRe.test(inputType))
|
|
777
|
+
throw Error("illegal type name: " + inputType);
|
|
778
|
+
}
|
|
779
|
+
if (outputType != null && outputType !== "") {
|
|
780
|
+
if (typeof outputType !== "string" || !typeRefRe.test(outputType))
|
|
781
|
+
throw Error("illegal type name: " + outputType);
|
|
782
|
+
}
|
|
783
|
+
|
|
765
784
|
return new Method(
|
|
766
785
|
// unnamedMethodIndex is global, not per service, because we have no ref to a service here
|
|
767
786
|
descriptor.name && descriptor.name.length ? descriptor.name : "Method" + unnamedMethodIndex++,
|
|
768
787
|
"rpc",
|
|
769
|
-
|
|
770
|
-
|
|
788
|
+
inputType,
|
|
789
|
+
outputType,
|
|
771
790
|
Boolean(descriptor.clientStreaming),
|
|
772
791
|
Boolean(descriptor.serverStreaming),
|
|
773
792
|
fromDescriptorOptions(descriptor.options, exports.MethodOptions)
|
package/index.d.ts
CHANGED
|
@@ -1271,12 +1271,16 @@ export class Reader {
|
|
|
1271
1271
|
*/
|
|
1272
1272
|
public skip(length?: number): Reader;
|
|
1273
1273
|
|
|
1274
|
+
/** Recursion limit. */
|
|
1275
|
+
public static recursionLimit: number;
|
|
1276
|
+
|
|
1274
1277
|
/**
|
|
1275
1278
|
* Skips the next element of the specified wire type.
|
|
1276
1279
|
* @param wireType Wire type received
|
|
1280
|
+
* @param [depth] Depth of recursion to control nested calls; 0 if omitted
|
|
1277
1281
|
* @returns `this`
|
|
1278
1282
|
*/
|
|
1279
|
-
public skipType(wireType: number): Reader;
|
|
1283
|
+
public skipType(wireType: number, depth?: number): Reader;
|
|
1280
1284
|
}
|
|
1281
1285
|
|
|
1282
1286
|
/** Wire format reader using node buffers. */
|
|
@@ -1697,11 +1701,13 @@ export class Type extends NamespaceBase {
|
|
|
1697
1701
|
* Decodes a message of this type.
|
|
1698
1702
|
* @param reader Reader or buffer to decode from
|
|
1699
1703
|
* @param [length] Length of the message, if known beforehand
|
|
1704
|
+
* @param [end] Expected group end tag, if decoding a group
|
|
1705
|
+
* @param [depth] Current nesting depth
|
|
1700
1706
|
* @returns Decoded message
|
|
1701
1707
|
* @throws {Error} If the payload is not a reader or valid buffer
|
|
1702
1708
|
* @throws {util.ProtocolError<{}>} If required fields are missing
|
|
1703
1709
|
*/
|
|
1704
|
-
public decode(reader: (Reader|Uint8Array), length?: number): Message<{}>;
|
|
1710
|
+
public decode(reader: (Reader|Uint8Array), length?: number, end?: number, depth?: number): Message<{}>;
|
|
1705
1711
|
|
|
1706
1712
|
/**
|
|
1707
1713
|
* Decodes a message of this type preceeded by its byte length as a varint.
|
|
@@ -1715,16 +1721,18 @@ export class Type extends NamespaceBase {
|
|
|
1715
1721
|
/**
|
|
1716
1722
|
* Verifies that field values are valid and that required fields are present.
|
|
1717
1723
|
* @param message Plain object to verify
|
|
1724
|
+
* @param [depth] Current nesting depth
|
|
1718
1725
|
* @returns `null` if valid, otherwise the reason why it is not
|
|
1719
1726
|
*/
|
|
1720
|
-
public verify(message: { [k: string]: any }): (null|string);
|
|
1727
|
+
public verify(message: { [k: string]: any }, depth?: number): (null|string);
|
|
1721
1728
|
|
|
1722
1729
|
/**
|
|
1723
1730
|
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
|
1724
1731
|
* @param object Plain object to convert
|
|
1732
|
+
* @param [depth] Current nesting depth
|
|
1725
1733
|
* @returns Message instance
|
|
1726
1734
|
*/
|
|
1727
|
-
public fromObject(object: { [k: string]: any }): Message<{}>;
|
|
1735
|
+
public fromObject(object: { [k: string]: any }, depth?: number): Message<{}>;
|
|
1728
1736
|
|
|
1729
1737
|
/**
|
|
1730
1738
|
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
|
@@ -2119,6 +2127,16 @@ export namespace util {
|
|
|
2119
2127
|
*/
|
|
2120
2128
|
function merge(dst: { [k: string]: any }, src: { [k: string]: any }, ifNotSet?: boolean): { [k: string]: any };
|
|
2121
2129
|
|
|
2130
|
+
/** Recursion limit. */
|
|
2131
|
+
let recursionLimit: number;
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* Makes a property safe for assignment as an own property.
|
|
2135
|
+
* @param obj Object
|
|
2136
|
+
* @param key Property key
|
|
2137
|
+
*/
|
|
2138
|
+
function makeProp(obj: { [k: string]: any }, key: string): void;
|
|
2139
|
+
|
|
2122
2140
|
/**
|
|
2123
2141
|
* Converts the first character of a string to lower case.
|
|
2124
2142
|
* @param str String to convert
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.6",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript (& TypeScript).",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
],
|
|
28
28
|
"main": "index.js",
|
|
29
29
|
"types": "index.d.ts",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"tag": "latest-7"
|
|
32
|
+
},
|
|
30
33
|
"scripts": {
|
|
31
34
|
"bench": "node bench",
|
|
32
35
|
"build": "npm run build:bundle && npm run build:types",
|
|
@@ -53,14 +56,14 @@
|
|
|
53
56
|
"dependencies": {
|
|
54
57
|
"@protobufjs/aspromise": "^1.1.2",
|
|
55
58
|
"@protobufjs/base64": "^1.1.2",
|
|
56
|
-
"@protobufjs/codegen": "^2.0.
|
|
59
|
+
"@protobufjs/codegen": "^2.0.5",
|
|
57
60
|
"@protobufjs/eventemitter": "^1.1.0",
|
|
58
61
|
"@protobufjs/fetch": "^1.1.0",
|
|
59
62
|
"@protobufjs/float": "^1.0.2",
|
|
60
|
-
"@protobufjs/inquire": "^1.1.
|
|
63
|
+
"@protobufjs/inquire": "^1.1.1",
|
|
61
64
|
"@protobufjs/path": "^1.1.2",
|
|
62
65
|
"@protobufjs/pool": "^1.1.0",
|
|
63
|
-
"@protobufjs/utf8": "^1.1.
|
|
66
|
+
"@protobufjs/utf8": "^1.1.1",
|
|
64
67
|
"@types/node": ">=13.7.0",
|
|
65
68
|
"long": "^5.0.0"
|
|
66
69
|
},
|
package/src/converter.js
CHANGED
|
@@ -43,7 +43,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
43
43
|
} else gen
|
|
44
44
|
("if(typeof d%s!==\"object\")", prop)
|
|
45
45
|
("throw TypeError(%j)", field.fullName + ": object expected")
|
|
46
|
-
("m%s=types[%i].fromObject(d%s)", prop, fieldIndex, prop);
|
|
46
|
+
("m%s=types[%i].fromObject(d%s,n+1)", prop, fieldIndex, prop);
|
|
47
47
|
} else {
|
|
48
48
|
var isUnsigned = false;
|
|
49
49
|
switch (field.type) {
|
|
@@ -105,9 +105,12 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
|
|
|
105
105
|
converter.fromObject = function fromObject(mtype) {
|
|
106
106
|
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
107
107
|
var fields = mtype.fieldsArray;
|
|
108
|
-
var gen = util.codegen(["d"], mtype.name + "$fromObject")
|
|
108
|
+
var gen = util.codegen(["d", "n"], mtype.name + "$fromObject")
|
|
109
109
|
("if(d instanceof this.ctor)")
|
|
110
|
-
("return d")
|
|
110
|
+
("return d")
|
|
111
|
+
("if(n===undefined)n=0")
|
|
112
|
+
("if(n>util.recursionLimit)")
|
|
113
|
+
("throw Error(\"maximum nesting depth exceeded\")");
|
|
111
114
|
if (!fields.length) return gen
|
|
112
115
|
("return new this.ctor");
|
|
113
116
|
gen
|
|
@@ -123,6 +126,9 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
123
126
|
("throw TypeError(%j)", field.fullName + ": object expected")
|
|
124
127
|
("m%s={}", prop)
|
|
125
128
|
("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
|
|
129
|
+
gen
|
|
130
|
+
("if(ks[i]===\"__proto__\")")
|
|
131
|
+
("util.makeProp(m%s,ks[i])", prop);
|
|
126
132
|
genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[ks[i]]")
|
|
127
133
|
("}")
|
|
128
134
|
("}");
|
|
@@ -253,11 +259,11 @@ converter.toObject = function toObject(mtype) {
|
|
|
253
259
|
("}else")
|
|
254
260
|
("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
|
|
255
261
|
else if (field.bytes) {
|
|
256
|
-
var arrayDefault =
|
|
262
|
+
var arrayDefault = Array.prototype.slice.call(field.typeDefault);
|
|
257
263
|
gen
|
|
258
264
|
("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
|
|
259
265
|
("else{")
|
|
260
|
-
("d%s=%
|
|
266
|
+
("d%s=%j", prop, arrayDefault)
|
|
261
267
|
("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
|
|
262
268
|
("}");
|
|
263
269
|
} else gen
|
|
@@ -277,6 +283,9 @@ converter.toObject = function toObject(mtype) {
|
|
|
277
283
|
("if(m%s&&(ks2=Object.keys(m%s)).length){", prop, prop)
|
|
278
284
|
("d%s={}", prop)
|
|
279
285
|
("for(var j=0;j<ks2.length;++j){");
|
|
286
|
+
gen
|
|
287
|
+
("if(ks2[j]===\"__proto__\")")
|
|
288
|
+
("util.makeProp(d%s,ks2[j])", prop);
|
|
280
289
|
genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[ks2[j]]")
|
|
281
290
|
("}");
|
|
282
291
|
} else if (field.repeated) { gen
|
package/src/decoder.js
CHANGED
|
@@ -16,9 +16,12 @@ function missing(field) {
|
|
|
16
16
|
*/
|
|
17
17
|
function decoder(mtype) {
|
|
18
18
|
/* eslint-disable no-unexpected-multiline */
|
|
19
|
-
var gen = util.codegen(["r", "l", "e"], mtype.name + "$decode")
|
|
19
|
+
var gen = util.codegen(["r", "l", "e", "n"], mtype.name + "$decode")
|
|
20
20
|
("if(!(r instanceof Reader))")
|
|
21
21
|
("r=Reader.create(r)")
|
|
22
|
+
("if(n===undefined)n=0")
|
|
23
|
+
("if(n>Reader.recursionLimit)")
|
|
24
|
+
("throw Error(\"maximum nesting depth exceeded\")")
|
|
22
25
|
("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
|
|
23
26
|
("while(r.pos<c){")
|
|
24
27
|
("var t=r.uint32()")
|
|
@@ -57,22 +60,27 @@ function decoder(mtype) {
|
|
|
57
60
|
("case 2:");
|
|
58
61
|
|
|
59
62
|
if (types.basic[type] === undefined) gen
|
|
60
|
-
("value=types[%i].decode(r,r.uint32())", i); // can't be groups
|
|
63
|
+
("value=types[%i].decode(r,r.uint32(),undefined,n+1)", i); // can't be groups
|
|
61
64
|
else gen
|
|
62
65
|
("value=r.%s()", type);
|
|
63
66
|
|
|
64
67
|
gen
|
|
65
68
|
("break")
|
|
66
69
|
("default:")
|
|
67
|
-
("r.skipType(tag2&7)")
|
|
70
|
+
("r.skipType(tag2&7,n)")
|
|
68
71
|
("break")
|
|
69
72
|
("}")
|
|
70
73
|
("}");
|
|
71
74
|
|
|
72
75
|
if (types.long[field.keyType] !== undefined) gen
|
|
73
76
|
("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref);
|
|
74
|
-
else
|
|
77
|
+
else {
|
|
78
|
+
if (field.keyType === "string") gen
|
|
79
|
+
("if(k===\"__proto__\")")
|
|
80
|
+
("util.makeProp(%s,k)", ref);
|
|
81
|
+
gen
|
|
75
82
|
("%s[k]=value", ref);
|
|
83
|
+
}
|
|
76
84
|
|
|
77
85
|
// Repeated fields
|
|
78
86
|
} else if (field.repeated) { gen
|
|
@@ -90,15 +98,15 @@ function decoder(mtype) {
|
|
|
90
98
|
|
|
91
99
|
// Non-packed
|
|
92
100
|
if (types.basic[type] === undefined) gen(field.delimited
|
|
93
|
-
? "%s.push(types[%i].decode(r,undefined,((t&~7)|4)))"
|
|
94
|
-
: "%s.push(types[%i].decode(r,r.uint32()))", ref, i);
|
|
101
|
+
? "%s.push(types[%i].decode(r,undefined,((t&~7)|4),n+1))"
|
|
102
|
+
: "%s.push(types[%i].decode(r,r.uint32(),undefined,n+1))", ref, i);
|
|
95
103
|
else gen
|
|
96
104
|
("%s.push(r.%s())", ref, type);
|
|
97
105
|
|
|
98
106
|
// Non-repeated
|
|
99
107
|
} else if (types.basic[type] === undefined) gen(field.delimited
|
|
100
|
-
? "%s=types[%i].decode(r,undefined,((t&~7)|4))"
|
|
101
|
-
: "%s=types[%i].decode(r,r.uint32())", ref, i);
|
|
108
|
+
? "%s=types[%i].decode(r,undefined,((t&~7)|4),n+1)"
|
|
109
|
+
: "%s=types[%i].decode(r,r.uint32(),undefined,n+1)", ref, i);
|
|
102
110
|
else gen
|
|
103
111
|
("%s=r.%s()", ref, type);
|
|
104
112
|
gen
|
|
@@ -107,7 +115,7 @@ function decoder(mtype) {
|
|
|
107
115
|
// Unknown fields
|
|
108
116
|
} gen
|
|
109
117
|
("default:")
|
|
110
|
-
("r.skipType(t&7)")
|
|
118
|
+
("r.skipType(t&7,n)")
|
|
111
119
|
("break")
|
|
112
120
|
|
|
113
121
|
("}")
|
package/src/enum.js
CHANGED
|
@@ -74,7 +74,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
74
74
|
|
|
75
75
|
if (values)
|
|
76
76
|
for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
|
|
77
|
-
if (typeof values[keys[i]] === "number") // use forward entries only
|
|
77
|
+
if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
|
|
78
78
|
this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -153,6 +153,9 @@ Enum.prototype.add = function add(name, id, comment, options) {
|
|
|
153
153
|
if (!util.isInteger(id))
|
|
154
154
|
throw TypeError("id must be an integer");
|
|
155
155
|
|
|
156
|
+
if (name === "__proto__")
|
|
157
|
+
return this;
|
|
158
|
+
|
|
156
159
|
if (this.values[name] !== undefined)
|
|
157
160
|
throw Error("duplicate name '" + name + "' in " + this);
|
|
158
161
|
|
package/src/namespace.js
CHANGED
|
@@ -116,7 +116,7 @@ function Namespace(name, options) {
|
|
|
116
116
|
* @type {Object.<string,ReflectionObject|null>}
|
|
117
117
|
* @private
|
|
118
118
|
*/
|
|
119
|
-
this._lookupCache =
|
|
119
|
+
this._lookupCache = Object.create(null);
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Whether or not objects contained in this namespace need feature resolution.
|
|
@@ -135,12 +135,12 @@ function Namespace(name, options) {
|
|
|
135
135
|
|
|
136
136
|
function clearCache(namespace) {
|
|
137
137
|
namespace._nestedArray = null;
|
|
138
|
-
namespace._lookupCache =
|
|
138
|
+
namespace._lookupCache = Object.create(null);
|
|
139
139
|
|
|
140
140
|
// Also clear parent caches, since they include nested lookups.
|
|
141
141
|
var parent = namespace;
|
|
142
142
|
while(parent = parent.parent) {
|
|
143
|
-
parent._lookupCache =
|
|
143
|
+
parent._lookupCache = Object.create(null);
|
|
144
144
|
}
|
|
145
145
|
return namespace;
|
|
146
146
|
}
|
|
@@ -221,8 +221,9 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
|
|
|
221
221
|
* @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
|
|
222
222
|
*/
|
|
223
223
|
Namespace.prototype.get = function get(name) {
|
|
224
|
-
return this.nested && this.nested
|
|
225
|
-
|
|
224
|
+
return this.nested && Object.prototype.hasOwnProperty.call(this.nested, name)
|
|
225
|
+
? this.nested[name]
|
|
226
|
+
: null;
|
|
226
227
|
};
|
|
227
228
|
|
|
228
229
|
/**
|
|
@@ -233,7 +234,7 @@ Namespace.prototype.get = function get(name) {
|
|
|
233
234
|
* @throws {Error} If there is no such enum
|
|
234
235
|
*/
|
|
235
236
|
Namespace.prototype.getEnum = function getEnum(name) {
|
|
236
|
-
if (this.nested && this.nested[name] instanceof Enum)
|
|
237
|
+
if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name) && this.nested[name] instanceof Enum)
|
|
237
238
|
return this.nested[name].values;
|
|
238
239
|
throw Error("no such enum: " + name);
|
|
239
240
|
};
|
|
@@ -250,6 +251,9 @@ Namespace.prototype.add = function add(object) {
|
|
|
250
251
|
if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
|
|
251
252
|
throw TypeError("object must be a valid nested object");
|
|
252
253
|
|
|
254
|
+
if (object.name === "__proto__")
|
|
255
|
+
return this;
|
|
256
|
+
|
|
253
257
|
if (!this.nested)
|
|
254
258
|
this.nested = {};
|
|
255
259
|
else {
|
package/src/object.js
CHANGED
|
@@ -283,6 +283,8 @@ ReflectionObject.prototype.getOption = function getOption(name) {
|
|
|
283
283
|
* @returns {ReflectionObject} `this`
|
|
284
284
|
*/
|
|
285
285
|
ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
286
|
+
if (name === "__proto__")
|
|
287
|
+
return this;
|
|
286
288
|
if (!this.options)
|
|
287
289
|
this.options = {};
|
|
288
290
|
if (/^features\./.test(name)) {
|
|
@@ -303,6 +305,8 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
|
|
|
303
305
|
* @returns {ReflectionObject} `this`
|
|
304
306
|
*/
|
|
305
307
|
ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
|
|
308
|
+
if (name === "__proto__")
|
|
309
|
+
return this;
|
|
306
310
|
if (!this.parsedOptions) {
|
|
307
311
|
this.parsedOptions = [];
|
|
308
312
|
}
|
package/src/parse.js
CHANGED
|
@@ -23,9 +23,9 @@ var base10Re = /^[1-9][0-9]*$/,
|
|
|
23
23
|
base16NegRe = /^-?0[x][0-9a-fA-F]+$/,
|
|
24
24
|
base8Re = /^0[0-7]+$/,
|
|
25
25
|
base8NegRe = /^-?0[0-7]+$/,
|
|
26
|
-
numberRe =
|
|
26
|
+
numberRe = util.patterns.numberRe,
|
|
27
27
|
nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
|
|
28
|
-
typeRefRe =
|
|
28
|
+
typeRefRe = util.patterns.typeRefRe;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Result object returned from {@link parse}.
|
|
@@ -740,7 +740,8 @@ function parse(source, root, options) {
|
|
|
740
740
|
if (prevValue)
|
|
741
741
|
value = [].concat(prevValue).concat(value);
|
|
742
742
|
|
|
743
|
-
|
|
743
|
+
if (propName !== "__proto__")
|
|
744
|
+
objectResult[propName] = value;
|
|
744
745
|
|
|
745
746
|
// Semicolons and commas can be optional
|
|
746
747
|
skip(",", true);
|
package/src/reader.js
CHANGED
|
@@ -352,12 +352,22 @@ Reader.prototype.skip = function skip(length) {
|
|
|
352
352
|
return this;
|
|
353
353
|
};
|
|
354
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Recursion limit.
|
|
357
|
+
* @type {number}
|
|
358
|
+
*/
|
|
359
|
+
Reader.recursionLimit = util.recursionLimit;
|
|
360
|
+
|
|
355
361
|
/**
|
|
356
362
|
* Skips the next element of the specified wire type.
|
|
357
363
|
* @param {number} wireType Wire type received
|
|
364
|
+
* @param {number} [depth] Depth of recursion to control nested calls; 0 if omitted
|
|
358
365
|
* @returns {Reader} `this`
|
|
359
366
|
*/
|
|
360
|
-
Reader.prototype.skipType = function(wireType) {
|
|
367
|
+
Reader.prototype.skipType = function(wireType, depth) {
|
|
368
|
+
if (depth === undefined) depth = 0;
|
|
369
|
+
if (depth > Reader.recursionLimit)
|
|
370
|
+
throw Error("maximum nesting depth exceeded");
|
|
361
371
|
switch (wireType) {
|
|
362
372
|
case 0:
|
|
363
373
|
this.skip();
|
|
@@ -370,7 +380,7 @@ Reader.prototype.skipType = function(wireType) {
|
|
|
370
380
|
break;
|
|
371
381
|
case 3:
|
|
372
382
|
while ((wireType = this.uint32() & 7) !== 4) {
|
|
373
|
-
this.skipType(wireType);
|
|
383
|
+
this.skipType(wireType, depth + 1);
|
|
374
384
|
}
|
|
375
385
|
break;
|
|
376
386
|
case 5:
|
package/src/service.js
CHANGED
|
@@ -9,6 +9,8 @@ var Method = require("./method"),
|
|
|
9
9
|
util = require("./util"),
|
|
10
10
|
rpc = require("./rpc");
|
|
11
11
|
|
|
12
|
+
var reservedRe = util.patterns.reservedRe;
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Constructs a new service instance.
|
|
14
16
|
* @classdesc Reflected service.
|
|
@@ -102,8 +104,9 @@ function clearCache(service) {
|
|
|
102
104
|
* @override
|
|
103
105
|
*/
|
|
104
106
|
Service.prototype.get = function get(name) {
|
|
105
|
-
return this.methods
|
|
106
|
-
|
|
107
|
+
return Object.prototype.hasOwnProperty.call(this.methods, name)
|
|
108
|
+
? this.methods[name]
|
|
109
|
+
: Namespace.prototype.get.call(this, name);
|
|
107
110
|
};
|
|
108
111
|
|
|
109
112
|
/**
|
|
@@ -138,12 +141,13 @@ Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive
|
|
|
138
141
|
* @override
|
|
139
142
|
*/
|
|
140
143
|
Service.prototype.add = function add(object) {
|
|
141
|
-
|
|
142
144
|
/* istanbul ignore if */
|
|
143
145
|
if (this.get(object.name))
|
|
144
146
|
throw Error("duplicate name '" + object.name + "' in " + this);
|
|
145
147
|
|
|
146
148
|
if (object instanceof Method) {
|
|
149
|
+
if (object.name === "__proto__")
|
|
150
|
+
return this;
|
|
147
151
|
this.methods[object.name] = object;
|
|
148
152
|
object.parent = this;
|
|
149
153
|
return clearCache(this);
|
|
@@ -179,7 +183,7 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
|
|
|
179
183
|
var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
|
|
180
184
|
for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
|
|
181
185
|
var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
|
|
182
|
-
rpcService[methodName] = util.codegen(["r","c"],
|
|
186
|
+
rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
|
|
183
187
|
m: method,
|
|
184
188
|
q: method.resolvedRequestType.ctor,
|
|
185
189
|
s: method.resolvedResponseType.ctor
|
package/src/type.js
CHANGED
|
@@ -205,7 +205,7 @@ Type.generateConstructor = function generateConstructor(mtype) {
|
|
|
205
205
|
else if (field.repeated) gen
|
|
206
206
|
("this%s=[]", util.safeProp(field.name));
|
|
207
207
|
return gen
|
|
208
|
-
("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)") // omit undefined or null
|
|
208
|
+
("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null&&ks[i]!==\"__proto__\")") // omit undefined or null
|
|
209
209
|
("this[ks[i]]=p[ks[i]]");
|
|
210
210
|
/* eslint-enable no-unexpected-multiline */
|
|
211
211
|
};
|
|
@@ -338,10 +338,13 @@ Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(ed
|
|
|
338
338
|
* @override
|
|
339
339
|
*/
|
|
340
340
|
Type.prototype.get = function get(name) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
if (Object.prototype.hasOwnProperty.call(this.fields, name))
|
|
342
|
+
return this.fields[name];
|
|
343
|
+
if (this.oneofs && Object.prototype.hasOwnProperty.call(this.oneofs, name))
|
|
344
|
+
return this.oneofs[name];
|
|
345
|
+
if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name))
|
|
346
|
+
return this.nested[name];
|
|
347
|
+
return null;
|
|
345
348
|
};
|
|
346
349
|
|
|
347
350
|
/**
|
|
@@ -352,7 +355,6 @@ Type.prototype.get = function get(name) {
|
|
|
352
355
|
* @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
|
|
353
356
|
*/
|
|
354
357
|
Type.prototype.add = function add(object) {
|
|
355
|
-
|
|
356
358
|
if (this.get(object.name))
|
|
357
359
|
throw Error("duplicate name '" + object.name + "' in " + this);
|
|
358
360
|
|
|
@@ -368,6 +370,8 @@ Type.prototype.add = function add(object) {
|
|
|
368
370
|
throw Error("id " + object.id + " is reserved in " + this);
|
|
369
371
|
if (this.isReservedName(object.name))
|
|
370
372
|
throw Error("name '" + object.name + "' is reserved in " + this);
|
|
373
|
+
if (object.name === "__proto__")
|
|
374
|
+
return this;
|
|
371
375
|
|
|
372
376
|
if (object.parent)
|
|
373
377
|
object.parent.remove(object);
|
|
@@ -377,6 +381,8 @@ Type.prototype.add = function add(object) {
|
|
|
377
381
|
return clearCache(this);
|
|
378
382
|
}
|
|
379
383
|
if (object instanceof OneOf) {
|
|
384
|
+
if (object.name === "__proto__")
|
|
385
|
+
return this;
|
|
380
386
|
if (!this.oneofs)
|
|
381
387
|
this.oneofs = {};
|
|
382
388
|
this.oneofs[object.name] = object;
|
|
@@ -525,12 +531,14 @@ Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
|
|
|
525
531
|
* Decodes a message of this type.
|
|
526
532
|
* @param {Reader|Uint8Array} reader Reader or buffer to decode from
|
|
527
533
|
* @param {number} [length] Length of the message, if known beforehand
|
|
534
|
+
* @param {number} [end] Expected group end tag, if decoding a group
|
|
535
|
+
* @param {number} [depth] Current nesting depth
|
|
528
536
|
* @returns {Message<{}>} Decoded message
|
|
529
537
|
* @throws {Error} If the payload is not a reader or valid buffer
|
|
530
538
|
* @throws {util.ProtocolError<{}>} If required fields are missing
|
|
531
539
|
*/
|
|
532
|
-
Type.prototype.decode = function decode_setup(reader, length) {
|
|
533
|
-
return this.setup().decode(reader, length); // overrides this method
|
|
540
|
+
Type.prototype.decode = function decode_setup(reader, length, end, depth) {
|
|
541
|
+
return this.setup().decode(reader, length, end, depth); // overrides this method
|
|
534
542
|
};
|
|
535
543
|
|
|
536
544
|
/**
|
|
@@ -549,19 +557,21 @@ Type.prototype.decodeDelimited = function decodeDelimited(reader) {
|
|
|
549
557
|
/**
|
|
550
558
|
* Verifies that field values are valid and that required fields are present.
|
|
551
559
|
* @param {Object.<string,*>} message Plain object to verify
|
|
560
|
+
* @param {number} [depth] Current nesting depth
|
|
552
561
|
* @returns {null|string} `null` if valid, otherwise the reason why it is not
|
|
553
562
|
*/
|
|
554
|
-
Type.prototype.verify = function verify_setup(message) {
|
|
555
|
-
return this.setup().verify(message); // overrides this method
|
|
563
|
+
Type.prototype.verify = function verify_setup(message, depth) {
|
|
564
|
+
return this.setup().verify(message, depth); // overrides this method
|
|
556
565
|
};
|
|
557
566
|
|
|
558
567
|
/**
|
|
559
568
|
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
|
560
569
|
* @param {Object.<string,*>} object Plain object to convert
|
|
570
|
+
* @param {number} [depth] Current nesting depth
|
|
561
571
|
* @returns {Message<{}>} Message instance
|
|
562
572
|
*/
|
|
563
|
-
Type.prototype.fromObject = function fromObject(object) {
|
|
564
|
-
return this.setup().fromObject(object);
|
|
573
|
+
Type.prototype.fromObject = function fromObject(object, depth) {
|
|
574
|
+
return this.setup().fromObject(object, depth);
|
|
565
575
|
};
|
|
566
576
|
|
|
567
577
|
/**
|