Skip to content

Commit

Permalink
[] (0) Revamp and clean up the concept of script execution contexts.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.whatwg.org/webapps@1658 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed May 21, 2008
1 parent e3ec31d commit 32e5ea3
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 142 deletions.
182 changes: 106 additions & 76 deletions index
Original file line number Diff line number Diff line change
Expand Up @@ -23548,10 +23548,9 @@ XXXDVT (also check for '- -' bits in the part above) -->
href="#the-scripts">the script's type</a></var> (see the <a
href="#scriptingLanguages">scripting languages</a> section below).</p>

<p>Scripts must be executed in the scope of the <a
href="#browsing1">browsing context</a> of the element's
<code>Document</code>. The <a href="#script2">script execution
browsing context</a> is that browsing context.</p>
<p>The <a href="#script2">script execution context</a> of the script
must be the <code><a href="#window">Window</a></code> object of that
<a href="#browsing1">browsing context</a>.</p>

<p class=note>The element's attributes' values might have changed
between when the element was inserted into the document and when the
Expand Down Expand Up @@ -28655,8 +28654,15 @@ never reset. This is nice and consistent.)
href="#browsing1">browsing context</a> was just created as part of the <a
href="#the-rules">the rules for chosing a browsing context given a
browsing context name</a>. The navigation must be done with the <a
href="#script2">script execution browsing context</a> of the script that
invoked the method as the <a href="#source0">source browsing context</a>.
href="#browsing1">browsing context</a> corresponding to the <code><a
href="#window">Window</a></code> object that is the <a
href="#script2">script execution context</a> of the script that invoked
the method as the <a href="#source0">source browsing context</a>.

<p class=note>If the <a href="#script2">script execution context</a> of a
script isn't a <code><a href="#window">Window</a></code> object, then it
can't ever get to a <code><a href="#window">Window</a></code> object to
call this method.

<p>The method must return the <code><a href="#window">Window</a></code>
object of the default view of the <a href="#browsing1">browsing
Expand Down Expand Up @@ -28860,8 +28866,9 @@ never reset. This is nice and consistent.)
protocol"><code>javascript:</code> URI</a>

<dd>The <a href="#origin0">origin</a> is equal to the <a
href="#origin0">origin</a> of the script of that
<code>javascript:</code> URI.
href="#origin0">origin</a> of the script of that <a
href="#the-javascript" title="javascript
protocol"><code>javascript:</code> URI</a>.

<dt>If a <code>Document</code> or image was served over the network and
has an address that uses a URI scheme with a server-based naming
Expand Down Expand Up @@ -29084,39 +29091,41 @@ never reset. This is nice and consistent.)

<h4 id=script0><span class=secno>4.4.1 </span>Script execution contexts</h4>

<p>The <dfn id=script2>script execution browsing context</dfn> of a script
is defined when that script is created. It is typically the <a
href="#browsing1">browsing context</a> of the <code><a
href="#window">Window</a></code> object that is being used as the script's
dereference context.
<p>The <dfn id=script2>script execution context</dfn> of a script is
defined when that script is created. It is typically a <code><a
href="#window">Window</a></code> object.

<p>All <a href="#browsing1" title="browsing context">browsing contexts</a>
are, by definition, potential <a href="#script2" title="script execution
browsing context">script execution browsing contexts</a>.
<p>A <a href="#script2">script execution context</a> always has an
associated <a href="#browsing1">browsing context</a>. If the <a
href="#script2">script execution context</a> is a <code><a
href="#window">Window</a></code> object, then that object's <a
href="#browsing1">browsing context</a> is it. Otherwise, the <a
href="#script2">script execution context</a> is associated explicitly with
a <a href="#browsing1">browsing context</a> when it is created.

<p>It is said that <dfn id=scripting1>scripting is disabled</dfn> in a <a
href="#script2">script execution browsing context</a> when any of the
following conditions are true:
href="#script2">script execution context</a> when any of the following
conditions are true:

<ul>
<li>The user agent does not support scripting.

<li>The user has disabled scripting for this <a href="#script2">script
execution browsing 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="#script2"
title="script execution browsing context">script execution browsing
contexts</a>.)
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="#script2" title="script
execution context">script execution contexts</a>.)

