github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/syscall/js/go113_js.go (about) 1 // +build js 2 // +build go1.13 3 4 package js 5 6 func (v Value) String() string { 7 switch v.Type() { 8 case TypeString: 9 return v.internal().String() 10 case TypeUndefined: 11 return "<undefined>" 12 case TypeNull: 13 return "<null>" 14 case TypeBoolean: 15 return "<boolean: " + v.internal().String() + ">" 16 case TypeNumber: 17 return "<number: " + v.internal().String() + ">" 18 case TypeSymbol: 19 return "<symbol>" 20 case TypeObject: 21 return "<object>" 22 case TypeFunction: 23 return "<function>" 24 default: 25 panic("bad type") 26 } 27 } 28 29 // CopyBytesToGo copies bytes from the Uint8Array src to dst. 30 // It returns the number of bytes copied, which will be the minimum of the lengths of src and dst. 31 // CopyBytesToGo panics if src is not an Uint8Array. 32 func CopyBytesToGo(dst []byte, src Value) int { 33 return copy(dst, src.internal().Interface().([]byte)) 34 } 35 36 // func CopyBytesToGo(dst []byte, src Value) int { 37 // s := make([]byte, src.Get("byteLength").Int()) 38 // a := TypedArrayOf(s) 39 // a.Call("set", src) 40 // a.Release() 41 // return copy(dst, s) 42 // } 43 44 // CopyBytesToJS copies bytes from src to the Uint8Array dst. 45 // It returns the number of bytes copied, which will be the minimum of the lengths of src and dst. 46 // CopyBytesToJS panics if dst is not an Uint8Array. 47 func CopyBytesToJS(dst Value, src []byte) int { 48 return copy(dst.internal().Interface().([]byte), src) 49 } 50 51 // func CopyBytesToJS(dst Value, src []byte) int { 52 // n := dst.Get("byteLength").Int() 53 // if n > len(src) { 54 // n = len(src) 55 // } 56 // a := TypedArrayOf(src[:n]) 57 // dst.Call("set", a) 58 // a.Release() 59 // return n 60 // }