Allen Wirfs-Brock (2014-06-10T22:41:05.000Z)
domenic at domenicdenicola.com (2014-06-17T20:41:08.059Z)
On Jun 10, 2014, at 2:08 PM, Ian Hickson wrote: > What is an "ECMAScript environment" in this context? Is it the scripting > engine behind a unit of related similar-origin browsing contexts? Or is it > the scripting engine associated with a particular event loop? > > - http://www.whatwg.org/html#unit-of-related-similar-origin-browsing-contexts > - http://www.whatwg.org/html#event-loop > > In the case of two pages that are running in different origins, each with > their own Window object, does the ES spec attempt to answer the question > of how those two scripts should interact if they access each others' > Window objects? Or is that something for the HTML spec? Almost every concept you used in the above two paragraphs are web platform specific concepts that are not even in the normal ECMAScript domain of discourse. By an ECMAScript Environment (and this is what Ecma-262 defines, although it doesn't actually use that name) I mean a heap of ECMAScript objects (and related values) that may directly reference (point to) each other and a single thread of execution of ECMAScript code. The environment may include multiple "global objects". In web terms, this could means several (same-origin??) windows and any associated Iframes, as long as there is only a single thread of ES code execution that encompasses them. It could not include a both the object/script state of Window and of a WebWorker because logically a WebWorker's tobjects may not contain references to the Window's object (and visa-versa) and because both the Window and the Worker have independent and potentially concurrent execution threads for ES code. While the spec. doesn't directly address this, I also like to assume fault isolation between ES environment. A fault in one ES environment should not be able to directly cause failure of another ES environment. Basically, like a Unix process. Whether certain Web constructs are modeled by sharing a single ES environment or as separate (but possibly communicating) ES environment is up to you and/or browser implementors. The possibility of interactions within an ES environment is all at the level of pointers between objects. If ES code has access to an object that contains a pointer to another object, then the code can interact with the second object. You might interpose proxying mechanism to try to isolate subgraphs of objects, but at the level of the ES semantics, such proxies are just additional objects with their own behaviors. > Such a "utility Realm" sounds like an implementation detail that wouldn't > appear in a spec, though, no? Would it be exposed or detectable in any way > from aithor script? > > There's not really a "first" Window from the point of view of the HTML > spec. I'm not sure how an initial Realm would really map to a browser. Such a "utility Realm" doen't appear in the ES spec. But it might have a used in the spec. that defines some specific hosting environment. I suppose, "first Window" could literally mean the first window opened by a browser. However, a browser like FF that uses JavaScript to implement its chrome might start up a Chrome Realm as its first Realm. If you want all documents from a given origin to operate within a single ES environment (is that a reasonable model?) then the first time you load a document from a new origin you might launch a new ES Environment with a a new Window object as its first Realm. > Ok. I think part of my confusion comes from step 7, then, which says "one > or more" scripts. I think if that was changed to "zero or more", I could > say in the HTML spec that the Initialization steps run as required by the > ES spec, and that in HTML implementations, step 7 must obtain no scripts. > Then, separate from this, I would call CreateRealm() to get a realm and > then call InitializeFirstRealm(realm) with that realm? Is that right? Yes, sounds about right. Particularly if I apply some renaming. > If step 7's "one or more" is what is intended (as opposed to the "zero or > more", see above), what is the script that a browser obtains in step 7? I think it should be zero or more. > Well, we want to make sure that browsers only have one dependency > algorithm, we wouldn't want to have redundancy there. See the "Integrating > the Webs' dependency systems" thread from a few weeks back. I'm trying to > understand how ES6's loading logic works so that I can figure out how to > integrate or extend it to handle the more elaborate needs of other parts > of the Web platform, so that we can e.g. have image loading handled by the > same logic as module loading, since they need to share network resources, > can have interdependencies, etc. We may have some chicken and egg issues to work through. But, in general the ES spec. only needs to address the semantic issues of things it defines. For example, it cares about the relative ordering of Promise Tasks because that is part of the ES promise emantics. But it doesn't care about the relative ordering of individual PromiseTasks and future cript evaluation tasks because there are no defined semantic dependencies between those. However, as we move more semantics into ES (for example, event callbacks and timeouts are likely future additions) we will probably have more dependencies to specify. > Are these tasks related in any way to the HTML spec's task queues and > event loop mechanism? Should we integrate these somehow also? At our latest TC39 meeting we decided to use the term "Job" for what we had been calling "Task" in the ES spec. Specifically to avoid confusion with the HTML spec. We need to avoid over-coupling the ES spec. to the HTML spec as ES is used in other host environments. That's why for Tasks(soon to be Jobs) we only define the minimum needed to have a consistent semantics across all ES hosts. Basically, what you should do is use ES Jobs as the mechanism for saying here is a bit of ES code that needs to be executed before/after/independently from some other bit of code. But the actual criteria for deciding to make such a request needs to be in your spec. > Do you have an example of how any of those steps could fail? The implementation provided global object could throw during the processing of SetDefualtGlobalBindings > It seems to me that if step 6 triggers, the whole scripting engine has > failed to start up, which seems like it should be something that is > non-conforming. :-) Exactly, the spec. essentially says that if exceptions occur during start-up then a conforming implementation must terminate. If we said nothing then an implementation might not check for such exceptions and could start ES code execution with in incompletely initialized set of global bindings. > NextTask seems like it is somewhat redundant with the HTML event loop > mechanism. Ideally I think I'd like to have the hooks set up so that when > a task completes on the ES side, it just returns to the HTML event loop, > which then does its stuff, and eventually calls back into the ES spec to > run the next script. That's pretty much what NextTask is. Steps 1-3 cleans up after the just completed task. Steps 4-5 calls out to the host provided task scheduler. Steps 6-10 initiates execution of the task that was selected by the host. Step 9 is an extra hook that allow the host environment to do additional host-spec processing for each task immediately before it is executed. It's something Boris asked for to manage domain switching issues.