| 79 |
this.input = i; |
this.input = i; |
| 80 |
this.scriptsExecutedAfterParsing = []; |
this.scriptsExecutedAfterParsing = []; |
| 81 |
this.scriptsExecutedSoon = []; |
this.scriptsExecutedSoon = []; |
| 82 |
|
this.scriptsExecutedAsynchronously = []; |
| 83 |
} // Parser |
} // Parser |
| 84 |
|
|
| 85 |
Parser.prototype.getNextToken = function () { |
Parser.prototype.getNextToken = function () { |
| 336 |
|
|
| 337 |
// "When a script completes loading" rules start applying. |
// "When a script completes loading" rules start applying. |
| 338 |
|
|
| 339 |
// List of scripts that will execute as soon as possible |
while (this.scriptsExecutedSoon.length > 0 || |
| 340 |
for (var i = 0; i < this.scriptsExecutedSoon.length; i++) { |
this.scriptsExecutedAsynchronously.length > 0) { |
| 341 |
var e = this.scriptsExecutedSoon[i]; |
// Handle "list of scripts that will execute as soon as possible". |
| 342 |
|
while (this.scriptsExecutedSoon.length > 0) { |
| 343 |
|
var e = this.scriptsExecutedSoon.shift (); |
| 344 |
|
|
| 345 |
|
// If it has completed loading |
| 346 |
|
log ('Execute an external script not inserted by parser...'); |
| 347 |
|
executeScript (this.doc, e); |
| 348 |
|
|
| 349 |
|
// NOTE: It MAY be executed before the end of the parsing, according |
| 350 |
|
// to the spec. |
| 351 |
|
this.hasAsyncScript = true; |
| 352 |
|
} |
| 353 |
|
|
| 354 |
|
// Handle "list of scripts that will execute asynchronously". |
| 355 |
|
while (this.scriptsExecutedAsynchronously.length > 0) { |
| 356 |
|
var e = this.scriptsExecutedAsynchronously.shift (); |
| 357 |
|
|
| 358 |
|
// Step 1. |
| 359 |
|
// We assume that all scripts have been loaded at this time. |
| 360 |
|
|
| 361 |
|
// Step 2. |
| 362 |
|
log ('Execute an asynchronous script...'); |
| 363 |
|
executeScript (this.doc, e); |
| 364 |
|
|
| 365 |
|
// Step 3. |
| 366 |
|
// |
| 367 |
|
|
| 368 |
|
// Step 4. |
| 369 |
|
// |
| 370 |
|
|
| 371 |
// If it has completed loading |
this.hasAsyncScript = true; |
| 372 |
log ('Execute an external script not inserted by parser...'); |
} |
|
executeScript (this.doc, e); |
|
|
|
|
|
// NOTE: It MAY be executed before the end of the parsing, according |
|
|
// to the spec. |
|
|
this.hasAsyncScript = true; |
|
| 373 |
} |
} |
| 374 |
|
|
|
// TODO: Handles |
|
|
// "list of scripts that will execute asynchronously" |
|
|
|
|
| 375 |
// Handle "list of scripts that will execute when the document has finished |
// Handle "list of scripts that will execute when the document has finished |
| 376 |
// parsing". |
// parsing". |
| 377 |
var list = this.scriptsExecutedAfterParsing; |
var list = this.scriptsExecutedAfterParsing; |
| 465 |
p.scriptsExecutedAfterParsing.push (e); |
p.scriptsExecutedAfterParsing.push (e); |
| 466 |
log ('Running a script: aborted (defer)'); |
log ('Running a script: aborted (defer)'); |
| 467 |
} else if (e.async && e.src != null) { |
} else if (e.async && e.src != null) { |
| 468 |
// TODO |
p.scriptsExecutedAsynchronously.push (e); |
| 469 |
} else if (e.async && e.src == null |
log ('Running a script: aborted (async src)'); |
| 470 |
/* && list of scripts that will execute asynchronously is not empty */) { |
} else if (e.async && e.src == null && |
| 471 |
// TODO |
p.scriptsExecutedAsynchronously.length > 0) { |
| 472 |
|
p.scriptsExecutedAsynchronously.push (e); |
| 473 |
|
log ('Running a script: aborted (async)'); |
| 474 |
|
// ISSUE: What is the difference with the case above? |
| 475 |
} else if (e.src != null && e.manakaiParserInserted) { |
} else if (e.src != null && e.manakaiParserInserted) { |
| 476 |
if (p.scriptExecutedWhenParserResumes) { |
if (p.scriptExecutedWhenParserResumes) { |
| 477 |
log ('Error: There is a script that will execute as soon as the parser resumes.'); |
log ('Error: There is a script that will execute as soon as the parser resumes.'); |
| 816 |
the regular expression <code>^javascript:\s*(?:"[^"]*"|'[^']*')\s*$</code>. |
the regular expression <code>^javascript:\s*(?:"[^"]*"|'[^']*')\s*$</code>. |
| 817 |
<li>Only supports <code>\u<var>HHHH</var></code> escapes in JavaScript |
<li>Only supports <code>\u<var>HHHH</var></code> escapes in JavaScript |
| 818 |
string literals. |
string literals. |
| 819 |
|
<li>Does not handle <i>stop parsing</i> phase correctly if the document is |
| 820 |
|
replaced by <code>document.open ()</code> call. In other word, delayed |
| 821 |
|
(deferred or asynchronous) script executions and event firings might be |
| 822 |
|
treated in a wrong way if a <code>document.open ()</code> invocation |
| 823 |
|
is implicitly done by <code>document.write ()</code> in a delayed script. |
| 824 |
</ul> |
</ul> |
| 825 |
|
|
| 826 |
<p>For some reason, this parser does not work in browsers that do |
<p>For some reason, this parser does not work in browsers that do |
| 827 |
not support JavaScript 1.5. |
not support JavaScript 1.5. |
| 828 |
|
|
| 829 |
|
<!-- TODO: |src| attribute value should refer the value at the time |
| 830 |
|
when it is inserted into the document, not the value when the script is |
| 831 |
|
executed. Currently it does not matter, since we don't allow dynamic |
| 832 |
|
modification to the |src| content/DOM attribute value yet. --> |
| 833 |
|
|
| 834 |
<!-- TODO: license --> |
<!-- TODO: license --> |
| 835 |
|
|
| 836 |
</body> |
</body> |