ruby.wasm icon indicating copy to clipboard operation
ruby.wasm copied to clipboard

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

Open krmbn0576 opened this issue 1 year ago • 4 comments

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 avatar Feb 05 '24 01:02 krmbn0576

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

krmbn0576 avatar Feb 05 '24 01:02 krmbn0576

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.

krmbn0576 avatar Feb 05 '24 09:02 krmbn0576

@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 :bow:

kateinoigakukun avatar Feb 05 '24 10:02 kateinoigakukun

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 😇

krmbn0576 avatar Feb 06 '24 02:02 krmbn0576