Bug 967468 - Webconsole - autocompletion: Consider underscore and dollar as alphanumeric when determining a prefix filter to use. r=robcee
authorSami Jaktholm <sjakthol@outlook.com>
Fri, 09 May 2014 09:15:00 -0400
changeset 211948 759429576b4baa003eb6080526d9987af53a8c47
parent 211855 3519e987aa3bba37b00dfe70e1382b4a5832d374
child 211949 e36a9703263f7af83b907758ff1538699fbe9553
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs967468
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 967468 - Webconsole - autocompletion: Consider underscore and dollar as alphanumeric when determining a prefix filter to use. r=robcee
browser/devtools/webconsole/test/browser.ini
browser/devtools/webconsole/test/browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js
browser/devtools/webconsole/webconsole.js
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -265,16 +265,17 @@ run-if = os == "mac"
 [browser_webconsole_split.js]
 [browser_webconsole_split_escape_key.js]
 [browser_webconsole_view_source.js]
 [browser_webconsole_reflow.js]
 [browser_webconsole_log_file_filter.js]
 [browser_webconsole_expandable_timestamps.js]
 [browser_webconsole_autocomplete_in_debugger_stackframe.js]
 [browser_webconsole_autocomplete_popup_close_on_tab_switch.js]
+[browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js]
 [browser_console_hide_jsterm_when_devtools_chrome_enabled_false.js]
 [browser_webconsole_output_01.js]
 [browser_webconsole_output_02.js]
 [browser_webconsole_output_03.js]
 [browser_webconsole_output_04.js]
 [browser_webconsole_output_05.js]
 [browser_webconsole_output_dom_elements_01.js]
 [browser_webconsole_output_dom_elements_02.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_webconsole_autocomplete-properties-with-non-alphanumeric-names.js
@@ -0,0 +1,42 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+// Test that properties starting with underscores or dollars can be
+// autocompleted (bug 967468).
+
+function test() {
+  const TEST_URI = "data:text/html;charset=utf8,test autocompletion with $ or _";
+  Task.spawn(runner).then(finishTest);
+
+  function* runner() {
+    function autocomplete(term) {
+      let deferred = promise.defer();
+
+      jsterm.setInputValue(term);
+      jsterm.complete(jsterm.COMPLETE_HINT_ONLY, deferred.resolve);
+
+      yield deferred.promise;
+
+      ok(popup.itemCount > 0, "There's suggestions for '" + term + "'");
+    }
+
+    yield addTab(TEST_URI);
+    let { jsterm } = yield openConsole(tab);
+    let popup = jsterm.autocompletePopup;
+
+    jsterm.execute("let testObject = {$$aaab: '', $$aaac: ''}");
+
+    // Should work with bug 967468.
+    yield autocomplete("Object.__d");
+    yield autocomplete("testObject.$$a");
+
+    // Here's when things go wrong in bug 967468.
+    yield autocomplete("Object.__de");
+    yield autocomplete("testObject.$$aa");
+  }
+}
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -4287,18 +4287,18 @@ JSTerm.prototype = {
     // Check if last character is non-alphanumeric
     if (!/[a-zA-Z0-9]$/.test(input) || frameActor != this._lastFrameActorId) {
       this._autocompleteQuery = null;
       this._autocompleteCache = null;
     }
 
     if (this._autocompleteQuery && input.startsWith(this._autocompleteQuery)) {
       let filterBy = input;
-      // Find the last non-alphanumeric if exists.
-      let lastNonAlpha = input.match(/[^a-zA-Z0-9][a-zA-Z0-9]*$/);
+      // Find the last non-alphanumeric other than _ or $ if it exists.
+      let lastNonAlpha = input.match(/[^a-zA-Z0-9_$][a-zA-Z0-9_$]*$/);
       // If input contains non-alphanumerics, use the part after the last one
       // to filter the cache
       if (lastNonAlpha) {
         filterBy = input.substring(input.lastIndexOf(lastNonAlpha) + 1);
       }
 
       let newList = cache.sort().filter(function(l) {
         return l.startsWith(filterBy);