fasttime / JScrewIt

Write any JavaScript with six characters: ! ( ) + [ ]
https://jscrew.it
ISC License
159 stars 12 forks source link

optimization of "O" #26

Closed Clayblockunova closed 3 years ago

Clayblockunova commented 3 years ago

afaik, constructor of array iterator ([].entries()) is Object(), same as INTL and plain object, so I used array iterator as a method to get "O"

fasttime commented 3 years ago

Great one! Thanks for the PR. I merged your changes into the update branch. They will be live with the next release.

I also made two post-merge changes: a stylistic one and a functional one.

In the definitions of "O" I moved the defineCharAtFnPos line to the top for consistency with the other entries where defineCharAtFnPos is also at the top. Definition order is important sometimes because it can change the way things are encoded. That is not the case for character definitions, it's just a matter of style.

Another issue is that the constructor of array iterators is not Object in Safari 7.1 and Safari 8. JScrewIt still supports such ancient browsers because they are supported by jQuery 3. Now, old versions of Safari are well known for poor implementation of array iterators, to the extent that there is already a feature to exclude them from certain optimizations: NO_OLD_SAFARI_ARRAY_ITERATOR. So I updated that feature to reflect the fact that the array iterator constructor should be Object, then I modified your definition of the Object constant to require NO_OLD_SAFARI_ARRAY_ITERATOR instead of just ARRAY_ITERATOR.

Finally, I ran npm run build to rebuild JScrewIt and then opened test/spec-runner.html in Safari 7.1 and Safari 8 to make sure that all tests are green. You may need to run a rm -rf node_modules first in case the build fails.

Clayblockunova commented 3 years ago

and, what is constructor of array iterators in Safari 7.1 and 8? is OLD_SAFARI_ARRAY_ITERATOR still useless?

fasttime commented 3 years ago

It's a non-standard function: [].entries().constructor.name: "" [].entries().constructor.prototype: undefined [].entries().constructor + '': TypeError [].entries().constructor.__proto__ === Function.prototype: true

OLD_SAFARI_ARRAY_ITERATOR would be only useful to extract characters from the string [object ArrayIterator], i.e. [].entries() + [].