Ian Hickson (2014-06-10T23:04:31.000Z)
domenic at domenicdenicola.com (2014-06-17T20:42:57.653Z)
On Tue, 10 Jun 2014, Allen Wirfs-Brock wrote: > 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". Ok. Sounds like that mays to an event loop, on the HTML side. That should be quite workable. I'll invoke 8.5 when I create an event loop (with zero scripts), and I'll invoke CreateRealm() and then 8.5.1 when I create a Window. > I suppose, "first Window" could literally mean the first window opened > by a browser. There might not be one. There's nothing stopping a browser from spawning multiple Windows at once on startup, or, indeed, from restoring old state all the way down to restoring a pre-existing Web page and JS environment. But that's ok, I think if we define things in terms of when the event loop is created, it should work out. > However, a browser like FF that uses JavaScript to implement its chrome > might start up a Chrome Realm as its first Realm. That part of Firefox is an implementation detail; from HTML's point of view, it doesn't exist. There should not be any way to distinguish (and therefore there should not be anything in the specs that would distinguish) a browser that uses JS under the hood and one that doesn't. > We may have some chicken and egg issues to work through. Don't we always! > 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. Sure. But browsers want to make sure they only implement one dependency mechanism, and so we have to make sure that all the dependency systems we specify can be implemented in terms of a single mechanism. Whether we end up doing this by speccing it as one, or speccing it as one that calls out to another, or whatever, remains to be seen. At this point I'm just trying to learn all I can about the various mechanisms. > 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. Cool. > 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. Right. > 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. I think ES should just say that an implementation must not fail on startup. But that's a separate topic. :-) > 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. Right, but what I'm saying is that from an editorial perspective it would be simpler for host specs to hook into the ES spec, and would be easier for implementors to understand, if the loop was turned inside-out from what it is now. Instead of the ES spec having an algorithm that works like this: ``` NextTask result: handle problems arising from the last job (result) stop running code get more code to run start running code (eventually calls NextTask) ``` ...it would be easier if it was: ``` RunCode (code): start running code stop running code let result be the result of running the code handle problems arising from the last job (result) return to calling algorithm in host spec ``` ...where RunCode is called by the host spec to run code. On a related note, it would be easier if algorithms that said to "Perform any implementation or host environment defined processing" named the specific steps. For example, in EnqueueTask step 7, it could say "Perform any implementation- or host-environment-defined processing of /pending/ to *queue a new task*", where "queue a new task" is a magic phrase (hook) that I would then be able to reference in HTML, e.g. by saying "When the ES spec says to *queue a new task*, follow these steps...".