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

Add experimental support for ES7 function bind. #1518

Merged
merged 5 commits into from
May 14, 2015
Merged

Conversation

RReverser
Copy link
Member

Please review and let me know about possible issues (syntax is somewhat tricky so I could miss some edge cases). /cc @sebmck @zenparsing

Please note that I implemented it as if tc39/proposal-bind-operator#4 would take place.

Closes #1287.

@RReverser RReverser mentioned this pull request May 13, 2015
stage: 0
};

var CALL = t.identifier("call");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AST is currently considered to be highly mutable so this isn't really safe to do. ie. properties could be added to it that would cause race conditions when ran multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np, will fix now.

@RReverser RReverser changed the title Add experimental support for ES7 function bind. (issue #1287) Add experimental support for ES7 function bind. May 13, 2015
@@ -214,7 +214,12 @@ pp.parseExprSubscripts = function(refShorthandDefaultPos) {
}

pp.parseSubscripts = function(base, start, noCalls) {
if (this.eat(tt.dot)) {
if (this.eat(tt.doubleColon)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the following case:

new X::y;

We want (new X)::y rather than new (X::y). Agree?

Similarly, for:

x :: y :: z 

We want (x :: y) :: z rather than x :: (y :: z)

So I think we should only eat :: if noCalls is false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kevin!

As for the first case - makes sense to me.

As for the second one - I don't see any benefits from such construct at all since second .bind anyway doesn't change context of prebound function, so it's kinda convoluted example IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

(_context = ctx, ns.obj.func).call(_context);
(_context = ns.obj).func.call(_context);

(_context = ns.obj2, ns.obj1.func).call(_context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RReverser You were right, and this looks good to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zenparsing Thanks for confirmation and review in general!

@RReverser
Copy link
Member Author

@sebmck Can it be merged now?

stage: 0
};

function getTempId(scope) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this UID caching might introduce race conditions with nested binding expressions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide any example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I was also worried about that so specifically added complex tests with nested binding expressions - both transformation and execution seem to be fine)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like the scoping stuff covers it as the order of evaluation will always be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - and sequence of operations is always like:

  1. Store context to _context.
  2. Get .bind / .call property.
  3. Call it with _context as first argument.

So, according to semantics, nothing can happen between storing and using _context.

sebmck added a commit that referenced this pull request May 14, 2015
Add experimental support for ES7 function bind.
@sebmck sebmck merged commit 7407b37 into master May 14, 2015
@sebmck sebmck deleted the es7.functionBind branch May 14, 2015 15:30
@sebmck
Copy link
Contributor

sebmck commented May 14, 2015

Awesome, thanks! I've added in handling for "static" contexts in commit 724bf52. The scope API methods will need to be refactored/renamed as they're a bit crap. I'll hopefully push this out later tonight. A short blog post would also be awesome if anyone wants to volunteer.

@UltCombo
Copy link

Awesome work, thanks @RReverser and @sebmck. 😄

@RReverser
Copy link
Member Author

@sebmck Cool, thanks. I could do the blog post - but never did them before here, so need some pointers (or maybe @thejameskyle or @zenparsing want to do it).

@RReverser
Copy link
Member Author

@sebmck Also, maybe better to release this before writing in the blog so people could actually play with it?

@sebmck
Copy link
Contributor

sebmck commented May 14, 2015

Released as of 5.4.0 💃

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 8, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ES7 function bind
4 participants