[html5] r2529 - [cgiowrt] (2) MAJOR CHANGES: Revamp the way scripts are specified, along with th [...]

whatwg at whatwg.org whatwg at whatwg.org
Fri Dec 12 00:46:25 PST 2008


Author: ianh
Date: 2008-12-12 00:46:24 -0800 (Fri, 12 Dec 2008)
New Revision: 2529

Modified:
   index
   source
Log:
[cgiowrt] (2) MAJOR CHANGES: Revamp the way scripts are specified, along with their interaction with resolving relative URLs, etc. Give enough detail to justify objects in the DOM not being garbage collected randomly when still in use. Define script groups, to handle scripts going away during document.open() and session history navigation. Define why and how setTimeout(), database transactions, etc, handle page transitions. Drop the terms 'with' and 'without' script, use script is 'enabled'/'disabled' instead. Define 'unload' and 'beforeunload'. Rework how onfoo='' and .onfoo event handler attributes are defined. Rework how the content model of <noscript> is defined. Reword the way javascript: is defined to use the new terminology. Add a few notes of things that came up while I was doing all that.

Modified: index
===================================================================
--- index	2008-12-03 01:27:37 UTC (rev 2528)
+++ index	2008-12-12 08:46:24 UTC (rev 2529)
@@ -17,7 +17,7 @@
   <div class=head>
    <p><a class=logo href=http://www.whatwg.org/ rel=home><img alt=WHATWG src=/images/logo></a></p>
    <h1>HTML 5</h1>
-   <h2 class="no-num no-toc" id=draft-recommendation-—-date:-01-jan-1901>Draft Recommendation — 3 December 2008</h2>
+   <h2 class="no-num no-toc" id=draft-recommendation-—-date:-01-jan-1901>Draft Recommendation — 12 December 2008</h2>
    <p>You can take part in this work. <a href=http://www.whatwg.org/mailing-list>Join the working group's discussion list.</a></p>
    <p><strong>Web designers!</strong> We have a <a href=http://blog.whatwg.org/faq/>FAQ</a>, a <a href=http://forums.whatwg.org/>forum</a>, and a <a href=http://www.whatwg.org/mailing-list#help>help mailing list</a> for you!</p>
    <dl><dt>Multiple-page version:</dt>
@@ -270,7 +270,8 @@
      <li><a href=#domtokenlist><span class=secno>2.8.3 </span>DOMTokenList</a></li>
      <li><a href=#domstringmap><span class=secno>2.8.4 </span>DOMStringMap</a></li>
      <li><a href=#dom-feature-strings><span class=secno>2.8.5 </span>DOM feature strings</a></li>
-     <li><a href=#exceptions><span class=secno>2.8.6 </span>Exceptions</a></ol></ol></li>
+     <li><a href=#exceptions><span class=secno>2.8.6 </span>Exceptions</a></li>
+     <li><a href=#garbage-collection><span class=secno>2.8.7 </span>Garbage collection</a></ol></ol></li>
  <li><a href=#dom><span class=secno>3 </span>Semantics and structure of HTML documents</a>
   <ol>
    <li><a href=#semantics-intro><span class=secno>3.1 </span>Introduction</a></li>
@@ -636,23 +637,30 @@
     <ol>
      <li><a href=#security-2><span class=secno>5.2.1 </span>Security</a></li>
      <li><a href=#apis-for-creating-and-navigating-browsing-contexts-by-name><span class=secno>5.2.2 </span>APIs for creating and navigating browsing contexts by name</a></li>
-     <li><a href=#accessing-other-browsing-contexts><span class=secno>5.2.3 </span>Accessing other browsing contexts</a></ol></li>
+     <li><a href=#accessing-other-browsing-contexts><span class=secno>5.2.3 </span>Accessing other browsing contexts</a></li>
+     <li><a href=#garbage-collection-and-browsing-contexts><span class=secno>5.2.4 </span>Garbage collection and browsing contexts</a></ol></li>
    <li><a href=#origin><span class=secno>5.3 </span>Origin</a>
     <ol>
      <li><a href=#relaxing-the-same-origin-restriction><span class=secno>5.3.1 </span>Relaxing the same-origin restriction</a></ol></li>
    <li><a href=#scripting><span class=secno>5.4 </span>Scripting</a>
     <ol>
-     <li><a href=#script-execution-contexts><span class=secno>5.4.1 </span>Script execution contexts</a></li>
-     <li><a href=#event-loops><span class=secno>5.4.2 </span>Event loops</a>
+     <li><a href=#introduction-0><span class=secno>5.4.1 </span>Introduction</a></li>
+     <li><a href=#enabling-and-disabling-scripting><span class=secno>5.4.2 </span>Enabling and disabling scripting</a></li>
+     <li><a href=#processing-model-1><span class=secno>5.4.3 </span>Processing model</a>
       <ol>
-       <li><a href=#generic-task-sources><span class=secno>5.4.2.1 </span>Generic task sources</a></ol></li>
-     <li><a href=#javascript-protocol><span class=secno>5.4.3 </span>The <code title="">javascript:</code> protocol</a></li>
-     <li><a href=#events><span class=secno>5.4.4 </span>Events</a>
+       <li><a href=#definitions-0><span class=secno>5.4.3.1 </span>Definitions</a></li>
+       <li><a href=#calling-scripts><span class=secno>5.4.3.2 </span>Calling scripts</a></li>
+       <li><a href=#creating-scripts><span class=secno>5.4.3.3 </span>Creating scripts</a></ol></li>
+     <li><a href=#event-loops><span class=secno>5.4.4 </span>Event loops</a>
       <ol>
-       <li><a href=#event-handler-attributes><span class=secno>5.4.4.1 </span>Event handler attributes</a></li>
-       <li><a href=#event-firing><span class=secno>5.4.4.2 </span>Event firing</a></li>
-       <li><a href=#events-and-the-window-object><span class=secno>5.4.4.3 </span>Events and the <code>Window</code> object</a></li>
-       <li><a href=#runtime-script-errors><span class=secno>5.4.4.4 </span>Runtime script errors</a></ol></ol></li>
+       <li><a href=#generic-task-sources><span class=secno>5.4.4.1 </span>Generic task sources</a></ol></li>
+     <li><a href=#javascript-protocol><span class=secno>5.4.5 </span>The <code title="">javascript:</code> protocol</a></li>
+     <li><a href=#events><span class=secno>5.4.6 </span>Events</a>
+      <ol>
+       <li><a href=#event-handler-attributes><span class=secno>5.4.6.1 </span>Event handler attributes</a></li>
+       <li><a href=#event-firing><span class=secno>5.4.6.2 </span>Event firing</a></li>
+       <li><a href=#events-and-the-window-object><span class=secno>5.4.6.3 </span>Events and the <code>Window</code> object</a></li>
+       <li><a href=#runtime-script-errors><span class=secno>5.4.6.4 </span>Runtime script errors</a></ol></ol></li>
    <li><a href=#user-prompts><span class=secno>5.5 </span>User prompts</a>
     <ol>
      <li><a href=#simple-dialogs><span class=secno>5.5.1 </span>Simple dialogs</a></li>
@@ -668,7 +676,7 @@
        <li><a href=#sample-handler-impl><span class=secno>5.6.2.2 </span>Sample user interface</a></ol></ol></li>
    <li><a href=#offline><span class=secno>5.7 </span>Offline Web applications</a>
     <ol>
-     <li><a href=#introduction-0><span class=secno>5.7.1 </span>Introduction</a></li>
+     <li><a href=#introduction-1><span class=secno>5.7.1 </span>Introduction</a></li>
      <li><a href=#appcache><span class=secno>5.7.2 </span>Application caches</a></li>
      <li><a href=#manifests><span class=secno>5.7.3 </span>The cache manifest syntax</a>
       <ol>
@@ -676,7 +684,7 @@
        <li><a href=#writing-cache-manifests><span class=secno>5.7.3.2 </span>Writing cache manifests</a></li>
        <li><a href=#parsing-cache-manifests><span class=secno>5.7.3.3 </span>Parsing cache manifests</a></ol></li>
      <li><a href=#updating-an-application-cache><span class=secno>5.7.4 </span>Updating an application cache</a></li>
-     <li><a href=#processing-model-1><span class=secno>5.7.5 </span>Processing model</a>
+     <li><a href=#processing-model-2><span class=secno>5.7.5 </span>Processing model</a>
       <ol>
        <li><a href=#changesToNetworkingModel><span class=secno>5.7.5.1 </span>Changes to the networking model</a></ol></li>
      <li><a href=#application-cache-api><span class=secno>5.7.6 </span>Application cache API</a></li>
@@ -701,27 +709,29 @@
      <li><a href=#read-ua-inline><span class=secno>5.9.7 </span>Page load processing model for inline content that doesn't have a DOM</a></li>
      <li><a href=#scroll-to-fragid><span class=secno>5.9.8 </span>Navigating to a fragment identifier</a></li>
      <li><a href=#history-traversal><span class=secno>5.9.9 </span>History traversal</a></li>
-     <li><a href=#closing-a-browsing-context><span class=secno>5.9.10 </span>Closing a browsing context</a></ol></li>
+     <li><a href=#unloading-documents><span class=secno>5.9.10 </span>Unloading documents</a>
+      <ol>
+       <li><a href=#event-definition><span class=secno>5.9.10.1 </span>Event definition</a></ol></ol></li>
    <li><a href=#structured-client-side-storage><span class=secno>5.10 </span>Structured client-side storage</a>
     <ol>
      <li><a href=#storage><span class=secno>5.10.1 </span>Storing name/value pairs</a>
       <ol>
-       <li><a href=#introduction-1><span class=secno>5.10.1.1 </span>Introduction</a></li>
+       <li><a href=#introduction-2><span class=secno>5.10.1.1 </span>Introduction</a></li>
        <li><a href=#the-storage-interface><span class=secno>5.10.1.2 </span>The <code>Storage</code> interface</a></li>
        <li><a href=#the-sessionstorage-attribute><span class=secno>5.10.1.3 </span>The <code title=dom-sessionStorage>sessionStorage</code> attribute</a></li>
        <li><a href=#the-localstorage-attribute><span class=secno>5.10.1.4 </span>The <code title=dom-localStorage>localStorage</code> attribute</a></li>
        <li><a href=#the-storage-event><span class=secno>5.10.1.5 </span>The <code title=event-storage>storage</code> event</a>
         <ol>
-         <li><a href=#event-definition><span class=secno>5.10.1.5.1 </span>Event definition</a></ol></li>
+         <li><a href=#event-definition-0><span class=secno>5.10.1.5.1 </span>Event definition</a></ol></li>
        <li><a href=#threads><span class=secno>5.10.1.6 </span>Threads</a></ol></li>
      <li><a href=#sql><span class=secno>5.10.2 </span>Database storage</a>
       <ol>
-       <li><a href=#introduction-2><span class=secno>5.10.2.1 </span>Introduction</a></li>
+       <li><a href=#introduction-3><span class=secno>5.10.2.1 </span>Introduction</a></li>
        <li><a href=#databases><span class=secno>5.10.2.2 </span>Databases</a></li>
        <li><a href=#executing-sql-statements><span class=secno>5.10.2.3 </span>Executing SQL statements</a></li>
        <li><a href=#database-query-results><span class=secno>5.10.2.4 </span>Database query results</a></li>
        <li><a href=#errors><span class=secno>5.10.2.5 </span>Errors</a></li>
-       <li><a href=#processing-model-2><span class=secno>5.10.2.6 </span>Processing model</a></ol></li>
+       <li><a href=#processing-model-3><span class=secno>5.10.2.6 </span>Processing model</a></ol></li>
      <li><a href=#disk-space><span class=secno>5.10.3 </span>Disk space</a></li>
      <li><a href=#privacy><span class=secno>5.10.4 </span>Privacy</a>
       <ol>
@@ -792,7 +802,7 @@
      <li><a href=#making-entire-documents-editable><span class=secno>6.7.2 </span>Making entire documents editable</a></ol></li>
    <li><a href=#dnd><span class=secno>6.8 </span>Drag and drop</a>
     <ol>
-     <li><a href=#introduction-3><span class=secno>6.8.1 </span>Introduction</a></li>
+     <li><a href=#introduction-4><span class=secno>6.8.1 </span>Introduction</a></li>
      <li><a href=#the-dragevent-and-datatransfer-interfaces><span class=secno>6.8.2 </span>The <code>DragEvent</code> and <code>DataTransfer</code> interfaces</a></li>
      <li><a href=#events-fired-during-a-drag-and-drop-action><span class=secno>6.8.3 </span>Events fired during a drag-and-drop action</a></li>
      <li><a href=#drag-and-drop-processing-model><span class=secno>6.8.4 </span>Drag-and-drop processing model</a>
@@ -846,7 +856,7 @@
        <li><a href=#closing-the-connection><span class=secno>7.3.4.3 </span>Closing the connection</a></ol></ol></li>
    <li><a href=#crossDocumentMessages><span class=secno>7.4 </span>Cross-document messaging</a>
     <ol>
-     <li><a href=#introduction-4><span class=secno>7.4.1 </span>Introduction</a></li>
+     <li><a href=#introduction-5><span class=secno>7.4.1 </span>Introduction</a></li>
      <li><a href=#security-5><span class=secno>7.4.2 </span>Security</a>
       <ol>
        <li><a href=#authors><span class=secno>7.4.2.1 </span>Authors</a></li>
@@ -856,11 +866,11 @@
      <li><a href=#posting-structured-data><span class=secno>7.4.5 </span>Posting structured data</a></ol></li>
    <li><a href=#channel-messaging><span class=secno>7.5 </span>Channel messaging</a>
     <ol>
-     <li><a href=#introduction-5><span class=secno>7.5.1 </span>Introduction</a></li>
+     <li><a href=#introduction-6><span class=secno>7.5.1 </span>Introduction</a></li>
      <li><a href=#message-channels><span class=secno>7.5.2 </span>Message channels</a></li>
      <li><a href=#message-ports><span class=secno>7.5.3 </span>Message ports</a>
       <ol>
-       <li><a href=#ports-and-browsing-contexts><span class=secno>7.5.3.1 </span>Ports and browsing contexts</a></li>
+       <li><a href=#message-port-discarding><span class=secno>7.5.3.1 </span>Ports and browsing contexts</a></li>
        <li><a href=#ports-and-garbage-collection><span class=secno>7.5.3.2 </span>Ports and garbage collection</a></ol></ol></ol></li>
  <li><a href=#syntax><span class=secno>8 </span>The HTML syntax</a>
   <ol>
@@ -1389,7 +1399,7 @@
   that no scripts execute (e.g. no event handlers, no timers,
   etc). User agents should remain responsive to user input while
   paused, however, albeit without letting the user interact with Web
-  pages where that would involve invoking any script.</p>
+  pages where that would involve invoking any <a href=#concept-script title=concept-script>script</a>.</p>
 
 
   <h4 id=xml><span class=secno>2.1.1 </span>XML</h4>
@@ -3764,12 +3774,7 @@
 
   <h4 id=terminology-0><span class=secno>2.5.1 </span>Terminology</h4>
 
-  <p>A <dfn id=url>URL</dfn> is a string used to identify a resource. <span id=urldoc>A <a href=#url>URL</a> is always associated with a
-  <code>Document</code>, either explicitly when the URL is created or
-  defined; or through a DOM node, in which case the associated
-  <code>Document</code> is the node's <code>Document</code>; or
-  through a script, in which case the associated <code>Document</code>
-  is the script's <a href=#script-document-context>script document context</a>.</span></p>
+  <p>A <dfn id=url>URL</dfn> is a string used to identify a resource.</p>
 
   <p>A <a href=#url>URL</a> is a <dfn id=valid-url>valid URL</dfn> if at least one of
   the following conditions holds:</p>
@@ -3785,7 +3790,26 @@
    <li><p>The <a href=#url>URL</a> is a valid IRI reference and the <a href="#document's-character-encoding" title="document's character encoding">character encoding</a> of
    the URL's <code>Document</code> is UTF-8 or UTF-16. <a href=#refsRFC3987>[RFC3987]</a></li>
 
-  </ul><p class=note>The term "URL" in this specification is used in a
+  </ul><p>A <a href=#url>URL</a> has an associated <dfn id=url-character-encoding>URL character
+  encoding</dfn>, determined as follows:</p>
+
+  <dl class=switch><dt>If the URL came from a script (e.g. as an argument to a
+   method)</dt>
+
+   <dd>The URL character encoding is the <a href="#script's-character-encoding">script's character
+   encoding</a>.</dd>
+
+   <dt>If the URL came from a DOM node (e.g. from an element)</dt>
+
+   <dd>The node has a <code>Document</code>, and the URL character
+   encoding is the <a href="#document's-character-encoding">document's character encoding</a>.</dd>
+
+   <dt>If the URL had a character encoding defined when the URL was
+   created or defined</dt>
+
+   <dd>The URL character encoding is as defined.</dd>
+
+  </dl><p class=note>The term "URL" in this specification is used in a
   manner distinct from the precise technical meaning it is given in
   RFC 3986. Readers familiar with that RFC will find it easier to read
   <em>this</em> specification if they pretend the term "URL" as used
@@ -3922,8 +3946,7 @@
 
   <dl class=switch><dt>If the URL to be resolved was passed to an API</dt>
 
-   <dd><p>The base URL is the <a href=#document-base-url>document base URL</a> of the
-   script's <a href=#script-document-context>script document context</a>.</dd>
+   <dd><p>The base URL is the <a href="#script's-base-url">script's base URL</a>.</dd>
 
    <dt>If the URL to be resolved is from the value of a content
    attribute</dt>
@@ -3982,12 +4005,9 @@
   <ol><li><p>Let <var title="">url</var> be the <a href=#url>URL</a> being
    resolved.</li>
 
-   <li><p>Let <var title="">document</var> be the
-   <code>Document</code> <a href=#urldoc>associated with</a> <var title="">url</var>.</li>
+   <li><p>Let <var title="">encoding</var> be the <a href=#url-character-encoding>URL character
+   encoding</a>.</li>
 
-   <li><p>Let <var title="">encoding</var> be the <a href="#document's-character-encoding" title="document's character encoding">character encoding</a> of
-   <var title="">document</var>.</li>
-
    <li><p>If <var title="">encoding</var> is UTF-16, then change it to
    UTF-8.</li>
 
@@ -5628,10 +5648,30 @@
    <li value=20><dfn id=abort_err><code>ABORT_ERR</code></dfn></li> <!-- actually in XHR for now -->
    <li value=21><dfn id=url_mismatch_err><code>URL_MISMATCH_ERR</code></dfn></li> <!-- actually in workers for now -->
    <li value=22><dfn id=quota_exceeded_err><code>QUOTA_EXCEEDED_ERR</code></dfn></li> <!-- actually defined right here for now -->
+   <li value=23><dfn id=unavailable_script_err><code>UNAVAILABLE_SCRIPT_ERR</code></dfn></li> <!-- actually defined right here for now -->
    <li value=81><dfn id=parse_err><code>PARSE_ERR</code></dfn></li> <!-- actually defined in dom3ls -->
    <li value=82><dfn id=serialise_err><code>SERIALISE_ERR</code></dfn></li> <!-- actually defined in dom3ls -->
-  </ol><h2 id=dom><span class=secno>3 </span>Semantics and structure of HTML documents</h2>
+  </ol><h4 id=garbage-collection><span class=secno>2.8.7 </span>Garbage collection</h4>
 
+  <p>There is an <dfn id=implied-strong-reference>implied strong reference</dfn> from any DOM
+  attribute that returns a pre-existing object to that object.</p>
+
+  <div class=example>
+
+   <p>For example, the <code>document.defaultView</code> attribute
+   means that there is a strong reference from a <code>Document</code>
+   object to its <code><a href=#window>Window</a></code> object. Similarly, there is
+   always a strong reference from a <code>Document</code> to any
+   descendant nodes, and from any node to its owner
+   <code>Document</code>.</p>
+
+  </div>
+
+
+
+
+  <h2 id=dom><span class=secno>3 </span>Semantics and structure of HTML documents</h2>
+
   <h3 id=semantics-intro><span class=secno>3.1 </span>Introduction</h3>
 
   <p><em>This section is non-normative.</em></p>
@@ -5647,10 +5687,10 @@
   <p><dfn id="the-document's-address">The document's address</dfn> is an <a href=#absolute-url>absolute URL</a>
   that is set when the <code>Document</code> is created.</p>
 
-  <p>When a <code>Document</code> is created by a script using the
-  <code title="">createDocument()</code> API, <a href="#the-document's-address">the document's
+  <p>When a <code>Document</code> is created by a <a href=#concept-script title=concept-script>script</a> using the <code title="">createDocument()</code> API, <a href="#the-document's-address">the document's
   address</a> is the same as <a href="#the-document's-address">the document's address</a> of
-  the <a href=#script-document-context>script document context</a> of that script.</p>
+  the <a href=#active-document>active document</a> of the <a href="#script's-browsing-context">script's browsing
+  context</a>.</p>
 
   <p><code>Document</code> objects are assumed to be <dfn id=xml-documents>XML
   documents</dfn> unless they are flagged as being <dfn id=html-documents>HTML
@@ -5662,8 +5702,14 @@
   <code>DOMImplementation</code> object is initially an <a href=#xml-documents title="XML documents">XML document</a>, but can be made into an
   <a href=#html-documents title="HTML documents">HTML document</a> by calling <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> on it.</p>
 
+  <p>When a <code>Document</code> is first created, a new <a href=#script-group>script
+  group</a> must be created. This is the <code>Document</code>'s
+  <dfn id=current-script-group>current script group</dfn> until the script group is changed
+  (which can happen if <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> is invoked on the
+  <code>Document</code>).</p>
 
 
+
   <h4 id=documents-in-the-dom><span class=secno>3.2.1 </span>Documents in the DOM</h4>
 
   <p>All <code>Document</code> objects (in user agents implementing
@@ -7300,8 +7346,8 @@
   with the parser, and thus their behavior varies depending on whether
   they are used with <a href=#html-documents>HTML documents</a> (and the <a href=#html-parser>HTML
   parser</a>) or XHTML in <a href=#xml-documents>XML documents</a> (and the
-  <span>XML parser</span>). The following table cross-references the
-  various versions of these APIs.</p>
+  <span>XML parser</span><!-- XXX xref -->). The following table
+  cross-references the various versions of these APIs.</p>
 
   <table><thead><tr><td></td>
      <th>For documents that are <a href=#html-documents>HTML documents</a></th>
@@ -7371,8 +7417,11 @@
 
    </li>
 
-   <li><p class=XXX>onbeforeunload, onunload, reset timers, empty event queue, kill any pending transactions, XMLHttpRequests, etc</li>
-   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Ciframe%20src%3D%22document%22%3E%3C%2Fiframe%3E%0A%3Cscript%3Eonload%20%3D%20function%20()%20{%20f%20%3D%20document.getElementsByTagName(%27iframe%27)[0]%3B%20d%20%3D%20f.contentDocument%3B%20}%3C%2Fscript%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22w(d.documentElement.innerHTML)%22%20value%3D%22dump%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.body.bgColor%3D%27red%27%22%20value%3D%22color%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22f.style.border%3D%27lime%20solid%27%22%20value%3D%22color%20frame%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write(%27%3Cp%3Etest%3C%2Fp%3E%27)%3B%20d.close()%22%20value%3D%22replace%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write(%27%3Cp%3E%3Cscript%3Ei%20%3D%200%3B%20setInterval(%26quot%3Bparent.w(i%2B%2B)%26quot%3B%2C%20500)%3C%2Fscript%3E%3C%2Fp%3E%27)%3B%20d.close()%22%20value%3D%22replace%20with%20timer%22%3E%0A -->
+   <li><p><a href=#unload-a-document title="unload a document">Unload</a> the
+   <code>Document</code> object, with the <var title="">recycle</var>
+   parameter set to true. If the user <a href=#refused-to-allow-the-document-to-be-unloaded>refused to allow the
+   document to be unloaded</a>, then these steps must be
+   aborted.</li>
 
    <li><p>If the document has an <span>active parser</span><!--XXX
    xref-->, then stop that parser, and throw away any pending content
@@ -7381,14 +7430,28 @@
    XHTML, or image document, or something?</span></li><!-- XXX see
    also innerHTML in HTML -->
 
+   <li><p>Freeze the document's <a href=#current-script-group>current script
+   group</a>.</li>
+
+   <li><p>Unregister all event listeners registered on the
+   <code>Document</code> node and its descendants.</p>
+
    <li><p>Remove all child nodes of the document, without firing any
    mutation events.</li>
 
+   <li><p>Create a new <a href=#script-group>script group</a> and let the
+   document's <a href=#current-script-group>current script group</a> be that new
+   group. (The old script group is now permanently frozen.)</li>
+
+   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Ciframe%20src%3D%22document%22%3E%3C%2Fiframe%3E%0A%3Cscript%3Eonload%20%3D%20function%20()%20%7B%20f%20%3D%20document.getElementsByTagName('iframe')%5B0%5D%3B%20d%20%3D%20f.contentWindow.document%3B%20%7D%3C%2Fscript%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22w(d.documentElement.innerHTML)%22%20value%3D%22dump%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cscript%3Evar%20x%20%3D%20new%20XMLHttpRequest()%3Bx.open(%26quot%3BGET%26quot%3B%2C%20%26quot%3BGET%26quot%3B)%3Bx.onreadystatechange%3Dfunction()%20%7B%20alert(x.readyState)%3B%20%7D%3Bx.send(null)%3B%3C%2Fscript%3E')%3Bd.close()%3B%20setTimeout(function()%20%7B%20d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%20%7D%2C%200)%3B%22%20value%3D%22xhr%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.onclick%20%3D%20function()%20%7B%20w('click')%20%7D%22%20value%3D%22add%20click%20handler%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3E%3Cscript%3Ei%20%3D%200%3B%20setTimeout(%26quot%3Bparent.w(i%2B%2B)%26quot%3B%2C%202000)%3C%2Fscript%3E%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%20with%20timer%22%3E -->
+
    <li><p>Change the <a href="#document's-character-encoding">document's character encoding</a> to
    UTF-16.</li>
 
-   <li><p>Change <a href="#the-document's-address">the document's address</a> to the <a href="#the-document's-address" title="the document's address">address</a> of the <a href=#script-document-context>script
-   document context</a> of the script that invoked the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method.</li>
+   <li><p>Change <a href="#the-document's-address">the document's address</a> to the <a href="#the-document's-address">the
+   document's address</a> of the <a href=#active-document>active document</a> of
+   the <a href="#script's-browsing-context" title="script's browsing context">browsing context</a>
+   of the <a href=#concept-script title=concept-script>script</a> that invoked the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method.</li>
 
    <li><p>Create a new <a href=#html-parser>HTML parser</a> and associate it with
    the document. This is a <dfn id=script-created-parser>script-created parser</dfn> (meaning
@@ -7484,8 +7547,10 @@
 
     <p>If the <a href=#insertion-point>insertion point</a> is undefined, the <code title=dom-document-open><a href=#dom-document-open>open()</a></code> method must be called
     (with no arguments) on the <code title=Document>document</code>
-    object. The <a href=#insertion-point>insertion point</a> will point at just before
-    the end of the (empty) <a href=#the-input-stream>input stream</a>.</p>
+    object. If the user <a href=#refused-to-allow-the-document-to-be-unloaded>refused to allow the document to be
+    unloaded</a>, then these steps must be aborted. Otherwise, the
+    <a href=#insertion-point>insertion point</a> will point at just before the end of
+    the (empty) <a href=#the-input-stream>input stream</a>.</p>
 
    </li>
 
@@ -7921,7 +7986,7 @@
 
   <ol><li>
 
-    <p>The user agent must create a new <span>XML parser</span>.</p>
+    <p>The user agent must create a new <span>XML parser</span><!-- XXX xref -->.</p>
 
    </li>
 
@@ -9303,13 +9368,13 @@
   second is a flag indicating whether the element was
   <dfn id=parser-inserted>"parser-inserted"</dfn>. This flag is set by the <a href=#html-parser>HTML
   parser</a> and is used to handle <code title=dom-document-write-HTML><a href=#dom-document-write-html>document.write()</a></code> calls. The
-  third and fourth pieces of metadata are <dfn id="the-script's-type"><var>the script's
-  type</var></dfn> and <dfn id="the-script's-character-encoding"><var>the script's character
+  third and fourth pieces of metadata are <dfn id="the-script-block's-type"><var>the script block's
+  type</var></dfn> and <dfn id="the-script-block's-character-encoding"><var>the script block's character
   encoding</var></dfn>. They are determined when the script is run,
   based on the attributes on the element at that time.</p>
 
-  <p>When an <span>XML parser</span> creates a <code><a href=#script>script</a></code>
-  element, it must be marked as being
+  <p>When an <span>XML parser</span><!-- XXX xref --> creates a
+  <code><a href=#script>script</a></code> element, it must be marked as being
   <a href=#parser-inserted>"parser-inserted"</a>. When the element's end tag is
   parsed, the user agent must <a href=#running-a-script title="running a
   script">run</a> the <code><a href=#script>script</a></code> element.</p>
@@ -9340,45 +9405,46 @@
 
      <li>the <code><a href=#script>script</a></code> element has neither a <code title=attr-script-type><a href=#attr-script-type>type</a></code> attribute nor a <code title=attr-script-language>language</code> attribute, then</li>
 
-    </ul><p>...let <var><a href="#the-script's-type">the script's type</a></var> for this
+    </ul><p>...let <var><a href="#the-script-block's-type">the script block's type</a></var> for this
     <code><a href=#script>script</a></code> element be "<code title="">text/javascript</code>".</p>
 
-    <p>Otherwise, if the <code><a href=#script>script</a></code> element has a <code title=attr-script-type><a href=#attr-script-type>type</a></code> attribute, let <var><a href="#the-script's-type">the
-    script's type</a></var> for this <code><a href=#script>script</a></code> element be the
-    value of that attribute.</p>
+    <p>Otherwise, if the <code><a href=#script>script</a></code> element has a <code title=attr-script-type><a href=#attr-script-type>type</a></code> attribute, let <var><a href="#the-script-block's-type">the
+    script block's type</a></var> for this <code><a href=#script>script</a></code> element be
+    the value of that attribute.</p>
 
     <p>Otherwise, the element has a <code title=attr-script-language>language</code> attribute; let
-    <var><a href="#the-script's-type">the script's type</a></var> for this <code><a href=#script>script</a></code> element
-    be the concatenation of the string "<code title="">text/</code>"
-    followed by the value of the <code title=attr-script-language>language</code> attribute.</p>
-    <!-- user agents already support, e.g., type="text/javascript1.3",
-    so we don't have to support that separately. -->
+    <var><a href="#the-script-block's-type">the script block's type</a></var> for this <code><a href=#script>script</a></code>
+    element be the concatenation of the string "<code title="">text/</code>" followed by the value of the <code title=attr-script-language>language</code> attribute.</p> <!--
+    user agents already support, e.g., type="text/javascript1.3", so
+    we don't have to support that separately. -->
 
    </li>
 
    <li>
 
     <p>If the <code><a href=#script>script</a></code> element has a <code title=attr-script-charset><a href=#attr-script-charset>charset</a></code> attribute, then let
-    <var><a href="#the-script's-character-encoding">the script's character encoding</a></var> for this
+    <var><a href="#the-script-block's-character-encoding">the script block's character encoding</a></var> for this
     <code><a href=#script>script</a></code> element be the encoding given by the <code title=attr-script-charset><a href=#attr-script-charset>charset</a></code> attribute.</p>
 
-    <p>Otherwise, let <var><a href="#the-script's-character-encoding">the script's character encoding</a></var> for
-    this <code><a href=#script>script</a></code> element be the same as <a href="#document's-character-encoding" title="document's character encoding">the encoding of the document
+    <p>Otherwise, let <var><a href="#the-script-block's-character-encoding">the script block's character encoding</a></var>
+    for this <code><a href=#script>script</a></code> element be the same as <a href="#document's-character-encoding" title="document's character encoding">the encoding of the document
     itself</a>.</p>
 
    </li>
 
    <li>
 
-    <p>If the <code><a href=#script>script</a></code> element is <a href=#without-script>without
-    script</a>, or if the <code><a href=#script>script</a></code> element was created
-    by an <span>XML parser</span> that itself was created as part of
+    <p>If <a href=#concept-n-noscript title=concept-n-noscript>scripting is
+    disabled</a> for the <code><a href=#script>script</a></code> element, or if the
+    <code><a href=#script>script</a></code> element was created by an <span>XML
+    parser</span><!-- XXX xref --> that itself was created as part of
     the processing of the <code title=dom-innerHTML-XML><a href=#dom-innerhtml-xml>innerHTML</a></code> attribute's setter<!--
     no need to worry about the HTML case, as the HTML parser handles
     that for us -->, or if the user agent does not <a href=#support-the-scripting-language>support the
-    scripting language</a> given by <var><a href="#the-script's-type">the script's type</a></var>
-    for this <code><a href=#script>script</a></code> element, then the user agent must
-    abort these steps at this point. The script is not executed.</p>
+    scripting language</a> given by <var><a href="#the-script-block's-type">the script block's
+    type</a></var> for this <code><a href=#script>script</a></code> element, then the user
+    agent must abort these steps at this point. The script is not
+    executed.</p>
 
    </li>
 
@@ -9478,41 +9544,43 @@
      <dt>Otherwise</dt>
 
      <dd>The user agent must immediately <a href=#executing-a-script-block title="executing a
-     script block">execute the script</a>, even if other scripts
-     are already executing.</dd>
+     script block">execute the script block</a>, even if other
+     scripts are already executing.</dd>
 
     </dl></li>
 
-  </ol><p><dfn id=when-a-script-completes-loading>When a script completes loading</dfn>: If the script's
-  element was added to one of the lists mentioned above and the
-  document is still being parsed, then the parser handles
-  it. Otherwise, the UA must run the following steps as the <a href=#concept-task title=concept-task>task</a> that the <a href=#networking-task-source>networking task
-  source</a> places on the <a href=#task-queue>task queue</a>:</p>
+  </ol><p><dfn id=when-a-script-completes-loading>When a script completes loading</dfn>: If the
+  <code><a href=#script>script</a></code> element was added to one of the lists mentioned
+  above and the document is still being parsed, then the parser
+  handles it. Otherwise, the UA must run the following steps as the
+  <a href=#concept-task title=concept-task>task</a> that the <a href=#networking-task-source>networking
+  task source</a> places on the <a href=#task-queue>task queue</a>:</p>
 
-  <dl class=switch><dt>If the script's element was added to the <dfn id=list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list of scripts
-   that will execute when the document has finished parsing</dfn>:</dt>
+  <dl class=switch><dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-when-the-document-has-finished-parsing>list
+   of scripts that will execute when the document has finished
+   parsing</dfn>:</dt>
 
    <dd>
 
     <ol><li>
 
-      <p>If the script's element is not the first element in the list,
-      then do nothing yet. Stop going through these steps.</p>
+      <p>If the <code><a href=#script>script</a></code> element is not the first element
+      in the list, then do nothing yet. Stop going through these
+      steps.</p>
 
      </li>
 
      <li>
 
       <p>Otherwise, <a href=#executing-a-script-block title="executing a script block">execute the
-      script</a> (that is, the script associated with the first
-      element in the list).</p>
+      script block</a> (the first element in the list).</p>
 
      </li>
 
      <li>
 
-      <p>Remove the script's element from the list (i.e. shift out the
-      first entry in the list).</p>
+      <p>Remove the <code><a href=#script>script</a></code> element from the list
+      (i.e. shift out the first entry in the list).</p>
 
      </li>
 
@@ -9526,8 +9594,8 @@
 
     </ol></dd>
 
-   <dt>If the script's element was added to the <dfn id=list-of-scripts-that-will-execute-asynchronously>list of scripts
-   that will execute asynchronously</dfn>:</dt>
+   <dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-asynchronously>list
+   of scripts that will execute asynchronously</dfn>:</dt>
 
    <dd>
 
@@ -9540,16 +9608,15 @@
 
      <li>
 
-      <p><a href=#executing-a-script-block title="executing a script block">Execute the
-      script</a> (the script associated with the first element in
-      the list).</p>
+      <p><a href=#executing-a-script-block title="executing a script block">Execute the script
+      block</a> (the first element in the list).</p>
 
      </li>
 
      <li>
 
-      <p>Remove the script's element from the list (i.e. shift out the
-      first entry in the list).</p>
+      <p>Remove the <code><a href=#script>script</a></code> element from the list
+      (i.e. shift out the first entry in the list).</p>
 
      </li>
 
@@ -9565,21 +9632,21 @@
 
     </ol></dd>
 
-   <dt>If the script's element was added to the <dfn id=list-of-scripts-that-will-execute-as-soon-as-possible>list of scripts
-   that will execute as soon as possible</dfn>:</dt>
+   <dt>If the <code><a href=#script>script</a></code> element was added to the <dfn id=list-of-scripts-that-will-execute-as-soon-as-possible>list
+   of scripts that will execute as soon as possible</dfn>:</dt>
 
    <dd>
 
     <ol><li>
 
       <p><a href=#executing-a-script-block title="executing a script block">Execute the
-      script</a>.</p>
+      script block</a>.</p>
 
      </li>
 
      <li>
 
-      <p>Remove the script's element from the list.</p>
+      <p>Remove the <code><a href=#script>script</a></code> element from the list.</p>
 
      </li>
 
@@ -9588,35 +9655,36 @@
   </dl><p>Fetching an external script must <a href=#delay-the-load-event>delay the <code title=event-load>load</code> event</a>.</p>
 
   <p><dfn id=executing-a-script-block title="executing a script block">Executing a script
-  block</dfn>: When the steps above require that the script be
+  block</dfn>: When the steps above require that the script block be
   executed, the user agent must act as follows:</p>
 
   <dl class=switch><dt>If the load resulted in an error (for example a DNS error, or
    an HTTP 404 error)</dt>
 
-   <dd><p>Executing the script must just consist of <a href=#fire-an-error-event title="fire
-   an error event">firing an <code title=event-error>error</code>
-   event</a> at the element.</dd>
+   <dd><p>Executing the script block must just consist of <a href=#fire-an-error-event title="fire an error event">firing an <code title=event-error>error</code> event</a> at the
+   element.</dd>
 
    <dt>If the load was successful</dt>
 
+   <!-- SCRIPT EXEC -->
    <dd>
 
     <ol><li>
 
-      <p>If the <code><a href=#script>script</a></code> element's <code>Document</code> is
-      the <a href=#active-document>active document</a> in its <a href=#browsing-context>browsing
-      context</a>, the user agent must execute the script:</p>
+      <p>Initialise <dfn id="the-script-block's-source"><var>the script block's source</var></dfn> as
+      follows:</p>
 
       <dl class=switch><dt>If the script is from an external file</dt>
 
        <dd>
 
-        <p>That file must be used as the file to execute.</p>
+        <p>The contents of that file, interpreted as as string of
+        Unicode characters, are the script source.</p>
 
-        <p>The file must be interpreted using the character encoding
-        given by <var><a href="#the-script's-character-encoding">the script's character encoding</a></var>, regardless
-        of any metadata given by the file's <a href=#content-type-0 title=Content-Type>Content-Type metadata</a>.</p>
+        <p>The file must be converted to Unicode using the character
+        encoding given by <var><a href="#the-script-block's-character-encoding">the script block's character
+        encoding</a></var>, regardless of any metadata given by the file's
+        <a href=#content-type-0 title=Content-Type>Content-Type metadata</a>.</p>
 
         <p class=XXX>This means that a UTF-16 document will
         always assume external scripts are UTF-16...? This applies,
@@ -9627,46 +9695,44 @@
 
        </dd>
 
-       <dt>If the script is inline</dt>
+       <dt>If the script is inline and <var><a href="#the-script-block's-type">the script block's type</a></var> is a text-based language</dt>
 
        <dd>
 
-        <p>For scripting languages that consist of pure text, user
-        agents must use the value of the DOM <code title=dom-script-text><a href=#dom-script-text>text</a></code> attribute (defined below) as
-        the script to execute, and for XML-based scripting languages,
-        user agents must use all the child nodes of the
-        <code><a href=#script>script</a></code> element as the script to execute.</p>
+        <p>The value of the DOM <code title=dom-script-text><a href=#dom-script-text>text</a></code> attribute at the time the
+        "<a href=#running-a-script>running a script</a>" algorithm was first invoked is
+        the script source.</p>
 
        </dd>
 
-      </dl><!-- SCRIPT EXEC --><p>In any case, the user agent must execute the script according to
-      the semantics defined by the language associated with <var><a href="#the-script's-type">the
-      script's type</a></var> (see the <a href=#scriptingLanguages>scripting
-      languages</a> section below).</p>
+       <dt>If the script is inline and <var><a href="#the-script-block's-type">the script block's type</a></var> is an XML-based language</dt>
 
-      <p>The <a href=#script-execution-context>script execution context</a> of the script must
-      be the <code><a href=#window>Window</a></code> object of that <a href=#browsing-context>browsing
-      context</a>.</p>
+       <dd>
 
-      <p>The <a href=#script-document-context>script document context</a> of the script must
-      be the <code>Document</code> object that owns the
-      <code><a href=#script>script</a></code> element.</p>
+        <p>The child nodes of the <code><a href=#script>script</a></code> element at the
+        time the "<a href=#running-a-script>running a script</a>" algorithm was first
+        invoked are the script source.</p>
 
-      <p class=note>The element's attributes' values might have changed
-      between when the element was inserted into the document and when the
-      script has finished loading, as may its other attributes; similarly,
-      the element itself might have been taken back out of the DOM, or had
-      other changes made. These changes do not in any way affect the above
-      steps; only the values of the attributes at the time the
-      <code><a href=#script>script</a></code> element is first inserted into the document
-      matter.</p>
+       </dd>
 
+      </dl></li>
+
+     <li>
+
+      <p><a href=#create-a-script-from-a-node title="create a script from a node">Create a
+      script</a> from the <code><a href=#script>script</a></code> element node, using
+      the <var><a href="#the-script-block's-source">the script block's source</a></var> and the <var><a href="#the-script-block's-type">the script
+      block's type</a></var>.</p>
+
+      <p class=note>This is where the script is compiled and
+      actually executed.</p>
+
      </li>
 
      <li>
 
-      <p>Then, the user agent must <a href=#fire-a-load-event>fire a <code title=event-load>load</code> event</a> at the
-      <code><a href=#script>script</a></code> element.</p>
+      <p><a href=#fire-a-load-event>Fire a <code title=event-load>load</code>
+      event</a> at the <code><a href=#script>script</a></code> element.</p>
 
      </li>
 
@@ -9711,8 +9777,8 @@
   <h5 id=scriptingLanguages><span class=secno>4.3.1.1 </span>Scripting languages</h5>
 
   <p>A user agent is said to <dfn id=support-the-scripting-language>support the scripting language</dfn>
-  if <var><a href="#the-script's-type">the script's type</a></var> matches the MIME type of a scripting
-  language that the user agent implements.</p>
+  if <var><a href="#the-script-block's-type">the script block's type</a></var> matches the MIME type of a
+  scripting language that the user agent implements.</p>
 
   <p>The following lists some MIME types and the languages to which
   they refer:</p>
@@ -9747,9 +9813,9 @@
    <dd>In a <code><a href=#the-head-element>head</a></code> element of an <a href=#html-documents title="HTML documents">HTML document</a>, if there are no ancestor <code><a href=#the-noscript-element>noscript</a></code> elements.</dd>
    <dd>Where <a href=#phrasing-content-0>phrasing content</a> is expected in <a href=#html-documents>HTML documents</a>, if there are no ancestor <code><a href=#the-noscript-element>noscript</a></code> elements.</dd>
    <dt>Content model:</dt>
-   <dd><a href=#without-script>Without script</a>, in a <code><a href=#the-head-element>head</a></code> element: in any order, zero or more <code><a href=#the-link-element>link</a></code> elements, zero or more <code><a href=#the-style-element>style</a></code> elements, and zero or more <code><a href=#meta>meta</a></code> elements.</dd>
-   <dd><a href=#without-script>Without script</a>, not in a <code><a href=#the-head-element>head</a></code> element: <a href=#transparent>transparent</a>, but there must be no <code><a href=#the-noscript-element>noscript</a></code> element descendants.</dd>
-   <dd><a href=#with-script>With script</a>: text that conforms to the requirements given in the prose.</dd>
+   <dd>When <a href=#concept-n-noscript title=concept-n-noscript>scripting is disabled</a>, in a <code><a href=#the-head-element>head</a></code> element: in any order, zero or more <code><a href=#the-link-element>link</a></code> elements, zero or more <code><a href=#the-style-element>style</a></code> elements, and zero or more <code><a href=#meta>meta</a></code> elements.</dd>
+   <dd>When <a href=#concept-n-noscript title=concept-n-noscript>scripting is disabled</a>, not in a <code><a href=#the-head-element>head</a></code> element: <a href=#transparent>transparent</a>, but there must be no <code><a href=#the-noscript-element>noscript</a></code> element descendants.</dd>
+   <dd>Otherwise: text that conforms to the requirements given in the prose.</dd>
    <dt>Element-specific attributes:</dt>
    <dd>None.</dd>
    <dt>DOM interface:</dt>
@@ -9759,102 +9825,109 @@
   scripting and those that don't support scripting, by affecting how
   the document is parsed.</p>
 
-  <p>The <code><a href=#the-noscript-element>noscript</a></code> element must not be used in <a href=#xml-documents>XML
-  documents</a>.</p>
-
-  <p class=note><strong>The <code><a href=#the-noscript-element>noscript</a></code> element is only
-  effective in the <span title="">HTML serialization</span><!-- XXX
-  xref -->, it has no effect in the <span title="">XML
-  serialization</span><!-- XXX xref -->.</strong></p>
-
   <p>When used in <a href=#html-documents>HTML documents</a>, the allowed content
   model is as follows:</p>
 
-  <p>In a <code><a href=#the-head-element>head</a></code> element, if the <code><a href=#the-noscript-element>noscript</a></code>
-  element is <a href=#without-script>without script</a>, then the content model of a
-  <code><a href=#the-noscript-element>noscript</a></code> element must contain only <code><a href=#the-link-element>link</a></code>,
-  <code><a href=#the-style-element>style</a></code>, and <code><a href=#meta>meta</a></code> elements. If the
-  <code><a href=#the-noscript-element>noscript</a></code> element is <a href=#with-script>with script</a>, then the
-  content model of a <code><a href=#the-noscript-element>noscript</a></code> element is text, except
-  that invoking the <a href=#html-fragment-parsing-algorithm>HTML fragment parsing algorithm</a> with
-  the <code><a href=#the-noscript-element>noscript</a></code> element as the <var title="">context</var>
-  element and the text contents as the <var title="">input</var> must
-  result in a list of nodes that consists only of <code><a href=#the-link-element>link</a></code>,
-  <code><a href=#the-style-element>style</a></code>, and <code><a href=#meta>meta</a></code> elements.</p>
+  <dl><dt>In a <code><a href=#the-head-element>head</a></code> element, if <a href=#concept-n-noscript title=concept-n-noscript>scripting is disabled</a> for the
+   <code><a href=#the-noscript-element>noscript</a></code> element</dt>
 
-  <p>Outside of <code><a href=#the-head-element>head</a></code> elements, if the
-  <code><a href=#the-noscript-element>noscript</a></code> element is <a href=#without-script>without script</a>, then
-  the content model of a <code><a href=#the-noscript-element>noscript</a></code> element is
-  <a href=#transparent>transparent</a>, with the additional restriction that a
-  <code><a href=#the-noscript-element>noscript</a></code> element must not have a <code><a href=#the-noscript-element>noscript</a></code>
-  element as an ancestor (that is, <code><a href=#the-noscript-element>noscript</a></code> can't be
-  nested).</p>
+   <dd><p>The <code><a href=#the-noscript-element>noscript</a></code> element must contain only
+   <code><a href=#the-link-element>link</a></code>, <code><a href=#the-style-element>style</a></code>, and <code><a href=#meta>meta</a></code>
+   elements.</dd>
 
-  <p>Outside of <code><a href=#the-head-element>head</a></code> elements, if the
-  <code><a href=#the-noscript-element>noscript</a></code> element is <a href=#with-script>with script</a>, then the
-  content model of a <code><a href=#the-noscript-element>noscript</a></code> element is text, except
-  that the text must be such that running the following algorithm
-  results in a conforming document with no <code><a href=#the-noscript-element>noscript</a></code>
-  elements and no <code><a href=#script>script</a></code> elements, and such that no step
-  in the algorithm causes an <a href=#html-parser>HTML parser</a> to flag a
-  <a href=#parse-error>parse error</a>:</p>
+   <dt>In a <code><a href=#the-head-element>head</a></code> element, if <a href=#concept-n-noscript title=concept-n-noscript>scripting is enabled</a> for the
+   <code><a href=#the-noscript-element>noscript</a></code> element</dt>
 
-  <ol><li>Remove every <code><a href=#script>script</a></code> element from the
-   document.</li>
+   <dd><p>The <code><a href=#the-noscript-element>noscript</a></code> element must contain only text,
+   except that invoking the <a href=#html-fragment-parsing-algorithm>HTML fragment parsing
+   algorithm</a> with the <code><a href=#the-noscript-element>noscript</a></code> element as the <var title="">context</var> element and the text contents as the <var title="">input</var> must result in a list of nodes that consists
+   only of <code><a href=#the-link-element>link</a></code>, <code><a href=#the-style-element>style</a></code>, and
+   <code><a href=#meta>meta</a></code> elements.</dd>
 
-   <li>Make a list of every <code><a href=#the-noscript-element>noscript</a></code> element in the
-   document. For every <code><a href=#the-noscript-element>noscript</a></code> element in that list,
-   perform the following steps:
+   <dt>Outside of <code><a href=#the-head-element>head</a></code> elements, if <a href=#concept-n-noscript title=concept-n-noscript>scripting is disabled</a> for the
+   <code><a href=#the-noscript-element>noscript</a></code> element</dt>
 
-    <ol><li>Let the <var title="">parent element</var> be the parent
-     element of the <code><a href=#the-noscript-element>noscript</a></code> element.</li>
+   <dd><p>The <code><a href=#the-noscript-element>noscript</a></code> element's content model is
+   <a href=#transparent>transparent</a>, with the additional restriction that a
+   <code><a href=#the-noscript-element>noscript</a></code> element must not have a <code><a href=#the-noscript-element>noscript</a></code>
+   element as an ancestor (that is, <code><a href=#the-noscript-element>noscript</a></code> can't be
+   nested).</dd>
 
-     <li>Take all the children of the <var title="">parent element</var>
-     that come before the <code><a href=#the-noscript-element>noscript</a></code> element, and call these
-     elements <var title="">the before children</var>.</li>
+   <dt>Outside of <code><a href=#the-head-element>head</a></code> elements, if <a href=#concept-n-noscript title=concept-n-noscript>scripting is enabled</a> for the
+   <code><a href=#the-noscript-element>noscript</a></code> element</dt>
 
-     <li>Take all the children of the <var title="">parent element</var>
-     that come <em>after</em> the <code><a href=#the-noscript-element>noscript</a></code> element, and
-     call these elements <var title="">the after children</var>.</li>
+   <dd>
 
-     <li>Let <var title="">s</var> be the concatenation of all the
-     <a href=#text-node>text node</a> children of the <code><a href=#the-noscript-element>noscript</a></code>
-     element.</li>
+    <p>The <code><a href=#the-noscript-element>noscript</a></code> element must contain only text,
+    except that the text must be such that running the following
+    algorithm results in a conforming document with no
+    <code><a href=#the-noscript-element>noscript</a></code> elements and no <code><a href=#script>script</a></code>
+    elements, and such that no step in the algorithm causes an
+    <a href=#html-parser>HTML parser</a> to flag a <a href=#parse-error>parse error</a>:</p>
 
-     <li>Set the <code title=dom-innerHTML-HTML><a href=#dom-innerhtml-html>innerHTML</a></code>
-     attribute of the <var title="">parent element</var> to the value
-     of <var title="">s</var>. (This, as a side-effect, causes the
-     <code><a href=#the-noscript-element>noscript</a></code> element to be removed from the
-     document.)</li>
+    <ol><li>Remove every <code><a href=#script>script</a></code> element from the
+     document.</li>
 
-     <li>Insert <var title="">the before children</var> at the start of
-     the <var title="">parent element</var>, preserving their original
-     relative order.</li>
+     <li>Make a list of every <code><a href=#the-noscript-element>noscript</a></code> element in the
+     document. For every <code><a href=#the-noscript-element>noscript</a></code> element in that list,
+     perform the following steps:
 
-     <li>Insert <var title="">the after children</var> at the end of the
-     <var title="">parent element</var>, preserving their original
-     relative order.</li>
+      <ol><li>Let the <var title="">parent element</var> be the parent
+       element of the <code><a href=#the-noscript-element>noscript</a></code> element.</li>
 
-    </ol></li>
+       <li>Take all the children of the <var title="">parent element</var>
+       that come before the <code><a href=#the-noscript-element>noscript</a></code> element, and call these
+       elements <var title="">the before children</var>.</li>
 
-  </ol><p>The <code><a href=#the-noscript-element>noscript</a></code> element has no other requirements. In
-  particular, children of the <code><a href=#the-noscript-element>noscript</a></code> element are not
-  exempt from form submission, scripting, and so forth, even when the
-  element is <a href=#with-script>with script</a>.</p>
+       <li>Take all the children of the <var title="">parent element</var>
+       that come <em>after</em> the <code><a href=#the-noscript-element>noscript</a></code> element, and
+       call these elements <var title="">the after children</var>.</li>
 
-  <p class=note>All these contortions are required because, for
+       <li>Let <var title="">s</var> be the concatenation of all the
+       <a href=#text-node>text node</a> children of the <code><a href=#the-noscript-element>noscript</a></code>
+       element.</li>
+
+       <li>Set the <code title=dom-innerHTML-HTML><a href=#dom-innerhtml-html>innerHTML</a></code>
+       attribute of the <var title="">parent element</var> to the value
+       of <var title="">s</var>. (This, as a side-effect, causes the
+       <code><a href=#the-noscript-element>noscript</a></code> element to be removed from the
+       document.)</li>
+
+       <li>Insert <var title="">the before children</var> at the start of
+       the <var title="">parent element</var>, preserving their original
+       relative order.</li>
+
+       <li>Insert <var title="">the after children</var> at the end of the
+       <var title="">parent element</var>, preserving their original
+       relative order.</li>
+
+      </ol></li>
+
+    </ol></dd>
+
+  </dl><p class=note>All these contortions are required because, for
   historical reasons, the <code><a href=#the-noscript-element>noscript</a></code> element is handled
   differently by the <a href=#html-parser>HTML parser</a> based on whether <a href=#scripting-flag title="scripting flag">scripting was enabled or not</a> when the
   parser was invoked. The element is not allowed in XML, because in
   XML the parser is not affected by such state, and thus the element
   would not have the desired effect.</p>
 
-  <p class=note>The <code><a href=#the-noscript-element>noscript</a></code> element interacts poorly
-  with the <code title=dom-document-designMode><a href=#designMode>designMode</a></code>
-  feature. Authors are encouraged to not use <code><a href=#the-noscript-element>noscript</a></code>
-  elements on pages that will have <code title=dom-document-designMode><a href=#designMode>designMode</a></code> enabled.</p>
+  <p>The <code><a href=#the-noscript-element>noscript</a></code> element must not be used in <a href=#xml-documents>XML
+  documents</a>.</p>
 
+  <p class=note><strong>The <code><a href=#the-noscript-element>noscript</a></code> element is only
+  effective in the <span>HTML serialization</span><!-- XXX xref -->,
+  it has no effect in the <span>XML serialization</span><!-- XXX xref
+  -->.</strong></p>
 
+  <p>The <code><a href=#the-noscript-element>noscript</a></code> element has no other requirements. In
+  particular, children of the <code><a href=#the-noscript-element>noscript</a></code> element are not
+  exempt from form submission, scripting, and so forth, even when
+  <a href=#concept-n-script title=concept-n-script>scripting is enabled</a> for the
+  element.</p>
+
+
+
   <h4 id=the-eventsource-element><span class=secno>4.3.3 </span>The <dfn><code>eventsource</code></dfn> element</h4>
 
   <dl class=element><dt>Categories</dt>
@@ -14576,7 +14649,7 @@
   processed. Otherwise, the attribute must return false.</p>
 
   <p class=note>The value of <code title=dom-img-complete><a href=#dom-img-complete>complete</a></code> can thus change while a
-  script is executing.</p>
+  <a href=#concept-script title=concept-script>script</a> is executing.</p>
 
   <p>Three constructors are provided for creating
   <code><a href=#htmlimageelement>HTMLImageElement</a></code> objects (in addition to the factory
@@ -15615,7 +15688,9 @@
   (either directly or indirectly through other nested browsing
   contexts) must have the following flags set:</p>
 
-  <dl><dt>The <dfn id=sandboxed-navigation-browsing-context-flag>sandboxed navigation browsing context flag</dfn></dt>
+  <dl><!-- XXX disallow cross-origin loads of any kind (networking
+        override that only allows same-origin URLs or about:,
+        javascript:, data:) --><!-- XXX block access to 'contentWindow.frames' from iframe owner --><!-- XXX block access to 'parent.frames' from sandbox --><dt>The <dfn id=sandboxed-navigation-browsing-context-flag>sandboxed navigation browsing context flag</dfn></dt>
 
    <dd>
 
@@ -18484,14 +18559,15 @@
 
   <p>The <dfn id=attr-media-controls title=attr-media-controls><code>controls</code></dfn>
   attribute is a <a href=#boolean-attribute>boolean attribute</a>. If the attribute is
-  present, or if the <a href=#media-element>media element</a> is <a href=#without-script>without
-  script</a>, then the user agent should <dfn id=expose-a-user-interface-to-the-user>expose a user
-  interface to the user</dfn>. This user interface should include
-  features to begin playback, pause playback, seek to an arbitrary
-  position in the content (if the content supports arbitrary seeking),
-  change the volume, and show the media content in manners more
-  suitable to the user (e.g. full-screen video or in an independent
-  resizable window). Other controls may also be made available.</p>
+  present, or if <a href=#concept-n-noscript title=concept-n-noscript>scripting is
+  disabled</a> for the <a href=#media-element>media element</a>, then the user
+  agent should <dfn id=expose-a-user-interface-to-the-user>expose a user interface to the user</dfn>. This
+  user interface should include features to begin playback, pause
+  playback, seek to an arbitrary position in the content (if the
+  content supports arbitrary seeking), change the volume, and show the
+  media content in manners more suitable to the user (e.g. full-screen
+  video or in an independent resizable window). Other controls may
+  also be made available.</p>
 
   <p>If the attribute is absent, then the user agent should avoid
   making a user interface available that could conflict with an
@@ -18757,8 +18833,8 @@
   element. The contents of the <code><a href=#the-canvas-element>canvas</a></code> element, if any,
   are the element's <a href=#fallback-content>fallback content</a>.</p>
 
-  <p>In interactive visual media, if the <code><a href=#the-canvas-element>canvas</a></code> element
-  is <a href=#with-script>with script</a>, the <code><a href=#the-canvas-element>canvas</a></code> element
+  <p>In interactive visual media, if <a href=#concept-n-script title=concept-n-script>scripting is enabled</a> for the
+  <code><a href=#the-canvas-element>canvas</a></code> element, the <code><a href=#the-canvas-element>canvas</a></code> element
   represents an embedded element with a dynamically created image.</p>
 
   <p>In non-interactive, static, visual media, if the
@@ -18770,10 +18846,9 @@
   size. Otherwise, the element represents its <a href=#fallback-content>fallback
   content</a> instead.</p>
 
-  <p>In non-visual media, and in visual media if the
-  <code><a href=#the-canvas-element>canvas</a></code> element is <a href=#without-script>without script</a>, the
-  <code><a href=#the-canvas-element>canvas</a></code> element represents its <a href=#fallback-content>fallback
-  content</a> instead.</p>
+  <p>In non-visual media, and in visual media if <a href=#concept-n-noscript title=concept-n-noscript>scripting is disabled</a> for the
+  <code><a href=#the-canvas-element>canvas</a></code> element, the <code><a href=#the-canvas-element>canvas</a></code> element
+  represents its <a href=#fallback-content>fallback content</a> instead.</p>
 
   <p>The <code><a href=#the-canvas-element>canvas</a></code> element has two attributes to control the
   size of the coordinate space: <dfn id=attr-canvas-width title=attr-canvas-width><code>width</code></dfn> and <dfn id=attr-canvas-height title=attr-canvas-height><code>height</code></dfn>. These
@@ -32738,12 +32813,13 @@
           http://www.mozilla.org/docs/dom/domref/dom_window_ref.html
           http://lxr.mozilla.org/mozilla/source/dom/public/idl/base/nsIDOMWindow.idl - scrollBy, etc
           http://lxr.mozilla.org/mozilla/source/dom/public/idl/base/nsIDOMWindowInternal.idl - DOM level 0
+      close() focus() blur()
    -->
 
   <p>The <dfn id=dom-window title=dom-window><code>window</code></dfn>, <dfn id=dom-frames title=dom-frames><code>frames</code></dfn>, and <dfn id=dom-self title=dom-self><code>self</code></dfn> DOM attributes must all
   return the <code><a href=#window>Window</a></code> object itself.</p>
 
-  <p>The <code><a href=#window>Window</a></code> object also provides the scope for script
+  <p>The <code><a href=#window>Window</a></code> object also provides the scope for <a href=#concept-script title=concept-script>script</a>
   execution. Each <code>Document</code> in a <a href=#browsing-context>browsing
   context</a> has an associated <dfn id=list-of-added-properties>list of added properties</dfn>
   that, when a document is <a href=#active-document title="active
@@ -32840,9 +32916,9 @@
   enabled</a>; otherwise, it must not be enabled unless the
   <a href=#browsing-context>browsing context</a> was just created as part of the
   <a href=#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name>the rules for choosing a browsing context given a browsing
-  context name</a>. The navigation must be done with the
-  <a href=#script-browsing-context>script browsing context</a> of the script that invoked the
-  method as the <a href=#source-browsing-context>source browsing context</a>.</p>
+  context name</a>. The navigation must be done with the <a href="#script's-browsing-context" title="script's browsing context">browsing context</a> of the
+  <a href=#concept-script title=concept-script>script</a> that invoked the method as the <a href=#source-browsing-context>source browsing
+  context</a>.</p>
 
   <p>The method must return the <code><a href=#window>Window</a></code> object of the
   default view of the <a href=#browsing-context>browsing context</a> that was
@@ -32873,6 +32949,41 @@
 
 
 
+  <h4 id=garbage-collection-and-browsing-contexts><span class=secno>5.2.4 </span>Garbage collection and browsing contexts</h4>
+
+  <p>A <a href=#browsing-context>browsing context</a> has a strong reference to each of
+  its <code>Document</code>s and <a href=#view title=view>views</a>, and
+  the user agent itself has a strong reference to its <a href=#top-level-browsing-context title="top-level browsing context">top-level browsing
+  contexts</a>.</p>
+
+  <p>When a <a href=#browsing-context>browsing context</a> is to <dfn id=discard-a-document>discard a
+  <code>Document</code></dfn>, that means that it is to lose the
+  strong reference from the <code>Document</code>'s <a href=#browsing-context>browsing
+  context</a> to the <code>Document</code>.</p>
+
+  <p class=note>The <a href=#browsing-context>browsing context</a>'s <a href=#default-view>default
+  view</a>'s <code><a href=#window>Window</a></code> object <a href=#implied-strong-reference title="implied strong
+  reference">has a strong reference of its own</a> to the
+  <code>Document</code> object of the <a href=#browsing-context>browsing context</a>'s
+  <a href=#active-document>active document</a>.</p>
+
+  <p>When <dfn id=a-browsing-context-is-discarded>a <em><span>browsing context</span></em> is
+  discarded</dfn>, the strong reference from the user agent itself to
+  the <a href=#browsing-context>browsing context</a> must be severed, and all the
+  <code>Document</code> objects for all the entries in the
+  <a href=#browsing-context>browsing context</a>'s session history must be <a href=#discard-a-document title="discard a document">discarded</a> as well.</p>
+
+  <p>User agents may <a href=#a-browsing-context-is-discarded title="a browsing context is
+  discarded">discard</a> <a href=#top-level-browsing-context title="top-level browsing
+  context">top-level browsing contexts</a> at any time (typically,
+  in response to user requests, e.g. when a user closes a window
+  containing one or more <a href=#top-level-browsing-context title="top-level browsing
+  context">top-level browsing contexts</a>). Other <a href=#browsing-context title="browsing context">browsing contexts</a> must be discarded
+  once their <code><a href=#window>Window</a></code> object is eligible for garbage
+  collection.</p>
+
+
+
   <h3 id=origin><span class=secno>5.3 </span>Origin</h3>
   <!-- Hallowed are the Ori -->
 
@@ -33291,6 +33402,8 @@
 
   <h3 id=scripting><span class=secno>5.4 </span>Scripting</h3>
 
+  <h4 id=introduction-0><span class=secno>5.4.1 </span>Introduction</h4>
+
   <p>Various mechanisms can cause author-provided executable code to
   run in the context of a document. These mechanisms include, but are
   probably not limited to:</p>
@@ -33309,85 +33422,246 @@
    <li>Processing of technologies like XBL or SVG that have their own
    scripting features.</li>
 
-  </ul><p>When a script is created<!-- which is marked by SCRIPT EXEC in
-  this spec -->, it is associated with a <a href=#script-execution-context>script execution
-  context</a>, a <a href=#script-browsing-context>script browsing context</a>, and a
-  <a href=#script-document-context>script document context</a>.</p>
+  </ul><h4 id=enabling-and-disabling-scripting><span class=secno>5.4.2 </span>Enabling and disabling scripting</h4>
 
+  <p><dfn id=concept-bc-script title=concept-bc-script>Scripting is enabled</dfn> in a
+  <em><a href=#browsing-context>browsing context</a></em> when all of the
+  following conditions are true:</p>
 
+  <ul><li>The user agent supports scripting.</li>
 
-  <!-- SCRIPT EXEC -->
-  <h4 id=script-execution-contexts><span class=secno>5.4.1 </span>Script execution contexts</h4>
+   <li>The user has not disabled scripting for this <a href=#browsing-context>browsing
+   context</a> at this time. (User agents may provide users with
+   the option to disable scripting globally, or in a finer-grained
+   manner, e.g. on a per-origin basis.)</li>
 
-  <p>The <dfn id=script-execution-context>script execution context</dfn> of a script is defined
-  when that script is created. In this specification, it is either a
-  <code><a href=#window>Window</a></code> object or an empty object; other specifications
-  might make the script execution context be some other object.</p>
+   <li id=sandboxScriptBlocked>The <a href=#browsing-context>browsing context</a>
+   does not have the <a href=#sandboxed-scripts-browsing-context-flag>sandboxed scripts browsing context
+   flag</a> set.</li>
 
-  <p>When the <a href=#script-execution-context>script execution context</a> of a script is an
-  empty object, it can't do anything that interacts with the
-  environment.</p>
+  </ul><p><dfn id=concept-bc-noscript title=concept-bc-noscript>Scripting is disabled</dfn> in a
+  <a href=#browsing-context>browsing context</a> when any of the above conditions are
+  false (i.e. when scripting is not <a href=#concept-bc-script title=concept-bc-script>enabled</a>).</p>
 
-  <p>A <a href=#script-execution-context>script execution context</a> always has an associated
-  <a href=#browsing-context>browsing context</a>, known as the <dfn id=script-browsing-context>script browsing
-  context</dfn>. If the <a href=#script-execution-context>script execution context</a> is a
-  <code><a href=#window>Window</a></code> object, then that object's <a href=#browsing-context>browsing
-  context</a> is it. Otherwise, the <a href=#script-execution-context>script execution
-  context</a> is associated explicitly with a <a href=#browsing-context>browsing
-  context</a> when it is created.</p>
+  <hr><p><dfn id=concept-n-script title=concept-n-script>Scripting is enabled</dfn> for a
+  <em>node</em> if the <code>Document</code> object of the node (the
+  node itself, if it is itself a <code>Document</code> object) has an
+  associated <a href=#browsing-context>browsing context</a>, and <a href=#concept-bc-script title=concept-bc-script>scripting is enabled</a> in that
+  <a href=#browsing-context>browsing context</a>.</p>
 
-  <p>Every script whose <a href=#script-execution-context>script execution context</a> is a
-  <code><a href=#window>Window</a></code> object is also associated with a
-  <code>Document</code> object, known as its <dfn id=script-document-context>script document
-  context</dfn>. It is used to <a href=#resolve-a-url title="resolve a
-  url">resolve</a> URLs. The document is assigned when the script
-  is created, as with the <a href=#script-browsing-context>script browsing context</a>.</p>
+  <p><dfn id=concept-n-noscript title=concept-n-noscript>Scripting is disabled</dfn> for a
+  node if there is no such <a href=#browsing-context>browsing context</a>, or if <a href=#concept-bc-noscript title=concept-bc-noscript>scripting is disabled</a> in that
+  <a href=#browsing-context>browsing context</a>.</p>
 
-  <hr><p>It is said that <dfn id=scripting-is-disabled>scripting is disabled</dfn> in a
-  <a href=#script-execution-context>script execution context</a> when any of the following
-  conditions are true:</p>
 
-  <ul><li>The user agent does not support scripting.</li>
 
-   <li>The user has disabled scripting for this <a href=#script-execution-context>script execution
-   context</a>. (User agents may provide users with the option to
-   disable scripting globally, on a per-origin basis, or in other ways
-   down to the granularity of individual <a href=#script-execution-context title="script execution
-   context">script execution contexts</a>.)</li>
+  <!-- SCRIPT EXEC (marks areas related to creation of scripts) -->
+  <h4 id=processing-model-1><span class=secno>5.4.3 </span>Processing model</h4>
 
-   <li id=designModeScriptBlocked>The <a href=#script-execution-context>script execution
-   context</a>'s associated <a href=#browsing-context>browsing context</a>'s
-   <a href=#active-document>active document</a> has <code title=dom-document-designMode><a href=#designMode>designMode</a></code> enabled.</li>
+  <h5 id=definitions-0><span class=secno>5.4.3.1 </span>Definitions</h5>
 
-   <li id=sandboxScriptBlocked>The <a href=#script-execution-context>script execution
-   context</a>'s associated <a href=#browsing-context>browsing context</a> has the
-   <a href=#sandboxed-scripts-browsing-context-flag>sandboxed scripts browsing context flag</a> set.</li>
+  <p>A <dfn id=concept-script title=concept-script>script</dfn> has:</p>
 
-  </ul><p>A node is said to be <dfn id=without-script>without script</dfn> if either the
-  <code>Document</code> object of the node (the node itself, if it is
-  itself a <code>Document</code> object) does not have an associated
-  <a href=#browsing-context>browsing context</a>, or <a href=#scripting-is-disabled>scripting is disabled</a>
-  in that <a href=#browsing-context>browsing context</a>.</p>
+  <dl><dt>A <dfn id=script-execution-environment>script execution environment</dfn></dt>
 
-  <p>A node is said to be <dfn id=with-script>with script</dfn> if it is not
-  <a href=#without-script>without script</a>.</p>
+   <dd>
 
-  <p class=XXX>If you can find a better pair of terms than
-  "with script" and "without script" let me know. The only things I
-  can find that are less confusing are also way, way longer.</p>
+    <p>The characteristics of the script execution environment depend
+    on the language, and are not defined by this specification.</p>
 
-  <p>When a script is to be executed in a <a href=#script-execution-context>script execution
-  context</a> in which <a href=#scripting-is-disabled>scripting is disabled</a>, the
-  script must do nothing and return nothing (a void return value).</p>
+    <p class=example>In JavaScript, the script execution environment
+    consists of the interpreter, the stack of <i>execution
+    contexts</i>, the <i>global code</i> and <i>function code</i> and
+    the Function objects resulting, and so forth.</p>
 
-  <p class=note>Thus, for instance, enabling <code title=dom-document-designMode><a href=#designMode>designMode</a></code> will disable any
-  event handler attributes, event listeners, timeouts, etc, that were
-  set by scripts in the document.</p>
+   </dd>
 
+   <dt>A <dfn id=list-of-code-entry-points>list of code entry-points</dfn></dt>
 
+   <dd>
 
-  <h4 id=event-loops><span class=secno>5.4.2 </span>Event loops</h4>
+    <p>Each code entry-point represents a block of executable code
+    that the script exposes to other scripts and to the user
+    agent.</p>
 
+    <p class=example>Each Function object in a JavaScript
+    <a href=#script-execution-environment>script execution environment</a> has a corresponding code
+    entry-point, for instance.</p>
+
+    <p>The main program code of the script, if any, is the
+    <dfn id=initial-code-entry-point><i>initial code entry-point</i></dfn>. Typically, the code
+    corresponding to this entry-point is executed immediately after
+    the script is parsed.</p>
+
+    <p class=example>In JavaScript, this corresponds to the
+    execution context of the global code.</p>
+
+   </dd>
+
+   <dt>A relationship with the <dfn id="script's-global-object">script's global object</dfn></dt>
+
+   <dd>
+
+    <p>An object that provides the APIs that the code can use.</p>
+
+    <p class=example>This is typically a <code><a href=#window>Window</a></code>
+    object. In JavaScript, this corresponds to the <i>global
+    object</i>.</p>
+
+    <p class=note>When a <a href="#script's-global-object">script's global object</a> is an
+    empty object, it can't do anything that interacts with the
+    environment.</p>
+
+   </dd>
+
+   <dt>A relationship with the <dfn id="script's-browsing-context">script's browsing context</dfn></dt>
+
+   <dd>
+
+    <p>A <a href=#browsing-context>browsing context</a> that is assigned responsibility
+    for actions taken by the script.</p>
+
+    <p class=example>When a script creates and <a href=#navigate title=navigate>navigates</a> a new <a href=#top-level-browsing-context>top-level browsing
+    context</a>, the <code title=dom-opener><a href=#dom-opener>opener</a></code>
+    attribute of the new <a href=#browsing-context>browsing context</a>'s
+    <code><a href=#window>Window</a></code> object will be set to the <a href="#script's-browsing-context">script's
+    browsing context</a>'s <code><a href=#window>Window</a></code> object.</p>
+
+   </dd>
+
+   <dt>A <dfn id="script's-character-encoding" title="script's character encoding">character encoding</dfn></dt>
+
+   <dd>
+
+    <p>A character encoding, set when the script is created, used to
+    encode URLs.  <span id=sce-not-copy>If the character encoding is
+    set from another source, e.g. a <a href="#document's-character-encoding">document's character
+    encoding</a>, then the <a href="#script's-character-encoding">script's character encoding</a>
+    must follow the source, so that if the source's changes, so does
+    the script's.</span></p>
+
+   </dd>
+
+   <dt>A <dfn id="script's-base-url" title="script's base URL">base URL</dfn></dt>
+
+   <dd>
+
+    <p>A <a href=#url>URL</a>, set when the script is created, used to
+    resolve relative URLs. <span id=sbu-not-copy>If the base URL is
+    set from another source, e.g. a <a href=#document-base-url>document base URL</a>,
+    then the <a href="#script's-base-url">script's base URL</a> must follow the source, so
+    that if the source's changes, so does the script's.</span></p>
+
+   </dd>
+
+   <dt>Membership in a <dfn id=script-group>script group</dfn></dt>
+
+   <dd>
+
+    <p>A group of one or more scripts that are loaded in the same
+    context, which are always disabled as a group. Scripts in a script
+    group all have the same <a href="#script's-global-object" title="script's global
+    object">global object</a> and <a href="#script's-browsing-context" title="script's browsing
+    context">browsing context</a>.</p>
+
+    <p>A script group can be <i>frozen</i>. When a script group is
+    frozen, any code defined in that script group will throw an
+    exception when invoked. A frozen script group can be
+    <i>unfrozen</i>, allowing scripts in that script group to run
+    normally again.</p>
+
+   </dd>
+
+  </dl><h5 id=calling-scripts><span class=secno>5.4.3.2 </span>Calling scripts</h5>
+
+  <p>When a user agent is to <dfn id=jump-to-a-code-entry-point>jump to a code entry-point</dfn> for
+  a <a href=#concept-script title=concept-script>script</a>, if <a href=#concept-bc-noscript title=concept-bc-noscript>scripting is disabled</a> in the
+  <a href="#script's-browsing-context">script's browsing context</a>, or if the script's
+  <a href=#script-group>script group</a> is <i>frozen</i>, then the user agent must
+  throw an <code><a href=#unavailable_script_err>UNAVAILABLE_SCRIPT_ERR</a></code> exception. Otherwise,
+  the <a href=#script-execution-environment title="script execution environment">script execution
+  environment</a> for the <a href=#concept-script title=concept-script>script</a> must execute the code for the
+  given code entry-point.</p>
+
+  <p>When executable code in one <a href=#concept-script title=concept-script>script</a> makes a call to another <a href=#concept-script title=concept-script>script</a>, the user agent must <a href=#jump-to-a-code-entry-point title="jump to a code entry-point">jump</a> to the corresponding
+  code entry-point in that second script.</p>
+
+  <p>Any time the user agent to invoke a callback defined in a <a href=#concept-script title=concept-script>script</a>, the user agent must <a href=#jump-to-a-code-entry-point title="jump to a code entry-point">jump</a> to the corresponding
+  code entry-point in that second script.</p>
+
+
+
+  <h5 id=creating-scripts><span class=secno>5.4.3.3 </span>Creating scripts</h5>
+
+  <p>When the specification says that a <a href=#concept-script title=concept-script>script</a> is to be <dfn id=create-a-script title="create a
+  script">created</dfn>, given some script source, its scripting
+  language, a global object, a browsing context, a character encoding,
+  a base URL, and a script group, the user agent must run the
+  following steps:</p>
+
+  <ol><li><p>Set up a <a href=#script-execution-environment>script execution environment</a> as
+   appropriate for the scripting language.</li>
+
+   <li><p>Parse/compile/initialise the source of the script using the
+   <a href=#script-execution-environment>script execution environment</a>, as appropriate for the
+   scripting language, and thus obtain the <a href=#list-of-code-entry-points>list of code
+   entry-points</a> for the script. If the semantics of the
+   scripting language and the given source code are such that there is
+   executable code to be immediately run, then the <i><a href=#initial-code-entry-point>initial code
+   entry-point</a></i> is the entry-point for that code.</li>
+
+   <li><p>Set up the <a href="#script's-global-object">script's global object</a>, the
+   <a href="#script's-browsing-context">script's browsing context</a>, the <a href="#script's-character-encoding">script's
+   character encoding</a>, and the <a href="#script's-base-url">script's base URL</a>
+   from the settings passed to this algorithm.</li>
+
+   <li><p>Add the <a href=#concept-script title=concept-script>script</a> to the given <a href=#script-group>script
+   group</a>.</li>
+
+   <li><p><a href=#jump-to-a-code-entry-point title="jump to a code entry-point">Jump</a> to the
+   <a href=#concept-script title=concept-script>script</a>'s <i><a href=#initial-code-entry-point>initial code
+   entry-point</a></i>.</li>
+
+  </ol><hr><p>When the user agent is to <dfn id=create-an-impotent-script>create an impotent script</dfn>,
+  given some script source, its scripting language, and a browsing
+  context, the user agent must <a href=#create-a-script>create a script</a>, using the
+  given script source and scripting language, using a new empty object
+  as the global object, using the given browsing context as the
+  browsing context, and using a new script group as the script
+  group. The character encoding and base URL for the resulting <a href=#concept-script title=concept-script>script</a> are not important as no APIs
+  are exposed to the script.</p>
+
+  <hr><p>When the specification says that a <a href=#concept-script title=concept-script>script</a> is to be <dfn id=create-a-script-from-a-node title="create a
+  script from a node">created from a node</dfn> <var title="">node</var>, given some script source and its scripting
+  language, the user agent <a href=#create-a-script>create a script</a>, using the
+  given script source and scripting language, and using <a href=#the-script-settings-determined-from-the-node>the
+  script settings determined from the node</a> <var title="">node</var>.</p>
+
+  <p><dfn id=the-script-settings-determined-from-the-node>The script settings determined from the node</dfn> <var title="">node</var> are computed as follows:</p>
+
+  <ol><li><p>Let <var title="">document</var> be the
+   <code>Document</code> of <var title="">node</var> (or <var title="">node</var> itself if it is a
+   <code>Document</code>).</li>
+
+   <li><p>The browsing context is the <a href=#browsing-context>browsing context</a> of
+   <var title="">document</var>.</p>
+
+   <li><p>The global object is the <code><a href=#window>Window</a></code> object of the
+   <a href=#default-view>default view</a> of the <a href=#browsing-context>browsing context</a> of
+   <var title="">document</var>.</li>
+
+   <li><p>The character encoding is the <a href="#document's-character-encoding" title="document's
+   character encoding">character encoding</a> of <var title="">document</var>. (<a href=#sce-not-copy>This is a
+   reference, not a copy</a>.)</li>
+
+   <li><p>The base URL is the <a href=#document-base-url title="document base URL">base
+   URL</a> of <var title="">document</var>. (<a href=#sbu-not-copy>This is a reference, not a copy</a>.)</li>
+
+   <li><p>The script group is the <a href=#current-script-group>current script group</a> of
+   <var title="">document</var>.</li>
+
+  </ol><h4 id=event-loops><span class=secno>5.4.4 </span>Event loops</h4>
+
   <p>To coordinate events, user interaction, scripts, rendering,
   networking, and so forth, user agents must use <dfn id=event-loop title="event
   loop">event loops</dfn> as described in this section.</p>
@@ -33445,7 +33719,18 @@
    manipulation, e.g. when that element is <a href=#insert-an-element-into-a-document title="insert an
    element into a document">inserted into the document</a>.</p>
 
-  </dl><p>When a user agent is to <dfn id=queue-a-task>queue a task</dfn>, it must add the
+  </dl><p>Each <a href=#concept-task title=concept-task>task</a> is associated with a
+  <code>Document</code>; if the task was queued in the context of an
+  element, then it is the element's <code>Document</code>; if the task
+  was queued in the context of a <a href=#browsing-context>browsing context</a>, then
+  it is the <a href=#browsing-context>browsing context</a>'a <a href=#active-document>active
+  document</a> at the time the task was queued; if the task was
+  queued by or for a <a href=#concept-script title=concept-script>script</a> then
+  the document is the script's <a href="#script's-browsing-context">script's browsing
+  context</a>'s <a href=#active-document>active document</a> at the time the task
+  was queued.</p>
+
+  <p>When a user agent is to <dfn id=queue-a-task>queue a task</dfn>, it must add the
   given task to one of the <a href=#task-queue title="task queue">task queues</a>
   of the relevant <a href=#event-loop>event loop</a>. All the tasks from one
   particular <dfn id=task-source>task source</dfn> (e.g. the callbacks generated by
@@ -33467,8 +33752,10 @@
   following steps for as long as it exists:</p>
 
   <ol><li><p>Run the oldest task on one of the <a href=#event-loop>event loop</a>'s
-   <a href=#task-queue title="task queue">task queues</a>. The user agent may
-   pick any <a href=#task-queue>task queue</a>.</li>
+   <a href=#task-queue title="task queue">task queues</a>, ignoring tasks whose
+   associated <code>Document</code>s are not <a href=#active-document title="active
+   document">active</a>. The user agent may pick any <a href=#task-queue>task
+   queue</a>.</li>
 
    <li><p>Remove that task from its <a href=#task-queue>task queue</a>.</li>
 
@@ -33479,7 +33766,7 @@
    <li><p>Return to the first step of the <a href=#event-loop>event
    loop</a>.</li>
 
-  </ol><h5 id=generic-task-sources><span class=secno>5.4.2.1 </span>Generic task sources</h5>
+  </ol><h5 id=generic-task-sources><span class=secno>5.4.4.1 </span>Generic task sources</h5>
 
   <p>The following <a href=#task-source title="task source">task sources</a> are
   used by a number of mostly unrelated features in this and other
@@ -33525,61 +33812,107 @@
 
    </dd>
 
-  </dl><!-- SCRIPT EXEC --><h4 id=javascript-protocol><span class=secno>5.4.3 </span><dfn title="javascript protocol">The <code title="">javascript:</code> protocol</dfn></h4>
+  </dl><!-- SCRIPT EXEC --><h4 id=javascript-protocol><span class=secno>5.4.5 </span><dfn title="javascript protocol">The <code title="">javascript:</code> protocol</dfn></h4>
 
-  <p>A URL using the <code title="">javascript:</code> protocol must,
-  if and when <dfn id=concept-js-deref title=concept-js-deref>dereferenced</dfn>, be
-  evaluated by executing the script obtained using the content
-  retrieval operation defined for <code title="">javascript:</code>
-  URLs. <a href=#refsJSURL>[JSURL]</a></p>
+  <p>When a <a href=#url>URL</a> using the <code title="">javascript:</code> protocol is <dfn id=concept-js-deref title=concept-js-deref>dereferenced</dfn>, the user agent must run
+  the following steps:</p>
 
+  <ol><li><p>Let the script source be the string obtained using the
+   content retrieval operation defined for <code title="">javascript:</code> URLs. <a href=#refsJSURL>[JSURL]</a></li>
+
 <!--
 JSURL: http://ietfreport.isoc.org/all-ids/draft-hoehrmann-javascript-scheme-00.txt and
        http://www.websitedev.de/ietf/draft-hoehrmann-javascript-scheme-00.txt should be as stable as it gets,
        http://ietfreport.isoc.org/idref/draft-hoehrmann-javascript-scheme/ for the latest version
 -->
 
-  <p>When a <a href=#browsing-context>browsing context</a> is <a href=#navigate title=navigate>navigated</a> to a <code>javascript:</code> URL,
-  and the <a href=#active-document>active document</a> of that browsing context has
-  the <a href=#same-origin>same origin</a> as the script given by that URL, the
-  <a href=#script-execution-context>script execution context</a> must be the
-  <code><a href=#window>Window</a></code> object of the <a href=#browsing-context>browsing context</a>
-  being navigated, and the <a href=#script-document-context>script document context</a> must
-  be that <a href=#active-document>active document</a>.</p>
+   <li>
 
-  <p>When a <a href=#browsing-context>browsing context</a> is <a href=#navigate title=navigate>navigated</a> to a <code>javascript:</code> URL,
-  and the <a href=#active-document>active document</a> of that browsing context has an
-  <a href=#origin-0>origin</a> that is <em>not</em> the <a href=#same-origin title="same
-  origin">same</a> as that of the script given by the URL, the
-  <a href=#script-execution-context>script execution context</a> must be an empty object, and
-  the <a href=#script-browsing-context>script browsing context</a> must be the <a href=#browsing-context>browsing
-  context</a> being <a href=#navigate title=navigate>navigated</a>.</p>
+    <p>Use the appropriate step from the following list:</p>
 
-  <p>Otherwise, if the <code>Document</code> object of the element,
-  attribute, or style sheet from which the <code>javascript:</code>
-  URL was reached has an associated <a href=#browsing-context>browsing context</a>, the
-  <a href=#script-execution-context>script execution context</a> must be an empty object, and
-  the <a href=#script-execution-context>script execution context</a>'s associated
-  <a href=#browsing-context>browsing context</a> must be that <a href=#browsing-context>browsing
-  context</a>.</p>
+    <dl><dt>If a <a href=#browsing-context>browsing context</a> is being <a href=#navigate title=navigate>navigated</a> to a <code>javascript:</code>
+     URL, and the <a href=#active-document>active document</a> of that browsing
+     context has the <a href=#same-origin>same origin</a> as the script given by
+     that URL</dt>
 
-  <p>Otherwise, the script is not executed and its return value is
-  void.</p>
+     <dd>
 
-  <p>If the result of executing the script is void (there is no return
-  value), then the URL must be treated in a manner equivalent to an
-  HTTP resource with an HTTP 204 No Content response.</p>
+      <p><a href=#create-a-script-from-a-node title="create a script from a node">Create a
+      script</a> from the <code>Document</code> node of the
+      <a href=#active-document>active document</a>, using the aforementioned script
+      source, and assuming the scripting language is JavaScript.</p>
 
-  <p>Otherwise, the URL must be treated in a manner equivalent to an
-  HTTP resource with a 200 OK response whose <a href=#content-type-0 title=Content-Type>Content-Type metadata</a> is <code title="">text/html</code> and whose response body is the return
-  value converted to a string value.</p>
+      <p>Let <var title="">result</var> be the return value of the
+      <i><a href=#initial-code-entry-point>initial code entry-point</a></i> of this <a href=#concept-script title=concept-script>script</a>. If an exception was
+      raised, let <var title="">result</var> be void instead.</p>
 
-  <p class=note>Certain contexts, in particular <code><a href=#the-img-element>img</a></code>
-  elements, ignore the <a href=#content-type-0 title=Content-Type>Content-Type
-  metadata</a>.</p>
+     </dd>
 
-  <div class=example>
+     <dt>If a <a href=#browsing-context>browsing context</a> is being <a href=#navigate title=navigate>navigated</a> to a <code>javascript:</code>
+     URL, and the <a href=#active-document>active document</a> of that browsing
+     context has an <a href=#origin-0>origin</a> that is <em>not</em> the <a href=#same-origin title="same origin">same</a> as that of the script given by
+     the URL</dt>
 
+     <dd>
+
+      <p><a href=#create-an-impotent-script>Create an impotent script</a> using the
+      aforementioned script source, with the scripting language set to
+      JavaScript, and with the <a href=#browsing-context>browsing context</a> being
+      <a href=#navigate title=navigate>navigated</a> as the browsing
+      context.</p>
+
+      <p>Let <var title="">result</var> be the return value of the
+      <i><a href=#initial-code-entry-point>initial code entry-point</a></i> of this <a href=#concept-script title=concept-script>script</a>. If an exception was
+      raised, let <var title="">result</var> be void instead.</p>
+
+     </dd>
+
+     <dt>If the <code>Document</code> object of the element,
+     attribute, or style sheet from which the <code>javascript:</code>
+     URL was reached has an associated <a href=#browsing-context>browsing
+     context</a></dt>
+
+     <dd>
+
+      <p><a href=#create-an-impotent-script>Create an impotent script</a> using the
+      aforementioned script source, with the scripting language set to
+      JavaScript, and with the <code>Document</code>'s object's
+      <a href=#browsing-context>browsing context</a> as the browsing context.</p>
+
+      <p>Let <var title="">result</var> be the return value of the
+      <i><a href=#initial-code-entry-point>initial code entry-point</a></i> of this <a href=#concept-script title=concept-script>script</a>. If an exception was
+      raised, let <var title="">result</var> be void instead.</p>
+
+     </dd>
+
+     <dt>Otherwise</dt>
+
+     <dd>
+
+      <p>Let <var title="">result</var> be void.</p>
+
+     </dd>
+
+    </dl></li>
+
+   <li>
+
+    <p>If the result of executing the script is void (there is no
+    return value), then the URL must be treated in a manner equivalent
+    to an HTTP resource with an HTTP 204 No Content response.</p>
+
+    <p>Otherwise, the URL must be treated in a manner equivalent to an
+    HTTP resource with a 200 OK response whose <a href=#content-type-0 title=Content-Type>Content-Type metadata</a> is <code title="">text/html</code> and whose response body is the return
+    value converted to a string value.</p>
+
+    <p class=note>Certain contexts, in particular <code><a href=#the-img-element>img</a></code>
+    elements, ignore the <a href=#content-type-0 title=Content-Type>Content-Type
+    metadata</a>.</p>
+
+   </li>
+
+  </ol><div class=example>
+
    <p>So for example a <code title="">javascript:</code> URL for a
    <code title=attr-img-src><a href=#attr-img-src>src</a></code> attribute of an
    <code><a href=#the-img-element>img</a></code> element would be evaluated in the context of an
@@ -33598,13 +33931,13 @@
 
   </div>
 
-  <p class=note>The rules for handling script execution in a
-  <a href=#script-execution-context>script execution context</a> include making the script not
-  execute (and just return void) in certain cases, e.g. in a sandbox
-  or when the user has disabled scripting altogether.</p>
+  <p class=note>The rules for <a href=#create-a-script title="create a script">creating
+  a script</a> include making the script not execute (and just
+  return void) in certain cases, e.g. in a sandbox or when the user
+  has disabled scripting altogether.</p>
 
 
-  <h4 id=events><span class=secno>5.4.4 </span>Events</h4>
+  <h4 id=events><span class=secno>5.4.6 </span>Events</h4>
 
   <p class=XXX>We need to define how to handle events that are
   to be fired on a Document that is no longer the active document of
@@ -33616,71 +33949,83 @@
   when the document isn't active.</p>
 
 
-  <h5 id=event-handler-attributes><span class=secno>5.4.4.1 </span>Event handler attributes</h5>
+  <h5 id=event-handler-attributes><span class=secno>5.4.6.1 </span>Event handler attributes</h5>
 
   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A...%3Cscript%3E%0Aw(a%3Ddocument.implementation.createDocument(null%2C%20null%2C%20null))%3B%0Aw(a.appendChild(a.createElementNS('http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml'%2C%20'html')))%3B%0Aw(b%3Da.firstChild.appendChild(a.createElementNS('http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml'%2C%20'body')))%3B%0Aw(b.test%20%3D%20w)%3B%0Aw(b.setAttribute('onclick'%2C%20'test(%22fire%3A%20%22%20%2B%20event)'))%3B%0Aw(b.onclick)%3B%0Aw(e%3Da.createEvent('Event'))%3B%0Aw(e.initEvent('click'%2C%20false%2C%20false))%3B%0Aw(b.dispatchEvent(e))%3B%0A%3C%2Fscript%3E -->
 
-  <p><a href=#html-elements>HTML elements</a> can have <dfn id=event-handler-attributes-0>event handler
-  attributes</dfn> specified. These act as bubbling event listeners
-  for the element on which they are specified.</p>
+  <p>Many objects can have <dfn id=event-handler-attributes-0>event handler attributes</dfn>
+  specified. These act as bubbling event listeners for the element on
+  which they are specified.</p>
 
-  <p>Each event handler attribute has two parts, an <a href=#event-handler-content-attributes title="event
-  handler content attributes">event handler content attribute</a>
-  and an <a href=#event-handler-dom-attributes title="event handler DOM attributes">event handler DOM
-  attribute</a>. Event handler attributes must initially be set to
-  null. When their value changes (through the changing of their event
-  handler content attribute or their event handler DOM attribute),
-  they will either be null, or have an <code>EventListener</code>
-  object assigned to them.</p>
+  <p>On <a href=#html-elements>HTML elements</a>, each event handler attribute has
+  two parts, an <a href=#event-handler-content-attributes title="event handler content attributes">event
+  handler content attribute</a> and an <a href=#event-handler-dom-attributes title="event handler
+  DOM attributes">event handler DOM attribute</a>. Event handler
+  attributes must initially be set to null. When their value changes
+  (through the changing of their event handler content attribute or
+  their event handler DOM attribute), they will either be null, or
+  have an <code>EventListener</code> object assigned to them.</p>
 
   <p>Objects other than <code>Element</code> objects, in particular
   <code><a href=#window>Window</a></code>, only have <a href=#event-handler-dom-attributes title="event handler DOM
   attributes">event handler DOM attribute</a> (since they have no
   content attributes).</p>
 
-  <p><dfn id=event-handler-content-attributes>Event handler content attributes</dfn>, when specified, must
+  <hr><p><dfn id=event-handler-content-attributes>Event handler content attributes</dfn>, when specified, must
   contain valid ECMAScript code matching the ECMAScript <code title="">FunctionBody</code> production. <a href=#refsECMA262>[ECMA262]</a></p>
 
   <!-- SCRIPT EXEC -->
   <p>When an event handler content attribute is set, if the element is
   owned by a <code>Document</code> that is in a <a href=#browsing-context>browsing
-  context</a>, its new value must be interpreted as the body of an
-  anonymous function with a single argument called <code>event</code>,
-  with the new function's scope chain being linked from the activation
-  object of the handler, to the element, to the element's
-  <code><a href=#the-form-element>form</a></code> element if it is a form control, to the
-  <code>Document</code> object, to the <code><a href=#window>Window</a></code> object of
-  the <a href=#browsing-context>browsing context</a> of that <code>Document</code>. The
-  function's <code>this</code> parameter must be the
-  <code>Element</code> object representing the element. The resulting
-  function must then be set as the value of the corresponding event
-  handler attribute, and the new value must be set as the value of the
-  content attribute. If the given function body fails to compile, then
-  the corresponding event handler attribute must be set to null
-  instead (the content attribute must still be updated to the new
-  value, though).</p>
+  context</a>, the user agent must run the following steps to
+  create a <a href=#concept-script title=concept-script>script</a> after setting
+  the content attribute to its new value:</p>
 
-  <p class=note>See ECMA262 Edition 3, sections 10.1.6 and 10.2.3,
-  for more details on activation objects. <a href=#refsECMA262>[ECMA262]</a></p>
+  <ol><li><p>Set up a <a href=#script-execution-environment>script execution environment</a> for
+   JavaScript.</li>
 
-  <p>The <a href=#script-execution-context>script execution context</a> of the event handler
-  must be the <code><a href=#window>Window</a></code> object at the end of the scope
-  chain. The <a href=#script-document-context>script document context</a> of the event handler
-  must be the <code>Document</code> object that owns the event handler
-  content attribute that was set.</p>
+   <li><p>Using this script execution environment, interpret the
+   attribute's new value as the body of an anonymous function with a
+   single argument called <code>event</code>. Link the new function's
+   scope chain from the activation object of the handler, to the
+   element's object, to the element's <a href=#form-owner>form owner</a>, if it
+   has one, to the element's <code>Document</code> object, to the
+   <code><a href=#window>Window</a></code> object of the <a href=#browsing-context>browsing context</a> of
+   that <code>Document</code>. Set the function's <code>this</code>
+   parameter to the <code>Element</code> object representing the
+   element. Let this function be the only entry in the script's
+   <a href=#list-of-code-entry-points>list of code entry-points</a>.</p>
 
-  <p>When an event handler content attribute is set on an element
-  owned by a <code>Document</code> that is not in a <a href=#browsing-context>browsing
-  context</a>, the corresponding event handler attribute is not
-  changed.</p>
+   <p class=note>See ECMA262 Edition 3, sections 10.1.6 and 10.2.3,
+   for more details on activation objects. <a href=#refsECMA262>[ECMA262]</a></li>
 
+   <li><p>If the previous steps failed to compile the script, then set
+   the corresponding event handler attribute to null and abort these
+   steps.</li>
+
+   <li><p>Set up the <a href="#script's-global-object">script's global object</a>, the
+   <a href="#script's-browsing-context">script's browsing context</a>, the <a href="#script's-character-encoding">script's
+   character encoding</a>, and the <a href="#script's-base-url">script's base URL</a>
+   from <a href=#the-script-settings-determined-from-the-node>the script settings determined from the node</a> on
+   which the attribute is being set, and add the <a href=#concept-script title=concept-script>script</a> to the
+   <a href=#script-group>script group</a> determined from that node as
+   well.</li>
+
+   <li><p>Set the corresponding event handler attribute to the
+   aforementioned function.</li>
+
+  </ol><p class=note>When an event handler content attribute is set on an
+  element owned by a <code>Document</code> that is not in a
+  <a href=#browsing-context>browsing context</a>, the corresponding event handler
+  attribute is not changed.</p>
+
   <p class=note>Removing an event handler content attribute does not
-  reset the corresponding event handler attribute either.</p>
+  reset the corresponding event handler attribute.</p>
   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A...%3Cbody%20onload%3D%22w(%27pass%27)%22%3E%0A%3Cscript%3Edocument.body.removeAttribute(%27onload%27)%3B%3C%2Fscript%3E -->
 
   <p class=XXX>How do we allow non-JS event handlers?</p>
 
-  <p><dfn id=event-handler-dom-attributes>Event handler DOM attributes</dfn>, on setting, must set the
+  <hr><p><dfn id=event-handler-dom-attributes>Event handler DOM attributes</dfn>, on setting, must set the
   corresponding event handler attribute to their new value, and on
   getting, must return whatever the current value of the corresponding
   event handler attribute is (possibly null).</p>
@@ -33894,19 +34239,31 @@
    <dt><dfn id=handler-onunload title=handler-onunload><code>onunload</code></dfn></dt> <!-- widely used -->
 
    <dd><p>Must be invoked whenever an <code title=event-unload>unload</code> event is targeted at or bubbles
-   through the element.</dd> <!-- XXX need to fire this -->
+   through the element.</dd>
 
   </dl><p>When an event handler attribute is invoked, its argument must be
-  set to the <code>Event</code> object of the event in question. If
-  the function returns the exact boolean value false, the event's
-  <code>preventDefault()</code> method must then invoked. Exception:
-  for historical reasons, for the HTML <code>mouseover</code> event,
-  the <code>preventDefault()</code> method must be called when the
-  function returns true instead.</p>
+  set to the <code>Event</code> object of the event in question.</p>
 
-  <!-- IE actually uncancels the event if the function returns true -->
+  <p>The handler's return value must be processed as follows:</p>
 
-  <p>All event handler attributes on an element, whether set to null
+  <dl class=switch><dt>If the event type is <code class=event-mouseover>mouseover</code></dt>
+
+   <dd><p>If the return value is a boolean with the value true, then
+   the event must be canceled.</dd>
+
+   <dt>If the event object is a <code><a href=#beforeunloadevent>BeforeUnloadEvent</a></code> object</dt>
+
+   <dd><p>If the return value is a string, and the event object's
+   <code title=dom-BeforeUnloadEvent-returnValue><a href=#dom-beforeunloadevent-returnvalue>returnValue</a></code>
+   attribute's value is the empty string, then set the <code title=dom-BeforeUnloadEvent-returnValue><a href=#dom-beforeunloadevent-returnvalue>returnValue</a></code>
+   attribute's value to the return value.</dd>
+
+   <dt>Otherwise</dt>
+
+   <dd><p>If the return value is a boolean with the value false, then
+   the event must be canceled.</dd>
+
+  </dl><!-- IE actually uncancels the event if the function returns true --><p>All event handler attributes on an element, whether set to null
   or to a function, must be registered as event listeners on the
   element, as if the <code title=dom-EventTarget-addEventListenerNS>addEventListenerNS()</code>
   method on the <code>Element</code> object's <code>EventTarget</code>
@@ -33925,7 +34282,7 @@
   itself.)</p>
 
 
-  <h5 id=event-firing><span class=secno>5.4.4.2 </span>Event firing</h5>
+  <h5 id=event-firing><span class=secno>5.4.6.2 </span>Event firing</h5>
 
   <p class=XXX>maybe this should be moved higher up
   (terminology? conformance? DOM?) Also, the whole terminology thing
@@ -33995,7 +34352,7 @@
   dispatched in expected ways.</p>
 
 
-  <h5 id=events-and-the-window-object><span class=secno>5.4.4.3 </span>Events and the <code><a href=#window>Window</a></code> object</h5>
+  <h5 id=events-and-the-window-object><span class=secno>5.4.6.3 </span>Events and the <code><a href=#window>Window</a></code> object</h5>
 
   <p>When an event is dispatched at a DOM node in a
   <code>Document</code> in a <a href=#browsing-context>browsing context</a>, if the
@@ -34011,7 +34368,7 @@
    <code><a href=#window>Window</a></code> object at the end of the phase, unless bubbling
    has been prevented.</li>
 
-  </ol><h5 id=runtime-script-errors><span class=secno>5.4.4.4 </span>Runtime script errors</h5>
+  </ol><h5 id=runtime-script-errors><span class=secno>5.4.6.4 </span>Runtime script errors</h5>
 
   <p><em>This section only applies to user agents that support
   scripting in general and ECMAScript in particular.</em></p>
@@ -34201,7 +34558,7 @@
 
      <li>have an <a href=#active-document>active document</a> whose
      <a href=#origin-0>origin</a> is the <a href=#same-origin title="same origin">same</a>
-     as the <a href=#origin-0>origin</a> of the script that called the <code title=dom-showModalDialog><a href=#dom-showmodaldialog>showModalDialog()</a></code> method at
+     as the <a href=#origin-0>origin</a> of the <a href=#concept-script title=concept-script>script</a> that called the <code title=dom-showModalDialog><a href=#dom-showmodaldialog>showModalDialog()</a></code> method at
      the time the method was called,</li> <!-- Note that changing
      document.domain to talk to another domain doesn't make you able
      to block that domain -->
@@ -34246,16 +34603,16 @@
    <li>
 
     <p>Let the <a href="#dialog-arguments'-origin">dialog arguments' origin</a> be the
-    <a href=#origin-0>origin</a> of the script that called the <code title=dom-showModalDialog><a href=#dom-showmodaldialog>showModalDialog()</a></code> method.</p>
+    <a href=#origin-0>origin</a> of the <a href=#concept-script title=concept-script>script</a> that called the <code title=dom-showModalDialog><a href=#dom-showmodaldialog>showModalDialog()</a></code> method.</p>
 
    </li>
 
    <li>
 
     <p><a href=#navigate>Navigate</a> the new browsing context to <var title="">url</var>, with <a href=#replacement-enabled>replacement enabled</a>, and
-    with the <a href=#script-browsing-context>script browsing context</a> of the script that
-    invoked the method as the <a href=#source-browsing-context>source browsing
-    context</a>.</p>
+    with the <a href="#script's-browsing-context" title="script's browsing context">browsing
+    context</a> of the <a href=#concept-script title=concept-script>script</a> that invoked the method as the
+    <a href=#source-browsing-context>source browsing context</a>.</p>
 
    </li>
 
@@ -34355,18 +34712,18 @@
   <p>The <dfn id=dom-shownotification title=dom-showNotification><code>showNotification(<var title="">title</var>, <var title="">subtitle</var>, <var title="">description</var>, <var title="">onclick</var>)</code></dfn> method, when invoked, must
   cause the user agent to show a notification.</p>
 
-  <p id=sandboxNotifications>If the method was invoked from a script
-  whose <a href=#script-browsing-context>script browsing context</a> has the <a href=#sandboxed-annoyances-browsing-context-flag>sandboxed
-  annoyances browsing context flag</a> set, then the notification
-  must be shown within that <a href=#browsing-context>browsing context</a>. The
-  notification is said to be a <dfn id=sandboxed-notification>sandboxed notification</dfn>.</p>
+  <p id=sandboxNotifications>If the method was invoked from a <a href=#concept-script title=concept-script>script</a>
+  whose <a href="#script's-browsing-context" title="script's browsing context">browsing
+  context</a> has the <a href=#sandboxed-annoyances-browsing-context-flag>sandboxed annoyances browsing context
+  flag</a> set, then the notification must be shown within that
+  <a href=#browsing-context>browsing context</a>. The notification is said to be a
+  <dfn id=sandboxed-notification>sandboxed notification</dfn>.</p>
 
-  <p>Otherwise, if the <a href=#origin-0>origin</a> of the <a href=#script-browsing-context>script
-  browsing context</a> of the script that invoked the method is
-  <em>not</em> flagged as being a <a href=#trusted-notification-source>trusted notification
-  source</a>, then the notification should be rendered within the
-  <a href=#top-level-browsing-context>top-level browsing context</a> of the <a href=#script-browsing-context>script browsing
-  context</a> of the script that invoked the method. The
+  <p>Otherwise, if the <a href=#origin-0>origin</a> of the <a href="#script's-browsing-context" title="script's browsing context">browsing context</a> of the
+  <a href=#concept-script title=concept-script>script</a> that invoked the method is <em>not</em> flagged as being a
+  <a href=#trusted-notification-source>trusted notification source</a>, then the notification
+  should be rendered within the <a href=#top-level-browsing-context>top-level browsing
+  context</a> of the <a href="#script's-browsing-context">script's browsing context</a>. The
   notification is said to be a <dfn id=normal-notification>normal notification</dfn>. User
   agents should provide a way to set the origin's <a href=#trusted-notification-source>trusted
   notification source</a> flag from the notification, so that the
@@ -34415,16 +34772,15 @@
   <p>When a <a href=#normal-notification>normal notification</a> (but not a
   <a href=#sandboxed-notification>sandboxed notification</a>) is shown, the user agent may
   bring the user's attention to the <a href=#top-level-browsing-context>top-level browsing
-  context</a> of the <a href=#script-browsing-context>script browsing context</a> of the
-  script that invoked the method, if that would be useful; but user
-  agents should not use system-wide notification mechanisms to do
-  so.</p>
+  context</a> of the <a href="#script's-browsing-context" title="script's browsing
+  context">browsing context</a> of the <a href=#concept-script title=concept-script>script</a> that invoked the
+  method, if that would be useful; but user agents should not use
+  system-wide notification mechanisms to do so.</p>
 
   <p>When a <a href=#trusted-notification>trusted notification</a> is shown, the user agent
-  should bring the user's attention to the notification and the
-  <a href=#script-browsing-context>script browsing context</a> of the script that invoked the
-  method, as per the platform conventions for attracting the user's
-  attention to applications.</p>
+  should bring the user's attention to the notification and the <a href="#script's-browsing-context" title="script's browsing context">browsing context</a> of the
+  <a href=#concept-script title=concept-script>script</a> that invoked the method, as per the platform conventions for
+  attracting the user's attention to applications.</p>
 
   <div class=example>
 
@@ -34448,8 +34804,9 @@
 
    <li>The <a href=#meta-application-name title=meta-application-name>application
    name</a>, if available, or else the <a href=#document.title title=dom-document-title>document title</a>, of the
-   <a href=#active-document>active document</a> of the <a href=#script-browsing-context>script browsing
-   context</a> of the script that invoked the method.</li>
+   <a href=#active-document>active document</a> of the <a href="#script's-browsing-context" title="script's browsing
+   context">browsing context</a> of the <a href=#concept-script title=concept-script>script</a> that invoked the
+   method.</li>
 
    <li>An icon chosen from the <a href=#external-resource-link title="external resource
    link">external resource links</a> of type <code title=rel-icon><a href=#rel-icon>icon</a></code>, if any are available.</li>
@@ -34485,10 +34842,11 @@
   <p>User agents should support user interaction with notifications,
   if and as appropriate given the platform conventions. If a user
   activates a notification, and the <var title="">onclick</var>
-  callback argument was present and is not null, then the <a href=#script-browsing-context>script
-  browsing context</a> of the function given by <var title="">onclick</var> should be brought to the user's attention,
-  and the <var title="">onclick</var> callback should then be
-  invoked.</p>
+  callback argument was present and is not null, then the <a href="#script's-browsing-context" title="script's browsing context">browsing context</a> of the
+  <a href=#concept-script title=concept-script>script</a> of the function given by
+  <var title="">onclick</var> should be brought to the user's
+  attention, and the <var title="">onclick</var> callback should then
+  be invoked.</p>
 
 
 
@@ -34665,9 +35023,8 @@
     first occurrence of the exact literal string "<code>%s</code>"
     with an escaped version of the URL of the content in question (as
     defined below), then <a href=#resolve-a-url title="resolve a url">resolve</a>
-    the resulting URL (using the <a href=#document-base-url>document base URL</a> of the
-    <a href=#script-document-context>script document context</a> of the script that originally
-    invoked the <code title=dom-navigator-registerContentHandler><a href=#dom-navigator-registercontenthandler>registerContentHandler()</a></code>
+    the resulting URL (using the <a href="#script's-base-url" title="script's base URL">base
+    URL</a> of the script that originally invoked the <code title=dom-navigator-registerContentHandler><a href=#dom-navigator-registercontenthandler>registerContentHandler()</a></code>
     or <code title=dom-navigator-registerProtocolHandler><a href=#dom-navigator-registerprotocolhandler>registerProtocolHandler()</a></code>
     method), and then <a href=#fetch>fetch</a> the resulting URL using the
     GET method (<a href=#concept-http-equivalent-get title=concept-http-equivalent-get>or
@@ -34904,7 +35261,7 @@
 
   <h3 id=offline><span class=secno>5.7 </span>Offline Web applications</h3>
 
-  <h4 id=introduction-0><span class=secno>5.7.1 </span>Introduction</h4>
+  <h4 id=introduction-1><span class=secno>5.7.1 </span>Introduction</h4>
 
   <p><em>This section is non-normative.</em></p>
 
@@ -35902,7 +36259,7 @@
 
 
 
-  <h4 id=processing-model-1><span class=secno>5.7.5 </span>Processing model</h4>
+  <h4 id=processing-model-2><span class=secno>5.7.5 </span>Processing model</h4>
 
   <p>The processing model of application caches for offline support in
   Web applications is part of the <a href=#navigate title=navigate>navigation</a> model, but references the
@@ -36738,8 +37095,9 @@
   enabled</a>.</p>
 
   <p>Navigation for the <code title=dom-location-assign><a href=#dom-location-assign>assign()</a></code> and <code title=dom-location-replace><a href=#dom-location-replace>replace()</a></code> methods must be done
-  with the <a href=#script-browsing-context>script browsing context</a> of the script that
-  invoked the method as the <a href=#source-browsing-context>source browsing context</a>.</p>
+  with the <a href="#script's-browsing-context" title="script's browsing context">browsing
+  context</a> of the script that invoked the method as the
+  <a href=#source-browsing-context>source browsing context</a>.</p>
 
 <!--XXX
   <dfn title="dom-location-reload"><code>reload()</code></dfn>
@@ -36953,7 +37311,7 @@
     synchronous, but if fetching the resource depends on external
     resources, as it usually does for URLs that use HTTP or other
     networking protocols, then at this point the user agents must
-    yield to whatever script invoked the navigation steps, if they
+    yield to whatever <a href=#concept-script title=concept-script>script</a> invoked the navigation steps, if they
     were invoked by script.</p>
 
    </li>
@@ -37115,19 +37473,11 @@
   <ol><li><p class=XXX>pause for scripts -- but don't use the
    "pause" definition since that involves not running script!</li>
 
-   <li><p class=XXX>onbeforeunload, and if present set flag that we will kill document</li>
-   <!--
-   when we define onbeforeunload, then we have to say that the JS
-   implementation of EventListener::handleEvent checks for that event,
-   treating the return value as the string to use for the unload warning
-   message if there is a return value, and calling preventDefault if
-   there isn't.
-   -->
+   <li><p><a href=#unload-a-document title="unload a document">Unload</a> the
+   <code>Document</code> object of the <a href=#current-entry>current entry</a>,
+   with the <var title="">recycle</var> parameter set to
+   false.</li>
 
-   <li><p class=XXX>onunload, and if present set flag that we will kill document</li>
-
-   <li><p class=XXX>if flag is set: <a href=#discard-a-document title="discard a document">discard the <code>Document</code></a></li>
-
    <li>
 
     <dl><dt>If the navigation was initiated for <dfn id=entry-update>entry update</dfn> of
@@ -37483,8 +37833,8 @@
    <code>Document</code> object than the <a href=#current-entry>current entry</a>
    then the user agent must run the following substeps:</p>
 
-    <ol><li class=XXX>freeze any timers, intervals,
-     XMLHttpRequests, database transactions, etc</li>
+    <ol><li>Freeze the <a href=#active-document>active document</a>'s <a href=#current-script-group>current
+     script group</a>.</li>
 
      <li>The user agent must move any properties that have been added
      to the browsing context's default view's <code><a href=#window>Window</a></code>
@@ -37538,8 +37888,8 @@
      <a href=#list-of-added-properties>list of added properties</a> to browsing context's
      default view's <code><a href=#window>Window</a></code> object.</li>
 
-     <li class=XXX>unfreeze any timers, intervals,
-     XMLHttpRequests, database transactions, etc</li>
+     <li>Unfreeze the <a href=#active-document>active document</a>'s <a href=#current-script-group>current
+     script group</a>.</li>
 
     </ol></li>
 
@@ -37577,32 +37927,84 @@
   affect .watch() when seen from other Windows?</p>
 
 
-  <h4 id=closing-a-browsing-context><span class=secno>5.9.10 </span>Closing a browsing context</h4>
 
-  <p class=XXX>Closing a browsing context and discarding it
-  (vs closing it and keeping it around in memory).</p>
+  <h4 id=unloading-documents><span class=secno>5.9.10 </span>Unloading documents</h4>
 
-  <p class=XXX>when a browsing context is closed, all session
-  history entries' <code>Document</code> objects must be
-  discarded.</p>
+  <p>When a user agent is to <dfn id=unload-a-document>unload a document</dfn>, it must run
+  the following steps. These steps are passed an argument, <var title="">recycle</var>, which is either true or false, indicating
+  whether the <code>Document</code> object is going to be
+  re-used. (This is set by the <code title=dom-document-open><a href=#dom-document-open>document.open()</a></code> method.)</p>
 
-  <p class=XXX>When a user agent is to <dfn id=discard-a-document>discard a
-  <code>Document</code></dfn>, any frozen timers, intervals,
-  XMLHttpRequests, database transactions, etc, must be killed, and any
-  MessagePorts owned by the Window object must be
-  unentangled.</p>
+  <ol><li><p>Set <var title="">salvageable</var> to true.</li>
 
-  <p class=XXX>Also, <code title=event-unload>unload</code>
-  events should fire.</p>
+   <li><p>Let <var title="">event</var> be a new
+   <code><a href=#beforeunloadevent>BeforeUnloadEvent</a></code> event object with the name <code title=event-beforeunload>beforeunload</code>, with no namespace,
+   which does not bubble but is cancelable.</li>
 
+   <li><p>Dispatch <var title="">event</var> at <a href=#the-body-element-1>the
+   <code>body</code> element</a>.</li>
 
+   <li><p>If any event listeners were triggered by the previous step,
+   then set <var title="">salvageable</var> to false.</li>
 
+   <li>
 
+    <p>If the <code title=dom-BeforeUnloadEvent-returnValue><a href=#dom-beforeunloadevent-returnvalue>returnValue</a></code>
+    attribute of the <var title="">event</var> object is not the empty
+    string, or if the event was canceled, then the user agent should
+    ask the user to confirm that they wish to unload the document.</p>
+
+    <p>The prompt shown by the user agent may include the string of
+    the <code title=dom-BeforeUnloadEvent-returnValue><a href=#dom-beforeunloadevent-returnvalue>returnValue</a></code>
+    attribute, or some leading subset thereof. (A user agent may want
+    to truncate the string to 1024 characters for display, for
+    instance.)</p>
+
+    <p>The user agent must <a href=#pause>pause</a> while waiting for the
+    user's response.</p>
+
+    <p>If the user <dfn id=refused-to-allow-the-document-to-be-unloaded>refused to allow the document to be
+    unloaded</dfn> then these steps must be aborted.</p>
+
+   </li>
+
+   <li><p><a href=#fire-a-simple-event>Fire a simple event</a> called <code title=event-unload>unload</code> at <a href=#the-body-element-1>the <code>body</code>
+   element</a>.</li>
+
+   <li><p>If any event listeners were triggered by the previous step,
+   then set <var title="">salvageable</var> to false.</li>
+
+   <li><p>If there are any outstanding transactions that have
+   callbacks that involve <a href=#concept-script title=concept-script>scripts</a>
+   that are in the document's <a href=#current-script-group>current script group</a>, roll
+   them back (without invoking any of the callbacks) and set <var title="">salvageable</var> to false.</p>
+
+   <li><p>If <var title="">salvageable</var> and <var title="">recycle</var> are both false, <a href=#discard-a-document title="discard a
+   document">discard the <code>Document</code></a>.</li>
+
+  </ol><h5 id=event-definition><span class=secno>5.9.10.1 </span>Event definition</h5>
+
+  <pre class=idl>interface <dfn id=beforeunloadevent>BeforeUnloadEvent</dfn> : Event {
+           attribute DOMString <a href=#dom-beforeunloadevent-returnvalue title=dom-BeforeUnloadEvent-returnValue>returnValue</a>;
+};</pre>
+
+  <p class=note>There are no <code><a href=#beforeunloadevent>BeforeUnloadEvent</a></code>-specific
+  initialization methods.</p>
+
+  <p>The <dfn id=dom-beforeunloadevent-returnvalue title=dom-BeforeUnloadEvent-returnValue><code>returnValue</code></dfn>
+  attribute represents the message to show the user. When the event is
+  created, the attribute must be set to the empty string. On getting,
+  it must return the last value it was set to. On setting, the
+  attribute must be set to the new value.</p>
+
+
+
+
   <h3 id=structured-client-side-storage><span class=secno>5.10 </span>Structured client-side storage</h3>
 
   <h4 id=storage><span class=secno>5.10.1 </span>Storing name/value pairs</h4>
 
-  <h5 id=introduction-1><span class=secno>5.10.1.1 </span>Introduction</h5>
+  <h5 id=introduction-2><span class=secno>5.10.1.1 </span>Introduction</h5>
 
   <p><em>This section is non-normative.</em></p>
 
@@ -37840,14 +38242,14 @@
   separate, not affecting each other in any way.</p>
 
   <p>When a new <a href=#top-level-browsing-context>top-level browsing context</a> is created by
-  a script in an existing <a href=#browsing-context>browsing context</a>, or by the
-  user following a link in an existing browsing context, or in some
-  other way related to a specific <code><a href=#htmldocument>HTMLDocument</a></code>, then the
-  session storage area of the <a href=#origin-0>origin</a> of that
-  <code><a href=#htmldocument>HTMLDocument</a></code> must be copied into the new browsing
-  context when it is created.  From that point on, however, the two
-  session storage areas must be considered separate, not affecting
-  each other in any way.</p>
+  a <a href=#concept-script title=concept-script>script</a> in an existing
+  <a href=#browsing-context>browsing context</a>, or by the user following a link in an
+  existing browsing context, or in some other way related to a
+  specific <code><a href=#htmldocument>HTMLDocument</a></code>, then the session storage area of
+  the <a href=#origin-0>origin</a> of that <code><a href=#htmldocument>HTMLDocument</a></code> must be
+  copied into the new browsing context when it is created.  From that
+  point on, however, the two session storage areas must be considered
+  separate, not affecting each other in any way.</p>
 
   <p id=sessionStorageEvent>When the <code title=dom-Storage-setItem><a href=#dom-storage-setitem>setItem()</a></code>, <code title=dom-Storage-removeItem><a href=#dom-storage-removeitem>removeItem()</a></code>, and <code title=dom-Storage-clear><a href=#dom-storage-clear>clear()</a></code> methods are called on a
   <code><a href=#storage-0>Storage</a></code> object <var title="">x</var> that is associated
@@ -37930,7 +38332,7 @@
   otherwise.</p>
 
 
-  <h6 id=event-definition><span class=secno>5.10.1.5.1 </span>Event definition</h6>
+  <h6 id=event-definition-0><span class=secno>5.10.1.5.1 </span>Event definition</h6>
 
   <pre class=idl>interface <dfn id=storageevent>StorageEvent</dfn> : Event {
   readonly attribute DOMString <a href=#dom-storageevent-key title=dom-StorageEvent-key>key</a>;
@@ -38000,7 +38402,7 @@
         * handling the database getting corrupted
   -->
 
-  <h5 id=introduction-2><span class=secno>5.10.2.1 </span>Introduction</h5>
+  <h5 id=introduction-3><span class=secno>5.10.2.1 </span>Introduction</h5>
 
   <p><em>This section is non-normative.</em></p>
 
@@ -38364,7 +38766,7 @@
 
 
 
-  <h5 id=processing-model-2><span class=secno>5.10.2.6 </span>Processing model</h5>
+  <h5 id=processing-model-3><span class=secno>5.10.2.6 </span>Processing model</h5>
 
   <p>The <dfn id=transaction-steps>transaction steps</dfn> are as follows. These steps must
   be run asynchronously. These steps are invoked with a <i>transaction
@@ -40867,7 +41269,7 @@
   step).</p>
 
 
-  <h4 id=introduction-3><span class=secno>6.8.1 </span>Introduction</h4>
+  <h4 id=introduction-4><span class=secno>6.8.1 </span>Introduction</h4>
 
   <p><em>This section is non-normative.</em></p>
 
@@ -43725,7 +44127,7 @@
   attacks.</p>
 
 
-  <h4 id=introduction-4><span class=secno>7.4.1 </span>Introduction</h4>
+  <h4 id=introduction-5><span class=secno>7.4.1 </span>Introduction</h4>
 
   <p><em>This section is non-normative.</em></p>
 
@@ -43978,7 +44380,7 @@
 
   <h3 id=channel-messaging><span class=secno>7.5 </span><dfn>Channel messaging</dfn></h3>
 
-  <h4 id=introduction-5><span class=secno>7.5.1 </span>Introduction</h4>
+  <h4 id=introduction-6><span class=secno>7.5.1 </span>Introduction</h4>
 
   <p><em>This section is non-normative.</em></p>
 
@@ -43999,10 +44401,10 @@
   constructor is called, it must run the following algorithm:</p>
 
   <ol><li><p><a href=#create-a-new-messageport-object>Create a new <code>MessagePort</code> object</a>
-   owned by the <a href=#script-execution-context>script execution context</a>, and let <var title="">port1</var> be that object.</li>
+   owned by the <a href="#script's-global-object">script's global object</a>, and let <var title="">port1</var> be that object.</li>
 
    <li><p><a href=#create-a-new-messageport-object>Create a new <code>MessagePort</code> object</a>
-   owned by the <a href=#script-execution-context>script execution context</a>, and let <var title="">port2</var> be that object.</li>
+   owned by the <a href="#script's-global-object">script's global object</a>, and let <var title="">port2</var> be that object.</li>
 
    <li><p><a href=#entangle>Entangle</a> the <var title="">port1</var> and <var title="">port2</var> objects.</li>
 
@@ -44051,8 +44453,8 @@
   initially closed.</p>
 
   <p>When the user agent is to <dfn id=create-a-new-messageport-object>create a new
-  <code>MessagePort</code> object</dfn> owned by a <a href=#script-execution-context>script
-  execution context</a> object <var title="">owner</var>, it must
+  <code>MessagePort</code> object</dfn> owned by a <a href="#script's-global-object">script's
+  global object</a> object <var title="">owner</var>, it must
   instantiate a new <code><a href=#messageport>MessagePort</a></code> object, and let its owner
   be <var title="">owner</var>.</p>
 
@@ -44179,7 +44581,7 @@
    argument.</p></li>
 
    <li><p><span>Create a new <code>MessagePort</code> object</span>
-   owned by the <span>script execution context</span>, and let <var
+   owned by the <span>script's global object</span>, and let <var
    title="">port1</var> be that object.</p></li>
 
    <li><p>If the <var title="">source port</var> is not entangled with
@@ -44296,7 +44698,7 @@
    <dd><p>Must be invoked whenever an <code title=event-close>close</code> event is targeted at or bubbles
    through the <code><a href=#messageport>MessagePort</a></code> object.</dd>
 
-  </dl><h5 id=ports-and-browsing-contexts><span class=secno>7.5.3.1 </span>Ports and browsing contexts</h5>
+  </dl><h5 id=message-port-discarding><span class=secno>7.5.3.1 </span>Ports and browsing contexts</h5>
 
   <p>When a <code>Document</code> is <a href=#discard-a-document title="discard a
   document">discarded</a>, if there are any
@@ -44305,7 +44707,7 @@
   <ul class=brief><li>are entangled, and</li>
    <li>are owned by the <a href=#browsing-context>browsing context</a> that contained that <code>Document</code>, and</li>
    <li>were created while that <code>Document</code> was the <a href=#active-document>active document</a> of that <a href=#browsing-context>browsing context</a>, and</li>
-   <li>are entangled with a port that is either not owned by that <a href=#browsing-context>browsing context</a> or was not created while that <code>Document</code> was the <a href=#active-document>active document</a> of that <a href=#browsing-context>browsing context</a>,</li>
+   <li>are entangled with a port that is either not owned by that <a href=#browsing-context>browsing context</a>, or were not created while that <code>Document</code> was the <a href=#active-document>active document</a> of that <a href=#browsing-context>browsing context</a>,</li>
   </ul><p>...then the user agent must run the following steps for each such
   port:</p>
 
@@ -46183,10 +46585,9 @@
 
   <h5 id=the-scripting-state><span class=secno>8.2.3.5 </span>The scripting state</h5>
 
-  <p>The <dfn id=scripting-flag>scripting flag</dfn> is set to "enabled" if the
-  <code>Document</code> with which the parser is associated was
-  <a href=#with-script>with script</a> when the parser was created, and "disabled"
-  otherwise.</p>
+  <p>The <dfn id=scripting-flag>scripting flag</dfn> is set to "enabled" if the <a href=#concept-n-script title=concept-n-script>scripting was enabled</a> for the
+  <code>Document</code> with which the parser is associated when the
+  parser was created, and "disabled" otherwise.</p>
 
 
   <h4 id=tokenization><span class=secno>8.2.4 </span><dfn>Tokenization</dfn></h4>
@@ -53981,8 +54382,11 @@
   scope of the <a href=#browsing-context>browsing context</a> associated with the
   <code><a href=#window>Window</a></code> object on which the <code title=setTimeout>setTimeout()</code> method was invoked.</p>
 
-  <p class=XXX>Need to define <var title="">language</var>
-  values.</p>
+  <p class=XXX>Need to define <var title="">language</var> values;
+  need to define that the <a href=#concept-script title=concept-script>script</a>
+  corresponding to the <var title="">code</var> argument is created
+  before the timer is set up, so that the rule on pausing the ticker,
+  below, makes sense.</p>
 
   <p>The <dfn id=dom-windowtimers-setinterval title=dom-windowtimers-setInterval><code>setInterval(...)</code></dfn>
   variants must work in the same way as the <code>setTimeout</code>
@@ -54000,8 +54404,13 @@
   with a value that does not correspond to an active timeout or
   interval, the methods must return without doing anything.</p>
 
+  <p>For both <code title=dom-windowtimers-setTimeout><a href=#dom-windowtimers-settimeout>setTimeout()</a></code> and <code title=dom-windowtimers-setInterval><a href=#dom-windowtimers-setinterval>setInterval()</a></code>, the clock
+  upon which the timers are based must only tick while the
+  <a href=#script-group>script group</a> of their callbacks is not
+  <i>frozen</i>.</p>
 
 
+
   <h3 id=rendering-and-the-dom><span class=secno>11.5 </span>Rendering and the DOM</h3>
 
   <p class=XXX>This section is expected to be moved to its own

Modified: source
===================================================================
--- source	2008-12-03 01:27:37 UTC (rev 2528)
+++ source	2008-12-12 08:46:24 UTC (rev 2529)
@@ -428,7 +428,7 @@
   that no scripts execute (e.g. no event handlers, no timers,
   etc). User agents should remain responsive to user input while
   paused, however, albeit without letting the user interact with Web
-  pages where that would involve invoking any script.</p>
+  pages where that would involve invoking any <span title="concept-script">script</span>.</p>
 
 
   <h4>XML</h4>
@@ -3334,13 +3334,7 @@
 
   <h4>Terminology</h4>
 
-  <p>A <dfn>URL</dfn> is a string used to identify a resource. <span
-  id="urldoc">A <span>URL</span> is always associated with a
-  <code>Document</code>, either explicitly when the URL is created or
-  defined; or through a DOM node, in which case the associated
-  <code>Document</code> is the node's <code>Document</code>; or
-  through a script, in which case the associated <code>Document</code>
-  is the script's <span>script document context</span>.</span></p>
+  <p>A <dfn>URL</dfn> is a string used to identify a resource.</p>
 
   <p>A <span>URL</span> is a <dfn>valid URL</dfn> if at least one of
   the following conditions holds:</p>
@@ -3364,6 +3358,29 @@
 
   </ul>
 
+  <p>A <span>URL</span> has an associated <dfn>URL character
+  encoding</dfn>, determined as follows:</p>
+
+  <dl class="switch">
+
+   <dt>If the URL came from a script (e.g. as an argument to a
+   method)</dt>
+
+   <dd>The URL character encoding is the <span>script's character
+   encoding</span>.</dd>
+
+   <dt>If the URL came from a DOM node (e.g. from an element)</dt>
+
+   <dd>The node has a <code>Document</code>, and the URL character
+   encoding is the <span>document's character encoding</span>.</dd>
+
+   <dt>If the URL had a character encoding defined when the URL was
+   created or defined</dt>
+
+   <dd>The URL character encoding is as defined.</dd>
+
+  </dl>
+
   <p class="note">The term "URL" in this specification is used in a
   manner distinct from the precise technical meaning it is given in
   RFC 3986. Readers familiar with that RFC will find it easier to read
@@ -3522,8 +3539,7 @@
 
    <dt>If the URL to be resolved was passed to an API</dt>
 
-   <dd><p>The base URL is the <span>document base URL</span> of the
-   script's <span>script document context</span>.</p></dd>
+   <dd><p>The base URL is the <span>script's base URL</span>.</p></dd>
 
    <dt>If the URL to be resolved is from the value of a content
    attribute</dt>
@@ -3594,14 +3610,9 @@
    <li><p>Let <var title="">url</var> be the <span>URL</span> being
    resolved.</p></li>
 
-   <li><p>Let <var title="">document</var> be the
-   <code>Document</code> <a href="#urldoc">associated with</a> <var
-   title="">url</var>.</p></li>
+   <li><p>Let <var title="">encoding</var> be the <span>URL character
+   encoding</span>.</p></li>
 
-   <li><p>Let <var title="">encoding</var> be the <span
-   title="document's character encoding">character encoding</span> of
-   <var title="">document</var>.</p></li>
-
    <li><p>If <var title="">encoding</var> is UTF-16, then change it to
    UTF-8.</p></li>
 
@@ -5609,13 +5620,31 @@
    <li value="20"><dfn><code>ABORT_ERR</code></dfn></li> <!-- actually in XHR for now -->
    <li value="21"><dfn><code>URL_MISMATCH_ERR</code></dfn></li> <!-- actually in workers for now -->
    <li value="22"><dfn><code>QUOTA_EXCEEDED_ERR</code></dfn></li> <!-- actually defined right here for now -->
+   <li value="23"><dfn><code>UNAVAILABLE_SCRIPT_ERR</code></dfn></li> <!-- actually defined right here for now -->
    <li value="81"><dfn><code>PARSE_ERR</code></dfn></li> <!-- actually defined in dom3ls -->
    <li value="82"><dfn><code>SERIALISE_ERR</code></dfn></li> <!-- actually defined in dom3ls -->
   </ol>
 
 
+  <h4>Garbage collection</h4>
 
+  <p>There is an <dfn>implied strong reference</dfn> from any DOM
+  attribute that returns a pre-existing object to that object.</p>
 
+  <div class="example">
+
+   <p>For example, the <code>document.defaultView</code> attribute
+   means that there is a strong reference from a <code>Document</code>
+   object to its <code>Window</code> object. Similarly, there is
+   always a strong reference from a <code>Document</code> to any
+   descendant nodes, and from any node to its owner
+   <code>Document</code>.</p>
+
+  </div>
+
+
+
+
   <h2 id="dom">Semantics and structure of HTML documents</h2>
 
   <h3 id="semantics-intro">Introduction</h3>
@@ -5634,10 +5663,12 @@
   <p><dfn>The document's address</dfn> is an <span>absolute URL</span>
   that is set when the <code>Document</code> is created.</p>
 
-  <p>When a <code>Document</code> is created by a script using the
-  <code title="">createDocument()</code> API, <span>the document's
+  <p>When a <code>Document</code> is created by a <span
+  title="concept-script">script</span> using the <code
+  title="">createDocument()</code> API, <span>the document's
   address</span> is the same as <span>the document's address</span> of
-  the <span>script document context</span> of that script.</p>
+  the <span>active document</span> of the <span>script's browsing
+  context</span>.</p>
 
   <p><code>Document</code> objects are assumed to be <dfn>XML
   documents</dfn> unless they are flagged as being <dfn>HTML
@@ -5654,8 +5685,15 @@
   <span title="HTML documents">HTML document</span> by calling <code
   title="dom-document-open">document.open()</code> on it.</p>
 
+  <p>When a <code>Document</code> is first created, a new <span>script
+  group</span> must be created. This is the <code>Document</code>'s
+  <dfn>current script group</dfn> until the script group is changed
+  (which can happen if <code
+  title="dom-document-open">document.open()</code> is invoked on the
+  <code>Document</code>).</p>
 
 
+
   <h4>Documents in the DOM</h4>
 
   <p>All <code>Document</code> objects (in user agents implementing
@@ -7450,8 +7488,8 @@
   with the parser, and thus their behavior varies depending on whether
   they are used with <span>HTML documents</span> (and the <span>HTML
   parser</span>) or XHTML in <span>XML documents</span> (and the
-  <span>XML parser</span>). The following table cross-references the
-  various versions of these APIs.</p>
+  <span>XML parser</span><!-- XXX xref -->). The following table
+  cross-references the various versions of these APIs.</p>
 
   <table>
    <thead>
@@ -7550,8 +7588,11 @@
 
    </li>
 
-   <li><p class="XXX">onbeforeunload, onunload, reset timers, empty event queue, kill any pending transactions, XMLHttpRequests, etc</p></li>
-   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Ciframe%20src%3D%22document%22%3E%3C%2Fiframe%3E%0A%3Cscript%3Eonload%20%3D%20function%20()%20{%20f%20%3D%20document.getElementsByTagName(%27iframe%27)[0]%3B%20d%20%3D%20f.contentDocument%3B%20}%3C%2Fscript%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22w(d.documentElement.innerHTML)%22%20value%3D%22dump%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.body.bgColor%3D%27red%27%22%20value%3D%22color%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22f.style.border%3D%27lime%20solid%27%22%20value%3D%22color%20frame%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write(%27%3Cp%3Etest%3C%2Fp%3E%27)%3B%20d.close()%22%20value%3D%22replace%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write(%27%3Cp%3E%3Cscript%3Ei%20%3D%200%3B%20setInterval(%26quot%3Bparent.w(i%2B%2B)%26quot%3B%2C%20500)%3C%2Fscript%3E%3C%2Fp%3E%27)%3B%20d.close()%22%20value%3D%22replace%20with%20timer%22%3E%0A -->
+   <li><p><span title="unload a document">Unload</span> the
+   <code>Document</code> object, with the <var title="">recycle</var>
+   parameter set to true. If the user <span>refused to allow the
+   document to be unloaded</span>, then these steps must be
+   aborted.</p></li>
 
    <li><p>If the document has an <span>active parser</span><!--XXX
    xref-->, then stop that parser, and throw away any pending content
@@ -7560,15 +7601,28 @@
    XHTML, or image document, or something?</span></p></li><!-- XXX see
    also innerHTML in HTML -->
 
+   <li><p>Freeze the document's <span>current script
+   group</span>.</p></li>
+
+   <li><p>Unregister all event listeners registered on the
+   <code>Document</code> node and its descendants.</p>
+
    <li><p>Remove all child nodes of the document, without firing any
    mutation events.</p></li>
 
+   <li><p>Create a new <span>script group</span> and let the
+   document's <span>current script group</span> be that new
+   group. (The old script group is now permanently frozen.)</p></li>
+
+   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Ciframe%20src%3D%22document%22%3E%3C%2Fiframe%3E%0A%3Cscript%3Eonload%20%3D%20function%20()%20%7B%20f%20%3D%20document.getElementsByTagName('iframe')%5B0%5D%3B%20d%20%3D%20f.contentWindow.document%3B%20%7D%3C%2Fscript%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22w(d.documentElement.innerHTML)%22%20value%3D%22dump%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cscript%3Evar%20x%20%3D%20new%20XMLHttpRequest()%3Bx.open(%26quot%3BGET%26quot%3B%2C%20%26quot%3BGET%26quot%3B)%3Bx.onreadystatechange%3Dfunction()%20%7B%20alert(x.readyState)%3B%20%7D%3Bx.send(null)%3B%3C%2Fscript%3E')%3Bd.close()%3B%20setTimeout(function()%20%7B%20d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%20%7D%2C%200)%3B%22%20value%3D%22xhr%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.onclick%20%3D%20function()%20%7B%20w('click')%20%7D%22%20value%3D%22add%20click%20handler%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3Etest%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%22%3E%0A%3Cinput%20type%3Dbutton%20onclick%3D%22d.open()%3B%20d.write('%3Cp%3E%3Cscript%3Ei%20%3D%200%3B%20setTimeout(%26quot%3Bparent.w(i%2B%2B)%26quot%3B%2C%202000)%3C%2Fscript%3E%3C%2Fp%3E')%3B%20d.close()%22%20value%3D%22replace%20with%20timer%22%3E -->
+
    <li><p>Change the <span>document's character encoding</span> to
    UTF-16.</p></li>
 
-   <li><p>Change <span>the document's address</span> to the <span
-   title="the document's address">address</span> of the <span>script
-   document context</span> of the script that invoked the <code
+   <li><p>Change <span>the document's address</span> to the <span>the
+   document's address</span> of the <span>active document</span> of
+   the <span title="script's browsing context">browsing context</span>
+   of the <span title="concept-script">script</span> that invoked the <code
    title="dom-document-open">document.open()</code> method.</p></li>
 
    <li><p>Create a new <span>HTML parser</span> and associate it with
@@ -7685,8 +7739,10 @@
     <p>If the <span>insertion point</span> is undefined, the <code
     title="dom-document-open">open()</code> method must be called
     (with no arguments) on the <code title="Document">document</code>
-    object. The <span>insertion point</span> will point at just before
-    the end of the (empty) <span>input stream</span>.</p>
+    object. If the user <span>refused to allow the document to be
+    unloaded</span>, then these steps must be aborted. Otherwise, the
+    <span>insertion point</span> will point at just before the end of
+    the (empty) <span>input stream</span>.</p>
 
    </li>
 
@@ -8193,7 +8249,7 @@
 
    <li>
 
-    <p>The user agent must create a new <span>XML parser</span>.</p>
+    <p>The user agent must create a new <span>XML parser</span><!-- XXX xref -->.</p>
 
    </li>
 
@@ -9793,13 +9849,13 @@
   <dfn>"parser-inserted"</dfn>. This flag is set by the <span>HTML
   parser</span> and is used to handle <code
   title="dom-document-write-HTML">document.write()</code> calls. The
-  third and fourth pieces of metadata are <dfn><var>the script's
-  type</var></dfn> and <dfn><var>the script's character
+  third and fourth pieces of metadata are <dfn><var>the script block's
+  type</var></dfn> and <dfn><var>the script block's character
   encoding</var></dfn>. They are determined when the script is run,
   based on the attributes on the element at that time.</p>
 
-  <p>When an <span>XML parser</span> creates a <code>script</code>
-  element, it must be marked as being
+  <p>When an <span>XML parser</span><!-- XXX xref --> creates a
+  <code>script</code> element, it must be marked as being
   <span>"parser-inserted"</span>. When the element's end tag is
   parsed, the user agent must <span title="running a
   script">run</span> the <code>script</code> element.</p>
@@ -9841,23 +9897,23 @@
 
     </ul>
 
-    <p>...let <var>the script's type</var> for this
+    <p>...let <var>the script block's type</var> for this
     <code>script</code> element be "<code
     title="">text/javascript</code>".</p>
 
     <p>Otherwise, if the <code>script</code> element has a <code
     title="attr-script-type">type</code> attribute, let <var>the
-    script's type</var> for this <code>script</code> element be the
-    value of that attribute.</p>
+    script block's type</var> for this <code>script</code> element be
+    the value of that attribute.</p>
 
     <p>Otherwise, the element has a <code
     title="attr-script-language">language</code> attribute; let
-    <var>the script's type</var> for this <code>script</code> element
-    be the concatenation of the string "<code title="">text/</code>"
-    followed by the value of the <code
-    title="attr-script-language">language</code> attribute.</p>
-    <!-- user agents already support, e.g., type="text/javascript1.3",
-    so we don't have to support that separately. -->
+    <var>the script block's type</var> for this <code>script</code>
+    element be the concatenation of the string "<code
+    title="">text/</code>" followed by the value of the <code
+    title="attr-script-language">language</code> attribute.</p> <!--
+    user agents already support, e.g., type="text/javascript1.3", so
+    we don't have to support that separately. -->
 
    </li>
 
@@ -9865,12 +9921,12 @@
 
     <p>If the <code>script</code> element has a <code
     title="attr-script-charset">charset</code> attribute, then let
-    <var>the script's character encoding</var> for this
+    <var>the script block's character encoding</var> for this
     <code>script</code> element be the encoding given by the <code
     title="attr-script-charset">charset</code> attribute.</p>
 
-    <p>Otherwise, let <var>the script's character encoding</var> for
-    this <code>script</code> element be the same as <span
+    <p>Otherwise, let <var>the script block's character encoding</var>
+    for this <code>script</code> element be the same as <span
     title="document's character encoding">the encoding of the document
     itself</span>.</p>
 
@@ -9878,16 +9934,18 @@
 
    <li>
 
-    <p>If the <code>script</code> element is <span>without
-    script</span>, or if the <code>script</code> element was created
-    by an <span>XML parser</span> that itself was created as part of
+    <p>If <span title="concept-n-noscript">scripting is
+    disabled</span> for the <code>script</code> element, or if the
+    <code>script</code> element was created by an <span>XML
+    parser</span><!-- XXX xref --> that itself was created as part of
     the processing of the <code
     title="dom-innerHTML-XML">innerHTML</code> attribute's setter<!--
     no need to worry about the HTML case, as the HTML parser handles
     that for us -->, or if the user agent does not <span>support the
-    scripting language</span> given by <var>the script's type</var>
-    for this <code>script</code> element, then the user agent must
-    abort these steps at this point. The script is not executed.</p>
+    scripting language</span> given by <var>the script block's
+    type</var> for this <code>script</code> element, then the user
+    agent must abort these steps at this point. The script is not
+    executed.</p>
 
    </li>
 
@@ -9997,8 +10055,8 @@
      <dt>Otherwise</dt>
 
      <dd>The user agent must immediately <span title="executing a
-     script block">execute the script</span>, even if other scripts
-     are already executing.</dd>
+     script block">execute the script block</span>, even if other
+     scripts are already executing.</dd>
 
     </dl>
 
@@ -10006,17 +10064,18 @@
 
   </ol>
 
-  <p><dfn>When a script completes loading</dfn>: If the script's
-  element was added to one of the lists mentioned above and the
-  document is still being parsed, then the parser handles
-  it. Otherwise, the UA must run the following steps as the <span
-  title="concept-task">task</span> that the <span>networking task
-  source</span> places on the <span>task queue</span>:</p>
+  <p><dfn>When a script completes loading</dfn>: If the
+  <code>script</code> element was added to one of the lists mentioned
+  above and the document is still being parsed, then the parser
+  handles it. Otherwise, the UA must run the following steps as the
+  <span title="concept-task">task</span> that the <span>networking
+  task source</span> places on the <span>task queue</span>:</p>
 
   <dl class="switch">
 
-   <dt>If the script's element was added to the <dfn>list of scripts
-   that will execute when the document has finished parsing</dfn>:</dt>
+   <dt>If the <code>script</code> element was added to the <dfn>list
+   of scripts that will execute when the document has finished
+   parsing</dfn>:</dt>
 
    <dd>
 
@@ -10024,23 +10083,23 @@
 
      <li>
 
-      <p>If the script's element is not the first element in the list,
-      then do nothing yet. Stop going through these steps.</p>
+      <p>If the <code>script</code> element is not the first element
+      in the list, then do nothing yet. Stop going through these
+      steps.</p>
 
      </li>
 
      <li>
 
       <p>Otherwise, <span title="executing a script block">execute the
-      script</span> (that is, the script associated with the first
-      element in the list).</p>
+      script block</span> (the first element in the list).</p>
 
      </li>
 
      <li>
 
-      <p>Remove the script's element from the list (i.e. shift out the
-      first entry in the list).</p>
+      <p>Remove the <code>script</code> element from the list
+      (i.e. shift out the first entry in the list).</p>
 
      </li>
 
@@ -10056,8 +10115,8 @@
 
    </dd>
 
-   <dt>If the script's element was added to the <dfn>list of scripts
-   that will execute asynchronously</dfn>:</dt>
+   <dt>If the <code>script</code> element was added to the <dfn>list
+   of scripts that will execute asynchronously</dfn>:</dt>
 
    <dd>
 
@@ -10072,16 +10131,15 @@
 
      <li>
 
-      <p><span title="executing a script block">Execute the
-      script</span> (the script associated with the first element in
-      the list).</p>
+      <p><span title="executing a script block">Execute the script
+      block</span> (the first element in the list).</p>
 
      </li>
 
      <li>
 
-      <p>Remove the script's element from the list (i.e. shift out the
-      first entry in the list).</p>
+      <p>Remove the <code>script</code> element from the list
+      (i.e. shift out the first entry in the list).</p>
 
      </li>
 
@@ -10100,8 +10158,8 @@
 
    </dd>
 
-   <dt>If the script's element was added to the <dfn>list of scripts
-   that will execute as soon as possible</dfn>:</dt>
+   <dt>If the <code>script</code> element was added to the <dfn>list
+   of scripts that will execute as soon as possible</dfn>:</dt>
 
    <dd>
 
@@ -10110,13 +10168,13 @@
      <li>
 
       <p><span title="executing a script block">Execute the
-      script</span>.</p>
+      script block</span>.</p>
 
      </li>
 
      <li>
 
-      <p>Remove the script's element from the list.</p>
+      <p>Remove the <code>script</code> element from the list.</p>
 
      </li>
 
@@ -10130,7 +10188,7 @@
   title="event-load">load</code> event</span>.</p>
 
   <p><dfn title="executing a script block">Executing a script
-  block</dfn>: When the steps above require that the script be
+  block</dfn>: When the steps above require that the script block be
   executed, the user agent must act as follows:</p>
 
   <dl class="switch">
@@ -10138,21 +10196,22 @@
    <dt>If the load resulted in an error (for example a DNS error, or
    an HTTP 404 error)</dt>
 
-   <dd><p>Executing the script must just consist of <span title="fire
-   an error event">firing an <code title="event-error">error</code>
-   event</span> at the element.</p></dd>
+   <dd><p>Executing the script block must just consist of <span
+   title="fire an error event">firing an <code
+   title="event-error">error</code> event</span> at the
+   element.</p></dd>
 
    <dt>If the load was successful</dt>
 
+   <!-- SCRIPT EXEC -->
    <dd>
 
     <ol>
 
      <li>
 
-      <p>If the <code>script</code> element's <code>Document</code> is
-      the <span>active document</span> in its <span>browsing
-      context</span>, the user agent must execute the script:</p>
+      <p>Initialise <dfn><var>the script block's source</var></dfn> as
+      follows:</p>
 
       <dl class="switch">
 
@@ -10160,12 +10219,13 @@
 
        <dd>
 
-        <p>That file must be used as the file to execute.</p>
+        <p>The contents of that file, interpreted as as string of
+        Unicode characters, are the script source.</p>
 
-        <p>The file must be interpreted using the character encoding
-        given by <var>the script's character encoding</var>, regardless
-        of any metadata given by the file's <span
-        title="Content-Type">Content-Type metadata</span>.</p>
+        <p>The file must be converted to Unicode using the character
+        encoding given by <var>the script block's character
+        encoding</var>, regardless of any metadata given by the file's
+        <span title="Content-Type">Content-Type metadata</span>.</p>
 
         <p class="XXX">This means that a UTF-16 document will
         always assume external scripts are UTF-16...? This applies,
@@ -10176,51 +10236,47 @@
 
        </dd>
 
-       <dt>If the script is inline</dt>
+       <dt>If the script is inline and <var>the script block's type</var> is a text-based language</dt>
 
        <dd>
 
-        <p>For scripting languages that consist of pure text, user
-        agents must use the value of the DOM <code
-        title="dom-script-text">text</code> attribute (defined below) as
-        the script to execute, and for XML-based scripting languages,
-        user agents must use all the child nodes of the
-        <code>script</code> element as the script to execute.</p>
+        <p>The value of the DOM <code
+        title="dom-script-text">text</code> attribute at the time the
+        "<span>running a script</span>" algorithm was first invoked is
+        the script source.</p>
 
        </dd>
 
+       <dt>If the script is inline and <var>the script block's type</var> is an XML-based language</dt>
+
+       <dd>
+
+        <p>The child nodes of the <code>script</code> element at the
+        time the "<span>running a script</span>" algorithm was first
+        invoked are the script source.</p>
+
+       </dd>
+
       </dl>
 
-      <!-- SCRIPT EXEC -->
-      <p>In any case, the user agent must execute the script according to
-      the semantics defined by the language associated with <var>the
-      script's type</var> (see the <a href="#scriptingLanguages">scripting
-      languages</a> section below).</p>
+     </li>
 
-      <p>The <span>script execution context</span> of the script must
-      be the <code>Window</code> object of that <span>browsing
-      context</span>.</p>
+     <li>
 
-      <p>The <span>script document context</span> of the script must
-      be the <code>Document</code> object that owns the
-      <code>script</code> element.</p>
+      <p><span title="create a script from a node">Create a
+      script</span> from the <code>script</code> element node, using
+      the <var>the script block's source</var> and the <var>the script
+      block's type</var>.</p>
 
-      <p class="note">The element's attributes' values might have changed
-      between when the element was inserted into the document and when the
-      script has finished loading, as may its other attributes; similarly,
-      the element itself might have been taken back out of the DOM, or had
-      other changes made. These changes do not in any way affect the above
-      steps; only the values of the attributes at the time the
-      <code>script</code> element is first inserted into the document
-      matter.</p>
+      <p class="note">This is where the script is compiled and
+      actually executed.</p>
 
      </li>
 
      <li>
 
-      <p>Then, the user agent must <span>fire a <code
-      title="event-load">load</code> event</span> at the
-      <code>script</code> element.</p>
+      <p><span>Fire a <code title="event-load">load</code>
+      event</span> at the <code>script</code> element.</p>
 
      </li>
 
@@ -10275,8 +10331,8 @@
   <h5 id="scriptingLanguages">Scripting languages</h5>
 
   <p>A user agent is said to <dfn>support the scripting language</dfn>
-  if <var>the script's type</var> matches the MIME type of a scripting
-  language that the user agent implements.</p>
+  if <var>the script block's type</var> matches the MIME type of a
+  scripting language that the user agent implements.</p>
 
   <p>The following lists some MIME types and the languages to which
   they refer:</p>
@@ -10316,9 +10372,9 @@
    <dd>In a <code>head</code> element of an <span title="HTML documents">HTML document</span>, if there are no ancestor <code>noscript</code> elements.</dd>
    <dd>Where <span>phrasing content</span> is expected in <span>HTML documents</span>, if there are no ancestor <code>noscript</code> elements.</dd>
    <dt>Content model:</dt>
-   <dd><span>Without script</span>, in a <code>head</code> element: in any order, zero or more <code>link</code> elements, zero or more <code>style</code> elements, and zero or more <code>meta</code> elements.</dd>
-   <dd><span>Without script</span>, not in a <code>head</code> element: <span>transparent</span>, but there must be no <code>noscript</code> element descendants.</dd>
-   <dd><span>With script</span>: text that conforms to the requirements given in the prose.</dd>
+   <dd>When <span title="concept-n-noscript">scripting is disabled</span>, in a <code>head</code> element: in any order, zero or more <code>link</code> elements, zero or more <code>style</code> elements, and zero or more <code>meta</code> elements.</dd>
+   <dd>When <span title="concept-n-noscript">scripting is disabled</span>, not in a <code>head</code> element: <span>transparent</span>, but there must be no <code>noscript</code> element descendants.</dd>
+   <dd>Otherwise: text that conforms to the requirements given in the prose.</dd>
    <dt>Element-specific attributes:</dt>
    <dd>None.</dd>
    <dt>DOM interface:</dt>
@@ -10330,97 +10386,104 @@
   scripting and those that don't support scripting, by affecting how
   the document is parsed.</p>
 
-  <p>The <code>noscript</code> element must not be used in <span>XML
-  documents</span>.</p>
-
-  <p class="note"><strong>The <code>noscript</code> element is only
-  effective in the <span title="">HTML serialization</span><!-- XXX
-  xref -->, it has no effect in the <span title="">XML
-  serialization</span><!-- XXX xref -->.</strong></p>
-
   <p>When used in <span>HTML documents</span>, the allowed content
   model is as follows:</p>
 
-  <p>In a <code>head</code> element, if the <code>noscript</code>
-  element is <span>without script</span>, then the content model of a
-  <code>noscript</code> element must contain only <code>link</code>,
-  <code>style</code>, and <code>meta</code> elements. If the
-  <code>noscript</code> element is <span>with script</span>, then the
-  content model of a <code>noscript</code> element is text, except
-  that invoking the <span>HTML fragment parsing algorithm</span> with
-  the <code>noscript</code> element as the <var title="">context</var>
-  element and the text contents as the <var title="">input</var> must
-  result in a list of nodes that consists only of <code>link</code>,
-  <code>style</code>, and <code>meta</code> elements.</p>
+  <dl>
 
-  <p>Outside of <code>head</code> elements, if the
-  <code>noscript</code> element is <span>without script</span>, then
-  the content model of a <code>noscript</code> element is
-  <span>transparent</span>, with the additional restriction that a
-  <code>noscript</code> element must not have a <code>noscript</code>
-  element as an ancestor (that is, <code>noscript</code> can't be
-  nested).</p>
+   <dt>In a <code>head</code> element, if <span
+   title="concept-n-noscript">scripting is disabled</span> for the
+   <code>noscript</code> element</dt>
 
-  <p>Outside of <code>head</code> elements, if the
-  <code>noscript</code> element is <span>with script</span>, then the
-  content model of a <code>noscript</code> element is text, except
-  that the text must be such that running the following algorithm
-  results in a conforming document with no <code>noscript</code>
-  elements and no <code>script</code> elements, and such that no step
-  in the algorithm causes an <span>HTML parser</span> to flag a
-  <span>parse error</span>:</p>
+   <dd><p>The <code>noscript</code> element must contain only
+   <code>link</code>, <code>style</code>, and <code>meta</code>
+   elements.</p></dd>
 
-  <ol>
+   <dt>In a <code>head</code> element, if <span
+   title="concept-n-noscript">scripting is enabled</span> for the
+   <code>noscript</code> element</dt>
 
-   <li>Remove every <code>script</code> element from the
-   document.</li>
+   <dd><p>The <code>noscript</code> element must contain only text,
+   except that invoking the <span>HTML fragment parsing
+   algorithm</span> with the <code>noscript</code> element as the <var
+   title="">context</var> element and the text contents as the <var
+   title="">input</var> must result in a list of nodes that consists
+   only of <code>link</code>, <code>style</code>, and
+   <code>meta</code> elements.</p></dd>
 
-   <li>Make a list of every <code>noscript</code> element in the
-   document. For every <code>noscript</code> element in that list,
-   perform the following steps:
+   <dt>Outside of <code>head</code> elements, if <span
+   title="concept-n-noscript">scripting is disabled</span> for the
+   <code>noscript</code> element</dt>
 
+   <dd><p>The <code>noscript</code> element's content model is
+   <span>transparent</span>, with the additional restriction that a
+   <code>noscript</code> element must not have a <code>noscript</code>
+   element as an ancestor (that is, <code>noscript</code> can't be
+   nested).</p></dd>
+
+   <dt>Outside of <code>head</code> elements, if <span
+   title="concept-n-noscript">scripting is enabled</span> for the
+   <code>noscript</code> element</dt>
+
+   <dd>
+
+    <p>The <code>noscript</code> element must contain only text,
+    except that the text must be such that running the following
+    algorithm results in a conforming document with no
+    <code>noscript</code> elements and no <code>script</code>
+    elements, and such that no step in the algorithm causes an
+    <span>HTML parser</span> to flag a <span>parse error</span>:</p>
+
     <ol>
 
-     <li>Let the <var title="">parent element</var> be the parent
-     element of the <code>noscript</code> element.</li>
+     <li>Remove every <code>script</code> element from the
+     document.</li>
 
-     <li>Take all the children of the <var title="">parent element</var>
-     that come before the <code>noscript</code> element, and call these
-     elements <var title="">the before children</var>.</li>
+     <li>Make a list of every <code>noscript</code> element in the
+     document. For every <code>noscript</code> element in that list,
+     perform the following steps:
 
-     <li>Take all the children of the <var title="">parent element</var>
-     that come <em>after</em> the <code>noscript</code> element, and
-     call these elements <var title="">the after children</var>.</li>
+      <ol>
 
-     <li>Let <var title="">s</var> be the concatenation of all the
-     <span>text node</span> children of the <code>noscript</code>
-     element.</li>
+       <li>Let the <var title="">parent element</var> be the parent
+       element of the <code>noscript</code> element.</li>
 
-     <li>Set the <code title="dom-innerHTML-HTML">innerHTML</code>
-     attribute of the <var title="">parent element</var> to the value
-     of <var title="">s</var>. (This, as a side-effect, causes the
-     <code>noscript</code> element to be removed from the
-     document.)</li>
+       <li>Take all the children of the <var title="">parent element</var>
+       that come before the <code>noscript</code> element, and call these
+       elements <var title="">the before children</var>.</li>
 
-     <li>Insert <var title="">the before children</var> at the start of
-     the <var title="">parent element</var>, preserving their original
-     relative order.</li>
+       <li>Take all the children of the <var title="">parent element</var>
+       that come <em>after</em> the <code>noscript</code> element, and
+       call these elements <var title="">the after children</var>.</li>
 
-     <li>Insert <var title="">the after children</var> at the end of the
-     <var title="">parent element</var>, preserving their original
-     relative order.</li>
+       <li>Let <var title="">s</var> be the concatenation of all the
+       <span>text node</span> children of the <code>noscript</code>
+       element.</li>
 
+       <li>Set the <code title="dom-innerHTML-HTML">innerHTML</code>
+       attribute of the <var title="">parent element</var> to the value
+       of <var title="">s</var>. (This, as a side-effect, causes the
+       <code>noscript</code> element to be removed from the
+       document.)</li>
+
+       <li>Insert <var title="">the before children</var> at the start of
+       the <var title="">parent element</var>, preserving their original
+       relative order.</li>
+
+       <li>Insert <var title="">the after children</var> at the end of the
+       <var title="">parent element</var>, preserving their original
+       relative order.</li>
+
+      </ol>
+
+     </li>
+
     </ol>
 
-   </li>
+   </dd>
 
-  </ol>
+  </dl>
 
-  <p>The <code>noscript</code> element has no other requirements. In
-  particular, children of the <code>noscript</code> element are not
-  exempt from form submission, scripting, and so forth, even when the
-  element is <span>with script</span>.</p>
-
   <p class="note">All these contortions are required because, for
   historical reasons, the <code>noscript</code> element is handled
   differently by the <span>HTML parser</span> based on whether <span
@@ -10429,13 +10492,22 @@
   XML the parser is not affected by such state, and thus the element
   would not have the desired effect.</p>
 
-  <p class="note">The <code>noscript</code> element interacts poorly
-  with the <code title="dom-document-designMode">designMode</code>
-  feature. Authors are encouraged to not use <code>noscript</code>
-  elements on pages that will have <code
-  title="dom-document-designMode">designMode</code> enabled.</p>
+  <p>The <code>noscript</code> element must not be used in <span>XML
+  documents</span>.</p>
 
+  <p class="note"><strong>The <code>noscript</code> element is only
+  effective in the <span>HTML serialization</span><!-- XXX xref -->,
+  it has no effect in the <span>XML serialization</span><!-- XXX xref
+  -->.</strong></p>
 
+  <p>The <code>noscript</code> element has no other requirements. In
+  particular, children of the <code>noscript</code> element are not
+  exempt from form submission, scripting, and so forth, even when
+  <span title="concept-n-script">scripting is enabled</span> for the
+  element.</p>
+
+
+
   <h4>The <dfn><code>eventsource</code></dfn> element</h4>
 
   <dl class="element">
@@ -15596,7 +15668,7 @@
 
   <p class="note">The value of <code
   title="dom-img-complete">complete</code> can thus change while a
-  script is executing.</p>
+  <span title="concept-script">script</span> is executing.</p>
 
   <p>Three constructors are provided for creating
   <code>HTMLImageElement</code> objects (in addition to the factory
@@ -16695,6 +16767,12 @@
 
   <dl>
 
+   <!-- XXX disallow cross-origin loads of any kind (networking
+        override that only allows same-origin URLs or about:,
+        javascript:, data:) -->
+   <!-- XXX block access to 'contentWindow.frames' from iframe owner -->
+   <!-- XXX block access to 'parent.frames' from sandbox -->
+
    <dt>The <dfn>sandboxed navigation browsing context flag</dfn></dt>
 
    <dd>
@@ -20049,14 +20127,15 @@
 
   <p>The <dfn title="attr-media-controls"><code>controls</code></dfn>
   attribute is a <span>boolean attribute</span>. If the attribute is
-  present, or if the <span>media element</span> is <span>without
-  script</span>, then the user agent should <dfn>expose a user
-  interface to the user</dfn>. This user interface should include
-  features to begin playback, pause playback, seek to an arbitrary
-  position in the content (if the content supports arbitrary seeking),
-  change the volume, and show the media content in manners more
-  suitable to the user (e.g. full-screen video or in an independent
-  resizable window). Other controls may also be made available.</p>
+  present, or if <span title="concept-n-noscript">scripting is
+  disabled</span> for the <span>media element</span>, then the user
+  agent should <dfn>expose a user interface to the user</dfn>. This
+  user interface should include features to begin playback, pause
+  playback, seek to an arbitrary position in the content (if the
+  content supports arbitrary seeking), change the volume, and show the
+  media content in manners more suitable to the user (e.g. full-screen
+  video or in an independent resizable window). Other controls may
+  also be made available.</p>
 
   <p>If the attribute is absent, then the user agent should avoid
   making a user interface available that could conflict with an
@@ -20370,8 +20449,9 @@
   element. The contents of the <code>canvas</code> element, if any,
   are the element's <span>fallback content</span>.</p>
 
-  <p>In interactive visual media, if the <code>canvas</code> element
-  is <span>with script</span>, the <code>canvas</code> element
+  <p>In interactive visual media, if <span
+  title="concept-n-script">scripting is enabled</span> for the
+  <code>canvas</code> element, the <code>canvas</code> element
   represents an embedded element with a dynamically created image.</p>
 
   <p>In non-interactive, static, visual media, if the
@@ -20383,10 +20463,10 @@
   size. Otherwise, the element represents its <span>fallback
   content</span> instead.</p>
 
-  <p>In non-visual media, and in visual media if the
-  <code>canvas</code> element is <span>without script</span>, the
-  <code>canvas</code> element represents its <span>fallback
-  content</span> instead.</p>
+  <p>In non-visual media, and in visual media if <span
+  title="concept-n-noscript">scripting is disabled</span> for the
+  <code>canvas</code> element, the <code>canvas</code> element
+  represents its <span>fallback content</span> instead.</p>
 
   <p>The <code>canvas</code> element has two attributes to control the
   size of the coordinate space: <dfn
@@ -37230,6 +37310,7 @@
           http://www.mozilla.org/docs/dom/domref/dom_window_ref.html
           http://lxr.mozilla.org/mozilla/source/dom/public/idl/base/nsIDOMWindow.idl - scrollBy, etc
           http://lxr.mozilla.org/mozilla/source/dom/public/idl/base/nsIDOMWindowInternal.idl - DOM level 0
+      close() focus() blur()
    -->
 
   <p>The <dfn title="dom-window"><code>window</code></dfn>, <dfn
@@ -37237,7 +37318,7 @@
   title="dom-self"><code>self</code></dfn> DOM attributes must all
   return the <code>Window</code> object itself.</p>
 
-  <p>The <code>Window</code> object also provides the scope for script
+  <p>The <code>Window</code> object also provides the scope for <span title="concept-script">script</span>
   execution. Each <code>Document</code> in a <span>browsing
   context</span> has an associated <dfn>list of added properties</dfn>
   that, when a document is <span title="active
@@ -37343,9 +37424,10 @@
   enabled</span>; otherwise, it must not be enabled unless the
   <span>browsing context</span> was just created as part of the
   <span>the rules for choosing a browsing context given a browsing
-  context name</span>. The navigation must be done with the
-  <span>script browsing context</span> of the script that invoked the
-  method as the <span>source browsing context</span>.</p>
+  context name</span>. The navigation must be done with the <span
+  title="script's browsing context">browsing context</span> of the
+  <span title="concept-script">script</span> that invoked the method as the <span>source browsing
+  context</span>.</p>
 
   <p>The method must return the <code>Window</code> object of the
   default view of the <span>browsing context</span> that was
@@ -37378,6 +37460,44 @@
 
 
 
+  <h4>Garbage collection and browsing contexts</h4>
+
+  <p>A <span>browsing context</span> has a strong reference to each of
+  its <code>Document</code>s and <span title="view">views</span>, and
+  the user agent itself has a strong reference to its <span
+  title="top-level browsing context">top-level browsing
+  contexts</span>.</p>
+
+  <p>When a <span>browsing context</span> is to <dfn>discard a
+  <code>Document</code></dfn>, that means that it is to lose the
+  strong reference from the <code>Document</code>'s <span>browsing
+  context</span> to the <code>Document</code>.</p>
+
+  <p class="note">The <span>browsing context</span>'s <span>default
+  view</span>'s <code>Window</code> object <span title="implied strong
+  reference">has a strong reference of its own</span> to the
+  <code>Document</code> object of the <span>browsing context</span>'s
+  <span>active document</span>.</p>
+
+  <p>When <dfn>a <em><span>browsing context</span></em> is
+  discarded</dfn>, the strong reference from the user agent itself to
+  the <span>browsing context</span> must be severed, and all the
+  <code>Document</code> objects for all the entries in the
+  <span>browsing context</span>'s session history must be <span
+  title="discard a document">discarded</span> as well.</p>
+
+  <p>User agents may <span title="a browsing context is
+  discarded">discard</span> <span title="top-level browsing
+  context">top-level browsing contexts</span> at any time (typically,
+  in response to user requests, e.g. when a user closes a window
+  containing one or more <span title="top-level browsing
+  context">top-level browsing contexts</span>). Other <span
+  title="browsing context">browsing contexts</span> must be discarded
+  once their <code>Window</code> object is eligible for garbage
+  collection.</p>
+
+
+
   <h3>Origin</h3>
   <!-- Hallowed are the Ori -->
 
@@ -37871,6 +37991,8 @@
 
   <h3 id="scripting">Scripting</h3>
 
+  <h4>Introduction</h4>
+
   <p>Various mechanisms can cause author-provided executable code to
   run in the context of a document. These mechanisms include, but are
   probably not limited to:</p>
@@ -37895,91 +38017,293 @@
 
   </ul>
 
-  <p>When a script is created<!-- which is marked by SCRIPT EXEC in
-  this spec -->, it is associated with a <span>script execution
-  context</span>, a <span>script browsing context</span>, and a
-  <span>script document context</span>.</p>
 
 
 
-  <!-- SCRIPT EXEC -->
-  <h4>Script execution contexts</h4>
+  <h4>Enabling and disabling scripting</h4>
 
-  <p>The <dfn>script execution context</dfn> of a script is defined
-  when that script is created. In this specification, it is either a
-  <code>Window</code> object or an empty object; other specifications
-  might make the script execution context be some other object.</p>
+  <p><dfn title="concept-bc-script">Scripting is enabled</dfn> in a
+  <em><span>browsing context</span></em> when all of the
+  following conditions are true:</p>
 
-  <p>When the <span>script execution context</span> of a script is an
-  empty object, it can't do anything that interacts with the
-  environment.</p>
+  <ul>
 
-  <p>A <span>script execution context</span> always has an associated
-  <span>browsing context</span>, known as the <dfn>script browsing
-  context</dfn>. If the <span>script execution context</span> is a
-  <code>Window</code> object, then that object's <span>browsing
-  context</span> is it. Otherwise, the <span>script execution
-  context</span> is associated explicitly with a <span>browsing
-  context</span> when it is created.</p>
+   <li>The user agent supports scripting.</li>
 
-  <p>Every script whose <span>script execution context</span> is a
-  <code>Window</code> object is also associated with a
-  <code>Document</code> object, known as its <dfn>script document
-  context</dfn>. It is used to <span title="resolve a
-  url">resolve</span> URLs. The document is assigned when the script
-  is created, as with the <span>script browsing context</span>.</p>
+   <li>The user has not disabled scripting for this <span>browsing
+   context</span> at this time. (User agents may provide users with
+   the option to disable scripting globally, or in a finer-grained
+   manner, e.g. on a per-origin basis.)</li>
 
+   <li id="sandboxScriptBlocked">The <span>browsing context</span>
+   does not have the <span>sandboxed scripts browsing context
+   flag</span> set.</li>
+
+  </ul>
+
+  <p><dfn title="concept-bc-noscript">Scripting is disabled</dfn> in a
+  <span>browsing context</span> when any of the above conditions are
+  false (i.e. when scripting is not <span
+  title="concept-bc-script">enabled</span>).</p>
+
   <hr>
 
-  <p>It is said that <dfn>scripting is disabled</dfn> in a
-  <span>script execution context</span> when any of the following
-  conditions are true:</p>
+  <p><dfn title="concept-n-script">Scripting is enabled</dfn> for a
+  <em>node</em> if the <code>Document</code> object of the node (the
+  node itself, if it is itself a <code>Document</code> object) has an
+  associated <span>browsing context</span>, and <span
+  title="concept-bc-script">scripting is enabled</span> in that
+  <span>browsing context</span>.</p>
 
-  <ul>
+  <p><dfn title="concept-n-noscript">Scripting is disabled</dfn> for a
+  node if there is no such <span>browsing context</span>, or if <span
+  title="concept-bc-noscript">scripting is disabled</span> in that
+  <span>browsing context</span>.</p>
 
-   <li>The user agent does not support scripting.</li>
 
-   <li>The user has disabled scripting for this <span>script execution
-   context</span>. (User agents may provide users with the option to
-   disable scripting globally, on a per-origin basis, or in other ways
-   down to the granularity of individual <span title="script execution
-   context">script execution contexts</span>.)</li>
 
-   <li id="designModeScriptBlocked">The <span>script execution
-   context</span>'s associated <span>browsing context</span>'s
-   <span>active document</span> has <code
-   title="dom-document-designMode">designMode</code> enabled.</li>
+  <!-- SCRIPT EXEC (marks areas related to creation of scripts) -->
+  <h4>Processing model</h4>
 
-   <li id="sandboxScriptBlocked">The <span>script execution
-   context</span>'s associated <span>browsing context</span> has the
-   <span>sandboxed scripts browsing context flag</span> set.</li>
+  <h5>Definitions</h5>
 
-  </ul>
+  <p>A <dfn title="concept-script">script</dfn> has:</p>
 
-  <p>A node is said to be <dfn>without script</dfn> if either the
-  <code>Document</code> object of the node (the node itself, if it is
-  itself a <code>Document</code> object) does not have an associated
-  <span>browsing context</span>, or <span>scripting is disabled</span>
-  in that <span>browsing context</span>.</p>
+  <dl>
 
-  <p>A node is said to be <dfn>with script</dfn> if it is not
-  <span>without script</span>.</p>
+   <dt>A <dfn>script execution environment</dfn></dt>
 
-  <p class="XXX">If you can find a better pair of terms than
-  "with script" and "without script" let me know. The only things I
-  can find that are less confusing are also way, way longer.</p>
+   <dd>
 
-  <p>When a script is to be executed in a <span>script execution
-  context</span> in which <span>scripting is disabled</span>, the
-  script must do nothing and return nothing (a void return value).</p>
+    <p>The characteristics of the script execution environment depend
+    on the language, and are not defined by this specification.</p>
 
-  <p class="note">Thus, for instance, enabling <code
-  title="dom-document-designMode">designMode</code> will disable any
-  event handler attributes, event listeners, timeouts, etc, that were
-  set by scripts in the document.</p>
+    <p class="example">In JavaScript, the script execution environment
+    consists of the interpreter, the stack of <i>execution
+    contexts</i>, the <i>global code</i> and <i>function code</i> and
+    the Function objects resulting, and so forth.</p>
 
+   </dd>
 
+   <dt>A <dfn>list of code entry-points</dfn></dt>
 
+   <dd>
+
+    <p>Each code entry-point represents a block of executable code
+    that the script exposes to other scripts and to the user
+    agent.</p>
+
+    <p class="example">Each Function object in a JavaScript
+    <span>script execution environment</span> has a corresponding code
+    entry-point, for instance.</p>
+
+    <p>The main program code of the script, if any, is the
+    <dfn><i>initial code entry-point</i></dfn>. Typically, the code
+    corresponding to this entry-point is executed immediately after
+    the script is parsed.</p>
+
+    <p class="example">In JavaScript, this corresponds to the
+    execution context of the global code.</p>
+
+   </dd>
+
+   <dt>A relationship with the <dfn>script's global object</dfn></dt>
+
+   <dd>
+
+    <p>An object that provides the APIs that the code can use.</p>
+
+    <p class="example">This is typically a <code>Window</code>
+    object. In JavaScript, this corresponds to the <i>global
+    object</i>.</p>
+
+    <p class="note">When a <span>script's global object</span> is an
+    empty object, it can't do anything that interacts with the
+    environment.</p>
+
+   </dd>
+
+   <dt>A relationship with the <dfn>script's browsing context</dfn></dt>
+
+   <dd>
+
+    <p>A <span>browsing context</span> that is assigned responsibility
+    for actions taken by the script.</p>
+
+    <p class="example">When a script creates and <span
+    title="navigate">navigates</span> a new <span>top-level browsing
+    context</span>, the <code title="dom-opener">opener</code>
+    attribute of the new <span>browsing context</span>'s
+    <code>Window</code> object will be set to the <span>script's
+    browsing context</span>'s <code>Window</code> object.</p>
+
+   </dd>
+
+   <dt>A <dfn title="script's character encoding">character encoding</dfn></dt>
+
+   <dd>
+
+    <p>A character encoding, set when the script is created, used to
+    encode URLs.  <span id="sce-not-copy">If the character encoding is
+    set from another source, e.g. a <span>document's character
+    encoding</span>, then the <span>script's character encoding</span>
+    must follow the source, so that if the source's changes, so does
+    the script's.</span></p>
+
+   </dd>
+
+   <dt>A <dfn title="script's base URL">base URL</dfn></dt>
+
+   <dd>
+
+    <p>A <span>URL</span>, set when the script is created, used to
+    resolve relative URLs. <span id="sbu-not-copy">If the base URL is
+    set from another source, e.g. a <span>document base URL</span>,
+    then the <span>script's base URL</span> must follow the source, so
+    that if the source's changes, so does the script's.</span></p>
+
+   </dd>
+
+   <dt>Membership in a <dfn>script group</dfn></dt>
+
+   <dd>
+
+    <p>A group of one or more scripts that are loaded in the same
+    context, which are always disabled as a group. Scripts in a script
+    group all have the same <span title="script's global
+    object">global object</span> and <span title="script's browsing
+    context">browsing context</span>.</p>
+
+    <p>A script group can be <i>frozen</i>. When a script group is
+    frozen, any code defined in that script group will throw an
+    exception when invoked. A frozen script group can be
+    <i>unfrozen</i>, allowing scripts in that script group to run
+    normally again.</p>
+
+   </dd>
+
+  </dl>
+
+
+
+  <h5>Calling scripts</h5>
+
+  <p>When a user agent is to <dfn>jump to a code entry-point</dfn> for
+  a <span title="concept-script">script</span>, if <span
+  title="concept-bc-noscript">scripting is disabled</span> in the
+  <span>script's browsing context</span>, or if the script's
+  <span>script group</span> is <i>frozen</i>, then the user agent must
+  throw an <code>UNAVAILABLE_SCRIPT_ERR</code> exception. Otherwise,
+  the <span title="script execution environment">script execution
+  environment</span> for the <span
+  title="concept-script">script</span> must execute the code for the
+  given code entry-point.</p>
+
+  <p>When executable code in one <span
+  title="concept-script">script</span> makes a call to another <span
+  title="concept-script">script</span>, the user agent must <span
+  title="jump to a code entry-point">jump</span> to the corresponding
+  code entry-point in that second script.</p>
+
+  <p>Any time the user agent to invoke a callback defined in a <span
+  title="concept-script">script</span>, the user agent must <span
+  title="jump to a code entry-point">jump</span> to the corresponding
+  code entry-point in that second script.</p>
+
+
+
+  <h5>Creating scripts</h5>
+
+  <p>When the specification says that a <span
+  title="concept-script">script</span> is to be <dfn title="create a
+  script">created</dfn>, given some script source, its scripting
+  language, a global object, a browsing context, a character encoding,
+  a base URL, and a script group, the user agent must run the
+  following steps:</p>
+
+  <ol>
+
+   <li><p>Set up a <span>script execution environment</span> as
+   appropriate for the scripting language.</p></li>
+
+   <li><p>Parse/compile/initialise the source of the script using the
+   <span>script execution environment</span>, as appropriate for the
+   scripting language, and thus obtain the <span>list of code
+   entry-points</span> for the script. If the semantics of the
+   scripting language and the given source code are such that there is
+   executable code to be immediately run, then the <i>initial code
+   entry-point</i> is the entry-point for that code.</p></li>
+
+   <li><p>Set up the <span>script's global object</span>, the
+   <span>script's browsing context</span>, the <span>script's
+   character encoding</span>, and the <span>script's base URL</span>
+   from the settings passed to this algorithm.</p></li>
+
+   <li><p>Add the <span title="concept-script">script</span> to the given <span>script
+   group</span>.</p></li>
+
+   <li><p><span title="jump to a code entry-point">Jump</span> to the
+   <span title="concept-script">script</span>'s <i>initial code
+   entry-point</i>.</p></li>
+
+  </ol>
+
+  <hr>
+
+  <p>When the user agent is to <dfn>create an impotent script</dfn>,
+  given some script source, its scripting language, and a browsing
+  context, the user agent must <span>create a script</span>, using the
+  given script source and scripting language, using a new empty object
+  as the global object, using the given browsing context as the
+  browsing context, and using a new script group as the script
+  group. The character encoding and base URL for the resulting <span
+  title="concept-script">script</span> are not important as no APIs
+  are exposed to the script.</p>
+
+  <hr>
+
+  <p>When the specification says that a <span
+  title="concept-script">script</span> is to be <dfn title="create a
+  script from a node">created from a node</dfn> <var
+  title="">node</var>, given some script source and its scripting
+  language, the user agent <span>create a script</span>, using the
+  given script source and scripting language, and using <span>the
+  script settings determined from the node</span> <var
+  title="">node</var>.</p>
+
+  <p><dfn>The script settings determined from the node</dfn> <var
+  title="">node</var> are computed as follows:</p>
+
+  <ol>
+
+   <li><p>Let <var title="">document</var> be the
+   <code>Document</code> of <var title="">node</var> (or <var
+   title="">node</var> itself if it is a
+   <code>Document</code>).</p></li>
+
+   <li><p>The browsing context is the <span>browsing context</span> of
+   <var title="">document</var>.</p>
+
+   <li><p>The global object is the <code>Window</code> object of the
+   <span>default view</span> of the <span>browsing context</span> of
+   <var title="">document</var>.</p></li>
+
+   <li><p>The character encoding is the <span title="document's
+   character encoding">character encoding</span> of <var
+   title="">document</var>. (<a href="#sce-not-copy">This is a
+   reference, not a copy</a>.)</p></li>
+
+   <li><p>The base URL is the <span title="document base URL">base
+   URL</span> of <var title="">document</var>. (<a
+   href="#sbu-not-copy">This is a reference, not a copy</a>.)</p></li>
+
+   <li><p>The script group is the <span>current script group</span> of
+   <var title="">document</var>.</p></li>
+
+  </ol>
+
+
+
   <h4>Event loops</h4>
 
   <p>To coordinate events, user interaction, scripts, rendering,
@@ -38044,6 +38368,17 @@
 
   </dl>
 
+  <p>Each <span title="concept-task">task</span> is associated with a
+  <code>Document</code>; if the task was queued in the context of an
+  element, then it is the element's <code>Document</code>; if the task
+  was queued in the context of a <span>browsing context</span>, then
+  it is the <span>browsing context</span>'a <span>active
+  document</span> at the time the task was queued; if the task was
+  queued by or for a <span title="concept-script">script</span> then
+  the document is the script's <span>script's browsing
+  context</span>'s <span>active document</span> at the time the task
+  was queued.</p>
+
   <p>When a user agent is to <dfn>queue a task</dfn>, it must add the
   given task to one of the <span title="task queue">task queues</span>
   of the relevant <span>event loop</span>. All the tasks from one
@@ -38069,8 +38404,10 @@
   <ol>
 
    <li><p>Run the oldest task on one of the <span>event loop</span>'s
-   <span title="task queue">task queues</span>. The user agent may
-   pick any <span>task queue</span>.</p></li>
+   <span title="task queue">task queues</span>, ignoring tasks whose
+   associated <code>Document</code>s are not <span title="active
+   document">active</span>. The user agent may pick any <span>task
+   queue</span>.</p></li>
 
    <li><p>Remove that task from its <span>task queue</span>.</p></li>
 
@@ -38142,61 +38479,123 @@
   <!-- SCRIPT EXEC -->
   <h4 id="javascript-protocol"><dfn title="javascript protocol">The <code title="">javascript:</code> protocol</dfn></h4>
 
-  <p>A URL using the <code title="">javascript:</code> protocol must,
-  if and when <dfn title="concept-js-deref">dereferenced</dfn>, be
-  evaluated by executing the script obtained using the content
-  retrieval operation defined for <code title="">javascript:</code>
-  URLs. <a href="#refsJSURL">[JSURL]</a></p>
+  <p>When a <span>URL</span> using the <code
+  title="">javascript:</code> protocol is <dfn
+  title="concept-js-deref">dereferenced</dfn>, the user agent must run
+  the following steps:</p>
 
+  <ol>
+
+   <li><p>Let the script source be the string obtained using the
+   content retrieval operation defined for <code
+   title="">javascript:</code> URLs. <a
+   href="#refsJSURL">[JSURL]</a></p></li>
+
 <!--
 JSURL: http://ietfreport.isoc.org/all-ids/draft-hoehrmann-javascript-scheme-00.txt and
        http://www.websitedev.de/ietf/draft-hoehrmann-javascript-scheme-00.txt should be as stable as it gets,
        http://ietfreport.isoc.org/idref/draft-hoehrmann-javascript-scheme/ for the latest version
 -->
 
-  <p>When a <span>browsing context</span> is <span
-  title="navigate">navigated</span> to a <code>javascript:</code> URL,
-  and the <span>active document</span> of that browsing context has
-  the <span>same origin</span> as the script given by that URL, the
-  <span>script execution context</span> must be the
-  <code>Window</code> object of the <span>browsing context</span>
-  being navigated, and the <span>script document context</span> must
-  be that <span>active document</span>.</p>
+   <li>
 
-  <p>When a <span>browsing context</span> is <span
-  title="navigate">navigated</span> to a <code>javascript:</code> URL,
-  and the <span>active document</span> of that browsing context has an
-  <span>origin</span> that is <em>not</em> the <span title="same
-  origin">same</span> as that of the script given by the URL, the
-  <span>script execution context</span> must be an empty object, and
-  the <span>script browsing context</span> must be the <span>browsing
-  context</span> being <span title="navigate">navigated</span>.</p>
+    <p>Use the appropriate step from the following list:</p>
 
-  <p>Otherwise, if the <code>Document</code> object of the element,
-  attribute, or style sheet from which the <code>javascript:</code>
-  URL was reached has an associated <span>browsing context</span>, the
-  <span>script execution context</span> must be an empty object, and
-  the <span>script execution context</span>'s associated
-  <span>browsing context</span> must be that <span>browsing
-  context</span>.</p>
+    <dl>
 
-  <p>Otherwise, the script is not executed and its return value is
-  void.</p>
+     <dt>If a <span>browsing context</span> is being <span
+     title="navigate">navigated</span> to a <code>javascript:</code>
+     URL, and the <span>active document</span> of that browsing
+     context has the <span>same origin</span> as the script given by
+     that URL</dt>
 
-  <p>If the result of executing the script is void (there is no return
-  value), then the URL must be treated in a manner equivalent to an
-  HTTP resource with an HTTP 204 No Content response.</p>
+     <dd>
 
-  <p>Otherwise, the URL must be treated in a manner equivalent to an
-  HTTP resource with a 200 OK response whose <span
-  title="Content-Type">Content-Type metadata</span> is <code
-  title="">text/html</code> and whose response body is the return
-  value converted to a string value.</p>
+      <p><span title="create a script from a node">Create a
+      script</span> from the <code>Document</code> node of the
+      <span>active document</span>, using the aforementioned script
+      source, and assuming the scripting language is JavaScript.</p>
 
-  <p class="note">Certain contexts, in particular <code>img</code>
-  elements, ignore the <span title="Content-Type">Content-Type
-  metadata</span>.</p>
+      <p>Let <var title="">result</var> be the return value of the
+      <i>initial code entry-point</i> of this <span
+      title="concept-script">script</span>. If an exception was
+      raised, let <var title="">result</var> be void instead.</p>
 
+     </dd>
+
+     <dt>If a <span>browsing context</span> is being <span
+     title="navigate">navigated</span> to a <code>javascript:</code>
+     URL, and the <span>active document</span> of that browsing
+     context has an <span>origin</span> that is <em>not</em> the <span
+     title="same origin">same</span> as that of the script given by
+     the URL</dt>
+
+     <dd>
+
+      <p><span>Create an impotent script</span> using the
+      aforementioned script source, with the scripting language set to
+      JavaScript, and with the <span>browsing context</span> being
+      <span title="navigate">navigated</span> as the browsing
+      context.</p>
+
+      <p>Let <var title="">result</var> be the return value of the
+      <i>initial code entry-point</i> of this <span
+      title="concept-script">script</span>. If an exception was
+      raised, let <var title="">result</var> be void instead.</p>
+
+     </dd>
+
+     <dt>If the <code>Document</code> object of the element,
+     attribute, or style sheet from which the <code>javascript:</code>
+     URL was reached has an associated <span>browsing
+     context</span></dt>
+
+     <dd>
+
+      <p><span>Create an impotent script</span> using the
+      aforementioned script source, with the scripting language set to
+      JavaScript, and with the <code>Document</code>'s object's
+      <span>browsing context</span> as the browsing context.</p>
+
+      <p>Let <var title="">result</var> be the return value of the
+      <i>initial code entry-point</i> of this <span
+      title="concept-script">script</span>. If an exception was
+      raised, let <var title="">result</var> be void instead.</p>
+
+     </dd>
+
+     <dt>Otherwise</dt>
+
+     <dd>
+
+      <p>Let <var title="">result</var> be void.</p>
+
+     </dd>
+
+    </dl>
+
+   </li>
+
+   <li>
+
+    <p>If the result of executing the script is void (there is no
+    return value), then the URL must be treated in a manner equivalent
+    to an HTTP resource with an HTTP 204 No Content response.</p>
+
+    <p>Otherwise, the URL must be treated in a manner equivalent to an
+    HTTP resource with a 200 OK response whose <span
+    title="Content-Type">Content-Type metadata</span> is <code
+    title="">text/html</code> and whose response body is the return
+    value converted to a string value.</p>
+
+    <p class="note">Certain contexts, in particular <code>img</code>
+    elements, ignore the <span title="Content-Type">Content-Type
+    metadata</span>.</p>
+
+   </li>
+
+  </ol>
+
   <div class="example">
 
    <p>So for example a <code title="">javascript:</code> URL for a
@@ -38219,10 +38618,10 @@
 
   </div>
 
-  <p class="note">The rules for handling script execution in a
-  <span>script execution context</span> include making the script not
-  execute (and just return void) in certain cases, e.g. in a sandbox
-  or when the user has disabled scripting altogether.</p>
+  <p class="note">The rules for <span title="create a script">creating
+  a script</span> include making the script not execute (and just
+  return void) in certain cases, e.g. in a sandbox or when the user
+  has disabled scripting altogether.</p>
 
 
   <h4>Events</h4>
@@ -38241,24 +38640,26 @@
 
   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A...%3Cscript%3E%0Aw(a%3Ddocument.implementation.createDocument(null%2C%20null%2C%20null))%3B%0Aw(a.appendChild(a.createElementNS('http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml'%2C%20'html')))%3B%0Aw(b%3Da.firstChild.appendChild(a.createElementNS('http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml'%2C%20'body')))%3B%0Aw(b.test%20%3D%20w)%3B%0Aw(b.setAttribute('onclick'%2C%20'test(%22fire%3A%20%22%20%2B%20event)'))%3B%0Aw(b.onclick)%3B%0Aw(e%3Da.createEvent('Event'))%3B%0Aw(e.initEvent('click'%2C%20false%2C%20false))%3B%0Aw(b.dispatchEvent(e))%3B%0A%3C%2Fscript%3E -->
 
-  <p><span>HTML elements</span> can have <dfn>event handler
-  attributes</dfn> specified. These act as bubbling event listeners
-  for the element on which they are specified.</p>
+  <p>Many objects can have <dfn>event handler attributes</dfn>
+  specified. These act as bubbling event listeners for the element on
+  which they are specified.</p>
 
-  <p>Each event handler attribute has two parts, an <span title="event
-  handler content attributes">event handler content attribute</span>
-  and an <span title="event handler DOM attributes">event handler DOM
-  attribute</span>. Event handler attributes must initially be set to
-  null. When their value changes (through the changing of their event
-  handler content attribute or their event handler DOM attribute),
-  they will either be null, or have an <code>EventListener</code>
-  object assigned to them.</p>
+  <p>On <span>HTML elements</span>, each event handler attribute has
+  two parts, an <span title="event handler content attributes">event
+  handler content attribute</span> and an <span title="event handler
+  DOM attributes">event handler DOM attribute</span>. Event handler
+  attributes must initially be set to null. When their value changes
+  (through the changing of their event handler content attribute or
+  their event handler DOM attribute), they will either be null, or
+  have an <code>EventListener</code> object assigned to them.</p>
 
   <p>Objects other than <code>Element</code> objects, in particular
   <code>Window</code>, only have <span title="event handler DOM
   attributes">event handler DOM attribute</span> (since they have no
   content attributes).</p>
 
+  <hr>
+
   <p><dfn>Event handler content attributes</dfn>, when specified, must
   contain valid ECMAScript code matching the ECMAScript <code
   title="">FunctionBody</code> production. <a
@@ -38267,43 +38668,61 @@
   <!-- SCRIPT EXEC -->
   <p>When an event handler content attribute is set, if the element is
   owned by a <code>Document</code> that is in a <span>browsing
-  context</span>, its new value must be interpreted as the body of an
-  anonymous function with a single argument called <code>event</code>,
-  with the new function's scope chain being linked from the activation
-  object of the handler, to the element, to the element's
-  <code>form</code> element if it is a form control, to the
-  <code>Document</code> object, to the <code>Window</code> object of
-  the <span>browsing context</span> of that <code>Document</code>. The
-  function's <code>this</code> parameter must be the
-  <code>Element</code> object representing the element. The resulting
-  function must then be set as the value of the corresponding event
-  handler attribute, and the new value must be set as the value of the
-  content attribute. If the given function body fails to compile, then
-  the corresponding event handler attribute must be set to null
-  instead (the content attribute must still be updated to the new
-  value, though).</p>
+  context</span>, the user agent must run the following steps to
+  create a <span title="concept-script">script</span> after setting
+  the content attribute to its new value:</p>
 
-  <p class="note">See ECMA262 Edition 3, sections 10.1.6 and 10.2.3,
-  for more details on activation objects. <a
-  href="#refsECMA262">[ECMA262]</a></p>
+  <ol>
 
-  <p>The <span>script execution context</span> of the event handler
-  must be the <code>Window</code> object at the end of the scope
-  chain. The <span>script document context</span> of the event handler
-  must be the <code>Document</code> object that owns the event handler
-  content attribute that was set.</p>
+   <li><p>Set up a <span>script execution environment</span> for
+   JavaScript.</p></li>
 
-  <p>When an event handler content attribute is set on an element
-  owned by a <code>Document</code> that is not in a <span>browsing
-  context</span>, the corresponding event handler attribute is not
-  changed.</p>
+   <li><p>Using this script execution environment, interpret the
+   attribute's new value as the body of an anonymous function with a
+   single argument called <code>event</code>. Link the new function's
+   scope chain from the activation object of the handler, to the
+   element's object, to the element's <span>form owner</span>, if it
+   has one, to the element's <code>Document</code> object, to the
+   <code>Window</code> object of the <span>browsing context</span> of
+   that <code>Document</code>. Set the function's <code>this</code>
+   parameter to the <code>Element</code> object representing the
+   element. Let this function be the only entry in the script's
+   <span>list of code entry-points</span>.</p>
 
+   <p class="note">See ECMA262 Edition 3, sections 10.1.6 and 10.2.3,
+   for more details on activation objects. <a
+   href="#refsECMA262">[ECMA262]</a></p></li>
+
+   <li><p>If the previous steps failed to compile the script, then set
+   the corresponding event handler attribute to null and abort these
+   steps.</p></li>
+
+   <li><p>Set up the <span>script's global object</span>, the
+   <span>script's browsing context</span>, the <span>script's
+   character encoding</span>, and the <span>script's base URL</span>
+   from <span>the script settings determined from the node</span> on
+   which the attribute is being set, and add the <span title="concept-script">script</span> to the
+   <span>script group</span> determined from that node as
+   well.</p></li>
+
+   <li><p>Set the corresponding event handler attribute to the
+   aforementioned function.</p></li>
+
+  </ol>
+
+  <p class="note">When an event handler content attribute is set on an
+  element owned by a <code>Document</code> that is not in a
+  <span>browsing context</span>, the corresponding event handler
+  attribute is not changed.</p>
+
   <p class="note">Removing an event handler content attribute does not
-  reset the corresponding event handler attribute either.</p>
+  reset the corresponding event handler attribute.</p>
   <!-- http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A...%3Cbody%20onload%3D%22w(%27pass%27)%22%3E%0A%3Cscript%3Edocument.body.removeAttribute(%27onload%27)%3B%3C%2Fscript%3E -->
 
   <p class="XXX">How do we allow non-JS event handlers?</p>
 
+  <hr>
+
   <p><dfn>Event handler DOM attributes</dfn>, on setting, must set the
   corresponding event handler attribute to their new value, and on
   getting, must return whatever the current value of the corresponding
@@ -38555,18 +38974,37 @@
 
    <dd><p>Must be invoked whenever an <code
    title="event-unload">unload</code> event is targeted at or bubbles
-   through the element.</p></dd> <!-- XXX need to fire this -->
+   through the element.</p></dd>
 
   </dl>
 
   <p>When an event handler attribute is invoked, its argument must be
-  set to the <code>Event</code> object of the event in question. If
-  the function returns the exact boolean value false, the event's
-  <code>preventDefault()</code> method must then invoked. Exception:
-  for historical reasons, for the HTML <code>mouseover</code> event,
-  the <code>preventDefault()</code> method must be called when the
-  function returns true instead.</p>
+  set to the <code>Event</code> object of the event in question.</p>
 
+  <p>The handler's return value must be processed as follows:</p>
+
+  <dl class="switch">
+
+   <dt>If the event type is <code class="event-mouseover">mouseover</code></dt>
+
+   <dd><p>If the return value is a boolean with the value true, then
+   the event must be canceled.</p></dd>
+
+   <dt>If the event object is a <code>BeforeUnloadEvent</code> object</dt>
+
+   <dd><p>If the return value is a string, and the event object's
+   <code title="dom-BeforeUnloadEvent-returnValue">returnValue</code>
+   attribute's value is the empty string, then set the <code
+   title="dom-BeforeUnloadEvent-returnValue">returnValue</code>
+   attribute's value to the return value.</p></dd>
+
+   <dt>Otherwise</dt>
+
+   <dd><p>If the return value is a boolean with the value false, then
+   the event must be canceled.</p></dd>
+
+  </dl>
+
   <!-- IE actually uncancels the event if the function returns true -->
 
   <p>All event handler attributes on an element, whether set to null
@@ -38920,7 +39358,7 @@
 
      <li>have an <span>active document</span> whose
      <span>origin</span> is the <span title="same origin">same</span>
-     as the <span>origin</span> of the script that called the <code
+     as the <span>origin</span> of the <span title="concept-script">script</span> that called the <code
      title="dom-showModalDialog">showModalDialog()</code> method at
      the time the method was called,</li> <!-- Note that changing
      document.domain to talk to another domain doesn't make you able
@@ -38969,7 +39407,7 @@
    <li>
 
     <p>Let the <span>dialog arguments' origin</span> be the
-    <span>origin</span> of the script that called the <code
+    <span>origin</span> of the <span title="concept-script">script</span> that called the <code
     title="dom-showModalDialog">showModalDialog()</code> method.</p>
 
    </li>
@@ -38978,9 +39416,9 @@
 
     <p><span>Navigate</span> the new browsing context to <var
     title="">url</var>, with <span>replacement enabled</span>, and
-    with the <span>script browsing context</span> of the script that
-    invoked the method as the <span>source browsing
-    context</span>.</p>
+    with the <span title="script's browsing context">browsing
+    context</span> of the <span title="concept-script">script</span> that invoked the method as the
+    <span>source browsing context</span>.</p>
 
    </li>
 
@@ -39089,18 +39527,19 @@
   title="">onclick</var>)</code></dfn> method, when invoked, must
   cause the user agent to show a notification.</p>
 
-  <p id="sandboxNotifications">If the method was invoked from a script
-  whose <span>script browsing context</span> has the <span>sandboxed
-  annoyances browsing context flag</span> set, then the notification
-  must be shown within that <span>browsing context</span>. The
-  notification is said to be a <dfn>sandboxed notification</dfn>.</p>
+  <p id="sandboxNotifications">If the method was invoked from a <span title="concept-script">script</span>
+  whose <span title="script's browsing context">browsing
+  context</span> has the <span>sandboxed annoyances browsing context
+  flag</span> set, then the notification must be shown within that
+  <span>browsing context</span>. The notification is said to be a
+  <dfn>sandboxed notification</dfn>.</p>
 
-  <p>Otherwise, if the <span>origin</span> of the <span>script
-  browsing context</span> of the script that invoked the method is
-  <em>not</em> flagged as being a <span>trusted notification
-  source</span>, then the notification should be rendered within the
-  <span>top-level browsing context</span> of the <span>script browsing
-  context</span> of the script that invoked the method. The
+  <p>Otherwise, if the <span>origin</span> of the <span
+  title="script's browsing context">browsing context</span> of the
+  <span title="concept-script">script</span> that invoked the method is <em>not</em> flagged as being a
+  <span>trusted notification source</span>, then the notification
+  should be rendered within the <span>top-level browsing
+  context</span> of the <span>script's browsing context</span>. The
   notification is said to be a <dfn>normal notification</dfn>. User
   agents should provide a way to set the origin's <span>trusted
   notification source</span> flag from the notification, so that the
@@ -39149,16 +39588,16 @@
   <p>When a <span>normal notification</span> (but not a
   <span>sandboxed notification</span>) is shown, the user agent may
   bring the user's attention to the <span>top-level browsing
-  context</span> of the <span>script browsing context</span> of the
-  script that invoked the method, if that would be useful; but user
-  agents should not use system-wide notification mechanisms to do
-  so.</p>
+  context</span> of the <span title="script's browsing
+  context">browsing context</span> of the <span title="concept-script">script</span> that invoked the
+  method, if that would be useful; but user agents should not use
+  system-wide notification mechanisms to do so.</p>
 
   <p>When a <span>trusted notification</span> is shown, the user agent
-  should bring the user's attention to the notification and the
-  <span>script browsing context</span> of the script that invoked the
-  method, as per the platform conventions for attracting the user's
-  attention to applications.</p>
+  should bring the user's attention to the notification and the <span
+  title="script's browsing context">browsing context</span> of the
+  <span title="concept-script">script</span> that invoked the method, as per the platform conventions for
+  attracting the user's attention to applications.</p>
 
   <div class="example">
 
@@ -39185,8 +39624,9 @@
    <li>The <span title="meta-application-name">application
    name</span>, if available, or else the <span
    title="dom-document-title">document title</span>, of the
-   <span>active document</span> of the <span>script browsing
-   context</span> of the script that invoked the method.</li>
+   <span>active document</span> of the <span title="script's browsing
+   context">browsing context</span> of the <span title="concept-script">script</span> that invoked the
+   method.</li>
 
    <li>An icon chosen from the <span title="external resource
    link">external resource links</span> of type <code
@@ -39229,11 +39669,12 @@
   <p>User agents should support user interaction with notifications,
   if and as appropriate given the platform conventions. If a user
   activates a notification, and the <var title="">onclick</var>
-  callback argument was present and is not null, then the <span>script
-  browsing context</span> of the function given by <var
-  title="">onclick</var> should be brought to the user's attention,
-  and the <var title="">onclick</var> callback should then be
-  invoked.</p>
+  callback argument was present and is not null, then the <span
+  title="script's browsing context">browsing context</span> of the
+  <span title="concept-script">script</span> of the function given by
+  <var title="">onclick</var> should be brought to the user's
+  attention, and the <var title="">onclick</var> callback should then
+  be invoked.</p>
 
 
 
@@ -39425,9 +39866,8 @@
     first occurrence of the exact literal string "<code>%s</code>"
     with an escaped version of the URL of the content in question (as
     defined below), then <span title="resolve a url">resolve</span>
-    the resulting URL (using the <span>document base URL</span> of the
-    <span>script document context</span> of the script that originally
-    invoked the <code
+    the resulting URL (using the <span title="script's base URL">base
+    URL</span> of the script that originally invoked the <code
     title="dom-navigator-registerContentHandler">registerContentHandler()</code>
     or <code
     title="dom-navigator-registerProtocolHandler">registerProtocolHandler()</code>
@@ -41839,8 +42279,9 @@
   <p>Navigation for the <code
   title="dom-location-assign">assign()</code> and <code
   title="dom-location-replace">replace()</code> methods must be done
-  with the <span>script browsing context</span> of the script that
-  invoked the method as the <span>source browsing context</span>.</p>
+  with the <span title="script's browsing context">browsing
+  context</span> of the script that invoked the method as the
+  <span>source browsing context</span>.</p>
 
 <!--XXX
   <dfn title="dom-location-reload"><code>reload()</code></dfn>
@@ -42090,7 +42531,7 @@
     synchronous, but if fetching the resource depends on external
     resources, as it usually does for URLs that use HTTP or other
     networking protocols, then at this point the user agents must
-    yield to whatever script invoked the navigation steps, if they
+    yield to whatever <span title="concept-script">script</span> invoked the navigation steps, if they
     were invoked by script.</p>
 
    </li>
@@ -42279,19 +42720,11 @@
    <li><p class="XXX">pause for scripts -- but don't use the
    "pause" definition since that involves not running script!</p></li>
 
-   <li><p class="XXX">onbeforeunload, and if present set flag that we will kill document</p></li>
-   <!--
-   when we define onbeforeunload, then we have to say that the JS
-   implementation of EventListener::handleEvent checks for that event,
-   treating the return value as the string to use for the unload warning
-   message if there is a return value, and calling preventDefault if
-   there isn't.
-   -->
+   <li><p><span title="unload a document">Unload</span> the
+   <code>Document</code> object of the <span>current entry</span>,
+   with the <var title="">recycle</var> parameter set to
+   false.</p></li>
 
-   <li><p class="XXX">onunload, and if present set flag that we will kill document</p></li>
-
-   <li><p class="XXX">if flag is set: <span title="discard a document">discard the <code>Document</code></span></p></li>
-
    <li>
 
     <dl>
@@ -42692,8 +43125,8 @@
 
     <ol>
 
-     <li class="XXX">freeze any timers, intervals,
-     XMLHttpRequests, database transactions, etc</li>
+     <li>Freeze the <span>active document</span>'s <span>current
+     script group</span>.</li>
 
      <li>The user agent must move any properties that have been added
      to the browsing context's default view's <code>Window</code>
@@ -42756,8 +43189,8 @@
      <span>list of added properties</span> to browsing context's
      default view's <code>Window</code> object.</li>
 
-     <li class="XXX">unfreeze any timers, intervals,
-     XMLHttpRequests, database transactions, etc</li>
+     <li>Unfreeze the <span>active document</span>'s <span>current
+     script group</span>.</li>
 
     </ol>
 
@@ -42801,27 +43234,94 @@
   affect .watch() when seen from other Windows?</p>
 
 
-  <h4>Closing a browsing context</h4>
 
-  <p class="XXX">Closing a browsing context and discarding it
-  (vs closing it and keeping it around in memory).</p>
+  <h4>Unloading documents</h4>
 
-  <p class="XXX">when a browsing context is closed, all session
-  history entries' <code>Document</code> objects must be
-  discarded.</p>
+  <p>When a user agent is to <dfn>unload a document</dfn>, it must run
+  the following steps. These steps are passed an argument, <var
+  title="">recycle</var>, which is either true or false, indicating
+  whether the <code>Document</code> object is going to be
+  re-used. (This is set by the <code
+  title="dom-document-open">document.open()</code> method.)</p>
 
-  <p class="XXX">When a user agent is to <dfn>discard a
-  <code>Document</code></dfn>, any frozen timers, intervals,
-  XMLHttpRequests, database transactions, etc, must be killed, and any
-  MessagePorts owned by the Window object must be
-  unentangled.</p>
+  <ol>
 
-  <p class="XXX">Also, <code title="event-unload">unload</code>
-  events should fire.</p>
+   <li><p>Set <var title="">salvageable</var> to true.</p></li>
 
+   <li><p>Let <var title="">event</var> be a new
+   <code>BeforeUnloadEvent</code> event object with the name <code
+   title="event-beforeunload">beforeunload</code>, with no namespace,
+   which does not bubble but is cancelable.</p></li>
 
+   <li><p>Dispatch <var title="">event</var> at <span>the
+   <code>body</code> element</span>.</p></li>
 
+   <li><p>If any event listeners were triggered by the previous step,
+   then set <var title="">salvageable</var> to false.</p></li>
 
+   <li>
+
+    <p>If the <code
+    title="dom-BeforeUnloadEvent-returnValue">returnValue</code>
+    attribute of the <var title="">event</var> object is not the empty
+    string, or if the event was canceled, then the user agent should
+    ask the user to confirm that they wish to unload the document.</p>
+
+    <p>The prompt shown by the user agent may include the string of
+    the <code
+    title="dom-BeforeUnloadEvent-returnValue">returnValue</code>
+    attribute, or some leading subset thereof. (A user agent may want
+    to truncate the string to 1024 characters for display, for
+    instance.)</p>
+
+    <p>The user agent must <span>pause</span> while waiting for the
+    user's response.</p>
+
+    <p>If the user <dfn>refused to allow the document to be
+    unloaded</dfn> then these steps must be aborted.</p>
+
+   </li>
+
+   <li><p><span>Fire a simple event</span> called <code
+   title="event-unload">unload</code> at <span>the <code>body</code>
+   element</span>.</p></li>
+
+   <li><p>If any event listeners were triggered by the previous step,
+   then set <var title="">salvageable</var> to false.</p></li>
+
+   <li><p>If there are any outstanding transactions that have
+   callbacks that involve <span title="concept-script">scripts</span>
+   that are in the document's <span>current script group</span>, roll
+   them back (without invoking any of the callbacks) and set <var
+   title="">salvageable</var> to false.</p>
+
+   <li><p>If <var title="">salvageable</var> and <var
+   title="">recycle</var> are both false, <span title="discard a
+   document">discard the <code>Document</code></span>.</p></li>
+
+  </ol>
+
+
+
+  <h5>Event definition</h5>
+
+  <pre class="idl">interface <dfn>BeforeUnloadEvent</dfn> : Event {
+           attribute DOMString <span title="dom-BeforeUnloadEvent-returnValue">returnValue</span>;
+};</pre>
+
+  <p class="note">There are no <code>BeforeUnloadEvent</code>-specific
+  initialization methods.</p>
+
+  <p>The <dfn
+  title="dom-BeforeUnloadEvent-returnValue"><code>returnValue</code></dfn>
+  attribute represents the message to show the user. When the event is
+  created, the attribute must be set to the empty string. On getting,
+  it must return the last value it was set to. On setting, the
+  attribute must be set to the new value.</p>
+
+
+
+
   <h3>Structured client-side storage</h3>
 
   <h4 id="storage">Storing name/value pairs</h4>
@@ -43080,14 +43580,14 @@
   separate, not affecting each other in any way.</p>
 
   <p>When a new <span>top-level browsing context</span> is created by
-  a script in an existing <span>browsing context</span>, or by the
-  user following a link in an existing browsing context, or in some
-  other way related to a specific <code>HTMLDocument</code>, then the
-  session storage area of the <span>origin</span> of that
-  <code>HTMLDocument</code> must be copied into the new browsing
-  context when it is created.  From that point on, however, the two
-  session storage areas must be considered separate, not affecting
-  each other in any way.</p>
+  a <span title="concept-script">script</span> in an existing
+  <span>browsing context</span>, or by the user following a link in an
+  existing browsing context, or in some other way related to a
+  specific <code>HTMLDocument</code>, then the session storage area of
+  the <span>origin</span> of that <code>HTMLDocument</code> must be
+  copied into the new browsing context when it is created.  From that
+  point on, however, the two session storage areas must be considered
+  separate, not affecting each other in any way.</p>
 
   <p id="sessionStorageEvent">When the <code
   title="dom-Storage-setItem">setItem()</code>, <code
@@ -50206,11 +50706,11 @@
   <ol>
 
    <li><p><span>Create a new <code>MessagePort</code> object</span>
-   owned by the <span>script execution context</span>, and let <var
+   owned by the <span>script's global object</span>, and let <var
    title="">port1</var> be that object.</p></li>
 
    <li><p><span>Create a new <code>MessagePort</code> object</span>
-   owned by the <span>script execution context</span>, and let <var
+   owned by the <span>script's global object</span>, and let <var
    title="">port2</var> be that object.</p></li>
 
    <li><p><span>Entangle</span> the <var title="">port1</var> and <var
@@ -50265,8 +50765,8 @@
   initially closed.</p>
 
   <p>When the user agent is to <dfn>create a new
-  <code>MessagePort</code> object</dfn> owned by a <span>script
-  execution context</span> object <var title="">owner</var>, it must
+  <code>MessagePort</code> object</dfn> owned by a <span>script's
+  global object</span> object <var title="">owner</var>, it must
   instantiate a new <code>MessagePort</code> object, and let its owner
   be <var title="">owner</var>.</p>
 
@@ -50428,7 +50928,7 @@
    argument.</p></li>
 
    <li><p><span>Create a new <code>MessagePort</code> object</span>
-   owned by the <span>script execution context</span>, and let <var
+   owned by the <span>script's global object</span>, and let <var
    title="">port1</var> be that object.</p></li>
 
    <li><p>If the <var title="">source port</var> is not entangled with
@@ -50567,7 +51067,7 @@
 
 
 
-  <h5>Ports and browsing contexts</h5>
+  <h5 id="message-port-discarding">Ports and browsing contexts</h5>
 
   <p>When a <code>Document</code> is <span title="discard a
   document">discarded</span>, if there are any
@@ -50577,7 +51077,7 @@
    <li>are entangled, and</li>
    <li>are owned by the <span>browsing context</span> that contained that <code>Document</code>, and</li>
    <li>were created while that <code>Document</code> was the <span>active document</span> of that <span>browsing context</span>, and</li>
-   <li>are entangled with a port that is either not owned by that <span>browsing context</span> or was not created while that <code>Document</code> was the <span>active document</span> of that <span>browsing context</span>,</li>
+   <li>are entangled with a port that is either not owned by that <span>browsing context</span>, or were not created while that <code>Document</code> was the <span>active document</span> of that <span>browsing context</span>,</li>
   </ul>
 
   <p>...then the user agent must run the following steps for each such
@@ -52714,10 +53214,10 @@
 
   <h5>The scripting state</h5>
 
-  <p>The <dfn>scripting flag</dfn> is set to "enabled" if the
-  <code>Document</code> with which the parser is associated was
-  <span>with script</span> when the parser was created, and "disabled"
-  otherwise.</p>
+  <p>The <dfn>scripting flag</dfn> is set to "enabled" if the <span
+  title="concept-n-script">scripting was enabled</span> for the
+  <code>Document</code> with which the parser is associated when the
+  parser was created, and "disabled" otherwise.</p>
 
 
   <h4><dfn>Tokenization</dfn></h4>
@@ -58963,8 +59463,11 @@
   <code>Window</code> object on which the <code
   title="setTimeout">setTimeout()</code> method was invoked.</p>
 
-  <p class="XXX">Need to define <var title="">language</var>
-  values.</p>
+  <p class="XXX">Need to define <var title="">language</var> values;
+  need to define that the <span title="concept-script">script</span>
+  corresponding to the <var title="">code</var> argument is created
+  before the timer is set up, so that the rule on pausing the ticker,
+  below, makes sense.</p>
 
   <p>The <dfn
   title="dom-windowtimers-setInterval"><code>setInterval(...)</code></dfn>
@@ -58988,8 +59491,15 @@
   with a value that does not correspond to an active timeout or
   interval, the methods must return without doing anything.</p>
 
+  <p>For both <code
+  title="dom-windowtimers-setTimeout">setTimeout()</code> and <code
+  title="dom-windowtimers-setInterval">setInterval()</code>, the clock
+  upon which the timers are based must only tick while the
+  <span>script group</span> of their callbacks is not
+  <i>frozen</i>.</p>
 
 
+
   <h3>Rendering and the DOM</h3>
 
   <p class="XXX">This section is expected to be moved to its own




More information about the Commit-Watchers mailing list