@@ -4,7 +4,7 @@ if (typeof (Timestamp) != "undefined") {
44
55 // Reference: https://github.com/mongodb/mongo/blob/c4d21d3346572e28df2f174df4d87e7618df4a77/src/mongo/scripting/mozjs/timestamp.cpp#L67-L78
66 function validateTimestampComponent ( component , name ) {
7- const MAX_UINT32 = 4294967295 ;
7+ const MAX_UINT32 = 4294967295 ;
88
99 if ( typeof component !== 'number' ) {
1010 throw new TypeError ( `${ name } must be a number` ) ;
@@ -749,6 +749,41 @@ if (typeof (MinKey) != "undefined") {
749749 print ( "warning: no MinKey class" ) ;
750750}
751751
752+ // MaxKey
753+ if ( typeof ( MaxKey ) != "undefined" ) {
754+ const OriginalMaxKey = MaxKey ;
755+ MaxKey = function ( ) {
756+ if ( MaxKey . prototype . __instance__ === undefined ) {
757+ MaxKey . prototype . __instance__ = new OriginalMaxKey ( ) ;
758+ }
759+
760+ return MaxKey . prototype . __instance__ ;
761+ } ;
762+
763+ MaxKey . prototype = OriginalMaxKey . prototype ;
764+
765+ for ( const key of Object . getOwnPropertyNames ( OriginalMaxKey ) ) {
766+ // Skip prototype, length, name(function internals)
767+ if ( key !== 'prototype' && key !== 'length' && key !== 'name' ) {
768+ MaxKey [ key ] = OriginalMaxKey [ key ] ;
769+ }
770+ }
771+
772+ MaxKey . prototype . toJSON = function ( ) {
773+ return this . tojson ( ) ;
774+ } ;
775+
776+ MaxKey . prototype . tojson = function ( ) {
777+ return "{ \"$MaxKey\" : 1 }" ;
778+ } ;
779+
780+ MaxKey . prototype . toString = function ( ) {
781+ return "[object Function]" ;
782+ } ;
783+ } else {
784+ print ( "warning: no MaxKey class" ) ;
785+ }
786+
752787// Free Functions
753788tojsononeline = function ( x ) {
754789 return tojson ( x , " " , true ) ;
0 commit comments