Bug 1452569 - Implement Event's returnValue. r=smaug
authorAlphan Chen <alchen@mozilla.com>
Tue, 28 Aug 2018 06:28:56 +0000
changeset 488678 70767540914776745f09d26af6a4d20dfd15f855
parent 488677 72c2fc2d0ab17a10c5540714c82739fb346b0088
child 488679 8a38246f1a708ef0495415b1543d360f07d1ccd9
push id9734
push usershindli@mozilla.com
push dateThu, 30 Aug 2018 12:18:07 +0000
treeherdermozilla-beta@71c71ab3afae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1452569
milestone63.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 1452569 - Implement Event's returnValue. r=smaug Add retrunValue into Event's interface Differential Revision: https://phabricator.services.mozilla.com/D4084
dom/events/Event.cpp
dom/events/Event.h
dom/webidl/Event.webidl
testing/web-platform/meta/dom/events/AddEventListenerOptions-passive.html.ini
testing/web-platform/meta/dom/events/Event-constructors.html.ini
testing/web-platform/meta/dom/events/Event-defaultPrevented-after-dispatch.html.ini
testing/web-platform/meta/dom/events/Event-initEvent.html.ini
testing/web-platform/meta/dom/events/Event-returnValue.html.ini
testing/web-platform/meta/dom/events/EventTarget-dispatchEvent-returnvalue.html.ini
testing/web-platform/meta/dom/interfaces.html.ini
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -998,16 +998,30 @@ Event::DefaultPrevented(CallerType aCall
 
   // If preventDefault() has been called by content, return true.  Otherwise,
   // i.e., preventDefault() has been called by chrome, return true only when
   // this is called by chrome.
   return mEvent->DefaultPreventedByContent() ||
          aCallerType == CallerType::System;
 }
 
+bool
+Event::ReturnValue(CallerType aCallerType) const
+{
+  return !DefaultPrevented(aCallerType);
+}
+
+void
+Event::SetReturnValue(bool aReturnValue, CallerType aCallerType)
+{
+  if (!aReturnValue) {
+    PreventDefaultInternal(aCallerType == CallerType::System);
+  }
+}
+
 double
 Event::TimeStamp()
 {
   if (!sReturnHighResTimeStamp) {
     // In the situation where you have set a very old, not-very-supported
     // non-default preference, we will always reduce the precision,
     // regardless of system principal or not.
     // The timestamp is absolute, so we supply a zero context mix-in.
--- a/dom/events/Event.h
+++ b/dom/events/Event.h
@@ -276,16 +276,20 @@ public:
     return mEvent->mFlags.mDefaultPreventedByContent;
   }
 
   bool MultipleActionsPrevented() const
   {
     return mEvent->mFlags.mMultipleActionsPrevented;
   }
 
+  bool ReturnValue(CallerType aCallerType) const;
+
+  void SetReturnValue(bool aReturnValue, CallerType aCallerType);
+
   bool IsTrusted() const
   {
     return mEvent->IsTrusted();
   }
 
   bool IsSynthesized() const
   {
     return mEvent->mFlags.mIsSynthesizedForTests;
--- a/dom/webidl/Event.webidl
+++ b/dom/webidl/Event.webidl
@@ -32,16 +32,18 @@ interface Event {
   void stopPropagation();
   void stopImmediatePropagation();
 
   [Pure]
   readonly attribute boolean bubbles;
   [Pure]
   readonly attribute boolean cancelable;
   [NeedsCallerType]
+  attribute boolean returnValue;
+  [NeedsCallerType]
   void preventDefault();
   [Pure, NeedsCallerType]
   readonly attribute boolean defaultPrevented;
   [ChromeOnly, Pure]
   readonly attribute boolean defaultPreventedByChrome;
   [ChromeOnly, Pure]
   readonly attribute boolean defaultPreventedByContent;
   [Pure]
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/AddEventListenerOptions-passive.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[AddEventListenerOptions-passive.html]
-  [returnValue should be ignored if-and-only-if the passive option is true]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/Event-constructors.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[Event-constructors.html]
-  [Event constructors 2]
-    expected: FAIL
-
-  [Event constructors 3]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/Event-defaultPrevented-after-dispatch.html.ini
+++ /dev/null
@@ -1,4 +0,0 @@
-[Event-defaultPrevented-after-dispatch.html]
-  [Default prevention via returnValue]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/Event-initEvent.html.ini
+++ /dev/null
@@ -1,13 +0,0 @@
-[Event-initEvent.html]
-  [Properties of initEvent(type, true, true)]
-    expected: FAIL
-
-  [Properties of initEvent(type, true, false)]
-    expected: FAIL
-
-  [Properties of initEvent(type, false, true)]
-    expected: FAIL
-
-  [Properties of initEvent(type, false, false)]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/Event-returnValue.html.ini
+++ /dev/null
@@ -1,19 +0,0 @@
-[Event-returnValue.html]
-  [When an event is created, returnValue should be initialized to true.]
-    expected: FAIL
-
-  [preventDefault() should not change returnValue if cancelable is false.]
-    expected: FAIL
-
-  [returnValue=false should have no effect if cancelable is false.]
-    expected: FAIL
-
-  [preventDefault() should change returnValue if cancelable is true.]
-    expected: FAIL
-
-  [initEvent should unset returnValue.]
-    expected: FAIL
-
-  [returnValue=true should have no effect once the canceled flag was set.]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/EventTarget-dispatchEvent-returnvalue.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[EventTarget-dispatchEvent-returnvalue.html]
-  [Return value of EventTarget.dispatchEvent() affected by preventDefault().]
-    expected: FAIL
-
-  [Return value of EventTarget.dispatchEvent() affected by returnValue.]
-    expected: FAIL
-
--- a/testing/web-platform/meta/dom/interfaces.html.ini
+++ b/testing/web-platform/meta/dom/interfaces.html.ini
@@ -82,27 +82,16 @@
     expected: FAIL
 
   [Range interface: existence and properties of interface object]
     expected: FAIL
 
   [Range interface: existence and properties of interface prototype object]
     expected: FAIL
 
-  [Event interface: attribute returnValue]
-    expected: FAIL
-
-  [Event interface: document.createEvent("Event") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
-  [Event interface: new Event("foo") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
-  [Event interface: new CustomEvent("foo") must inherit property "returnValue" with the proper type]
-    expected: FAIL
 
 
 [interfaces.html?1-1000]
   [Test driver]
     expected: FAIL
 
 
 [interfaces.html?1001-last]
@@ -110,29 +99,16 @@
     expected: FAIL
 
 
 [interfaces.html?exclude=Node]
   [Test driver]
     expected: FAIL
 
 
-[interfaces.html?exclude=Node]
-  [Event interface: attribute returnValue]
-    expected: FAIL
-
-  [Event interface: document.createEvent("Event") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
-  [Event interface: new Event("foo") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
-  [Event interface: new CustomEvent("foo") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
   [Document interface: attribute origin]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "origin" with the proper type]
     expected: FAIL
 
   [Document interface: xmlDoc must inherit property "origin" with the proper type]
     expected: FAIL
@@ -193,27 +169,16 @@
 
   [Range interface: existence and properties of interface prototype object]
     expected: FAIL
 
 
 [interfaces.html?include=Node]
 
 [interfaces.html?exclude=Node]
-  [Event interface: attribute returnValue]
-    expected: FAIL
-
-  [Event interface: document.createEvent("Event") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
-  [Event interface: new Event("foo") must inherit property "returnValue" with the proper type]
-    expected: FAIL
-
-  [Event interface: new CustomEvent("foo") must inherit property "returnValue" with the proper type]
-    expected: FAIL
 
   [Document interface: attribute origin]
     expected: FAIL
 
   [Document interface: new Document() must inherit property "origin" with the proper type]
     expected: FAIL
 
   [Document interface: xmlDoc must inherit property "origin" with the proper type]