Bug 1173385 - Calling $$("") should throw an exception. r=fitzgen
authorFlorent Fayolle <fayolle-florent@orange.fr>
Mon, 15 Jun 2015 14:22:00 -0400
changeset 249070 4a5c802618fefe97bef4f09fd94eb9115d847693
parent 248956 87c9b69a0ec085e4bb78560c80c195112a803aa7
child 249071 6be0a4695e430147b88ed162a8fee461e2dff33d
push id28916
push userryanvm@gmail.com
push dateTue, 16 Jun 2015 18:31:18 +0000
treeherdermozilla-central@69dab4252c6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs1173385
milestone41.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 1173385 - Calling $$("") should throw an exception. r=fitzgen
toolkit/devtools/server/actors/webconsole.js
toolkit/devtools/webconsole/test/test_jsterm_queryselector.html
--- a/toolkit/devtools/server/actors/webconsole.js
+++ b/toolkit/devtools/server/actors/webconsole.js
@@ -806,28 +806,24 @@ WebConsoleActor.prototype =
     let evalInfo = this.evalWithDebugger(input, evalOptions);
     let evalResult = evalInfo.result;
     let helperResult = evalInfo.helperResult;
 
     let result, errorMessage, errorGrip = null;
     if (evalResult) {
       if ("return" in evalResult) {
         result = evalResult.return;
-      }
-      else if ("yield" in evalResult) {
+      } else if ("yield" in evalResult) {
         result = evalResult.yield;
-      }
-      else if ("throw" in evalResult) {
+      } else if ("throw" in evalResult) {
         let error = evalResult.throw;
         errorGrip = this.createValueGrip(error);
-        let errorToString = evalInfo.window
-                            .evalInGlobalWithBindings("ex + ''", {ex: error});
-        if (errorToString && typeof errorToString.return == "string") {
-          errorMessage = errorToString.return;
-        }
+        errorMessage = error && (typeof error === "object")
+          ? error.unsafeDereference().toString()
+          : "" + error;
       }
     }
 
     // If a value is encountered that the debugger server doesn't support yet,
     // the console should remain functional.
     let resultGrip;
     try {
       resultGrip = this.createValueGrip(result);
--- a/toolkit/devtools/webconsole/test/test_jsterm_queryselector.html
+++ b/toolkit/devtools/webconsole/test/test_jsterm_queryselector.html
@@ -18,17 +18,21 @@ let gState;
 function evaluateJS(input) {
   return new Promise((resolve) => gState.client.evaluateJS(input, resolve));
 }
 
 function startTest() {
   removeEventListener("load", startTest);
   attachConsole([], state => {
     gState = state;
-    let tests = [checkQuerySelectorAll, checkQuerySelectorAllNotExist];
+    let tests = [
+      checkQuerySelectorAll,
+      checkQuerySelectorAllNotExist,
+      checkQuerySelectorAllException
+    ];
     runTests(tests, testEnd);
   }, true);
 }
 
 let checkQuerySelectorAll = Task.async(function*() {
   info ("$$ returns an array");
   let response = yield evaluateJS("$$('body')");
   basicResultCheck(response, "$$('body')", {
@@ -49,16 +53,33 @@ let checkQuerySelectorAllNotExist = Task
     class: "Array",
     preview: {
       length: 0
     }
   });
   nextTest();
 });
 
+let checkQuerySelectorAllException = Task.async(function*() {
+  info ("$$ returns an exception if an invalid selector was provided");
+  let response = yield evaluateJS("$$(':foo')");
+  checkObject(response, {
+    input: "$$(':foo')",
+    exceptionMessage: "SyntaxError: An invalid or illegal string was specified",
+    exception: {
+      preview: {
+        kind: "DOMException",
+        name: "SyntaxError",
+        message: "An invalid or illegal string was specified"
+      }
+    }
+  });
+  nextTest();
+});
+
 function basicResultCheck(response, input, output) {
   checkObject(response, {
     from: gState.actor,
     input: input,
     result: output,
   });
   ok(!response.exception, "no eval exception");
   ok(!response.helperResult, "no helper result");