Bug 1287235 Wrap addon-sdk's Cu.getWeakReference() in a try/catch in case native objects are passed. r=bz a=sylvestre
authorBen Kelly <ben@wanderview.com>
Fri, 22 Jul 2016 10:18:21 -0700
changeset 342040 3ecc86179a9af4ddb53ab1fe478511a9832e9801
parent 342039 ccbdbee8d758c6aaf43b22c1b745cc9a13d51a6e
child 342041 02b002977b46df0249540aed40854f0905340bd4
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, sylvestre
bugs1287235
milestone49.0a2
Bug 1287235 Wrap addon-sdk's Cu.getWeakReference() in a try/catch in case native objects are passed. r=bz a=sylvestre
addon-sdk/source/lib/sdk/event/utils.js
--- a/addon-sdk/source/lib/sdk/event/utils.js
+++ b/addon-sdk/source/lib/sdk/event/utils.js
@@ -239,19 +239,26 @@ Input.prototype[end] = Input.end;
 // while also allowing the objects to be reclaimed.  It means, however,
 // input.value cannot be accessed long after the event was dispatched.
 const WeakValueGetterSetter = {
   get: function() {
     return this._weakValue ? this._weakValue.get() : this._simpleValue
   },
   set: function(v) {
     if (v && typeof v === "object") {
-      this._weakValue = Cu.getWeakReference(v)
-      this._simpleValue = undefined;
-      return;
+      try {
+        // Try to set a weak reference.  This can throw for some values.
+        // For example, if the value is a native object that does not
+        // implement nsISupportsWeakReference.
+        this._weakValue = Cu.getWeakReference(v)
+        this._simpleValue = undefined;
+        return;
+      } catch (e) {
+        // Do nothing.  Fall through to setting _simpleValue below.
+      }
     }
     this._simpleValue = v;
     this._weakValue = undefined;
   },
 }
 Object.defineProperty(Input.prototype, "value", WeakValueGetterSetter);
 
 exports.Input = Input;