<li id=designModeScriptBlocked>The <a href="#script2">script execution
browsing context</a> is a <a href="#browsing1">browsing context</a> whose
<a href="#active">active document</a> has <code
context</a>'s associated <a href="#browsing1">browsing context</a>'s <a
href="#active">active document</a> has <code
title=dom-document-designMode><a href="#designMode">designMode</a></code>
enabled.

<li id=sandboxScriptBlocked>The <a href="#script2">script execution
browsing context</a> is a <a href="#browsing1">browsing context</a> whose
<a href="#sandboxed3">sandboxed scripts browsing context flag</a> is set.
context</a>'s associated <a href="#browsing1">browsing context</a> has
the <a href="#sandboxed3">sandboxed scripts browsing context flag</a>
set.
</ul>

<p>A node is said to be <dfn id=without>without script</dfn> if either the
Expand All @@ -29133,9 +29142,8 @@ never reset. This is nice and consistent.)
are less confusing are also way, way longer.

<p>When a script is to be executed in a <a href="#script2">script execution
browsing context</a> in which <a href="#scripting1">scripting is
disabled</a>, the script must do nothing and return nothing (a void return
value).
context</a> in which <a href="#scripting1">scripting is disabled</a>, the
script must do nothing and return nothing (a void return value).

<p class=note>Thus, for instance, enabling <code
title=dom-document-designMode><a href="#designMode">designMode</a></code>
Expand All @@ -29150,48 +29158,51 @@ never reset. This is nice and consistent.)
id=the-javascript title="javascript protocol">The <code
title="">javascript:</code> protocol</dfn></h4>

<p>A URI using the <code title="">javascript:</code> protocol must, if
evaluated, be evaluated using the in-context evaluation operation defined
for <code title="">javascript:</code> URIs. <a
href="#refsJSURI">[JSURI]</a></p>
<p>A URI using the <code title="">javascript:</code> protocol must, if and
when dereferenced, be evaluated by executing the script obtained using the
content retrieval operation defined for <code title="">javascript:</code>
URIs. <a href="#refsJSURI">[JSURI]</a></p>
<!--
JSURI: 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 browsing context is <a href="#navigate"
<p>When a <a href="#browsing1">browsing context</a> is <a href="#navigate"
title=navigate>navigated</a> to a <code>javascript:</code> URI, and the <a
href="#active">active document</a> of that browsing context has the <a
href="#same-origin">same origin</a> as the script given by that URI, the
dereference context must be the <a href="#browsing1">browsing context</a>
being navigated. The <a href="#script2">script execution browsing
context</a> in that case is that same <a href="#browsing1">browsing
context</a>.</p>
<!-- (redundant with next paragraph)
<p>When a browsing context is <span
title="navigate">navigated</span> to a <code>javascript:</code> URI,
and the <span>active document</span> of that browsing context has a
an <span>origin</span> that is <em>not</em> the <span title="same
origin">same</span> as that of the script given by the URI, the
dereference context must be an empty object.</p>
-->

<p>Otherwise, the dereference context must be an empty object, and there is
no <a href="#script2">script execution browsing context</a>.
<a href="#script2">script execution context</a> must be the <code><a
href="#window">Window</a></code> object of the <a
href="#browsing1">browsing context</a> being navigated.

<p>URIs using the <code title="">javascript:</code> protocol should be
evaluated when the resource for that URI is needed.

<p>If the dereference by-product is void (there is no return value), then
the URI must be treated in a manner equivalent to an HTTP resource with an
HTTP 204 No Content response.
<p>When a browsing context is <a href="#navigate"
title=navigate>navigated</a> to a <code>javascript:</code> URI, and the <a
href="#active">active document</a> of that browsing context has an <a
href="#origin0">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 URI, the
<a href="#script2">script execution context</a> must be an empty object,
and the <a href="#script2">script execution context</a>'s associated <a
href="#browsing1">browsing context</a> must be the <a
href="#browsing1">browsing context</a> being <a href="#navigate"
title=navigate>navigated</a>.

