jashkenas / underscore

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

Adobe InDesign JS Engine fails on isEqual method #355

Closed kapooostin closed 13 years ago

kapooostin commented 13 years ago
735: if (hasOwnProperty.call(b, key) && !size--) break;

It cannot assign value in the second part of conjunction. Adding braces solves it:

735: if (hasOwnProperty.call(b, key) && !(size--)) break; //works fine
jashkenas commented 13 years ago

Thanks -- this should now be fixed on master.

Funnily enough, the Graphics desk here at the NYTimes also ran into this same bug -- they're using Underscore to script Illustrator, and I assume that all Adobe JS engines have this same operator precedence problem.

kapooostin commented 13 years ago

Great!

I didn't test it yet in Illustrator, but in InD I also changed the way how root is defined. Inside function this doesn't refer to global, so I passed it as a parameter, exactly as it is implemented in underscore.string.js.

(function(root){
    ...
}(this || window));

Should I open an issue for this or there are reasons for global scope not to be passed to module as a parameter?

jashkenas commented 13 years ago

Yes -- if you want to change the way that root is determined, you'll need to test it in browsers, Node.js, Rhino, JScript, Adobe, RingoJS, etc etc -- all of the runtimes.

The current way should be working properly, as other folks are using it successfully in Adobe products. Are you sure that this !== window?

michaelficarra commented 13 years ago

The fact that a product from Adobe has an operator precedence issue in their JS interpreter is astonishing. How can any serious piece of software include such a blatant flaw? I can only imagine that a single novice programmer has created their JS interpreter, and they don't have any operator precedence tests. That's pathetic. Shitty Adobe programmers strike again.

kapooostin commented 13 years ago

Yes. It throws an error. Here is a screenshot from of my tests http://db.tt/EHxdVDhF.

Actually this refers to anonymous function, not global scope.

jashkenas commented 13 years ago

Does changing the wrapper to:

(function(){
  ...
}).call(this);

Fix the problem for you? If so, please open a pull request.

michaelficarra commented 13 years ago

@kapooostin: What's the value of this inside the function? null?

kapooostin commented 13 years ago

@jashkenas: Yes, it solves the problem. Now _ is global. I'll open a pull request.

@michaelficarra: null would be too stupid, even for adobejs. Here is console output http://db.tt/VeVTFWry.

michaelficarra commented 13 years ago

Oh my god, functions are invoked with themselves as the context. Wow, I didn't realise just how bad that platform was...

kapooostin commented 13 years ago

@michaelficarra: you haven't tried to write scripts for Adobe Acrobat documents, I guess.

ghost commented 13 years ago

The context bug looks vaguely familiar...I think Windows Script Host under Windows XP does this as well.