You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ignoring the change to reference passing (not sure why that happens yet but it's not the issue) the new codegen grabs a reference to the JS function directly without its context, which leads to errors when the function is a method and requires its context on call site.
You can easily reproduce the same error in the browser console:
I'm filing this as a bug since upgrading the version did break my code, however I'm not sure if the thing I'm doing (and the docs in question) really should be the correct way to do this. Having to provide my own little snippets for function calls like that is annoying, but in the long run probably conveys the intent clearer.
I reckon alternative to reverting any changes here would be to change the docs stating that js_namespace shouldn't be used on built-in objects with methods. Sadly JS is extremely inconsistent about this, while you can't grab methods from document without the context, console methods (such as console.log) generally don't care about context at all.
The text was updated successfully, but these errors were encountered:
After filing this I now realize this behavior might have been there long before 0.2.95, but the change to passing things via reference (again not sure why that happens, might be something to do with Trunk) is what enables binding namespaced functions to imports directly.
I just looked at the code gen for imported JS function and wondered whether binding them as typeof fn == 'function' ? fn : notDefined('fn'); would cause problems. So I guess there is my answer.
I would agree that this code gen is incorrect, because it doesn't capture this.
You suggested fixing this with bind, but I think that even that is incorrect. The fix with bind is only correct if we assume that the namespace will always refer to the same object. If the namespace is an object that changes at runtime, then
Think you're right. I'd also prefer just wrapping the caller in a function to make the call site explicit. I only suggested bind since that ties in nicer with the ternary expression, but I suppose the ternary is only there to make debugging easier and is not necessary with the function.
Describe the Bug
I have the following imports in my Rust code:
These follow the examples given in the docs so I don't think I'm doing anything weird.
The codegen for 0.2.93 looks as follows:
This works as intended.
Since 0.2.94 got yanked I can't check that, however in 0.2.95 the codegen has changed:
Ignoring the change to reference passing (not sure why that happens yet but it's not the issue) the new codegen grabs a reference to the JS function directly without its context, which leads to errors when the function is a method and requires its context on call site.
You can easily reproduce the same error in the browser console:
Steps to Reproduce
Use this example from the docs:
Change the parameter from
&str
to a primitive such asu32
.Expected Behavior
The codegen should maintain the callsite as it did in 0.2.93, or it should use the
.bind
method:Additional Context
I'm filing this as a bug since upgrading the version did break my code, however I'm not sure if the thing I'm doing (and the docs in question) really should be the correct way to do this. Having to provide my own little snippets for function calls like that is annoying, but in the long run probably conveys the intent clearer.
I reckon alternative to reverting any changes here would be to change the docs stating that
js_namespace
shouldn't be used on built-in objects with methods. Sadly JS is extremely inconsistent about this, while you can't grab methods fromdocument
without the context,console
methods (such asconsole.log
) generally don't care about context at all.The text was updated successfully, but these errors were encountered: