Fields of Object are tab-completed at the top level

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Server Development Platform
    • ALL
    • Build B (10/30/15), Build C (11/20/15)
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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 )
               );
      

            Assignee:
            [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
            Reporter:
            Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: