<h3 dir="auto">Input Code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function Target(target){
        var errMsg = '';
       if (typeof target != 'object'){
            errMsg = 'target error - target itself must be window object';
        }
        if(errMsg){
            throw new Error(errMsg);
        }
        this.target = target;
}

// get iframe
var ifr = document.getElementsByTagName('iframe')[0];
// create messager target
var msg = new Target(ifr.contentWindow);"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-v">Target</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">errMsg</span> <span class="pl-c1">=</span> <span class="pl-s">''</span><span class="pl-kos">;</span>
       <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-k">typeof</span> <span class="pl-s1">target</span> <span class="pl-c1">!=</span> <span class="pl-s">'object'</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
            <span class="pl-s1">errMsg</span> <span class="pl-c1">=</span> <span class="pl-s">'target error - target itself must be window object'</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-s1">errMsg</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
            <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s1">errMsg</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">target</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c">// get iframe</span>
<span class="pl-k">var</span> <span class="pl-s1">ifr</span> <span class="pl-c1">=</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-en">getElementsByTagName</span><span class="pl-kos">(</span><span class="pl-s">'iframe'</span><span class="pl-kos">)</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
<span class="pl-c">// create messager target</span>
<span class="pl-k">var</span> <span class="pl-s1">msg</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Target</span><span class="pl-kos">(</span><span class="pl-s1">ifr</span><span class="pl-kos">.</span><span class="pl-c1">contentWindow</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">after babel transform</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var _typeof = typeof Symbol === &quot;function&quot; &amp;&amp; typeof Symbol.iterator === &quot;symbol&quot; ? function (obj) { return typeof obj; } : function (obj) { return obj &amp;&amp; typeof Symbol === &quot;function&quot; &amp;&amp; obj.constructor === Symbol &amp;&amp; obj !== Symbol.prototype ? &quot;symbol&quot; : typeof obj; };

function Target(target) {
    var errMsg = '';
    if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) != 'object') {
        errMsg = 'target error - target itself must be window object';
    }
    if (errMsg) {
        throw new Error(errMsg);
    }
    this.target = target;
}"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">_typeof</span> <span class="pl-c1">=</span> <span class="pl-k">typeof</span> <span class="pl-v">Symbol</span> <span class="pl-c1">===</span> <span class="pl-s">"function"</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-k">typeof</span> <span class="pl-v">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">iterator</span> <span class="pl-c1">===</span> <span class="pl-s">"symbol"</span> ? <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-k">typeof</span> <span class="pl-s1">obj</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> : <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-s1">obj</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-k">typeof</span> <span class="pl-v">Symbol</span> <span class="pl-c1">===</span> <span class="pl-s">"function"</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">obj</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span> <span class="pl-c1">===</span> <span class="pl-v">Symbol</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">obj</span> <span class="pl-c1">!==</span> <span class="pl-v">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span> ? <span class="pl-s">"symbol"</span> : <span class="pl-k">typeof</span> <span class="pl-s1">obj</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-v">Target</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">errMsg</span> <span class="pl-c1">=</span> <span class="pl-s">''</span><span class="pl-kos">;</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-k">typeof</span> <span class="pl-s1">target</span> <span class="pl-c1">===</span> <span class="pl-s">'undefined'</span> ? <span class="pl-s">'undefined'</span> : <span class="pl-s1">_typeof</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-c1">!=</span> <span class="pl-s">'object'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-s1">errMsg</span> <span class="pl-c1">=</span> <span class="pl-s">'target error - target itself must be window object'</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">errMsg</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s1">errMsg</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">target</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">when i use IE11.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SCRIPT5：Access is denied  // iframe.contentWindow.constructor"><pre class="notranslate"><code class="notranslate">SCRIPT5：Access is denied  // iframe.contentWindow.constructor
</code></pre></div>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">fixe <a href="https://github.com/babel/babel/blob/master/packages/babel-helpers/src/helpers.js#L8">helpers.typeof</a>.</p>
<h3 dir="auto">Your Environment</h3>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6.10.4</td>
</tr>
<tr>
<td>node</td>
<td>6.10.0</td>
</tr>
<tr>
<td>npm</td>
<td>3.10.10</td>
</tr>
<tr>
<td>Operating System</td>
<td>macOS 10.12.4</td>
</tr>
</tbody>
</table>
<p dir="auto"><code class="notranslate">transform-es2015-typeof-symbol</code> converts <code class="notranslate">typeof foo</code> to <code class="notranslate">_typeof(foo)</code> when <code class="notranslate">typeof Symbol.iterator !== "symbol"</code>. <code class="notranslate">_typeof</code> is implemented as follows:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function(obj) {
        return obj &amp;&amp; typeof Symbol === &quot;function&quot; &amp;&amp; obj.constructor === Symbol &amp;&amp; obj !== Symbol.prototype ? &quot;symbol&quot; : typeof obj;
}"><pre class="notranslate"><code class="notranslate">function(obj) {
        return obj &amp;&amp; typeof Symbol === "function" &amp;&amp; obj.constructor === Symbol &amp;&amp; obj !== Symbol.prototype ? "symbol" : typeof obj;
}
</code></pre></div>
<p dir="auto">That <code class="notranslate">obj.constructor</code> property lookup throws an error when it's applied to a cross-domain window object. For example, <code class="notranslate">typeof window.frames[0]</code> transpiles to <code class="notranslate">_typeof(window.frames[0])</code> which ends up calling <code class="notranslate">window.frames[0].constructor</code>, which triggers a cross-domain permission error.</p>
<h3 dir="auto">Input Code</h3>


