ccgus / CocoaScript

JavaScript + the Cocoa frameworks, and then ObjC brackets show up to party as well.
Other
618 stars 58 forks source link

Old scripts not working - some shims disappeared? #10

Open samdeane opened 10 years ago

samdeane commented 10 years ago

I recently upgraded from JSTalk to CocoaScript, and it seems like a bunch of old scripts aren’t working any more.

In particular, log() used to work and now doesn’t, and somensarray.length() used to work whereas now somensarray.count() is required.

I get the impression that what may be happening is that the point at which some bridging takes place has shifted somehow, so that things which were previously treated as (converted to?) javascript objects are now being treated as native cocoa objects.

Or something :)

Does this ring any bells? Have I missed an option somewhere that I’m supposed to have configured?

samdeane commented 10 years ago

Either that, or (as the title suggests), perhaps there was a mapping layer for certain functions somewhere that has gone away?

ccgus commented 10 years ago

CocoaScript uses a different bridge, so some things that JSCocoa (the previous bridge) did automatically aren't done anymore.

Try print() instead of log (or put print = log somewhere at the top of your script). I'll see about adding length() support - should be easy enough…

samdeane commented 10 years ago

That would explain it - thought it might be something along those lines.

I did add a log -> print alias to the preamble we add to user scripts, and we can easily add length as a category on NSArray, but it started feeling like the set of changes was potentially larger (and perhaps a bit unknown…).

We want to do our best not to break all our users scripts when we switch. I guess you’re going to go through the same thing with 4.4 of Acorn.

If we can figure out some reasonable set of the things that will break (even if we can’t get it exhaustive, we can hopefully find the common ones that crop up repeatedly), then we can maybe add a compatibility layer of mappings which we can use whilst deprecating the broken stuff?

ccgus commented 10 years ago

Mapping should be possible. I never used log or print or length in my scripts - so I don't think it ever came up :)

samdeane commented 10 years ago

The big one seems to be length. There's a hack in JSCocoaController which did some special case stuff for anything that supported the obejctAtIndex method - including switching any calls to "length" to use "count" instead.

I guess a category in the host app will fix it (if the host app wants to).

Confused us for a while because it was magically working for a custom array class of ours that had nothing to do with NSArray (because they were testing for objectAtIndex rather than just some relationship with NSArray).

ccgus commented 10 years ago

If you have any small snippets of code that used to work, that don't work - those would be great to have for testing (and fixing) in CocoaScript.

ccgus commented 10 years ago

Looking at the source for CocoaScript - looks like I added a special case for length at some point. And I'm about to push up a commit that adds support for log as well.

samdeane commented 10 years ago

We're keeping a track of the issues we spot here:

https://github.com/sketchplugins/cocoascript-migration

samdeane commented 10 years ago

Some of that stuff is Sketch specific, mind you...