Skip to content

Commit fb0d7a5

Browse files
committed
use firefox's template literal(>=Fx35)
1 parent 7d3dbdc commit fb0d7a5

File tree

9 files changed

+50
-8
lines changed

9 files changed

+50
-8
lines changed

common/content/javascript.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,12 @@ const JavaScript = Module("javascript", {
637637
options.add(["inspectcontentobjects"],
638638
"Allow completion of JavaScript objects coming from web content. POSSIBLY INSECURE!",
639639
"boolean", false);
640-
options.add(["expandtemplate"],
641-
"Expand TemplateLiteral",
642-
"boolean", !("XMLList" in window));
640+
641+
// TODO: delete me when minVersion is greater than 35
642+
if (!liberator.has("template")) {
643+
options.add(["expandtemplate"],
644+
"Expand TemplateLiteral",
645+
"boolean", !("XMLList" in window));
646+
}
643647
}
644648
})

common/content/liberator-overlay.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
(function () {
77
const modules = {};
8-
const BASE = "liberator://template/chrome://liberator/content/"
8+
var {isSupport: TemplateIsSupport} = Cu.import("resource://liberator/CheckTemplate.jsm", {});
9+
const BASE = TemplateIsSupport ?
10+
"chrome://liberator/content/" : "liberator://template/chrome://liberator/content/";
911

1012
modules.modules = modules;
1113

@@ -30,7 +32,7 @@
3032

3133
let prefix = [BASE];
3234

33-
Cu.import("resource://liberator/template-tag.js", modules);
35+
Cu.import("resource://liberator/template-tag" + (TemplateIsSupport ? ".js" : "-old.js"), modules);
3436

3537
// TODO: This list is much too long, we should try to minimize
3638
// the number of required components for easier porting to new applications

common/content/liberator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ const Liberator = Module("liberator", {
332332
* should be loaded.
333333
*/
334334
loadScript: function (uri, context) {
335+
// TODO: delete me when minVersion is greater than 35
335336
if (options.expandtemplate) {
336337
var prefix = "liberator://template/";
337338
if (uri.lastIndexOf(prefix, 0) === -1)
@@ -345,6 +346,7 @@ const Liberator = Module("liberator", {
345346
if (!context)
346347
context = userContext;
347348

349+
// TODO: delete me when minVersion is greater than 35
348350
if (options.expandtemplate) {
349351
var obj = new Object;
350352
Cu.import("resource://liberator/template.js", obj);

common/modules/CheckTemplate.jsm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// vim: ft=javascript
2+
3+
var EXPORTED_SYMBOLS = ["isSupport"];
4+
5+
try {
6+
var isSupport = eval("((a,b)=>a.length)`${1}` === 2");
7+
} catch (ex) {
8+
Components.utils.reportError(ex);
9+
isSupport = false;
10+
}

common/modules/template-tag-old.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
var EXPORTED_SYMBOLS = ["xml", "TemplateSupportsXML"];
3+
(function () {
4+
var {xml, TemplateSupportsXML} = Components.utils.import("resource://liberator/template-tag.js", {});
5+
this.xml = function xml_tagged_hack(portion, args) {
6+
try {
7+
return xml.apply(xml, [portion].concat(args));
8+
} catch (ex) {
9+
Components.utils.reportError(ex);
10+
Components.utils.reportError(ex.stack);
11+
throw ex;
12+
}
13+
};
14+
15+
for (var a in xml)
16+
this.xml[a] = xml[a];
17+
this.TemplateSupportsXML = TemplateSupportsXML;
18+
}).call(this);

common/modules/template-tag.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function TemplateXML(s) {this.value = s;}
6060
TemplateXML.prototype = new TemplateSupportsXML;
6161
TemplateXML.prototype.toString = function () this.value;
6262

63-
function templateXML(portion, args) // {{{
63+
function templateXML(portion, ...args) // {{{
6464
{
6565
var res = "";
6666

@@ -221,7 +221,7 @@ templateXML.map = function templateXmlMap(data, fn) {
221221

222222
var DOMParser = Components.Constructor("@mozilla.org/xmlextras/domparser;1");
223223
// xxx: xml check
224-
templateXML.raw = function templateXmlRaw(portion, args) {
224+
templateXML.raw = function templateXmlRaw(portion, ...args) {
225225
var str = templateRaw(portion, args);
226226
var ps = DOMParser();
227227
var doc = ps.parseFromString("<root>" + str + "</root>", "text/xml");
@@ -230,7 +230,7 @@ templateXML.raw = function templateXmlRaw(portion, args) {
230230
}
231231
return new TemplateXML(str);
232232
};
233-
templateXML.cdata = function templateXmlCDATA(portion, args) {
233+
templateXML.cdata = function templateXmlCDATA(portion, ...args) {
234234
return new TemplateXML("<![CDATA[" + templateRaw(portion, args).replace(/>/g, "&gt;") + "]]>");
235235
};
236236
templateXML["+="] = function (self, value) {

common/modules/template.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: delete me when minversion is greater than 35
12
var EXPORTED_SYMBOLS = ["convert"];
23
const Cu = Components.utils;
34

muttator/content/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const Config = Module("config", ConfigBase, {
99
init: function () {
1010
// don't wait too long when selecting new messages
1111
// GetThreadTree()._selectDelay = 300; // TODO: make configurable
12+
13+
var {isSupport} = Cu.import("resource://liberator/CheckTemplate.jsm", {});
14+
if (isSupport) this.features.add("template");
1215
},
1316

1417
/*** required options, no checks done if they really exist, so be careful ***/

vimperator/content/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
const Config = Module("config", ConfigBase, {
99
init: function () {
10+
var {isSupport} = Cu.import("resource://liberator/CheckTemplate.jsm", {});
11+
if (isSupport) this.features.add("template");
1012
},
1113

1214
/*** required options, no checks done if they really exist, so be careful ***/

0 commit comments

Comments
 (0)