Use 'self' instead of 'window' in browser, in order to work in a web worker

This commit is contained in:
Marijn Haverbeke 2012-11-29 10:08:32 +01:00
parent d36c70bbbf
commit f58bb9a480
2 changed files with 4 additions and 4 deletions

View File

@ -18,7 +18,7 @@
exports.version = "0.0.1"; exports.version = "0.0.1";
// The main exported interface (under `window.acorn` when in the // The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and // browser) is a `parse` function that takes a code string and
// returns an abstract syntax tree as specified by [Mozilla parser // returns an abstract syntax tree as specified by [Mozilla parser
// API][api], with the caveat that the SpiderMonkey-specific syntax // API][api], with the caveat that the SpiderMonkey-specific syntax
@ -1653,4 +1653,4 @@
return finishNode(node, "Identifier"); return finishNode(node, "Identifier");
} }
})(typeof exports === "undefined" ? (window.acorn = {}) : exports); })(typeof exports === "undefined" ? (self.acorn = {}) : exports);

View File

@ -13,7 +13,7 @@ https://github.com/marijnh/acorn.git
<p>Please use the <a href="https://github.com/marijnh/acorn/issues">github bug tracker</a> to report issues.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span> <p>Please use the <a href="https://github.com/marijnh/acorn/issues">github bug tracker</a> to report issues.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="p">{</span>
<span class="s2">&quot;use strict&quot;</span><span class="p">;</span> <span class="s2">&quot;use strict&quot;</span><span class="p">;</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">version</span> <span class="o">=</span> <span class="s2">&quot;0.0.1&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>The main exported interface (under <code>window.acorn</code> when in the <span class="nx">exports</span><span class="p">.</span><span class="nx">version</span> <span class="o">=</span> <span class="s2">&quot;0.0.1&quot;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>The main exported interface (under <code>self.acorn</code> when in the
browser) is a <code>parse</code> function that takes a code string and browser) is a <code>parse</code> function that takes a code string and
returns an abstract syntax tree as specified by <a href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API">Mozilla parser returns an abstract syntax tree as specified by <a href="https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API">Mozilla parser
API</a>, with the caveat that the SpiderMonkey-specific syntax API</a>, with the caveat that the SpiderMonkey-specific syntax
@ -1236,6 +1236,6 @@ identifiers.</p> </td> <td class="code"> <
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">&quot;Identifier&quot;</span><span class="p">);</span> <span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">&quot;Identifier&quot;</span><span class="p">);</span>
<span class="p">}</span> <span class="p">}</span>
<span class="p">})(</span><span class="k">typeof</span> <span class="nx">exports</span> <span class="o">===</span> <span class="s2">&quot;undefined&quot;</span> <span class="o">?</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">=</span> <span class="p">{})</span> <span class="o">:</span> <span class="nx">exports</span><span class="p">);</span> <span class="p">})(</span><span class="k">typeof</span> <span class="nx">exports</span> <span class="o">===</span> <span class="s2">&quot;undefined&quot;</span> <span class="o">?</span> <span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">acorn</span> <span class="o">=</span> <span class="p">{})</span> <span class="o">:</span> <span class="nx">exports</span><span class="p">);</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html> </pre></div> </td> </tr> </tbody> </table> </div> </body> </html>