From 0449ac603938657caba74b5a117f21ac1fe9fb9b Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Mon, 13 Jan 2020 09:39:37 +0000 Subject: [PATCH] Bug 1543190 - Fix console autocomplete throwing for null. r=nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D55391 --HG-- extra : moz-landing-system : lando --- .../webconsole/test/browser/_jsterm.ini | 1 + .../browser_jsterm_autocomplete_null.js | 70 +++++++++++++++++++ .../shared/webconsole/js-property-provider.js | 6 +- 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_null.js diff --git a/devtools/client/webconsole/test/browser/_jsterm.ini b/devtools/client/webconsole/test/browser/_jsterm.ini index 43044aed361c..b29a6c29851f 100644 --- a/devtools/client/webconsole/test/browser/_jsterm.ini +++ b/devtools/client/webconsole/test/browser/_jsterm.ini @@ -43,6 +43,7 @@ support-files = [browser_jsterm_autocomplete_inside_text.js] [browser_jsterm_autocomplete_native_getters.js] [browser_jsterm_autocomplete_nav_and_tab_key.js] +[browser_jsterm_autocomplete_null.js] [browser_jsterm_autocomplete_paste_undo.js] [browser_jsterm_autocomplete_race_on_enter.js] [browser_jsterm_autocomplete_return_key_no_selection.js] diff --git a/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_null.js b/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_null.js new file mode 100644 index 000000000000..0cea5b85ca50 --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_null.js @@ -0,0 +1,70 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function() { + await pushPref("devtools.chrome.enabled", true); + await addTab("about:blank"); + + info(`Open browser console with ctrl-shift-j`); + const opened = waitForBrowserConsole(); + EventUtils.synthesizeKey("j", { accelKey: true, shiftKey: true }, window); + const hud = await opened; + const { jsterm } = hud; + const { autocompletePopup: popup } = jsterm; + + info(`Clear existing messages`); + const onMessagesCleared = hud.ui.once("messages-cleared"); + await clearOutput(hud); + await onMessagesCleared; + + info(`Create a null variable`); + execute(hud, "globalThis.nullVar = null;"); + + info(`Check completion suggestions for "null"`); + const onPopUpOpen = popup.once("popup-opened"); + EventUtils.sendString("null", hud.iframeWindow); + await onPopUpOpen; + ok(popup.isOpen, "popup is open"); + const expectedPopupItems = ["null", "nullVar"]; + is( + popup.items.map(i => i.label).join("-"), + expectedPopupItems.join("-"), + "popup has expected items" + ); + + info(`Check completion suggestions for "null."`); + let onAutocompleteUpdated = jsterm.once("autocomplete-updated"); + EventUtils.sendString(".", hud.iframeWindow); + await onAutocompleteUpdated; + is(popup.itemCount, 0, "popup has no items"); + + info(`Check completion suggestions for "null"`); + onAutocompleteUpdated = jsterm.once("autocomplete-updated"); + EventUtils.synthesizeKey("KEY_Backspace", undefined, hud.iframeWindow); + await onAutocompleteUpdated; + is(popup.itemCount, 2, "popup has 2 items"); + + info(`Check completion suggestions for "nullVar"`); + onAutocompleteUpdated = jsterm.once("autocomplete-updated"); + EventUtils.sendString("Var.", hud.iframeWindow); + await onAutocompleteUpdated; + is(popup.itemCount, 0, "popup has no items"); + + info(`Check that no error was logged`); + await waitFor(() => findMessage(hud, "", ".message.error")).then( + message => { + ok(false, `Got error ${JSON.stringify(message.textContent)}`); + }, + error => { + if (!error.includes("waitFor - timed out")) { + throw error; + } + ok(true, `No error was logged`); + } + ); + + info(`Cleanup`); + execute(hud, "delete globalThis.nullVar;"); +}); diff --git a/devtools/shared/webconsole/js-property-provider.js b/devtools/shared/webconsole/js-property-provider.js index 09d0604165db..a8af64ffd5d9 100644 --- a/devtools/shared/webconsole/js-property-provider.js +++ b/devtools/shared/webconsole/js-property-provider.js @@ -980,9 +980,9 @@ var DebuggerEnvironmentSupport = { // FIXME: Need actual UI, bug 941287. if ( - result === undefined || - result.optimizedOut || - result.missingArguments + result == null || + (typeof result == "object" && + (result.optimizedOut || result.missingArguments)) ) { return null; }