Bug 1453385 - Fix actors trying to transfer functions or xpcom objects. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 12 Apr 2018 14:45:10 -0700
changeset 781942 a7903d7cc2357419d24c39ba1dca767fdba3f5d4
parent 781941 49b570f02f1d2bd7d4eccd2fd8e691be83524fe8
child 781943 7c961d6a54c671fe91e6720240fb6eeb2ebd7a36
push id106451
push userbmo:poirot.alex@gmail.com
push dateFri, 13 Apr 2018 20:48:33 +0000
reviewersjryans
bugs1453385
milestone61.0a1
Bug 1453385 - Fix actors trying to transfer functions or xpcom objects. r=jryans MozReview-Commit-ID: 74l85ePCcrY
devtools/client/shared/test/test-actor.js
devtools/server/actors/inspector/node.js
--- a/devtools/client/shared/test/test-actor.js
+++ b/devtools/client/shared/test/test-actor.js
@@ -656,17 +656,25 @@ var TestActor = exports.TestActor = prot
   /**
    * Evaluate a JS string in the context of the content document.
    * @param {String} js JS string to evaluate
    * @return {json} The evaluation result
    */
   eval: function(js) {
     // We have to use a sandbox, as CSP prevent us from using eval on apps...
     let sb = Cu.Sandbox(this.content, { sandboxPrototype: this.content });
-    return Cu.evalInSandbox(js, sb);
+    let result = Cu.evalInSandbox(js, sb);
+
+    // Ensure passing only serializable data to RDP
+    if (typeof result == "function") {
+      return null;
+    } else if (typeof result == "object") {
+      return JSON.parse(JSON.stringify(result));
+    }
+    return result;
   },
 
   /**
    * Scrolls the window to a particular set of coordinates in the document, or
    * by the given amount if `relative` is set to `true`.
    *
    * @param {Number} x
    * @param {Number} y
--- a/devtools/server/actors/inspector/node.js
+++ b/devtools/server/actors/inspector/node.js
@@ -173,32 +173,32 @@ const NodeActor = protocol.ActorClassWit
   },
 
   get isAfterPseudoElement() {
     return this.rawNode.nodeName === "_moz_generated_content_after";
   },
 
   get isShadowRoot() {
     let isFragment = this.rawNode.nodeType === Ci.nsIDOMNode.DOCUMENT_FRAGMENT_NODE;
-    return isFragment && this.rawNode.host;
+    return isFragment && !!this.rawNode.host;
   },
 
   get isShadowHost() {
     let shadowRoot = this.rawNode.shadowRoot;
     return shadowRoot && shadowRoot.nodeType === Ci.nsIDOMNode.DOCUMENT_FRAGMENT_NODE;
   },
 
   get isDirectShadowHostChild() {
     // Pseudo elements are always part of the anonymous tree.
     if (this.isBeforePseudoElement || this.isAfterPseudoElement) {
       return false;
     }
 
     let parentNode = this.rawNode.parentNode;
-    return parentNode && parentNode.shadowRoot;
+    return parentNode && !!parentNode.shadowRoot;
   },
 
   // Estimate the number of children that the walker will return without making
   // a call to children() if possible.
   get numChildren() {
     // For pseudo elements, childNodes.length returns 1, but the walker
     // will return 0.
     if (this.isBeforePseudoElement || this.isAfterPseudoElement) {