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

Discuss: automatically unwrap a wrapped function #293

Closed
leobalter opened this issue Mar 27, 2021 · 2 comments
Closed

Discuss: automatically unwrap a wrapped function #293

leobalter opened this issue Mar 27, 2021 · 2 comments
Labels

Comments

@leobalter
Copy link
Member

leobalter commented Mar 27, 2021

One question however is if the GetWrappedValue operation should automatically unwrap a wrapped function if its [[Realm]] matches callerRealm. Right now it would double wrap it.

Originally posted by @mhofman in #291 (comment)

My comment: We need to discuss if the api should unwrap or double wrap functions going back and forth.

I don't see much value or the goal in sending the same function back and forth cross realms. If the goal is to get a unique identity, symbols should resolve this trick in a much more lightweight manner.

Adding an extra check for every function to see if it can be unwrapped might end with some cost, but at the same time, it cuts a chain of references here and there.

@leobalter leobalter changed the title One question however is if the GetWrappedValue operation should automatically unwrap a wrapped function if its [[Realm]] matches callerRealm. Right now it would double wrap it. Discuss: automatically unwrap a wrapped function Mar 27, 2021
@mhofman
Copy link
Member

mhofman commented Mar 27, 2021

Thinking about this more, I think not unwrapping is the right way to go.

Unwrapping wouldn't create full unique identity since passing a normal callable would always create a new wrapper even if a wrapper for that callable already exists in the target realm, so it wouldn't negate the need for symbols. While I don't believe you can build a membrane without the cross realm references that wrapped functions provide, at least until symbols or some other object based unique identity can be used as WeakMap keys, giving more identity power to wrapper functions does seem wrong.

So I agree that auto unwrapping wouldn't be super useful for identity, but it would simplify the chain of reference. However, not specifying unwrapping actually doesn't prevent the implementation from optimizing those references. The implementation could detect these double wrapped functions and substitute them for a local realm bound function, removing the cross realm references, as that wouldn't be observable.

@leobalter
Copy link
Member Author

Closing this one. This API is not a membrane, there we should avoid this as it's a potential identity tracking mechanism. This feature would find immediate objection to move forward in the stage process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants