[SERVER-19074] Fields of Object are tab-completed at the top level Created: 23/Jun/15  Updated: 19/Jun/23  Resolved: 19/Jun/23

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kevin Pulo Assignee: [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
Resolution: Won't Do Votes: 0
Labels: move-stm, sdp-backlog-purge
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Development Platform
Operating System: ALL
Sprint: Build B (10/30/15), Build C (11/20/15)
Participants:

 Description   

The fields of Object are erroneously considered as possibilities when tab-completing at the top level. This leads to bizarreties like (multiple lines used to show interactivity):

MongoDB shell version: 3.1.4
connecting to: test
db: test
> pre
> pre<TAB>
> preventExtensions
2015-06-23T10:01:30.237+1000 E QUERY    [thread1] ReferenceError: preventExtensions is not defined
    at (shell):1:1
>
> Object.pre
> Object.pre<TAB>
> Object.preventExtensions(
> Object.preventExtensions(<BACKSPACE>
> Object.preventExtensions
function preventExtensions() { [native code] }
>

The reason is: inside worker in shellAutocomplete of shell/utils.js, when tabbing at the top level, curObj == global. This causes builtinMethods[curObj.__proto__.constructor] to resolve to the fields of Object (from line 424).

So the fix is just to not do that when tabbing at the top level, e.g.:

diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index 9dc2235..1dac232 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -476,7 +476,7 @@ shellAutocomplete = function ( /*prefix*/ ) { // outer scope function called on
             Object.keySet( curObj ),
             Object.keySet( curObj.__proto__ ),
             builtinMethods[curObj] || [], // curObj is a builtin constructor
-            builtinMethods[curObj.__proto__.constructor] || [], // curObj is made from a builtin constructor
+            curObj == global ? [] : (builtinMethods[curObj.__proto__.constructor] || []), // curObj is made from a builtin constructor
             curObj == global ? extraGlobals : [],
             customComplete( curObj )
         );



 Comments   
Comment by Alex Neben [ 19/Jun/23 ]

This has been identified as work that the SDP team won't do in the near term. Please reopen with a comment if you feel this work should be reprioritized and explain why.

Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Generated at Thu Feb 08 03:49:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.