-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Drop common.Bind for goja native support #1802
Comments
Hi @runner-mei, thanks for mentioning it, but what you are doing is what we are doing now, but without it being recursive. (which you probably know as you have our bind copied right next to this code ;)) The point of this issue is to drop all these additional calls and instead only set a global variable in goja that is our context and get it back from the Runtime provided in the call, without any additional code on our side and remembering that you need to call Yes, we still need to call The biggest problem again (apart from the time it will take to do and the risk of breaking something which are probably bigger) is that we will not be able to have the arguments to the methods be with their concrete types instead we will be taking |
Some findings while I was trying to drop the usage
This means that the context that Bind actually gives to the So what I am trying to say is that we can't drop the usage of |
Restating the problem: Technically this is not limited to Also, most js modules don't care about the The current solution and its problems:The current solution: Is for whatever will need access to this to call
###Original Proposal for the fix: For all intents and purposes, what we care about is some way to get to the thing (in this case
Proposal 2:Technically again ... all we care about is for the modules and their methods and objects(and their methods) created from it to have access to the thing ... somehow. And to its updated values So in practice, we can just ... give it to the module at initialization (or shortly after) and call it a day.
Proposal 2 variant 1:We can just have an interface like
Proposal 2 variant 2:given the above and the fact that, while we can just staple everything on the context it is probably not the "greatest" idea ever.
And then require the registering the module to have the signature
|
I don't grok all of the problems, requirements and potential solutions here yet, but I just wanted to mention that we need the current scenario context in every call of a Go function in the k6 JS API, so that Go function (e.g. Other than that, in general, I'd personally prefer a solution which makes writing Go modules as simple as possible, even if that means more reflection magic on the side of k6. |
My tangent about "the thing" instead of context was mostly to abstract the way the specific, as it doesn't matter really, even if just giving
does that mean that you want the stick with I am probably just going to showcase a PoC of the two(three) options from above with something like |
Maybe 🤷♂️ I don't have a strong opinion either way, but the current way to add Go modules is at least simple and works quite well. It has a few gotchas and warts, so if we can remove or minimize them, I won't have a lot of objections to it. Still, 👍 for a PoC of an alternative approach, it will be much easier to see the tradeoffs when we have a code diff to evaluate. |
This will need more work if we want to help users more and the returned object will likely need some help as well(which possibly can be done by the importing code).
In this case we give the Module a function to get the context and it needs to that whenever it needs it instead of just caching it's value ... Especially between function call or something like that
This goes all the way and tries (unfortunately not very well, I will try again) to make the user embed the ModuleInstance it gets in the return module so that it always has access to the Context and w/e else we decide to add to it. I also decided to force some esm along it (this is not required) to test out some ideas.
In this case we give the Module a function to get the context and it needs to that whenever it needs it instead of just caching it's value ... Especially between function call or something like that
In this case we give the Module a function to get the context and it needs to that whenever it needs it instead of just caching it's value ... Especially between function call or something like that
In this case we give the Module a function to get the context and it needs to that whenever it needs it instead of just caching it's value ... Especially between function call or something like that
This goes all the way and tries (unfortunately not very well, I will try again) to make the user embed the ModuleInstance it gets in the return module so that it always has access to the Context and w/e else we decide to add to it. I also decided to force some esm along it (this is not required) to test out some ideas.
This goes all the way and tries (unfortunately not very well, I will try again) to make the user embed the ModuleInstance it gets in the return module so that it always has access to the Context and w/e else we decide to add to it. I also decided to force some esm along it (this is not required) to test out some ideas.
closed by #2108 |
After dop251/goja@06e9948 the scratched out part of mine comment dop251/goja#243 (comment) is now possible 🎉 .
Whether we want to do is another question.
Summary of what currently common.Bind seems to be doing(probably missed something):
It's predominant roll is to make certain that for methods on the struct provided that look like:
ctx
will be set to the one provided as the argument to BindThe last point means that things such as using an interface in the arguments of a function, but
common.Bind
-ing the "to be" argument will lead to it not answering the interface{}. The code posted in the community forum showcases this a lot better, then I can put it in words 🤣 .Other problems with the current code include that it is kind of ... hard to read due to the sheer amount of reflect in it. It also having support for
*context.Context
(the pointer part), which seems completely unnecessary.Also needing to be called in order to have access to the context, is something that we will probably need to document for [xk6]*(https://github.com/k6io/xk6) and explain it.
Proposed change:
or for constructors - drop the 'X' and change to
This will mean that instead of having
we will have something like
This is a lot closer to how JS works so it might not be such a big downside.
This will likely take more than 1 release cycle and will likely turn out to have other problems so I am not even certain if it's really worth it
The text was updated successfully, but these errors were encountered: