Parent Directory
|
Revision Log
|
Patch
| revision 1.8 by wakaba, Sun Apr 27 08:56:34 2008 UTC | revision 1.12 by wakaba, Sun Apr 27 11:21:09 2008 UTC | |
|---|---|---|
| # | Line 47 | Line 47 |
| 47 | var p = new Parser (new InputStream (v)); | var p = new Parser (new InputStream (v)); |
| 48 | var doc = p.doc; | var doc = p.doc; |
| 49 | p.parse (); | p.parse (); |
| 50 | ||
| 51 | log (dumpTree (doc, '')); | log (dumpTree (doc, '')); |
| 52 | ||
| 53 | if (p.hasAsyncScript) { | |
| 54 | log ('Some script codes are executed asynchronously; it means that the document might be rendered in different ways depending on the network condition and other factors'); | |
| 55 | } | |
| 56 | } | } |
| 57 | } // update2 | } // update2 |
| 58 | ||
| # | Line 73 | Line 78 |
| 78 | this.openElements = [doc]; | this.openElements = [doc]; |
| 79 | this.input = i; | this.input = i; |
| 80 | this.scriptsExecutedAfterParsing = []; | this.scriptsExecutedAfterParsing = []; |
| 81 | this.scriptsExecutedSoon = []; | |
| 82 | this.scriptsExecutedAsynchronously = []; | |
| 83 | } // Parser | } // Parser |
| 84 | ||
| 85 | Parser.prototype.getNextToken = function () { | Parser.prototype.getNextToken = function () { |
| # | Line 150 | Line 157 |
| 157 | tagName = v.toLowerCase (); | tagName = v.toLowerCase (); |
| 158 | return ''; | return ''; |
| 159 | }); | }); |
| 160 | e = e.replace (/^\s*([^\s=]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^"']+)))?/, | while (true) { |
| 161 | function (x, attrName, attrValue1, attrValue2, attrValue3) { | var m = false; |
| 162 | v = attrValue1 || attrValue2 || attrValue3; | e = e.replace (/^\s*([^\s=]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^"'\s]*)))?/, |
| 163 | v = v.replace (/"/g, '"').replace (/'/g, "'") | function (x, attrName, attrValue1, attrValue2, attrValue3) { |
| 164 | .replace (/&/g, '&'); | v = attrValue1 || attrValue2 || attrValue3; |
| 165 | attrs[attrName.toLowerCase ()] = v; | v = v.replace (/"/g, '"').replace (/'/g, "'") |
| 166 | return ''; | .replace (/&/g, '&'); |
| 167 | }); | attrs[attrName.toLowerCase ()] = v; |
| 168 | m = true; | |
| 169 | return ''; | |
| 170 | }); | |
| 171 | if (!m) break; | |
| 172 | } | |
| 173 | if (e.length) { | if (e.length) { |
| 174 | log ('Broken start tag: "' + e + '"'); | log ('Broken start tag: "' + e + '"'); |
| 175 | } | } |
| # | Line 324 | Line 336 |
| 336 | ||
| 337 | // "When a script completes loading" rules start applying. | // "When a script completes loading" rules start applying. |
| 338 | ||
| 339 | // TODO: Handles "list of scripts that will execute as soon as possible" | while (this.scriptsExecutedSoon.length > 0 || |
| 340 | // and "list of scripts that will execute asynchronously" | this.scriptsExecutedAsynchronously.length > 0) { |
| 341 | // 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 | this.hasAsyncScript = true; | |
| 372 | } | |
| 373 | } | |
| 374 | ||
| 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". |
| # | Line 420 | Line 465 |
| 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) { |