diff options
-rw-r--r-- | jstests/core/autocomplete.js | 30 | ||||
-rw-r--r-- | jstests/noPassthrough/shell_error_codes.js | 18 | ||||
-rw-r--r-- | src/mongo/shell/error_codes.tpl.js | 4 |
3 files changed, 41 insertions, 11 deletions
diff --git a/jstests/core/autocomplete.js b/jstests/core/autocomplete.js index 6eb6e21a7a3..6511292a8d3 100644 --- a/jstests/core/autocomplete.js +++ b/jstests/core/autocomplete.js @@ -10,33 +10,45 @@ return __autocomplete__; } - // Create a collection + // Create a collection. db.auto_complete_coll.insert({}); - // Validate DB auto completion + // Validate DB auto completion. const db_stuff = testAutoComplete('db.'); - // Verify we enumerate built-in methods + // Verify we enumerate built-in methods. assert.contains('db.prototype', db_stuff); assert.contains('db.hasOwnProperty', db_stuff); assert.contains('db.toString(', db_stuff); - // Verify we have some methods we added + // Verify we have some methods we added. assert.contains('db.adminCommand(', db_stuff); assert.contains('db.runCommand(', db_stuff); - // Verify we enumerate collections + // Verify we enumerate collections. assert.contains('db.auto_complete_coll', db_stuff); - // Validate Collection autocompletion + // Validate Collection autocompletion. const coll_stuff = testAutoComplete('db.auto_complete_coll.'); - // Verify we enumerate built-in methods + // Verify we enumerate built-in methods. assert.contains('db.auto_complete_coll.prototype', coll_stuff); assert.contains('db.auto_complete_coll.hasOwnProperty', coll_stuff); assert.contains('db.auto_complete_coll.toString(', coll_stuff); - // Verify we have some methods we added + // Verify we have some methods we added. assert.contains('db.auto_complete_coll.aggregate(', coll_stuff); assert.contains('db.auto_complete_coll.runCommand(', coll_stuff); -})();
\ No newline at end of file + + // Validate autocompletion when prefix is specified. + const empty_stuff = testAutoComplete(''); + + assert.contains('Array(', empty_stuff); + assert.contains('print(', empty_stuff); + assert.contains('ErrorCodes', empty_stuff); + + // Validate autocompletion returns ErrorCodes when ErrorCodes is specified. + const error_codes_autocomplete = testAutoComplete('ErrorCodes.'); + + assert.contains('ErrorCodes.BadValue', error_codes_autocomplete); +})(); diff --git a/jstests/noPassthrough/shell_error_codes.js b/jstests/noPassthrough/shell_error_codes.js index 4dc9673ae4d..aadb46d7386 100644 --- a/jstests/noPassthrough/shell_error_codes.js +++ b/jstests/noPassthrough/shell_error_codes.js @@ -20,6 +20,24 @@ }); }); + tests.push(function errorCodesShouldNotThrowExceptionForInheritedAttributes() { + assert.doesNotThrow(() => { + return ErrorCodes.prototype; + }); + }); + + tests.push(function errorCodesShouldNotThrowExceptionForSymbols() { + assert.doesNotThrow(() => { + return print(+ErrorCodes); + }); + }); + + tests.push(function errorCodesShouldNotThrowExceptionForConstructor() { + assert.doesNotThrow(() => { + return ErrorCodes.constructor; + }); + }); + tests.push(function errorCodeStringsShouldThrowExceptionForNonExistingError() { assert.throws(() => { return ErrorCodeStrings[nonExistingErrorCode]; diff --git a/src/mongo/shell/error_codes.tpl.js b/src/mongo/shell/error_codes.tpl.js index 68985024cf0..76d71f6c50b 100644 --- a/src/mongo/shell/error_codes.tpl.js +++ b/src/mongo/shell/error_codes.tpl.js @@ -29,8 +29,8 @@ var {ErrorCodes, ErrorCodeStrings} = (function() { const handler = { get: function(obj, prop) { - if (!obj.hasOwnProperty(prop)) { - throw new Error('Unknown Error Code: ' + prop); + if (prop !== Symbol.toPrimitive && prop in obj === false && prop in Object === false) { + throw new Error('Unknown Error Code: ' + prop.toString()); } return obj[prop]; |