The "initialization" steps for Web browsers

Ian Hickson ian at hixie.ch
Mon Jul 21 13:17:17 PDT 2014


On Mon, 21 Jul 2014, Ian Hickson wrote:
> On Tue, 10 Jun 2014, Ian Hickson wrote:
> > 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.
> 
> So I started trying to figure out how this would work, but I'm still 
> having trouble (sorry).
> 
> When an event loop is created, we invoke the algorithm in 8.5 
> Initialization, with step 7 set to obtain zero scripts, right?. Now, the 
> user opens a tab or something, and so a Window object needs to be 
> created. What do I do, exactly? Do I need to create a new realm? New 
> execution context? Both? Do I basically do steps 1-5 of the 
> Initialization steps again? I guess I do nothing else until I see a 
> <script>; then what do I do? do I create a PendingTask record for the 
> execution of the script, push it to the front of the Task Queue, and let 
> 9.5's NextTask call procede with this new task?

Here's my best guess about how to integrate HTML and ES. So far I've only 
attempted to describe <script> execution, but the rest should follow 
pretty straight-forwardly in theory.

  When an event loop is created, invoke the algorithm in 8.5
  Initialization. Step 7 should obtain zero scripts. This results in
  8.4.2 NextTask being invoked. 8.4.2 NextTask is adjusted as follows:

   The "implementation defined unhandled exception processing" in step 1
   must be the "report an error" logic in the HTML spec.

   The "implementation defined manner" for selecting "a non-empty Task
   Queue" in step 4 is to return execution to the calling algorithm;
   subsequent logic in the HTML spec will then resume the NextTask
   algorithm when a new task has been primed.

  When a Window or Worker is created, run 8.5 Initialization steps 1-6,
  except that in 8.5.1 InitializeFirstRealm, "this implementation
  requires use of an exotic object object to serve as realm’s global
  object", namely, the Window or WorkerGlobalScope object. Then, suspend
  the execution context. Stash the realm in the script settings object
  for the Window.

  When you load a <script>, the browser fetches the file, gets the body,
  decodes it to Unicode, and then creates a PendingTask record whose
  [[Task]] is ScriptEvaluationTask, whose [[Arguments]] consists of a
  list with one member, the Unicode characters obtained earlier, and the
  [[Realm]] is the object stashed in the script settings object. That
  record is put in the Task Queue, and then the NextTask algorithm is
  resumed.

Does anyone see anything problematic here? Does it look ok?

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the es-discuss mailing list