Bug 917322 part.23 Store nsITextInputProcessor instance into WeakMap instead of window r=smaug
authorTooru Fujisawa <arai_a@mac.com>
Tue, 27 Jan 2015 19:12:23 +0900
changeset 239594 8d063686d243f74077828c4ffe6721d62f8e0811
parent 239593 b5d2f8341db40b0624320738ba731f03966ecd9a
child 239595 2af584e18fdb0788c1dc564650d2919b91ced287
push id500
push userjoshua.m.grant@gmail.com
push dateThu, 29 Jan 2015 01:48:36 +0000
reviewerssmaug
bugs917322
milestone38.0a1
Bug 917322 part.23 Store nsITextInputProcessor instance into WeakMap instead of window r=smaug
testing/mochitest/tests/SimpleTest/EventUtils.js
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -869,30 +869,37 @@ const COMPOSITION_ATTR_RAW_CLAUSE =
   _EU_Ci.nsITextInputProcessor.ATTR_RAW_CLAUSE;
 const COMPOSITION_ATTR_SELECTED_RAW_CLAUSE =
   _EU_Ci.nsITextInputProcessor.ATTR_SELECTED_RAW_CLAUSE;
 const COMPOSITION_ATTR_CONVERTED_CLAUSE =
   _EU_Ci.nsITextInputProcessor.ATTR_CONVERTED_CLAUSE;
 const COMPOSITION_ATTR_SELECTED_CLAUSE =
   _EU_Ci.nsITextInputProcessor.ATTR_SELECTED_CLAUSE;
 
+var TIPMap = new WeakMap();
+
 function _getTIP(aWindow, aCallback)
 {
   if (!aWindow) {
     aWindow = window;
   }
-  if (!aWindow._EU_TIP) {
-    aWindow._EU_TIP =
+  var tip;
+  if (TIPMap.has(aWindow)) {
+    tip = TIPMap.get(aWindow);
+  } else {
+    tip =
       _EU_Cc["@mozilla.org/text-input-processor;1"].
         createInstance(_EU_Ci.nsITextInputProcessor);
+    TIPMap.set(aWindow, tip);
   }
-  if (!aWindow._EU_TIP.initForTests(aWindow, aCallback)) {
-    aWindow._EU_TIP = null;
+  if (!tip.initForTests(aWindow, aCallback)) {
+    tip = null;
+    TIPMap.delete(aWindow);
   }
-  return aWindow._EU_TIP;
+  return tip;
 }
 
 /**
  * Synthesize a composition event.
  *
  * @param aEvent               The composition event information.  This must
  *                             have |type| member.  The value must be
  *                             "compositionstart", "compositionend",