Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/120836

Change subject: Use DOMParser in ve.createDocumentFromHtml() if available
......................................................................

Use DOMParser in ve.createDocumentFromHtml() if available

This speeds up the tests significantly, at least in browsers
that support DOMParser:

VE core tests in Chrome 33: 12.5s -> 5.2s
VE-MW tests in Chrome 33: 32.9s -> 20.0s
VE core tests in PhantomJS: unchanged at 9.4s (no DOMParser support)

Bug: 57586
Change-Id: Ie41cd0458e1814576fc91486208d4c81eef4b514
---
M modules/ve/ve.js
1 file changed, 11 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/36/120836/1

diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index fd12b74..69e37f9 100644
--- a/modules/ve/ve.js
+++ b/modules/ve/ve.js
@@ -713,16 +713,23 @@
         * @returns {HTMLDocument} Document constructed from the HTML string
         */
        ve.createDocumentFromHtml = function ( html ) {
-               // Here's how this function should look:
+               // Try using DOMParser if available. This only works in Firefox 
12+ and very modern
+               // versions of other browsers (Chrome 30+, Opera 17+, IE10+)
+               var newDocument, $iframe, iframe, parser;
+               try {
+                       newDocument = new DOMParser().parseFromString( html, 
'text/html' );
+                       if ( newDocument ) {
+                               return newDocument;
+                       }
+               } catch ( e ) { }
+
+               // Here's what this fallback code should look like:
                //
                //     var newDocument = 
document.implementation.createHtmlDocument( '' );
                //     newDocument.open();
                //     newDocument.write( html );
                //     newDocument.close();
                //     return newDocument;
-               //
-               // (Or possibly something involving 
DOMParser.prototype.parseFromString, but that's Firefox-only
-               // for now.)
                //
                // Sadly, it's impossible:
                // * On IE 9, calling open()/write() on such a document throws 
an "Unspecified error" (sic).

-- 
To view, visit https://gerrit.wikimedia.org/r/120836
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie41cd0458e1814576fc91486208d4c81eef4b514
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to