jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.33k stars 5.53k forks source link

Version 1.9.2 no longer works with ExtendScript .jsx #2827

Closed lohriialo closed 4 years ago

lohriialo commented 4 years ago
// #include "underscore-1.8.3.js"
#include "underscore-1.9.2.js"

var artists = ['Pharrel Williams', 'Led Zeppelin', 'Rolling Stones'];

_.each(artists, function(artist, index, artists) {
  alert('artist: ' + artist);
});

Error : _ is undefined

Now try version 1.8.3 it works like a charm

jgonggrijp commented 4 years ago

Looking at the big diff, it might or might not have something to do with the component.json having been deleted. Which, by the way, is not mentioned in the changelog. @lohriialo what package management system does ExtendScript use?

Looking up ExtendScript on wikipedia, I find that it is based on ES3. This hints at another possible cause. In 1.9.2, the underscore IIFE is called straight instead of with a .call(this), which, if I understand this page correctly, is equivalent in ES5 but not in ES3 (see section "Function").

Personally, I have no strong opinion on whether underscore 1.9 should support ExtendScript or not.

jashkenas commented 4 years ago

Yes, @lohriialo — if you don't mind taking a look, and seeing what we need to tweak to regain ExtendScript support ... I'd be happy to put it back in.

(At least until a future version perhaps becomes ES Modules)

lohriialo commented 4 years ago

If it makes any easier, break started with 1.9.0

jgonggrijp commented 4 years ago

@lohriialo Please make a local clone of underscore 1.9.2 and try whether you can make it work again by editing the source code yourself. @jashkenas said he would be happy to put the fix in underscore, but I think he meant he needs you to find the fix.

jgonggrijp commented 4 years ago

@lohriialo Could you please download both of the following (old) versions of underscore.js, and tell me for each of them whether it works with ExtendScript or not:

Version A

Version B

Thanks in advance.

lohriialo commented 4 years ago

@jgonggrijp thanks for looking into it, I'll test and update back

lohriialo commented 4 years ago

Btw, ExtendScript installer is available here https://github.com/Adobe-CEP/CEP-Resources/tree/master/ExtendScript-Toolkit

lohriialo commented 4 years ago

@jgonggrijp Version A works but not B

jgonggrijp commented 4 years ago

@lohriialo Thanks, that is the result I hoped for. How about the one below?

Version C

Btw, ExtendScript installer is available here https://github.com/Adobe-CEP/CEP-Resources/tree/master/ExtendScript-Toolkit

  • Install and run above test script

Thanks. I don't really mind doing that, but I would be an absolute beginner and I wouldn't fully trust the results I obtained while not knowing exactly what I'm doing. If we can arrive at a working 1.9.2+ version by cooperating in the way we do now, I think I'll know enough for the future in order to be able to support ExtendScript.

lohriialo commented 4 years ago

@jgonggrijp sure, I'm happy to help test

Version C doesn't work either

jgonggrijp commented 4 years ago

That's a shame, I really hoped that would work. But I won't give up yet.

jgonggrijp commented 4 years ago

@lohriialo I did some more research and arrived at three more versions, which are mostly experimental means to figure out what is needed. Could you please test these as well?

Version D

Version E

Version F

In addition, could you please tell me what is the output of the following script in JSX (without loading underscore)? If it errors out in any way, please tell me the exact error as well.

(function() {
    $.writeln('this ', typeof this);
    $.writeln('Function ', typeof Function);
    $.writeln('Global ', typeof Global);
    $.writeln('global ', typeof global);
    $.writeln('self ', typeof self);
    $.writeln('$ ', typeof $);
    $.writeln('$.global ', typeof $.global);
    $.writeln('identity ', ($.global.$ === $ ? 'true' : 'false'));
    $.writeln('$.Function ', typeof $.Function);
}());

I was about to test these things myself after all, but I'm on a recent version of macOS and I can't get any installer for the JSX toolkit to work.

lohriialo commented 4 years ago

@jgonggrijp All version works(D, E, F) and below is the output without underscorejs

this function
Function function
Global undefined
global undefined
self undefined
$ object
$.global object
identity true
$.Function undefined
jgonggrijp commented 4 years ago

@lohriialo Great. D is my preferred solution, I submitted a pull request for it (referenced right above this comment).

Interestingly, the only difference between C and D is a semicolon:

// version C
Function('return this;')()

// version D
Function('return this')()

I find the this and global outputs from the test script rather surprising, but fortunately we have a solution now.

lohriialo commented 4 years ago

@jgonggrijp Thanks for all your help looking into this!