C. Scott Ananian has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/386010 )
Change subject: Only use our hacked Node#normalize if domino is old
......................................................................
Only use our hacked Node#normalize if domino is old
We used a hacky reimplementation of Node#normalize to work around
a slow array-based DOM implementation in domino; if domino is
new enough, this will break (because Node#childNodes isn't writable).
Use the built-in Node#normalize in that case instead.
Change-Id: Ifdf176e6876bb9f8d861d21feedeea913d36841c
---
M lib/wt2html/pp/processors/normalize.js
1 file changed, 19 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/10/386010/1
diff --git a/lib/wt2html/pp/processors/normalize.js
b/lib/wt2html/pp/processors/normalize.js
index 22b12ac..73a03ef 100644
--- a/lib/wt2html/pp/processors/normalize.js
+++ b/lib/wt2html/pp/processors/normalize.js
@@ -1,6 +1,18 @@
'use strict';
var domino = require('domino');
+
+// Test for domino > 1.0.29, where childNodes was made a proper read-only
+// property. Not coincidentally, the workaround below for a slow implementation
+// of Node#normalize in domino became unnecessary after 1.0.29.
+var DOMINO_AFTER_1_0_29 = false;
+try {
+ domino.createDocument('test').body.childNodes = new
domino.impl.NodeList();
+} catch (e) {
+ DOMINO_AFTER_1_0_29 = true;
+}
+
+
var DU = require('../../../utils/DOMUtils').DOMUtils;
// Like Node.normalize() but it clones the childNodes arrays in order to avoid
@@ -56,12 +68,18 @@
newChunks.push(kids.slice(chunkStart));
}
// Clone childNodes by concatenating the chunks
+ // XXX: childNodes isn't really writable in DOM; this only works
+ // for domino <= 1.0.29
parent.childNodes = new
domino.impl.NodeList([].concat.apply([], newChunks));
}
}
function normalize(body, env) {
- normalizeNode(body);
+ if (DOMINO_AFTER_1_0_29) {
+ body.normalize();
+ } else {
+ normalizeNode(body);
+ }
}
if (typeof module === "object") {
--
To view, visit https://gerrit.wikimedia.org/r/386010
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifdf176e6876bb9f8d861d21feedeea913d36841c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits