Re: [HTML Imports]: what scope to run in

On Sat, Nov 23, 2013 at 1:51 AM, Jonas Sicking <jonas@sicking.cc> wrote:
>
>
> It would technically be possible to define that <script> elements
> inside the imported documents also run inside a scope object the same
> way that <module>s do. This way imported documents would be less
> likely to pollute the global object of the importing page. This idea
> didn't seem very popular though. (I still like it :) ).
>

Running JS in a function scope to avoid implicit global creation is quite
popular, the Immediate Invoked Function Expression (IIFE) pattern. Since
that option is available and since <module> should be available, we should
not redefine what <script> means in an import.


>
> One thing that we did discuss but that I think we never reached a
> conclusion on was if imported HTML documents need to block <module>
> tags in the main document. Otherwise there's a risk that named modules
> introduced by the imported HTML document won't be known at the time
> when name resolution happens in the main document. Whether this is a
> problem or not depends on now this name resolution works. I think this
> is still an outstanding question to resolve.
>

If we want HTML imports to be able to define named modules, then the ES
System loader must be able to load that module by name. IMO we cannot allow
named modules to be defined that cannot be loaded by name. Then the problem
you outline cannot happen: if the main document or any other ongoing HTML
Import or ES module loading needs a module it looks it up in the System and
blocks until the module is available.


jjb

Received on Saturday, 23 November 2013 18:08:50 UTC