jenkins-bot has submitted this change and it was merged.
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 User Agents
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, 13 insertions(+), 6 deletions(-)
Approvals:
Krinkle: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ve.js b/modules/ve/ve.js
index a426c87..b6f8e00 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;
+ 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).
@@ -743,8 +750,8 @@
// object...), so we're detecting that and using the innerHTML
hack described above.
// Create an invisible iframe
- var newDocument, $iframe = $( '<iframe frameborder="0"
width="0" height="0" />'),
- iframe = $iframe.get( 0 );
+ $iframe = $( '<iframe frameborder="0" width="0" height="0" />'
);
+ iframe = $iframe.get( 0 );
// Attach it to the document. We have to do this to get a new
document out of it
document.documentElement.appendChild( iframe );
// Write the HTML to it
--
To view, visit https://gerrit.wikimedia.org/r/120836
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie41cd0458e1814576fc91486208d4c81eef4b514
Gerrit-PatchSet: 8
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits