Bug 1499125 - Remove the bogus assertion r=arai a=RyanVM
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 30 Oct 2018 22:25:17 +0000
changeset 500972 b2f18c10db561c718b38bca0a163e216c40afdc8
parent 500971 b1225231edcae9f4d88f66c417ce6b2c4107178f
child 500973 14271099afebac2058d21b57dbdebc64879d3c06
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai, RyanVM
bugs1499125
milestone64.0
Bug 1499125 - Remove the bogus assertion r=arai a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D10094
js/src/builtin/Promise.cpp
js/src/builtin/Promise.h
js/src/jit-test/tests/promise/user-activation-propagation.js
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/builtin/Promise.cpp
+++ b/js/src/builtin/Promise.cpp
@@ -4484,28 +4484,26 @@ PromiseObject::setRequiresUserInteractio
     } else {
         RemovePromiseFlags(*this, PROMISE_FLAG_REQUIRES_USER_INTERACTION_HANDLING);
     }
 }
 
 void
 PromiseObject::setHadUserInteractionUponCreation(bool state)
 {
-    MOZ_ASSERT(this->state() == JS::PromiseState::Pending);
     if (state) {
         AddPromiseFlags(*this, PROMISE_FLAG_HAD_USER_INTERACTION_UPON_CREATION);
     } else {
         RemovePromiseFlags(*this, PROMISE_FLAG_HAD_USER_INTERACTION_UPON_CREATION);
     }
 }
 
 void
 PromiseObject::copyUserInteractionFlagsFrom(PromiseObject& rhs)
 {
-    MOZ_ASSERT(state() == JS::PromiseState::Pending);
     setRequiresUserInteractionHandling(rhs.requiresUserInteractionHandling());
     setHadUserInteractionUponCreation(rhs.hadUserInteractionUponCreation());
 }
 
 JSFunction*
 js::PromiseLookup::getPromiseConstructor(JSContext* cx)
 {
     const Value& val = cx->global()->getConstructor(JSProto_Promise);
--- a/js/src/builtin/Promise.h
+++ b/js/src/builtin/Promise.h
@@ -73,18 +73,17 @@ enum PromiseSlots {
 // promises while processing Promise#then.
 #define PROMISE_FLAG_REQUIRES_USER_INTERACTION_HANDLING 0x20
 
 // This flag indicates whether an activation behavior was in progress when the
 // original promise in the promise chain was created.  Activation behavior is a
 // concept defined by the HTML spec:
 // https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation
 // This flag is only effective when the
-// PROMISE_FLAG_REQUIRES_USER_INTERACTION_HANDLING is set.  Also, it is only
-// possible to set this flag on pending promises.
+// PROMISE_FLAG_REQUIRES_USER_INTERACTION_HANDLING is set.
 #define PROMISE_FLAG_HAD_USER_INTERACTION_UPON_CREATION 0x40
 
 class AutoSetNewObjectMetadata;
 
 class PromiseObject : public NativeObject
 {
   public:
     static const unsigned RESERVED_SLOTS = PromiseSlots;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/promise/user-activation-propagation.js
@@ -0,0 +1,19 @@
+function newPromiseCapability() {
+    return {};
+}
+function neverCalled() {}
+function resolveCapability(dIs) {}
+class P extends Promise {
+    constructor(executor) {
+        executor(resolveCapability, neverCalled);
+        var p = async function() {}();
+        p.constructor = {
+            [Symbol.species]: P
+        };
+        return p;
+    }
+}
+var {
+    promise: alwaysPending
+} = newPromiseCapability();
+P.race([alwaysPending]).then(neverCalled, neverCalled);
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -4565,19 +4565,16 @@ JS::SetPromiseUserInputEventHandlingStat
                                           JS::PromiseUserInputEventHandlingState state)
 {
     JSObject* promiseObj = CheckedUnwrap(promiseObj_);
     if (!promiseObj || !promiseObj->is<PromiseObject>()) {
         return false;
     }
 
     auto& promise = promiseObj->as<PromiseObject>();
-    if (promise.state() != JS::PromiseState::Pending) {
-      return false;
-    }
 
     switch (state) {
       case JS::PromiseUserInputEventHandlingState::DontCare:
         promise.setRequiresUserInteractionHandling(false);
         break;
       case JS::PromiseUserInputEventHandlingState::HadUserInteractionAtCreation:
         promise.setRequiresUserInteractionHandling(true);
         promise.setHadUserInteractionUponCreation(true);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -3433,18 +3433,17 @@ enum class PromiseUserInputEventHandling
  */
 extern JS_PUBLIC_API(PromiseUserInputEventHandlingState)
 GetPromiseUserInputEventHandlingState(JS::HandleObject promise);
 
 /**
  * Sets the given Promise's activation behavior state flag per above as a
  * JS::PromiseUserInputEventHandlingState value.
  *
- * Returns false if the given object is a wrapper that can't safely be unwrapped,
- * or if the promise isn't pending.
+ * Returns false if the given object is a wrapper that can't safely be unwrapped.
  */
 extern JS_PUBLIC_API(bool)
 SetPromiseUserInputEventHandlingState(JS::HandleObject promise,
                                       JS::PromiseUserInputEventHandlingState state);
 
 /**
  * Unforgeable version of the JS builtin Promise.all.
  *