Bug 1287235 Wrap addon-sdk's Cu.getWeakReference() in a try/catch in case native objects are passed. r=bz
authorBen Kelly <ben@wanderview.com>
Tue, 19 Jul 2016 17:14:04 -0700
changeset 305756 402ae3d3dec6f6b6dddca251adfb4457598bd8bc
parent 305755 4de50147d99cb9c51d11f0eaaac6663950f381ee
child 305757 77a8e7ea0fe57ebc175e6765075ecda3bb5e9793
push id30467
push usercbook@mozilla.com
push dateWed, 20 Jul 2016 09:21:53 +0000
treeherdermozilla-central@e904e18d7dfc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1287235
milestone50.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 1287235 Wrap addon-sdk's Cu.getWeakReference() in a try/catch in case native objects are passed. r=bz
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;