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

Improve function interop #1074

Merged
merged 2 commits into from Feb 4, 2022
Merged

Conversation

KurtGokhan
Copy link
Contributor

The last fixes I did were not ideal. Same function would resolve to different reference, and bound functions would not work. Also Call utility is a more proper way to solve this now I think.

@KurtGokhan KurtGokhan marked this pull request as draft February 3, 2022 15:32
@KurtGokhan
Copy link
Contributor Author

I think I may have introduced the old problem again. Will test this more before it is ready for merging.

@@ -959,10 +959,9 @@ private object ToObject(ObjectTraverseStack stack)
break;

case ObjectClass.Function:
if (this is FunctionInstance function)
if (this is ICallable function)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a PR trying to hide ICallable and possibly trying to remove it at some point altogether if possible. In spec there are function objects (in Jint FunctionInstance) that may be callable (IsCallable)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting I should check IsCallable? As I see it does this is ICallable for everything except Proxy.

Also this function is for converting script objects to their CLR counterpart. I don't think anything other than a function should be converted to a CLR function. So, proxies will not be hitting this line anyway.

As for removing ICallable, I can't imagine how it is going to work. If we agree on test cases, let's keep this for now and change when ICallable removed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah this was just a note. Proxy is a good example that function object might not be callable, even though it has to implement ICallable if the target would happen to be callable. My thinking is that we should be able to get away by having FunctionInstance (write your own implementation), ScriptFunctionInstance (anything from script) and ClrFunctionInstance (basically native function). All these have Call method from FunctionInstance. IConstructor and ICallable are a bit artificial constructs, is all.

The more test coverage the better. Always comes back biting for advanced usage that people like you have when doing interop. All coverage is much appreciated!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok. It was FunctionInstance before but I noticed bound functions did not derive from FunctionInstance and ICallable seemed like the only thing that covers all of these cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah the BoundFunction... OK that was the pain point we discussed earlier. Well it's a start to make ICallable internal at least..

@KurtGokhan KurtGokhan marked this pull request as ready for review February 3, 2022 19:25
Comment on lines -141 to +142
var result = OrdinaryCallEvaluateBody(_engine._activeEvaluationContext, arguments, calleeContext);
var context = _engine._activeEvaluationContext ?? new EvaluationContext(_engine);
var result = OrdinaryCallEvaluateBody(context, arguments, calleeContext);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know this change is required (because _activeEvaluationContext is used this way everywhere else). My app was crashing because of this, but I could not write a test which reproduces the issue in isolation.

@KurtGokhan
Copy link
Contributor Author

Ready for review

Copy link
Collaborator

@lahma lahma left a comment

Choose a reason for hiding this comment

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

Looks good, especially new test cases. We need to stay vigilant with that execution context that it doesn't get broken later on.

@lahma lahma merged commit 95f25aa into sebastienros:main Feb 4, 2022
@KurtGokhan KurtGokhan deleted the function-equality branch February 4, 2022 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants