Bug 1257734: Support set/get for mocked object in content for mochitest, r=bholley
☠☠ backed out by 2eeff30a5502 ☠ ☠
authorJunior Hsu <juhsu@mozilla.com>
Wed, 30 Mar 2016 15:05:09 +0800
changeset 291042 e8cd4e639e410abc015b6c4211059e700a39c9c3
parent 291041 0a14d675236ec1f37d1251b7e9ea5f9aa2aea35e
child 291043 2eeff30a55024f432f65e66bdb66690af8640aef
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1257734
milestone48.0a1
Bug 1257734: Support set/get for mocked object in content for mochitest, r=bholley
testing/specialpowers/content/specialpowersAPI.js
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -355,20 +355,23 @@ function wrapCallback(cb) {
     return cb.apply(this, args);
   }
 }
 
 function wrapCallbackObject(obj) {
   obj = Cu.waiveXrays(obj);
   var wrapper = {};
   for (var i in obj) {
-    if (typeof obj[i] == 'function')
-      wrapper[i] = wrapCallback(obj[i]);
-    else
-      wrapper[i] = obj[i];
+    var property = Object.getOwnPropertyDescriptor(obj, i);
+    for (var key in property) {
+      if (typeof property[key] == 'function') {
+        property[key] = wrapCallback(property[key]);
+      }
+    }
+    Object.defineProperty(wrapper, i, property);
   }
   return wrapper;
 }
 
 function setWrapped(obj, prop, val) {
   if (!isWrapper(obj))
     throw "You only need to use this for SpecialPowers wrapped objects";
 
@@ -685,17 +688,17 @@ SpecialPowersAPI.prototype = {
      }
      return delayedCallback;
   },
 
   /* apply permissions to the system and when the test case is finished (SimpleTest.finish())
      we will revert the permission back to the original.
 
      inPermissions is an array of objects where each object has a type, action, context, ex:
-     [{'type': 'SystemXHR', 'allow': 1, 'context': document}, 
+     [{'type': 'SystemXHR', 'allow': 1, 'context': document},
       {'type': 'SystemXHR', 'allow': Ci.nsIPermissionManager.PROMPT_ACTION, 'context': document}]
 
      Allow can be a boolean value of true/false or ALLOW_ACTION/DENY_ACTION/PROMPT_ACTION/UNKNOWN_ACTION
   */
   pushPermissions: function(inPermissions, callback) {
     inPermissions = Cu.waiveXrays(inPermissions);
     var pendingPermissions = [];
     var cleanupPermissions = [];