Bug 1444004. Implement Event.prototype.srcElement as an alias for .target, nightly-only. r=smaug
☠☠ backed out by 2cb86c6e003d ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 07 Mar 2018 23:15:32 -0500
changeset 407151 52d86f152c2d82082fe2ff21867c4fc7a07b8a11
parent 407150 b7f24d48cd55f77572a0179d9ce467cac835b2fe
child 407152 b18dbffb418d9d165707e4a18c9da952d5992f4a
push id33594
push usercbrindusan@mozilla.com
push dateThu, 08 Mar 2018 18:01:12 +0000
treeherdermozilla-central@55d91695f4bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1444004
milestone60.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 1444004. Implement Event.prototype.srcElement as an alias for .target, nightly-only. r=smaug MozReview-Commit-ID: 4UMNqUBfUnp
dom/base/nsDOMTokenList.h
dom/events/Event.cpp
dom/events/Event.h
dom/webidl/Event.webidl
--- a/dom/base/nsDOMTokenList.h
+++ b/dom/base/nsDOMTokenList.h
@@ -70,17 +70,17 @@ public:
   void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
   bool Contains(const nsAString& aToken);
   void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
   void Add(const nsTArray<nsString>& aTokens,
            mozilla::ErrorResult& aError);
   void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
   void Remove(const nsTArray<nsString>& aTokens,
               mozilla::ErrorResult& aError);
-  void Replace(const nsAString& aToken,
+  bool Replace(const nsAString& aToken,
                const nsAString& aNewToken,
                mozilla::ErrorResult& aError);
   bool Toggle(const nsAString& aToken,
               const mozilla::dom::Optional<bool>& force,
               mozilla::ErrorResult& aError);
   bool Supports(const nsAString& aToken,
                 mozilla::ErrorResult& aError);
 
@@ -94,17 +94,17 @@ protected:
   nsresult CheckToken(const nsAString& aStr);
   nsresult CheckTokens(const nsTArray<nsString>& aStr);
   void RemoveDuplicatesInternal(nsTArray<RefPtr<nsAtom>>* aArray,
                                 uint32_t aStart);
   void AddInternal(const nsAttrValue* aAttr,
                    const nsTArray<nsString>& aTokens);
   void RemoveInternal(const nsAttrValue* aAttr,
                       const nsTArray<nsString>& aTokens);
-  void ReplaceInternal(const nsAttrValue* aAttr,
+  bool ReplaceInternal(const nsAttrValue* aAttr,
                        const nsAString& aToken,
                        const nsAString& aNewToken);
   inline const nsAttrValue* GetParsedAttr();
 
   nsCOMPtr<Element> mElement;
   RefPtr<nsAtom> mAttrAtom;
   const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens;
 };
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -241,16 +241,27 @@ Event::GetTarget() const
 
 NS_IMETHODIMP
 Event::GetTarget(nsIDOMEventTarget** aTarget)
 {
   NS_IF_ADDREF(*aTarget = GetTarget());
   return NS_OK;
 }
 
+bool
+Event::IsSrcElementEnabled(JSContext* /* unused */, JSObject* /* unused */)
+{
+  // Not a pref, because that's a pain on workers.
+#ifdef NIGHTLY_BUILD
+  return true;
+#else
+  return false;
+#endif
+}
+
 EventTarget*
 Event::GetCurrentTarget() const
 {
   return mEvent->GetCurrentDOMEventTarget();
 }
 
 void
 Event::ComposedPath(nsTArray<RefPtr<EventTarget>>& aPath)
--- a/dom/events/Event.h
+++ b/dom/events/Event.h
@@ -166,16 +166,17 @@ public:
                                              const nsAString& aType,
                                              const EventInit& aParam,
                                              ErrorResult& aRv);
 
   // Implemented as xpidl method
   // void GetType(nsString& aRetval) {}
 
   EventTarget* GetTarget() const;
+  static bool IsSrcElementEnabled(JSContext* /* unused */, JSObject* /* unused */);
   EventTarget* GetCurrentTarget() const;
 
   void ComposedPath(nsTArray<RefPtr<EventTarget>>& aPath);
 
   uint16_t EventPhase() const;
 
   // xpidl implementation
   // void StopPropagation();
--- a/dom/webidl/Event.webidl
+++ b/dom/webidl/Event.webidl
@@ -12,16 +12,18 @@
 
 [Constructor(DOMString type, optional EventInit eventInitDict),
  Exposed=(Window,Worker,System), ProbablyShortLivingWrapper]
 interface Event {
   [Pure]
   readonly attribute DOMString type;
   [Pure]
   readonly attribute EventTarget? target;
+  [Pure, BinaryName="target", Func="Event::IsSrcElementEnabled"]
+  readonly attribute EventTarget? srcElement;
   [Pure]
   readonly attribute EventTarget? currentTarget;
 
   sequence<EventTarget> composedPath();
 
   const unsigned short NONE = 0;
   const unsigned short CAPTURING_PHASE = 1;
   const unsigned short AT_TARGET = 2;