Skip to content

Commit 1213951

Browse files
committed
remove e4x
1 parent 95c39f4 commit 1213951

File tree

4 files changed

+18
-109
lines changed

4 files changed

+18
-109
lines changed

common/content/commandline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ const CommandLine = Module("commandline", {
609609
action = this._echoMultiline;
610610
}
611611

612-
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(str) || typeof str == "xml" || str instanceof TemplateSupportsXML ) && !(flags & this.FORCE_SINGLELINE))
612+
if ((flags & this.FORCE_MULTILINE) || (/\n/.test(str) || str instanceof TemplateSupportsXML ) && !(flags & this.FORCE_SINGLELINE))
613613
action = this._echoMultiline;
614614

615615
if (single)

common/content/template.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Template = Module("template", {
3333
},
3434

3535
maybeXML: function maybeXML(val) {
36-
if (typeof val == "xml" || val instanceof TemplateSupportsXML)
36+
if (val instanceof TemplateSupportsXML)
3737
return val;
3838

3939
try {
@@ -120,8 +120,6 @@ const Template = Module("template", {
120120
if (processStrings && false)
121121
str = template.highlightFilter(str, "\n", function () xml`<span highlight="NonText">^J</span>`);
122122
return xml`<span highlight="Object">${str}</span>`;
123-
case "xml":
124-
return arg;
125123
default:
126124
return `<unknown type>`;
127125
}
@@ -181,7 +179,7 @@ const Template = Module("template", {
181179
},
182180

183181
highlightSubstrings: function highlightSubstrings(str, iter, highlight) {
184-
if (typeof str == "xml" || str instanceof TemplateSupportsXML)
182+
if (str instanceof TemplateSupportsXML)
185183
return str;
186184
if (str == "")
187185
return xml`${str}`;

common/content/util.js

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55

66
/** @scope modules */
77

8-
//xxx:
9-
this.$$Namespace = function (prefix, uri) {
10-
return "XMLList" in window ? Namespace(prefix, uri)
11-
: {
12-
prefix: prefix,
13-
uri: uri,
14-
toString: function () {
15-
return this.uri;
16-
},
8+
const {XHTML, XUL, NS} = (function () {
9+
function Namespace(prefix, uri) {
10+
this.prefix = prefix;
11+
this.uri = uri;
12+
}
13+
Namespace.prototype.toString = function toString() { return this.uri; };
14+
return {
15+
XHTML: new Namespace("html", "http://www.w3.org/1999/xhtml"),
16+
XUL : new Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"),
17+
NS : new Namespace("liberator", "http://vimperator.org/namespaces/liberator"),
1718
};
18-
}
19-
const XHTML = $$Namespace("html", "http://www.w3.org/1999/xhtml");
20-
const XUL = $$Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
21-
const NS = $$Namespace("liberator", "http://vimperator.org/namespaces/liberator");
22-
if ("XMLList" in window) eval("default xml namespace = XHTML");
23-
delete this.$$Namespace;
19+
})();
2420

2521
const Util = Module("util", {
2622
init: function () {
@@ -731,9 +727,6 @@ const Util = Module("util", {
731727
* @returns {Node|DocumentFragment}
732728
*/
733729
xmlToDom: function xmlToDom(node, doc, nodes) {
734-
if (typeof node === "xml")
735-
return this.xmlToDomForE4X(node, doc, nodes);
736-
737730
var dom = this.xmlToDomForTemplate(node, doc, nodes);
738731

739732
//xxx: change highlight's namespace
@@ -747,39 +740,6 @@ const Util = Module("util", {
747740
}
748741
return dom;
749742
},
750-
/**
751-
* Converts an E4X XML literal to a DOM node.
752-
*
753-
* @param {Node} node
754-
* @param {Document} doc
755-
* @param {Object} nodes
756-
* @returns {Node}
757-
* @deprecated
758-
* @see util.xmlToDom
759-
*/
760-
xmlToDomForE4X: function xmlToDomForE4X(node, doc, nodes) {
761-
if (node.length() != 1) {
762-
let domnode = doc.createDocumentFragment();
763-
for each (let child in node)
764-
domnode.appendChild(arguments.callee(child, doc, nodes));
765-
return domnode;
766-
}
767-
switch (node.nodeKind()) {
768-
case "text":
769-
return doc.createTextNode(String(node));
770-
case "element":
771-
let domnode = doc.createElementNS(node.namespace(), node.localName());
772-
for each (let attr in node.attributes())
773-
domnode.setAttributeNS(attr.name() == "highlight" ? NS.uri : attr.namespace(), attr.name(), String(attr));
774-
for each (let child in node.children())
775-
domnode.appendChild(arguments.callee(child, doc, nodes));
776-
if (nodes && node.attribute("key"))
777-
nodes[node.attribute("key")] = domnode;
778-
return domnode;
779-
default:
780-
return null;
781-
}
782-
},
783743
/**
784744
* Converts an string of TemplateXML object to a DOM node.
785745
*

common/modules/template-tag.js

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// vim: set fdm=marker:
2-
var EXPORTED_SYMBOLS = ["raw", "safehtml", "tmpl", "xml", "e4x", "cooked"];
2+
var EXPORTED_SYMBOLS = ["raw", "safehtml", "tmpl", "xml", "cooked"];
33

44
// {{{ escape function
55
//var obj1 = {};
@@ -248,9 +248,7 @@ function templateTmpl(portion, args) // {{{
248248
}
249249
}
250250
if (i >= j) break label_root;
251-
else if (typeof arg === "xml") {
252-
res += "`" + arg.toXMLString().replace(/([\\`])/g, "\\$1", "g") + "`";
253-
} else if (arg instanceof TemplateTmpl) {
251+
else if (arg instanceof TemplateTmpl) {
254252
res += "(" + arg.value + ")";
255253
} else if (arg instanceof TemplateXML) {
256254
res += "`" + arg.value.replace(/([\\`])/g, "\\$1", "g") + "`";
@@ -339,8 +337,6 @@ templateTmpl.map = function templateTmplMap(data, fn) {
339337
val = fn(data[i]);
340338
if (val instanceof TemplateTmpl)
341339
res += "(" + val.value + ")";
342-
else if (typeof val === "xml")
343-
res += encodeTmplXml(val.toXMLString());
344340
else if (val instanceof TemplateXML)
345341
res += encodeTmplXml(val.value);
346342
else
@@ -360,8 +356,6 @@ templateTmpl["+="] = function (self, value) {
360356
self.value += "(" + value.value + ")";
361357
else if (value instanceof TemplateXML)
362358
self.value += "`" + value.value.replace(/`/g, "\\`") + "`";
363-
else if (typeof value === "xml")
364-
self.value += "`" + value.toXMLString().replace(/`/g, "\\`") + "`";
365359
else
366360
self.value = "{" + String(value).replace(/}/g, "\\}") + "}";
367361
return self;
@@ -420,7 +414,7 @@ function templateXML(portion, args) // {{{
420414
}
421415
}
422416
if (i >= j) break label_root;
423-
else if (arg instanceof TemplateTmpl || typeof arg === "xml") {
417+
else if (arg instanceof TemplateTmpl) {
424418
res += arg.toXMLString();
425419
} else if (arg instanceof TemplateXML) {
426420
res += arg.value;
@@ -521,7 +515,7 @@ templateXML.map = function templateXmlMap(data, fn) {
521515
var val, res = "";
522516
for (var i = 0, j = data.length; i < j; i++) {
523517
val = fn(data[i]);
524-
if (val instanceof TemplateTmpl || typeof val === "xml")
518+
if (val instanceof TemplateTmpl)
525519
res += val.toXMLString();
526520
else if (val instanceof TemplateXML)
527521
res += val.value;
@@ -550,8 +544,6 @@ templateXML["+="] = function (self, value) {
550544
self.value += value.toXMLString();
551545
else if (value instanceof TemplateXML)
552546
self.value += value.value;
553-
else if (typeof value === "xml")
554-
self.value += value.toXMLString();
555547
else
556548
self.value += escapeHTML(value);
557549
return self;
@@ -594,51 +586,10 @@ function templateSafeHtml(portion, args) {
594586
return res;
595587
}
596588

597-
function templateE4X(portion, args) // e4x {{{
598-
{
599-
try {
600-
return new XMLList(templateXML(portion, args).value);
601-
} catch (ex) {
602-
alert(ex.stack);
603-
throw ex;
604-
}
605-
}
606-
templateE4X.raw = function raw(portion, args) {
607-
return new XMLList(templateRaw(portion, args));
608-
};
609-
templateE4X.cdata = function cdata(portion, args) {
610-
return new XMLList("<![CDATA[" + templateRaw(portion, args).replace(/>/g, "&gt;") + "]]>");
611-
};
612-
templateE4X["+"] = function operatorPlus(lhs, rhs) {
613-
function toE4X(a) {
614-
if (a instanceof TemplateTmpl)
615-
return new XMLList(a.toXMLString());
616-
else if (a instanceof TemplateXML)
617-
return new XMLList(a.toString());
618-
else
619-
return a;
620-
}
621-
return toE4X(lhs) + toE4X(rhs);
622-
};
623-
// xxx: xml object to E4X
624-
templateE4X.cast = function cast(obj) {
625-
if (obj instanceof TemplateTmpl)
626-
return new XMLList(obj.toXMLString());
627-
else if (obj instanceof TemplateXML)
628-
return new XMLList(obj.value);
629-
else
630-
return obj;
631-
};
632-
templateE4X["+="] = function (self, value) {
633-
if (typeof self !== "xml") throw SyntaxError();
634-
self += templateE4X.cast(value);
635-
return self;
636-
};
637589
//}}}
638590

639591
var tmpl = templateTmpl;
640592
var xml = templateXML;
641-
var e4x = templateE4X;
642593
var raw = templateRaw;
643594
var cooked = templateCooked;
644595
var safehtml = templateSafeHtml;

0 commit comments

Comments
 (0)