Skip to content

Asyncify template scripting #266

Closed
Closed
@benibela

Description

@benibela

Something suddenly installed a thunderbird update on my system and then everything was broken

I updated to "smartTemplate-fx-4.0pre256", and then only the %{% scripting was broken

I made it async:

$  diff /tmp/chrome/content/smartTemplate-overlay.js  ~/opt/smartTemplate-fx-4.0pre256/chrome/content/smartTemplate-overlay.js 
3871a3872,3875
>         //alert("B:"+supportEval);
>         //var oldLog = util.logDebugOptional;
>       
>       //util.logDebugOptional = function(x,y) { alert(x+":: "+y); oldLog(x,y) }
3881c3885
<     function replaceJavascript(dmy, script) {
---
>     async function replaceJavascript(dmy, script) {
3905c3909
<         sandbox.variable = function(name, arg) {
---
>         sandbox.variable = async function(name, arg) {
3908c3912
<           let retVariable = replaceReservedWords("", name, arg || "");
---
>           let retVariable = await replaceReservedWords("", name, arg || "");
3932c3936
<             return function(arg){
---
>             return async function(arg){
3943c3947
<               let sbVal = replaceReservedWords("", aname, arg);
---
>               let sbVal = await replaceReservedWords("", aname, arg);
3958c3962
<         x = Cu.evalInSandbox("(" + script + ").toString()", sandbox); 
---
>         x = await Cu.evalInSandbox("(" + script + ")", sandbox); //todo: need to check if await is safe here
3979c3983
<       msg = msg.replace(/%\{%((.|\n|\r)*?)%\}%/gm, replaceJavascript); // also remove all newlines and unnecessary white spaces
---
>       msg = await SmartTemplate4.Util.replaceAsync(msg, /%\{%((.|\n|\r)*?)%\}%/gm, replaceJavascript); // also remove all newlines and unnecessary white spaces

smartTemplate-overlay.txt

Although that breaks the templates because they need to be made async as well.
One can still write %{% subject.toString() %}%, but now it is not a string, but a Promise

So something like %{% subject.toString() + "abc" %}% gets broken and would needed to be changed to %{% async function () { return await subject.toString() + "a" } () %}% by each user

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions