maildev@lists.thunderbird.net

Thunderbird email developers

View all threads

Change in Components.utils.import in TB 61 breaks SugarJS, may break other things as well?

JK
Jonathan Kamens
Thu, Mar 15, 2018 11:31 PM

I use SugarJS https://sugarjs.com/ in one of my Thunderbird add-ons.
Earlier today I was testing something with last night's TB nightly build
and I discovered that my add-on wasn't working because SugarJS was
failing to load.

Here's how I load SugarJS:

  1. One of my scripts loaded from one of my XUL files calls
    Components.utils.import to import a JavaScript module that I wrote.
  2. The JavaScript module uses mozIJSSubScriptLoader.loadSubScript to
    load SugarJS.

This worked fine in the nightly build as recently as 2018-03-12 (which
was version 60.0a1, I believe), but it breaks in 2018-03-15, which is
61.0a1.

SugarJS does some magic at load time to locate the global context
object, so it can locate the prototypes for various object types (Array,
Date, etc.) in the global context and extend them. In Thunderbird's
JavaScript interpreter, its logic decides that this is the global
context object. It was before, but it isn't anymore.

In particular, in the old builds where SugarJS loads successfully, the
global context when SugarJS is loading is a BackstagePass object,
whereas the global context in the newer, breaking builds is a
NonSyntacticVariablesObject object.

I came up with a workaround for this problem
https://github.com/andrewplummer/Sugar/issues/627#issuecomment-373553228,
but I don't know if/when the maintainer of SugarJS will take my fix or
an equivalent one, and I don't know if there are other add-ons that use
SugarJS that won't know to update the SugarJS code in their add-ons, and
people may run into it with other code besides SugarJS.

Does anyone know if this is an intentional change? Is it documented
anywhere? Should it be?

Thanks,

jik

I use SugarJS <https://sugarjs.com/> in one of my Thunderbird add-ons. Earlier today I was testing something with last night's TB nightly build and I discovered that my add-on wasn't working because SugarJS was failing to load. Here's how I load SugarJS: 1. One of my scripts loaded from one of my XUL files calls Components.utils.import to import a JavaScript module that I wrote. 2. The JavaScript module uses mozIJSSubScriptLoader.loadSubScript to load SugarJS. This worked fine in the nightly build as recently as 2018-03-12 (which was version 60.0a1, I believe), but it breaks in 2018-03-15, which is 61.0a1. SugarJS does some magic at load time to locate the global context object, so it can locate the prototypes for various object types (Array, Date, etc.) in the global context and extend them. In Thunderbird's JavaScript interpreter, its logic decides that `this` is the global context object. It was before, but it isn't anymore. In particular, in the old builds where SugarJS loads successfully, the global context when SugarJS is loading is a `BackstagePass` object, whereas the global context in the newer, breaking builds is a `NonSyntacticVariablesObject` object. I came up with a workaround for this problem <https://github.com/andrewplummer/Sugar/issues/627#issuecomment-373553228>, but I don't know if/when the maintainer of SugarJS will take my fix or an equivalent one, and I don't know if there are other add-ons that use SugarJS that won't know to update the SugarJS code in their add-ons, and people may run into it with other code besides SugarJS. Does anyone know if this is an intentional change? Is it documented anywhere? Should it be? Thanks, jik
JK
Jörg Knobloch
Thu, Mar 15, 2018 11:56 PM

On 16/03/2018 00:31, Jonathan Kamens wrote:

Does anyone know if this is an intentional change? Is it documented
anywhere? Should it be?

Certainly not an intentional change by the TB team.

I've just fixed https://bugzilla.mozilla.org/show_bug.cgi?id=1446050
which suffered from https://bugzilla.mozilla.org/show_bug.cgi?id=1445551.

At 1 AM here I can only dream that this will affect many add-ons. BTW,
the 2018-03-15 version is today's Linux Daily which was already broken?
The Windows Daily ran a few minutes earlier and doesn't have bug 1445551
in it.

Jörg.

On 16/03/2018 00:31, Jonathan Kamens wrote: > Does anyone know if this is an intentional change? Is it documented > anywhere? Should it be? Certainly not an intentional change by the TB team. I've just fixed https://bugzilla.mozilla.org/show_bug.cgi?id=1446050 which suffered from https://bugzilla.mozilla.org/show_bug.cgi?id=1445551. At 1 AM here I can only dream that this will affect many add-ons. BTW, the 2018-03-15 version is today's Linux Daily which was already broken? The Windows Daily ran a few minutes earlier and doesn't have bug 1445551 in it. Jörg.
JK
Jonathan Kamens
Wed, Mar 21, 2018 3:02 PM

So I just tested the 2018-03-21 nightly TB build, which I believe has
your fixes referenced below in it, and it still has this problem (ref
original problem description
http://lists.thunderbird.net/pipermail/maildev_lists.thunderbird.net/2018-March/001072.html).

How do we figure out if this was an intentional vs. unintentional
mozilla-central change? If the former, I guess it needs to be documented
at https://wiki.mozilla.org/Thunderbird/Add-ons_Guide_57 with a link to
the m-c team's explanation of the change?

This looks extremely relevant --
https://groups.google.com/forum/#!topic/firefox-dev/J2frGYCb7Rg --
though I'm not versed well enough in all this to understand for certain
that that's the culprit or what the appropriate way to address this in
TB would be. This is particularly relevant:

The |(1,eval)(...)| and |new Function(...)| patterns now run in the
context of the shared global and are thus DEPRECATED. In future it
is likely that CSP will be used to deny all eval/Function usage.

new Function(...) is exactly how I worked around this issue in my fix to
make SugarJS start working again.

  jik

On 3/15/18 7:56 PM, Jörg Knobloch wrote:

On 16/03/2018 00:31, Jonathan Kamens wrote:

Does anyone know if this is an intentional change? Is it documented
anywhere? Should it be?

Certainly not an intentional change by the TB team.

I've just fixed https://bugzilla.mozilla.org/show_bug.cgi?id=1446050
which suffered from https://bugzilla.mozilla.org/show_bug.cgi?id=1445551.

At 1 AM here I can only dream that this will affect many add-ons. BTW,
the 2018-03-15 version is today's Linux Daily which was already
broken? The Windows Daily ran a few minutes earlier and doesn't have
bug 1445551 in it.

Jörg.


Maildev mailing list
Maildev@lists.thunderbird.net
http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net

So I just tested the 2018-03-21 nightly TB build, which I believe has your fixes referenced below in it, and it still has this problem (ref original problem description http://lists.thunderbird.net/pipermail/maildev_lists.thunderbird.net/2018-March/001072.html). How do we figure out if this was an intentional vs. unintentional mozilla-central change? If the former, I guess it needs to be documented at https://wiki.mozilla.org/Thunderbird/Add-ons_Guide_57 with a link to the m-c team's explanation of the change? This looks extremely relevant -- https://groups.google.com/forum/#!topic/firefox-dev/J2frGYCb7Rg -- though I'm not versed well enough in all this to understand for certain that that's the culprit or what the appropriate way to address this in TB would be. This is particularly relevant: The |(1,eval)(...)| and |new Function(...)| patterns now run in the context of the shared global and are thus DEPRECATED. In future it is likely that CSP will be used to deny all eval/Function usage. new Function(...) is exactly how I worked around this issue in my fix to make SugarJS start working again.   jik On 3/15/18 7:56 PM, Jörg Knobloch wrote: > On 16/03/2018 00:31, Jonathan Kamens wrote: >> Does anyone know if this is an intentional change? Is it documented >> anywhere? Should it be? > > Certainly not an intentional change by the TB team. > > I've just fixed https://bugzilla.mozilla.org/show_bug.cgi?id=1446050 > which suffered from https://bugzilla.mozilla.org/show_bug.cgi?id=1445551. > > At 1 AM here I can only dream that this will affect many add-ons. BTW, > the 2018-03-15 version is today's Linux Daily which was already > broken? The Windows Daily ran a few minutes earlier and doesn't have > bug 1445551 in it. > > Jörg. > > > _______________________________________________ > Maildev mailing list > Maildev@lists.thunderbird.net > http://lists.thunderbird.net/mailman/listinfo/maildev_lists.thunderbird.net > >