Bug 1019643 - use Cu.cloneInto for browser elements instead of manually looping through objects and exposing them, r=bholley
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 04 Jun 2014 13:21:08 +0100
changeset 205795 e5306a36435b0c892aec93e46f41cd5390abe948
parent 205794 8a3065aa8100a9bd217eb797b373b9ea4e639577
child 205796 d4625a62c1bb7df0a61ce1f13d80eaf8c61c9c78
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1019643
milestone32.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 1019643 - use Cu.cloneInto for browser elements instead of manually looping through objects and exposing them, r=bholley
dom/browser-element/BrowserElementParent.jsm
--- a/dom/browser-element/BrowserElementParent.jsm
+++ b/dom/browser-element/BrowserElementParent.jsm
@@ -35,36 +35,16 @@ function getIntPref(prefName, def) {
   try {
     return Services.prefs.getIntPref(prefName);
   }
   catch(err) {
     return def;
   }
 }
 
-function exposeAll(obj) {
-  // Filter for Objects and Arrays.
-  if (typeof obj !== "object" || !obj)
-    return;
-
-  // Recursively expose our children.
-  Object.keys(obj).forEach(function(key) {
-    exposeAll(obj[key]);
-  });
-
-  // If we're not an Array, generate an __exposedProps__ object for ourselves.
-  if (obj instanceof Array)
-    return;
-  var exposed = {};
-  Object.keys(obj).forEach(function(key) {
-    exposed[key] = 'rw';
-  });
-  obj.__exposedProps__ = exposed;
-}
-
 function defineAndExpose(obj, name, value) {
   obj[name] = value;
   if (!('__exposedProps__' in obj))
     obj.__exposedProps__ = {};
   obj.__exposedProps__[name] = 'r';
 }
 
 function visibilityChangeHandler(e) {
@@ -494,17 +474,17 @@ BrowserElementParent.prototype = {
       sendUnblockMsg();
     }
   },
 
   _createEvent: function(evtName, detail, cancelable) {
     // This will have to change if we ever want to send a CustomEvent with null
     // detail.  For now, it's OK.
     if (detail !== undefined && detail !== null) {
-      exposeAll(detail);
+      detail = Cu.cloneInto(detail, this._window);
       return new this._window.CustomEvent('mozbrowser' + evtName,
                                           { bubbles: true,
                                             cancelable: cancelable,
                                             detail: detail });
     }
 
     return new this._window.Event('mozbrowser' + evtName,
                                   { bubbles: true,