This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Replace spread operator with eval() to allow safe transpilation to ES5 #4
Open
kannonboy
wants to merge
1
commit into
darknoon:master
Choose a base branch
from
atlassian:replace-spread-with-eval
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is supposed to yield a string like
func(structPtr, selector, arguments[0], arguments[1], arguments[2])
, right?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would something like this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. That'd work in a normal JavaScript environment -- in fact that's pretty much how babel transforms the spread operator iirc. But it won't work in CocoaScript as the
MOBridgeSupportFunction
returned byCFunc
doesn't support.apply()
(apply
is undefined).The
eval()
I'm using here is really just a poor-mans.apply()
to pass all the supplied arguments on to theMOBridgeSupportFunction
invocation. There may be a better way to do it though?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kannonboy would it work to grab
apply
from somewhere else and then call it with aMOBridgeSupportFunction
?. eval is a pretty bad hack from a perf and cleanliness perspective. Overall this library has some nasty hacks on the objc side, so I guess we can use it if all else fails.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@darknoon I agree using
eval()
it's pretty far from ideal, but I think it might be the best option available.I tried to see if I could repurpose
Function.prototype.apply()
by messing around in Sketch's console, but it doesn't quite work as I'd hoped:Result is:
And the implementation of
.apply()
is native of course (you can test withlog(Function.prototype.apply.toString())
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance wise is slice bad for arguments and eval bad for variable lookup etc. See #8 for more + tested alternative solution :)