array.go 583 B

1234567891011121314151617181920212223
  1. package jsc
  2. import (
  3. _ "unsafe"
  4. "github.com/dop251/goja"
  5. )
  6. func NewUint8Array(runtime *goja.Runtime, data []byte) goja.Value {
  7. buffer := runtime.NewArrayBuffer(data)
  8. ctor, loaded := goja.AssertConstructor(runtimeGetUint8Array(runtime))
  9. if !loaded {
  10. panic(runtime.NewTypeError("missing UInt8Array constructor"))
  11. }
  12. array, err := ctor(nil, runtime.ToValue(buffer))
  13. if err != nil {
  14. panic(runtime.NewGoError(err))
  15. }
  16. return array
  17. }
  18. //go:linkname runtimeGetUint8Array github.com/dop251/goja.(*Runtime).getUint8Array
  19. func runtimeGetUint8Array(r *goja.Runtime) *goja.Object