<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>218361</bug_id>
          
          <creation_ts>2020-10-29 15:52:29 -0700</creation_ts>
          <short_desc>JS Promises in detached iframes do not settle</short_desc>
          <delta_ts>2020-10-30 16:59:59 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>218363</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=218363</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Chris Dumez">cdumez</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ggaren</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>rniwa</cc>
    
    <cc>saam</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1702904</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2020-10-29 15:52:29 -0700</bug_when>
    <thetext>JS Promises in detached iframes do not settle:

===
&lt;!doctype html&gt;
&lt;title&gt;Test that the promise from detached iframes do get resolved.&lt;/title&gt;
&lt;body&gt;&lt;/body&gt;
&lt;script&gt;
frame = document.createElement(&apos;iframe&apos;);
document.body.appendChild(frame);
frame.contentWindow.Promise.resolve(&quot;test&quot;).then(() =&gt; {
    alert(&quot;Resolved! URL is: &quot; + document.URL);
});
frame.remove();
&lt;/script&gt;
===

I see an alert in Chrome and Firefox (with the URL being the top document URL). No alert in Safari.

This is causing issues with our DOM API returning promises as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702906</commentid>
    <comment_count>1</comment_count>
    <who name="Keith Miller">keith_miller</who>
    <bug_when>2020-10-29 15:55:46 -0700</bug_when>
    <thetext>Do we check that the frame is still detached in the WebCore micro task queue? Seems likely that is the source of the problem here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702907</commentid>
    <comment_count>2</comment_count>
    <who name="Keith Miller">keith_miller</who>
    <bug_when>2020-10-29 15:56:18 -0700</bug_when>
    <thetext>(In reply to Keith Miller from comment #1)
&gt; Do we check that the frame is still detached in the WebCore micro task
&gt; queue? Seems likely that is the source of the problem here.

/detached/attached/s</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702912</commentid>
    <comment_count>3</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2020-10-29 16:06:48 -0700</bug_when>
    <thetext>Looks like this is the source of the issue:

diff --git a/Source/WebCore/dom/Microtasks.cpp b/Source/WebCore/dom/Microtasks.cpp
index 2e4aa4b56c10..73cb09642adf 100644
--- a/Source/WebCore/dom/Microtasks.cpp
+++ b/Source/WebCore/dom/Microtasks.cpp
@@ -56,7 +56,7 @@ void MicrotaskQueue::performMicrotaskCheckpoint()
         Vector&lt;std::unique_ptr&lt;EventLoopTask&gt;&gt; queue = WTFMove(m_microtaskQueue);
         for (auto&amp; task : queue) {
             auto* group = task-&gt;group();
-            if (!group || group-&gt;isStoppedPermanently())
+            if (!group/* || group-&gt;isStoppedPermanently()*/)
                 continue;
             if (group-&gt;isSuspended())
                 toKeep.append(WTFMove(task));</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702914</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2020-10-29 16:15:11 -0700</bug_when>
    <thetext>As Geoff pointed out on Slack:
&quot;&quot;&quot;
A browsing context group holds a browsing context set (a set of top-level browsing contexts).
A top-level browsing context is added to the group when the group is created. All subsequent top-level browsing contexts added to the group will be auxiliary browsing contexts.
&quot;&quot;&quot;

Seems wrong that we use different groups for documents in the same top-level browsing context.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702915</commentid>
    <comment_count>5</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2020-10-29 16:19:45 -0700</bug_when>
    <thetext>Is it related to https://bugs.webkit.org/show_bug.cgi?id=216149 ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702920</commentid>
    <comment_count>6</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2020-10-29 16:37:09 -0700</bug_when>
    <thetext>diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index c9e3be11872a..6f4ffa18644b 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -2711,8 +2711,8 @@ void Document::resumeActiveDOMObjects(ReasonForSuspension why)
 
 void Document::stopActiveDOMObjects()
 {
-    if (m_documentTaskGroup)
-        m_documentTaskGroup-&gt;stopAndDiscardAllTasks();
+    /*if (m_documentTaskGroup)
+        m_documentTaskGroup-&gt;stopAndDiscardAllTasks();*/
     ScriptExecutionContext::stopActiveDOMObjects();
     platformSuspendOrStopActiveDOMObjects();
 }
diff --git a/Source/WebCore/dom/Microtasks.cpp b/Source/WebCore/dom/Microtasks.cpp
index 2e4aa4b56c10..73cb09642adf 100644
--- a/Source/WebCore/dom/Microtasks.cpp
+++ b/Source/WebCore/dom/Microtasks.cpp
@@ -56,7 +56,7 @@ void MicrotaskQueue::performMicrotaskCheckpoint()
         Vector&lt;std::unique_ptr&lt;EventLoopTask&gt;&gt; queue = WTFMove(m_microtaskQueue);
         for (auto&amp; task : queue) {
             auto* group = task-&gt;group();
-            if (!group || group-&gt;isStoppedPermanently())
+            if (!group/* || group-&gt;isStoppedPermanently()*/)
                 continue;
             if (group-&gt;isSuspended())
                 toKeep.append(WTFMove(task));

Had to do both these changes to make WebAudio tests pass (Bug 218363).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1703262</commentid>
    <comment_count>7</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2020-10-30 16:59:59 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 218363 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>