tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug1739489-draftjs-beforeinput.js (1205B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Bug 1739489 - Entering an emoji using the MacOS IME "crashes" Draft.js editors.
      9 */
     10 
     11 /* globals exportFunction */
     12 
     13 console.info(
     14  "textInput event has been remapped to beforeinput for compatibility reasons. See https://bugzilla.mozilla.org/show_bug.cgi?id=1739489 for details."
     15 );
     16 
     17 window.wrappedJSObject.TextEvent = window.wrappedJSObject.InputEvent;
     18 
     19 const { CustomEvent, Event, EventTarget } = window.wrappedJSObject;
     20 var Remapped = [
     21  [CustomEvent, "constructor"],
     22  [Event, "constructor"],
     23  [Event, "initEvent"],
     24  [EventTarget, "addEventListener"],
     25  [EventTarget, "removeEventListener"],
     26 ];
     27 
     28 for (const [obj, name] of Remapped) {
     29  const { prototype } = obj;
     30  const orig = prototype[name];
     31  Object.defineProperty(prototype, name, {
     32    configurable: true,
     33    value: exportFunction(function (type, b, c, d) {
     34      if (type?.toLowerCase() === "textinput") {
     35        type = "beforeinput";
     36      }
     37      return orig.call(this, type, b, c, d);
     38    }, window),
     39  });
     40 }