-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added type annotations for a few glue code functions #4189
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am in favor of this change, but I don't feel comfortable approving this without any further input, ideally approval from another maintainer.
Cc @Liamolucko.
In the meantime, I think it would be good to split off the bugfixes you made into a separate PR.
I would also appreciate if you could do some code archeology into instance.ptr
and see where this originated and the context around it.
Didn't review it yet, but it needs a changelog entry.
This is amazing work by the way, thank you! |
Will do.
Seems like the pointer field changed names a few times. 240d3cd (7 years ago) changed it from |
I also found 5d697c1, which was the point where the return value stopped being used anymore but didn't get removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RunDevelopment I'm happy to go ahead and merge this after a rebase.
Would that solve the requirements for #4311 to run type checks on JS as well?
I added type annotations to a few commonly-used JS glue code functions. This makes it a lot easier to understand the glue, because I have TS to help me out.
Those type annotations also make it easier to verify the correctness of glue. And just to prove that: TS found 2 minor bugs in the JS glue code of our tests:
Fixes moved to #4192.
debugString
(this is the JS glue code version offormat!("{:?}", value)
) had a bug where it checked for a regex mismatch incorrectly. This would lead to dereferencingnull
at runtime, which throws aTypeError
._assertClass
returnedinstance.ptr
. Here's the full code of the function:Returninginstance.ptr
is weird for 2 reasons:It's not used anywhere in the code._assertClass
is only used in one place and its return value is ignored.There is noptr
field. The author probably meant__wbg_ptr
to get the internal pointer of a JS object.So I just removed the return statement andinstance.ptr
.Aside from that, I did one additional change: I inline
lTextDecoder
:This just made typing easier, but the expression something to get used to...