]> Cypherpunks repositories - gostls13.git/commitdiff
syscall/js: allow copyBytesTo(Go|JS) to use Uint8ClampedArray
authorAurélio A. Heckert <aurium@gmail.com>
Sun, 22 Mar 2020 23:38:42 +0000 (20:38 -0300)
committerRichard Musiol <neelance@gmail.com>
Tue, 24 Mar 2020 10:31:12 +0000 (10:31 +0000)
closes #38011

Change-Id: Ic50f2f27456dccdc3fca1bda076871af1eb81705
Reviewed-on: https://go-review.googlesource.com/c/go/+/224638
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Richard Musiol <neelance@gmail.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/wasm/wasm_exec.js
src/syscall/js/js.go

index 5ac40329935a0ca6c4689cbc60cef9f8fb95e69e..8cb297f3793f6fbf454489616785cdaceaa365c2 100644 (file)
                                        "syscall/js.copyBytesToGo": (sp) => {
                                                const dst = loadSlice(sp + 8);
                                                const src = loadValue(sp + 32);
-                                               if (!(src instanceof Uint8Array)) {
+                                               if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
                                                        this.mem.setUint8(sp + 48, 0);
                                                        return;
                                                }
                                        "syscall/js.copyBytesToJS": (sp) => {
                                                const dst = loadValue(sp + 8);
                                                const src = loadSlice(sp + 16);
-                                               if (!(dst instanceof Uint8Array)) {
+                                               if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
                                                        this.mem.setUint8(sp + 48, 0);
                                                        return;
                                                }
index 8a04399171162582ae4c7d1474c46fd10f3817f3..a48bbd4dd794b707bbb50a49fee6691b8eed7340 100644 (file)
@@ -565,28 +565,28 @@ func (e *ValueError) Error() string {
        return "syscall/js: call of " + e.Method + " on " + e.Type.String()
 }
 
-// CopyBytesToGo copies bytes from the Uint8Array src to dst.
+// CopyBytesToGo copies bytes from src to dst.
+// It panics if src is not an Uint8Array or Uint8ClampedArray.
 // It returns the number of bytes copied, which will be the minimum of the lengths of src and dst.
-// CopyBytesToGo panics if src is not an Uint8Array.
 func CopyBytesToGo(dst []byte, src Value) int {
        n, ok := copyBytesToGo(dst, src.ref)
        runtime.KeepAlive(src)
        if !ok {
-               panic("syscall/js: CopyBytesToGo: expected src to be an Uint8Array")
+               panic("syscall/js: CopyBytesToGo: expected src to be an Uint8Array or Uint8ClampedArray")
        }
        return n
 }
 
 func copyBytesToGo(dst []byte, src ref) (int, bool)
 
-// CopyBytesToJS copies bytes from src to the Uint8Array dst.
+// CopyBytesToJS copies bytes from src to dst.
+// It panics if dst is not an Uint8Array or Uint8ClampedArray.
 // It returns the number of bytes copied, which will be the minimum of the lengths of src and dst.
-// CopyBytesToJS panics if dst is not an Uint8Array.
 func CopyBytesToJS(dst Value, src []byte) int {
        n, ok := copyBytesToJS(dst.ref, src)
        runtime.KeepAlive(dst)
        if !ok {
-               panic("syscall/js: CopyBytesToJS: expected dst to be an Uint8Array")
+               panic("syscall/js: CopyBytesToJS: expected dst to be an Uint8Array or Uint8ClampedArray")
        }
        return n
 }