adobe/brackets — pull request #2816 by peterflynn (2013-02-08 06:18:44+00:00)
Title: Fix #2813 - Go to Definition can't find toString() methods

Fix bug #2813 (Go to Definition can't find toString() methods) - Use hasOwnProperty() with StringMatcher caches instead of simple truthy checks that will see Object.prototype members too. Includes unit test.

I did a quick skim for other instances of this bug (and added a few docs clarifications to this patch in the process). Most other places I found where we use objects as string sets/maps are fine because it's either impossible for a key to collide with something from JS (e.g. the strings are absolute paths, or keyboard shortcuts) or the string is hardcoded by the developer and thus hitting this bug would be easy to spot & work around (e.g. the strings are command ids).

JSUtils._findAllFunctionsInText() narrowly avoids this bug via an Array.isArray() check, but it seemed fragile enough that I added a unit test for it too.

I didn't do an exhaustive search, though, so there might be other bugs like this lurking around. I wish JS had real map/set constructs that weren't so bug-prone... :-/