<?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>231506</bug_id>
          
          <creation_ts>2021-10-11 03:10:02 -0700</creation_ts>
          <short_desc>Investigate `JSGlobalObject == JSDOMGlobalObject` WebCore assumption in presence of Shadow Realms</short_desc>
          <delta_ts>2022-02-16 13:57:44 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>230602</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Phillip Mates">pmates</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>joseph.j.griego</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1802563</commentid>
    <comment_count>0</comment_count>
    <who name="Phillip Mates">pmates</who>
    <bug_when>2021-10-11 03:10:02 -0700</bug_when>
    <thetext>A lot of WebCore code assumes that JSGlobalObject instances are the JSDOMGlobalObject subclass.
For example, when `incumbentDOMWindow` is traversing JSGlobalObjects in the callstack, and it assumes that these ones are JSDOMWindow.

After introducing Shadow Realms, via https://bugs.webkit.org/show_bug.cgi?id=230602, this won&apos;t necessarily be true. That is WebCore&apos;s assumption that `JSGlobalObject == JSDOMGlobalObject` might no longer be valid.

This ticket a is a reminder that we need to investigate this and properly adapt the code if needed</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1805506</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-10-18 03:10:17 -0700</bug_when>
    <thetext>&lt;rdar://problem/84363152&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1808479</commentid>
    <comment_count>2</comment_count>
    <who name="Phillip Mates">pmates</who>
    <bug_when>2021-10-25 10:54:00 -0700</bug_when>
    <thetext>Yusuke, you raised this initially. Looking at `incumbentDOMWindow`, it doesn&apos;t seem to be used in api contexts that the shadow realm has access to. For example, in the derived JSDOMWindow.cpp, `incumbentDOMWindow` is used for `postMessage`, `closeBody`, `focusBody`, etc, which won&apos;t be exposed to the shadow realm global object.

Can you think of other areas we need to look out for, or perhaps this assumption isn&apos;t an issue?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1808508</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2021-10-25 12:02:25 -0700</bug_when>
    <thetext>(In reply to Phillip Mates from comment #2)
&gt; Yusuke, you raised this initially. Looking at `incumbentDOMWindow`, it
&gt; doesn&apos;t seem to be used in api contexts that the shadow realm has access to.
&gt; For example, in the derived JSDOMWindow.cpp, `incumbentDOMWindow` is used
&gt; for `postMessage`, `closeBody`, `focusBody`, etc, which won&apos;t be exposed to
&gt; the shadow realm global object.
&gt; 
&gt; Can you think of other areas we need to look out for, or perhaps this
&gt; assumption isn&apos;t an issue?

What happens if you pass these functions to ShadowRealm and calling it inside ShadowRealm&apos;s user function?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1842514</commentid>
    <comment_count>4</comment_count>
    <who name="Joseph Griego">joseph.j.griego</who>
    <bug_when>2022-02-16 13:57:44 -0800</bug_when>
    <thetext>As mentioned on Slack (https://webkit.slack.com/archives/CTV4FGWF4/p1644353301940789) I think we are pretty comfortable not worrying about this, by the usual design of shadow realms, since when we call into parts of the runtime expecting a JSDOMObject on the stack, we will have the incubating realm&apos;s global object installed there because of the existing function wrapping;

I&apos;m gonna leave this open, for now, though; since this does change when we install web APIs into the shadow realm context.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>