@@ -64,10 +64,14 @@ export class DecodeError extends Error {
6464 constructor ( message : string ) {
6565 super ( message ) ;
6666
67- Object . defineProperty ( this , 'name' , {
67+ // fix the prototype chain in a cross-platform way
68+ const proto = Object . create ( DecodeError . prototype ) ;
69+ Object . setPrototypeOf ( this , proto ) ;
70+
71+ Object . defineProperty ( this , "name" , {
6872 configurable : true ,
6973 enumerable : false ,
70- value : this . constructor . name ,
74+ value : DecodeError . name ,
7175 } ) ;
7276 }
7377}
@@ -413,6 +417,9 @@ export class Decoder<ContextType> {
413417 if ( ! isValidMapKeyType ( object ) ) {
414418 throw new DecodeError ( "The type of key must be string or number but " + typeof object ) ;
415419 }
420+ if ( object === "__proto__" ) {
421+ throw new DecodeError ( "The key __proto__ is not allowed" ) ;
422+ }
416423
417424 state . key = object ;
418425 state . type = State . MAP_VALUE ;
@@ -498,7 +505,9 @@ export class Decoder<ContextType> {
498505
499506 private decodeUtf8String ( byteLength : number , headerOffset : number ) : string {
500507 if ( byteLength > this . maxStrLength ) {
501- throw new DecodeError ( `Max length exceeded: UTF-8 byte length (${ byteLength } ) > maxStrLength (${ this . maxStrLength } )` ) ;
508+ throw new DecodeError (
509+ `Max length exceeded: UTF-8 byte length (${ byteLength } ) > maxStrLength (${ this . maxStrLength } )` ,
510+ ) ;
502511 }
503512
504513 if ( this . bytes . byteLength < this . pos + headerOffset + byteLength ) {
0 commit comments