darknoon / cocoascript-class

Lets you create real ObjC classes in cocoascript so you can implement delegates, subclass builtin types, etc
MIT License
22 stars 8 forks source link

support older JSC; fixes #2, closes #4, closes #1 #8

Open leonardpauli opened 6 years ago

leonardpauli commented 6 years ago

fixes #2, closes #4, closes #1

  1. using babel-preset-env with targets safari 6 (with upgraded @babel/cli)
  2. proper Function+arguments workaround
// func.apply(void 0, ...args) doesn't work with some
// special functions in older JSC versions (eg. OSX 10.11)
//  - use Function instead of eval
//    see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
//  - beware of arguments gotchas
//    see https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
const args = [structPtr, selector]; [].push.apply(args, arguments);
const argsStr = args.map((_, i)=> `args[${i}]`).join(',');
return Function(`"use strict";return function (fn, args) { return fn(${argsStr}) }`)()(func, args);

I'm running El Capitan for "reasons", and many other have had this issue. This is a more robust and less hacky way than the previous attempts. My main issue which this solves (tested by npm link):

https://github.com/skpm/sketch-module-web-view/issues/51 and https://github.com/skpm/sketch-dev-tools/issues/24

also: https://github.com/airbnb/react-sketchapp/issues/106