<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="typeof window.frames[0];"><pre class="notranslate"><span class="pl-k">typeof</span> <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">frames</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

var _typeof = typeof Symbol === &quot;function&quot; &amp;&amp; typeof Symbol.iterator === &quot;symbol&quot; ? function (obj) { return typeof obj; } : function (obj) { return obj &amp;&amp; typeof Symbol === &quot;function&quot; &amp;&amp; obj.constructor === Symbol &amp;&amp; obj !== Symbol.prototype ? &quot;symbol&quot; : typeof obj; };

_typeof(window.frames[0]);"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">var</span> <span class="pl-s1">_typeof</span> <span class="pl-c1">=</span> <span class="pl-k">typeof</span> <span class="pl-v">Symbol</span> <span class="pl-c1">===</span> <span class="pl-s">"function"</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-k">typeof</span> <span class="pl-v">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">iterator</span> <span class="pl-c1">===</span> <span class="pl-s">"symbol"</span> ? <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-k">typeof</span> <span class="pl-s1">obj</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> : <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-s1">obj</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-k">typeof</span> <span class="pl-v">Symbol</span> <span class="pl-c1">===</span> <span class="pl-s">"function"</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">obj</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span> <span class="pl-c1">===</span> <span class="pl-v">Symbol</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">obj</span> <span class="pl-c1">!==</span> <span class="pl-v">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span> ? <span class="pl-s">"symbol"</span> : <span class="pl-k">typeof</span> <span class="pl-s1">obj</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-s1">_typeof</span><span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">frames</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Babel Configuration (.babelrc, package.json, cli command)</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
    &quot;presets&quot;: [ &quot;es2015&quot; ]
}"><pre class="notranslate"><span class="pl-kos">{</span>
    <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span> <span class="pl-s">"es2015"</span> <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto"><code class="notranslate">_typeof</code> should not try to access privileged properties on a cross-domain window object.</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto"><code class="notranslate">_typeof</code> tries to access privileged properties on a cross-domain window object.</p>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto"><code class="notranslate">try/catch</code> and fall-back to <code class="notranslate">typeof</code>?</p>
<h3 dir="auto">Context</h3>
<p dir="auto">Broke the following addition to <code class="notranslate">post-robot</code>, which allows sending messages to remote windows. We validate the passed window using <code class="notranslate">typeof</code> to ensure it's at least an <code class="notranslate">"object"</code></p>
<h3 dir="auto">Your Environment</h3>

<table role="table">
<thead>
<tr>
<th>software</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6</td>
</tr>
<tr>
<td>node</td>
<td>4</td>
</tr>
<tr>
<td>npm</td>
<td>3</td>
</tr>
<tr>
<td>Operating System</td>
<td>Windows 7 / IE9-11</td>
</tr>
</tbody>
</table>