[SERVER-4006] Shell command completion for function properties has 'prototype' 3 times Created: 04/Oct/11  Updated: 11/Jul/16  Resolved: 28/Nov/11

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

Type: Bug Priority: Trivial - P5
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Any


Operating System: ALL
Participants:

 Description   

In the Mongo shell, if you type v=function(){}; <Enter> v. <Tab> and then hit <Tab> repeatedly, you cycle through completions of apply(, call(, constructor, hasOwnProperty(, propertyIsEnumerable(, prototype, prototype, prototype, toLocaleString(, toString( and valueOf(. I tried arrays, objects, Dates, ISODates and NumberLongs and didn't see any others with any repetitions. From reading the code, I see that this set of completions is coming from a JavaScript routine shellAutocomplete() in shell/utils.js, and this code sets a JavaScript variable _autocomplete. So, the bug seems to be in shellAutocomplete() or one of its helper routines:

> _autocomplete_
[
"v.apply(",
"v.call(",
"v.constructor",
"v.hasOwnProperty(",
"v.propertyIsEnumerable(",
"v.prototype",
"v.prototype",
"v.prototype",
"v.toLocaleString(",
"v.toString(",
"v.valueOf("
]
>



 Comments   
Comment by Tad Marshall [ 28/Nov/11 ]

Fixed by commit 94602bb066d104cbf1fe8bb18203147774347bfe .

Comment by auto [ 28/Nov/11 ]

Author:

{u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-4006 – remove duplicates from autocomplete list

The logic comes up with three ways that "prototype" could be a
completion for a function name followed by a period, so just make
sure that we end up with only one in the final list. Also, convert
tabs to spaces and fix up for code style in shellAutocomplete().
Branch: master
https://github.com/mongodb/mongo/commit/94602bb066d104cbf1fe8bb18203147774347bfe

Comment by Tad Marshall [ 11/Oct/11 ]

I did some more testing, and a version of the code that I built on my machine from 1.8.3 sources showed the same issue with 'prototype' appearing 3 times in the _autocomplete_ variable. I haven't figured out what changed from my earlier report, but it may be the version of SpiderMonkey I'm using. We could potentially see different behavior from V8.

It doesn't really matter what the root cause is, because it is worth fixing and it's not hard. readline had code to remove duplicates and linenoise could (should?) have that feature. The JavaScript that generates the list is doing nothing to prevent duplicates and it could (should) remove them. The bug is user-visible and easy to fix so it's worth fixing.

Comment by Tad Marshall [ 09/Oct/11 ]

Version 1.8.4-rc1-pre- doesn't have this bug.

MongoDB shell version: 1.8.4-rc1-pre-
> v=function(){}
function () {
}
> v.<tab> // generate _autocomplete_ typing "v." and by hitting tab, then ctrl-u to erase
> _autocomplete_
[
"v.apply(",
"v.call(",
"v.constructor",
"v.hasOwnProperty(",
"v.propertyIsEnumerable(",
"v.prototype", // prototype only appears in the list once
"v.toLocaleString(",
"v.toString(",
"v.valueOf("
]
>

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