Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adobe ExtendScript errors with self and certain regular expressions #31

Closed
SheetJSDev opened this issue Mar 23, 2017 · 7 comments
Closed

Comments

@SheetJSDev
Copy link
Contributor

We were addressing an unexpected issue about running in Adobe ExtendScript SheetJS/sheetjs#603.
It's the scripting runtime for Adobe products, and it claims to be "extended" ECMAScript.

After some digging, we found two issues:

  1. self is not available in extendscript and the object assignment assumes self is defined:
  var object = typeof exports != 'undefined' ? exports : self; // #8: web workers
  // when exports and self are both undefined, this line fails thanks to the unguarded assignment 

The indirect eval trick (1,eval)('this') appeared to work:

  var object = typeof exports != 'undefined' ? exports : typeof self != 'undefined' ? self : (1,eval)('this')
  1. Regular expression literals starting with = are problematic:

screen shot 2017-03-23 at 19 32 44

I believe the fix here is to turn /=+$/ into a RegExp call: new RegExp("=+$")

@davidchambers
Copy link
Owner

Would you like to submit a pull request?

@SheetJSDev
Copy link
Contributor Author

I'm confident that the aforementioned fixes will work in IE6+, and I think I understand why they fail in the first place: in the first case the global variable is not available, and in the second case, there's a parse ambiguity wherein ExtendScript treats $ as a special variable, so it sees /=+$/ as a division-assignment for the value +$/...).

However there are two things that are not clear:

  1. What environments support Base64.js? Is it just "whatever happens to work" or do you have a specific target (e.g. IE6+) in mind?

  2. how do you test in the supported environments? I see a coffeescript test script -- do you manually generate the JS for it and add it to an HTML page? Do you use the mocha skeleton?

@davidchambers
Copy link
Owner

We'd like this package to work in as many environments as possible. The test suite only runs in Node so doesn't tell us whether the package works in other environments.

The approach I'm taking with this package is to make the smallest possible changes only when absolutely necessary. In lieu of a comprehensive test suite we rely on our reasoning abilities. As a result, changes should be small and well documented.

Does parenthesizing the regexp literal fix that problem? If so, let's go with that change. :)

@SheetJSDev
Copy link
Contributor Author

The second change is replacing the literal regexp syntax with the constructor form: new RegExp("=+$") rather than /=+$/. The RegExp constructor was introduced in ES3; I don't know when the regexp literals were introduced but it's likely ES3 as well.

@davidchambers
Copy link
Owner

Is it possible to use ExtendScript on macOS without installing Creative Cloud?

@SheetJSDev
Copy link
Contributor Author

The latest version unfortunately requires a CC account, but the CS5 ExtendScript toolkit is available at https://www.adobe.com/devnet/scripting/estk.html and you don't need to register to download. The OSX version is http://download.macromedia.com/pub/developer/estk/sdk/AdobeExtendScriptToolkit3.5.0-mul.dmg

@michaelficarra
Copy link
Collaborator

You can use the empty non-capturing group: /(?:)=+$/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants