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

syscall/js: copyBytesTo(Go|JS) could accept Uint8ClampedArray #38011

Closed
aurium opened this issue Mar 22, 2020 · 2 comments
Closed

syscall/js: copyBytesTo(Go|JS) could accept Uint8ClampedArray #38011

aurium opened this issue Mar 22, 2020 · 2 comments
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@aurium
Copy link
Contributor

aurium commented Mar 22, 2020

syscall/js: copyBytesTo(Go|JS) could accept Uint8ClampedArray

When compiling Go to WebAssembly (with go 1.13) you can get a great help from syscall/js to interact with JS and web APIs.

One limitation is in reading and updating canvas pixel data with (get|put)ImageData, because we need an intermediary translation between Uint8ClampedArray and Uint8Array. Oderwise CopyBytesToGo panics, also we can't use a ImageData like object with Uint8Array data, or the putImageData will fail.

However, Uint8ClampedArray is just a sugary Uint8Array. I see no problem to make copyBytesTo(Go|JS) accepts that as a source or destiny.

What did you do?

// jsImgData = js.Value of Uint8ClampedArray
imgData := make([]uint8, jsImgData.Length())
// fill imgData with magic...
js.CopyBytesToJS(jsImgData, imgData)

What did you expect to see?

jsImgData filled to be puted in a canvas

What did you see instead?

The log syscall/js: CopyBytesToJS: expected dst to be an Uint8Array.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/224638 mentions this issue: syscall/js: allow copyBytesTo(Go|JS) to use Uint8ClampedArray

@andybons
Copy link
Member

@neelance @cherrymui

@andybons andybons added arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 23, 2020
@andybons andybons added this to the Unplanned milestone Mar 23, 2020
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 28, 2020
@golang golang locked and limited conversation to collaborators Apr 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants