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

specialize ArrayBuffer#to_s and return ASCII-8BIT data #384

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

krmbn0576
Copy link
Contributor

To fix #342 , specialize ArrayBuffer#to_s and return ASCII-8BIT data.

Usage:

require "js"

response = JS.global.fetch("<dumped buffer's url>").await
puts response[:status]

arraybuffer = response.arrayBuffer.await

Marshal.load(arraybuffer.to_s) # we can Marshal.load now!

Of course this is destructive, but no one will spare the old behavior since the current to_s always returns [object ArrayBuffer] and is useless.

@krmbn0576
Copy link
Contributor Author

krmbn0576 commented Feb 5, 2024

Hey why doesn't linter give me an error message? I mean, there's nothing I can do about it.

Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

The "bindgen" files are auto generated sources and that's why CI lint complains about. Would you mind implementing it in other ways? Also would you mind adding test cases?

@krmbn0576
Copy link
Contributor Author

krmbn0576 commented Feb 5, 2024

Sorry for my lack of learning, but in my experiments, this worked fine.
What is the file from which rb-js-abi-host.js was generated?
I will edit that one, but I cannot find the corresponding *.wit file.

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Feb 5, 2024

@krmbn0576 This one https://github.com/ruby/ruby.wasm/blob/main/packages/gems/js/ext/witapi/bindgen/rb-abi-guest.wit

I recently moved the file and I might forget to update docs that pointing that old path. In that case, I'm sorry 🙇

@krmbn0576
Copy link
Contributor Author

Thanks! But it is unexpected. In that file, there are only definitions and no implementation. More to the point, there is not even a definition for the js-value-to-string function, so I cannot edit implementation.

It seems I am overloaded to properly edit bindgen to bring a complete solution to this issue. But no worries. I have confirmed that the patch works properly and faster in my product. My issue has been resolved 😇

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

Successfully merging this pull request may close these issues.

Port arraybuffer to ruby
2 participants