Skip to content

Commit

Permalink
integrated notes from smparkes
Browse files Browse the repository at this point in the history
  • Loading branch information
client9 committed Mar 22, 2010
1 parent d384f42 commit 701dd59
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/html/script.js
Expand Up @@ -31,7 +31,8 @@ __extend__(HTMLScriptElement.prototype, {
var imax = kids.length;
for (var i = 0; i < imax; ++i) {
kid = kids[i];
if (kid.nodeType == Node.TEXT_NODE || kid.nodeType == Node.CDATA_SECTION_NODE) {
if (kid.nodeType == Node.TEXT_NODE ||
kid.nodeType == Node.CDATA_SECTION_NODE) {
s += kid.nodeValue;
}
}
Expand All @@ -40,16 +41,31 @@ __extend__(HTMLScriptElement.prototype, {

/**
* HTML5 spec "Can be set, to replace the element's children with
* the given value." It *does not* execute the script!
* the given value."
*/
set text(value) {
// this deletes all children, and make a new single text node
// with value
this.textContent = value;

// it does not execute, but leaving this in for now
// only when the script is added THE FIRST time does
// this execute.
/* Currently we always execute, but this isn't quite right if
* the node has *not* been inserted into the document, then it
* should *not* fire. The more detailed answer from the spec:
*
* When a script element that is neither marked as having
* "already started" nor marked as being "parser-inserted"
* experiences one of the events listed in the following list,
* the user agent must synchronously run the script element:
*
* * The script element gets inserted into a document.
* * The script element is in a Document and its child nodes
* are changed.
* * The script element is in a Document and has a src
* attribute set where previously the element had no such
* attribute.
*
* And no doubt there are other cases as well.
*/
Envjs.loadInlineScript(this);
},

Expand Down

1 comment on commit 701dd59

@smparkes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there are lots of other cases, particularly the whole "parser inserted" stuff, which is complicated in the env.js case because we use the parser to parse innerHTML ... and in the case of innerHTML, it seems like scripts added via innerHTML directly into the doc should never get executed, but adding a script tag via innerHTML on an element not yet in the document and then adding that element to the document does get run when finally added.

Lots of corner cases.

I've got a hacked version of some of this in my fork, but nothing that should be integrated into 1.2.

Please sign in to comment.