<p>Otherwise, the <a href="#script2">script execution context</a> must be
an empty object, and the <a href="#script2">script execution context</a>'s
associated <a href="#browsing1">browsing context</a> must be the <a
href="#browsing1">browsing context</a> of the <code>Document</code> object
of the element, attribute, or style sheet from which the
<code>javascript:</code> URI was reached.

<p>If the result of executing the script is void (there is no return
value), then the URI must be treated in a manner equivalent to an HTTP
resource with an HTTP 204 No Content response.

<p>Otherwise, the URI must be treated in a manner equivalent to an HTTP
resource with a 200 OK response whose <a href="#content-type8"
title=Content-Type>Content-Type metadata</a> is <code
title="">text/html</code> and whose response body is the dereference
by-product, converted to a string value.
title="">text/html</code> and whose response body is the return value
converted to a string value.

<p class=note>Certain contexts, in particular <code><a
href="#img">img</a></code> elements, ignore the <a href="#content-type8"
Expand Down Expand Up @@ -29219,6 +29230,11 @@ JSURI: http://ietfreport.isoc.org/all-ids/draft-hoehrmann-javascript-scheme-00.t
context</a>.</p>
</div>

<p class=note>The rules for handling script execution in a <a
href="#script2">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.

<h4 id=events><span class=secno>4.4.4 </span>Events</h4>

<p class=big-issue>We need to define how to handle events that are to be
Expand Down Expand Up @@ -29261,24 +29277,25 @@ JSURI: http://ietfreport.isoc.org/all-ids/draft-hoehrmann-javascript-scheme-00.t
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 <a href="#browsing1">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).
<code>Document</code> object, to the <code><a
href="#window">Window</a></code> object of the <a
href="#browsing1">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 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>The <a href="#script2">script execution browsing context</a> of the
event handler must be the <a href="#browsing1">browsing context</a> at the
end of the scope chain.
<p>The <a href="#script2">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.

<p class=issue>How do we allow non-JS event handlers?
<p class=big-issue>How do we allow non-JS event handlers?

<p><dfn id=event4>Event handler DOM attributes</dfn>, on setting, must set
the corresponding event handler attribute to their new value, and on
Expand Down Expand Up @@ -29904,9 +29921,15 @@ JSURI: http://ietfreport.isoc.org/all-ids/draft-hoehrmann-javascript-scheme-00.t
<li>
<p><a href="#navigate">Navigate</a> the new browsing context to <var
title="">url</var>, with <a href="#replacement">replacement enabled</a>,
and with the <a href="#script2">script execution browsing context</a> of
the script that invoked the method as the <a href="#source0">source
browsing context</a>.</p>
and with the <a href="#browsing1">browsing context</a> of the <code><a
href="#window">Window</a></code> object that is the <a
href="#script2">script execution context</a> of the script that invoked
the method as the <a href="#source0">source browsing context</a>.</p>

<p class=note>If the <a href="#script2">script execution context</a> of a
script isn't a <code><a href="#window">Window</a></code> object, then it
can't ever get to a <code><a href="#window">Window</a></code> object to
call this method.</p>

<li>
<p>Wait for the browsing context to be closed. (The user agent must allow
Expand Down Expand Up @@ -32115,8 +32138,15 @@ JSURI: http://ietfreport.isoc.org/all-ids/draft-hoehrmann-javascript-scheme-00.t
<p>Navigation for the <code title=dom-location-assign><a
href="#assign">assign()</a></code> and <code title=dom-location-replace><a
href="#replace">replace()</a></code> methods must be done with the <a
href="#script2">script execution browsing context</a> of the script that
invoked the method as the <a href="#source0">source browsing context</a>.
href="#browsing1">browsing context</a> of the <code><a
href="#window">Window</a></code> object that is the <a
href="#script2">script execution context</a> of the script that invoked
the method as the <a href="#source0">source browsing context</a>.

<p class=note>If the <a href="#script2">script execution context</a> of a
script isn't a <code><a href="#window">Window</a></code> object, then it
can't ever get to a <code><a href="#location2">Location</a></code> object
to call these methods.

<p>Relative <var title="">url</var> arguments for <code
title=dom-location-assign><a href="#assign">assign()</a></code> and <code
Expand Down
Loading

0 comments on commit 32e5ea3

Please sign in to comment.