package goja

import (
	
	
	
	
	

	
)

type byteOrder bool

const (
	bigEndian    byteOrder = false
	littleEndian byteOrder = true
)

var (
	nativeEndian byteOrder

	arrayBufferType = reflect.TypeOf(ArrayBuffer{})
)

type typedArrayObjectCtor func(buf *arrayBufferObject, offset, length int, proto *Object) *typedArrayObject

type arrayBufferObject struct {
	baseObject
	detached bool
	data     []byte
}

// ArrayBuffer is a Go wrapper around ECMAScript ArrayBuffer. Calling Runtime.ToValue() on it
// returns the underlying ArrayBuffer. Calling Export() on an ECMAScript ArrayBuffer returns a wrapper.
// Use Runtime.NewArrayBuffer([]byte) to create one.
type ArrayBuffer struct {
	buf *arrayBufferObject
}

type dataViewObject struct {
	baseObject
	viewedArrayBuf      *arrayBufferObject
	byteLen, byteOffset int
}

type typedArray interface {
	toRaw(Value) uint64
	get(idx int) Value
	set(idx int, value Value)
	getRaw(idx int) uint64
	setRaw(idx int, raw uint64)
	less(i, j int) bool
	swap(i, j int)
	typeMatch(v Value) bool
	export(offset int, length int) interface{}
	exportType() reflect.Type
}

type uint8Array []byte
type uint8ClampedArray []byte
type int8Array []byte
type uint16Array []byte
type int16Array []byte
type uint32Array []byte
type int32Array []byte
type float32Array []byte
type float64Array []byte
type bigInt64Array []byte
type bigUint64Array []byte

type typedArrayObject struct {
	baseObject
	viewedArrayBuf *arrayBufferObject
	defaultCtor    *Object
	length, offset int
	elemSize       int
	typedArray     typedArray
}

func ( ArrayBuffer) ( *Runtime) Value {
	if .buf == nil {
		return _null
	}
	 := .buf.val
	if .runtime !=  {
		panic(.NewTypeError("Illegal runtime transition of an ArrayBuffer"))
	}
	return 
}

// Bytes returns the underlying []byte for this ArrayBuffer.
// For detached ArrayBuffers returns nil.
func ( ArrayBuffer) () []byte {
	return .buf.data
}

// Detach the ArrayBuffer. After this, the underlying []byte becomes unreferenced and any attempt
// to use this ArrayBuffer results in a TypeError.
// Returns false if it was already detached, true otherwise.
// Note, this method may only be called from the goroutine that 'owns' the Runtime, it may not
// be called concurrently.
func ( ArrayBuffer) () bool {
	if .buf.detached {
		return false
	}
	.buf.detach()
	return true
}

// Detached returns true if the ArrayBuffer is detached.
func ( ArrayBuffer) () bool {
	return .buf.detached
}

// NewArrayBuffer creates a new instance of ArrayBuffer backed by the provided byte slice.
//
// Warning: be careful when using unaligned slices (sub-slices that do not start at word boundaries). If later a
// typed array of a multibyte type (uint16, uint32, etc.) is created from a buffer backed by an unaligned slice,
// using this typed array will result in unaligned access which may cause performance degradation or runtime panics
// on some architectures or configurations.
func ( *Runtime) ( []byte) ArrayBuffer {
	 := ._newArrayBuffer(.getArrayBufferPrototype(), nil)
	.data = 
	return ArrayBuffer{
		buf: ,
	}
}

func ( *uint8Array) ( Value) uint64 {
	return uint64(toUint8())
}

func ( *uint8Array) ( int) *uint8 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*uint8)(unsafe.Pointer(uintptr() + uintptr()))
}

func ( *uint8Array) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *uint8Array) ( int,  Value) {
	*(.ptr()) = toUint8()
}

func ( *uint8Array) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *uint8Array) ( int,  uint64) {
	*(.ptr()) = uint8()
}

func ( *uint8Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *uint8Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *uint8Array) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= 0 &&  <= 255
	}
	return false
}

func ( *uint8Array) ( int,  int) interface{} {
	return ([]uint8)(*)[ : + : +]
}

func ( *uint8Array) () reflect.Type {
	return typeBytes
}

func ( *uint8ClampedArray) ( Value) uint64 {
	return uint64(toUint8Clamp())
}

func ( *uint8ClampedArray) ( int) *uint8 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*uint8)(unsafe.Pointer(uintptr() + uintptr()))
}

func ( *uint8ClampedArray) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *uint8ClampedArray) ( int,  Value) {
	*(.ptr()) = toUint8Clamp()
}

func ( *uint8ClampedArray) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *uint8ClampedArray) ( int,  uint64) {
	*(.ptr()) = uint8()
}

func ( *uint8ClampedArray) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *uint8ClampedArray) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *uint8ClampedArray) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= 0 &&  <= 255
	}
	return false
}

func ( *uint8ClampedArray) ( int,  int) interface{} {
	return ([]uint8)(*)[ : + : +]
}

func ( *uint8ClampedArray) () reflect.Type {
	return typeBytes
}

func ( *int8Array) ( int) *int8 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*int8)(unsafe.Pointer(uintptr() + uintptr()))
}

func ( *int8Array) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *int8Array) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *int8Array) ( int,  Value) {
	*(.ptr()) = toInt8()
}

func ( *int8Array) ( Value) uint64 {
	return uint64(toInt8())
}

func ( *int8Array) ( int,  uint64) {
	*(.ptr()) = int8()
}

func ( *int8Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *int8Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *int8Array) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= math.MinInt8 &&  <= math.MaxInt8
	}
	return false
}

func ( *int8Array) ( int,  int) interface{} {
	var  []int8
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()
	.Len = 
	.Cap = 
	return 
}

var typeInt8Array = reflect.TypeOf(([]int8)(nil))

func ( *int8Array) () reflect.Type {
	return typeInt8Array
}

func ( *uint16Array) ( Value) uint64 {
	return uint64(toUint16())
}

func ( *uint16Array) ( int) *uint16 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*uint16)(unsafe.Pointer(uintptr() + uintptr()*2))
}

func ( *uint16Array) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *uint16Array) ( int,  Value) {
	*(.ptr()) = toUint16()
}

func ( *uint16Array) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *uint16Array) ( int,  uint64) {
	*(.ptr()) = uint16()
}

func ( *uint16Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *uint16Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *uint16Array) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= 0 &&  <= math.MaxUint16
	}
	return false
}

var typeUint16Array = reflect.TypeOf(([]uint16)(nil))

func ( *uint16Array) ( int,  int) interface{} {
	var  []uint16
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*2
	.Len = 
	.Cap = 
	return 
}

func ( *uint16Array) () reflect.Type {
	return typeUint16Array
}

func ( *int16Array) ( int) *int16 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*int16)(unsafe.Pointer(uintptr() + uintptr()*2))
}

func ( *int16Array) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *int16Array) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *int16Array) ( int,  Value) {
	*(.ptr()) = toInt16()
}

func ( *int16Array) ( Value) uint64 {
	return uint64(toInt16())
}

func ( *int16Array) ( int,  uint64) {
	*(.ptr()) = int16()
}

func ( *int16Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *int16Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *int16Array) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= math.MinInt16 &&  <= math.MaxInt16
	}
	return false
}

func ( *int16Array) ( int,  int) interface{} {
	var  []int16
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*2
	.Len = 
	.Cap = 
	return 
}

var typeInt16Array = reflect.TypeOf(([]int16)(nil))

func ( *int16Array) () reflect.Type {
	return typeInt16Array
}

func ( *uint32Array) ( int) *uint32 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*uint32)(unsafe.Pointer(uintptr() + uintptr()*4))
}

func ( *uint32Array) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *uint32Array) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *uint32Array) ( int,  Value) {
	*(.ptr()) = toUint32()
}

func ( *uint32Array) ( Value) uint64 {
	return uint64(toUint32())
}

func ( *uint32Array) ( int,  uint64) {
	*(.ptr()) = uint32()
}

func ( *uint32Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *uint32Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *uint32Array) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= 0 &&  <= math.MaxUint32
	}
	return false
}

func ( *uint32Array) ( int,  int) interface{} {
	var  []uint32
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*4
	.Len = 
	.Cap = 
	return 
}

var typeUint32Array = reflect.TypeOf(([]uint32)(nil))

func ( *uint32Array) () reflect.Type {
	return typeUint32Array
}

func ( *int32Array) ( int) *int32 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*int32)(unsafe.Pointer(uintptr() + uintptr()*4))
}

func ( *int32Array) ( int) Value {
	return intToValue(int64(*(.ptr())))
}

func ( *int32Array) ( int) uint64 {
	return uint64(*(.ptr()))
}

func ( *int32Array) ( int,  Value) {
	*(.ptr()) = toInt32()
}

func ( *int32Array) ( Value) uint64 {
	return uint64(toInt32())
}

func ( *int32Array) ( int,  uint64) {
	*(.ptr()) = int32()
}

func ( *int32Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *int32Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *int32Array) ( Value) bool {
	if ,  := .(valueInt);  {
		return  >= math.MinInt32 &&  <= math.MaxInt32
	}
	return false
}

func ( *int32Array) ( int,  int) interface{} {
	var  []int32
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*4
	.Len = 
	.Cap = 
	return 
}

var typeInt32Array = reflect.TypeOf(([]int32)(nil))

func ( *int32Array) () reflect.Type {
	return typeInt32Array
}

func ( *float32Array) ( int) *float32 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*float32)(unsafe.Pointer(uintptr() + uintptr()*4))
}

func ( *float32Array) ( int) Value {
	return floatToValue(float64(*(.ptr())))
}

func ( *float32Array) ( int) uint64 {
	return uint64(math.Float32bits(*(.ptr())))
}

func ( *float32Array) ( int,  Value) {
	*(.ptr()) = toFloat32()
}

func ( *float32Array) ( Value) uint64 {
	return uint64(math.Float32bits(toFloat32()))
}

func ( *float32Array) ( int,  uint64) {
	*(.ptr()) = math.Float32frombits(uint32())
}

func typedFloatLess(,  float64) bool {
	 := math.IsNaN()
	 := math.IsNaN()
	if  {
		return !
	} else if  {
		return false
	}
	if  == 0 &&  == 0 { // handle neg zero
		return math.Signbit()
	}
	return  < 
}

func ( *float32Array) (,  int) bool {
	return typedFloatLess(float64(*(.ptr())), float64(*(.ptr())))
}

func ( *float32Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *float32Array) ( Value) bool {
	switch .(type) {
	case valueInt, valueFloat:
		return true
	}
	return false
}

func ( *float32Array) ( int,  int) interface{} {
	var  []float32
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*4
	.Len = 
	.Cap = 
	return 
}

var typeFloat32Array = reflect.TypeOf(([]float32)(nil))

func ( *float32Array) () reflect.Type {
	return typeFloat32Array
}

func ( *float64Array) ( int) *float64 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*float64)(unsafe.Pointer(uintptr() + uintptr()*8))
}

func ( *float64Array) ( int) Value {
	return floatToValue(*(.ptr()))
}

func ( *float64Array) ( int) uint64 {
	return math.Float64bits(*(.ptr()))
}

func ( *float64Array) ( int,  Value) {
	*(.ptr()) = .ToFloat()
}

func ( *float64Array) ( Value) uint64 {
	return math.Float64bits(.ToFloat())
}

func ( *float64Array) ( int,  uint64) {
	*(.ptr()) = math.Float64frombits()
}

func ( *float64Array) (,  int) bool {
	return typedFloatLess(*(.ptr()), *(.ptr()))
}

func ( *float64Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *float64Array) ( Value) bool {
	switch .(type) {
	case valueInt, valueFloat:
		return true
	}
	return false
}

func ( *float64Array) ( int,  int) interface{} {
	var  []float64
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*8
	.Len = 
	.Cap = 
	return 
}

var typeFloat64Array = reflect.TypeOf(([]float64)(nil))

func ( *float64Array) () reflect.Type {
	return typeFloat64Array
}

func ( *bigInt64Array) ( Value) uint64 {
	return toBigInt64().Uint64()
}

func ( *bigInt64Array) ( int) *int64 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*int64)(unsafe.Pointer(uintptr() + uintptr()*8))
}

func ( *bigInt64Array) ( int) Value {
	return (*valueBigInt)(big.NewInt(*.ptr()))
}

func toBigInt64( Value) *big.Int {
	 := (*big.Int)(toBigInt())

	 := new(big.Int).Lsh(big.NewInt(1), 64)
	 := new(big.Int).Lsh(big.NewInt(1), 63)

	 := new(big.Int).Mod(, )
	if .Cmp() >= 0 {
		return .Sub(, )
	}
	return 
}

func ( *bigInt64Array) ( int,  Value) {
	*(.ptr()) = toBigInt64().Int64()
}

func ( *bigInt64Array) ( int) uint64 {
	return uint64(*.ptr())
}

func ( *bigInt64Array) ( int,  uint64) {
	*(.ptr()) = int64()
}

func ( *bigInt64Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *bigInt64Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *bigInt64Array) ( Value) bool {
	if ,  := .(*valueBigInt);  {
		return true
	}
	return false
}

func ( *bigInt64Array) ( int,  int) interface{} {
	var  []int64
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*8
	.Len = 
	.Cap = 
	return 
}

var typeBigInt64Array = reflect.TypeOf(([]int64)(nil))

func ( *bigInt64Array) () reflect.Type {
	return typeBigInt64Array
}

func ( *bigUint64Array) ( Value) uint64 {
	return toBigUint64().Uint64()
}

func ( *bigUint64Array) ( int) *uint64 {
	 := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer()).Data)
	return (*uint64)(unsafe.Pointer(uintptr() + uintptr()*8))
}

func ( *bigUint64Array) ( int) Value {
	return (*valueBigInt)(new(big.Int).SetUint64(*.ptr()))
}

func toBigUint64( Value) *big.Int {
	 := (*big.Int)(toBigInt())
	return new(big.Int).Mod(, new(big.Int).Lsh(big.NewInt(1), 64))
}

func ( *bigUint64Array) ( int,  Value) {
	*(.ptr()) = toBigUint64().Uint64()
}

func ( *bigUint64Array) ( int) uint64 {
	return *.ptr()
}

func ( *bigUint64Array) ( int,  uint64) {
	*(.ptr()) = 
}

func ( *bigUint64Array) (,  int) bool {
	return *(.ptr()) < *(.ptr())
}

func ( *bigUint64Array) (,  int) {
	,  := .ptr(), .ptr()
	*, * = *, *
}

func ( *bigUint64Array) ( Value) bool {
	if ,  := .(*valueBigInt);  {
		return true
	}
	return false
}

func ( *bigUint64Array) ( int,  int) interface{} {
	var  []uint64
	 := (*reflect.SliceHeader)(unsafe.Pointer(&))
	.Data = (*reflect.SliceHeader)(unsafe.Pointer()).Data + uintptr()*8
	.Len = 
	.Cap = 
	return 
}

var typeBigUint64Array = reflect.TypeOf(([]uint64)(nil))

func ( *bigUint64Array) () reflect.Type {
	return typeBigUint64Array
}

func ( *typedArrayObject) ( int) Value {
	if 0 <=  &&  < .length {
		if !.viewedArrayBuf.ensureNotDetached(false) {
			return nil
		}
		return .typedArray.get( + .offset)
	}
	return nil
}

func ( *typedArrayObject) ( unistring.String) Value {
	,  := strToIntNum()
	if  {
		 := ._getIdx()
		if  != nil {
			return &valueProperty{
				value:        ,
				writable:     true,
				enumerable:   true,
				configurable: true,
			}
		}
		return nil
	}
	if  == 0 {
		return nil
	}
	return .baseObject.getOwnPropStr()
}

func ( *typedArrayObject) ( valueInt) Value {
	 := ._getIdx(toIntClamp(int64()))
	if  != nil {
		return &valueProperty{
			value:        ,
			writable:     true,
			enumerable:   true,
			configurable: true,
		}
	}
	return nil
}

func ( *typedArrayObject) ( unistring.String,  Value) Value {
	,  := strToIntNum()
	if  {
		return ._getIdx()
	}
	if  == 0 {
		return nil
	}
	return .baseObject.getStr(, )
}

func ( *typedArrayObject) ( valueInt,  Value) Value {
	return ._getIdx(toIntClamp(int64()))
}

func ( *typedArrayObject) ( int) bool {
	if .viewedArrayBuf.ensureNotDetached(false) {
		if  >= 0 &&  < .length {
			return true
		}
	}
	return false
}

func ( *typedArrayObject) ( int,  Value) {
	switch .typedArray.(type) {
	case *bigInt64Array, *bigUint64Array:
		 = toBigInt()
	default:
		 = .ToNumber()
	}
	if .isValidIntegerIndex() {
		.typedArray.set(+.offset, )
	}
}

func ( *typedArrayObject) ( int) bool {
	return .isValidIntegerIndex()
}

func ( *typedArrayObject) ( unistring.String,  Value,  bool) bool {
	,  := strToIntNum()
	if  {
		._putIdx(, )
		return true
	}
	if  == 0 {
		toNumeric() // make sure it throws
		return true
	}
	return .baseObject.setOwnStr(, , )
}

func ( *typedArrayObject) ( valueInt,  Value,  bool) bool {
	._putIdx(toIntClamp(int64()), )
	return true
}

func ( *typedArrayObject) ( unistring.String, ,  Value,  bool) ( bool,  bool) {
	return ._setForeignStr(, .getOwnPropStr(), , , )
}

func ( *typedArrayObject) ( valueInt, ,  Value,  bool) ( bool,  bool) {
	return ._setForeignIdx(, trueValIfPresent(.hasOwnPropertyIdx()), , , )
}

func ( *typedArrayObject) ( unistring.String) bool {
	,  := strToIntNum()
	if  {
		return ._hasIdx()
	}
	if  == 0 {
		return false
	}
	return .baseObject.hasOwnPropertyStr()
}

func ( *typedArrayObject) ( valueInt) bool {
	return ._hasIdx(toIntClamp(int64()))
}

func ( *typedArrayObject) ( unistring.String) bool {
	,  := strToIntNum()
	if  {
		return ._hasIdx()
	}
	if  == 0 {
		return false
	}
	return .baseObject.hasPropertyStr()
}

func ( *typedArrayObject) ( valueInt) bool {
	return .hasOwnPropertyIdx()
}

func ( *typedArrayObject) ( int,  PropertyDescriptor,  bool) bool {
	if .Configurable == FLAG_FALSE || .Enumerable == FLAG_FALSE || .IsAccessor() || .Writable == FLAG_FALSE {
		.val.runtime.typeErrorResult(, "Cannot redefine property: %d", )
		return false
	}
	,  := ._defineOwnProperty(unistring.String(strconv.Itoa()), .getOwnPropIdx(valueInt()), , )
	if  {
		if !.isValidIntegerIndex() {
			.val.runtime.typeErrorResult(, "Invalid typed array index")
			return false
		}
		._putIdx(, .Value)
		return true
	}
	return 
}

func ( *typedArrayObject) ( unistring.String,  PropertyDescriptor,  bool) bool {
	,  := strToIntNum()
	if  {
		return ._defineIdxProperty(, , )
	}
	if  == 0 {
		.viewedArrayBuf.ensureNotDetached()
		.val.runtime.typeErrorResult(, "Invalid typed array index")
		return false
	}
	return .baseObject.defineOwnPropertyStr(, , )
}

func ( *typedArrayObject) ( valueInt,  PropertyDescriptor,  bool) bool {
	return ._defineIdxProperty(toIntClamp(int64()), , )
}

func ( *typedArrayObject) ( unistring.String,  bool) bool {
	,  := strToIntNum()
	if  {
		if .isValidIntegerIndex() {
			.val.runtime.typeErrorResult(, "Cannot delete property '%d' of %s", , .val.String())
			return false
		}
		return true
	}
	if  == 0 {
		return true
	}
	return .baseObject.deleteStr(, )
}

func ( *typedArrayObject) ( valueInt,  bool) bool {
	if .viewedArrayBuf.ensureNotDetached(false) &&  >= 0 && int64() < int64(.length) {
		.val.runtime.typeErrorResult(, "Cannot delete property '%d' of %s", , .val.String())
		return false
	}

	return true
}

func ( *typedArrayObject) ( bool,  []Value) []Value {
	if  == nil {
		 = make([]Value, 0, .length)
	}
	for  := 0;  < .length; ++ {
		 = append(, asciiString(strconv.Itoa()))
	}
	return .baseObject.stringKeys(, )
}

type typedArrayPropIter struct {
	a   *typedArrayObject
	idx int
}

func ( *typedArrayPropIter) () (propIterItem, iterNextFunc) {
	if .idx < .a.length {
		 := strconv.Itoa(.idx)
		 := .a._getIdx(.idx)
		.idx++
		return propIterItem{name: asciiString(), value: }, .
	}

	return .a.baseObject.iterateStringKeys()()
}

func ( *typedArrayObject) () iterNextFunc {
	return (&typedArrayPropIter{
		a: ,
	}).next
}

func ( *typedArrayObject) ( reflect.Value,  reflect.Type,  *objectExportCtx) error {
	if  == typeBytes {
		.Set(reflect.ValueOf(.viewedArrayBuf.data))
		return nil
	}
	return .baseObject.exportToArrayOrSlice(, , )
}

func ( *typedArrayObject) ( *objectExportCtx) interface{} {
	return .typedArray.export(.offset, .length)
}

func ( *typedArrayObject) () reflect.Type {
	return .typedArray.exportType()
}

func ( *dataViewObject) ( reflect.Value,  reflect.Type,  *objectExportCtx) error {
	if  == typeBytes {
		.Set(reflect.ValueOf(.viewedArrayBuf.data))
		return nil
	}
	return .baseObject.exportToArrayOrSlice(, , )
}

func ( *Runtime) ( *arrayBufferObject, , ,  int,  *Object,  typedArray,  *Object) *typedArrayObject {
	 := &Object{runtime: }
	 := &typedArrayObject{
		baseObject: baseObject{
			val:        ,
			class:      classObject,
			prototype:  ,
			extensible: true,
		},
		viewedArrayBuf: ,
		offset:         ,
		length:         ,
		elemSize:       ,
		defaultCtor:    ,
		typedArray:     ,
	}
	.self = 
	.init()
	return 

}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	// Note, no need to use r.getUint8Array() here or in the similar methods below, because the value is already set
	// by the time they are called.
	return ._newTypedArrayObject(, , , 1, .global.Uint8Array, (*uint8Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 1, .global.Uint8ClampedArray, (*uint8ClampedArray)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 1, .global.Int8Array, (*int8Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 2, .global.Uint16Array, (*uint16Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 2, .global.Int16Array, (*int16Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 4, .global.Uint32Array, (*uint32Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 4, .global.Int32Array, (*int32Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 4, .global.Float32Array, (*float32Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 8, .global.Float64Array, (*float64Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 8, .global.BigInt64Array, (*bigInt64Array)(&.data), )
}

func ( *Runtime) ( *arrayBufferObject, ,  int,  *Object) *typedArrayObject {
	return ._newTypedArrayObject(, , , 8, .global.BigUint64Array, (*bigUint64Array)(&.data), )
}

func ( *dataViewObject) ( int,  Value,  int) (int, byteOrder) {
	.viewedArrayBuf.ensureNotDetached(true)
	if + > .byteLen {
		panic(.val.runtime.newError(.val.runtime.getRangeError(), "Index %d is out of bounds", ))
	}
	 += .byteOffset
	var  byteOrder
	if  != nil {
		if .ToBoolean() {
			 = littleEndian
		} else {
			 = bigEndian
		}
	} else {
		 = nativeEndian
	}
	return , 
}

func ( *arrayBufferObject) ( bool) bool {
	if .detached {
		.val.runtime.typeErrorResult(, "ArrayBuffer is detached")
		return false
	}
	return true
}

func ( *arrayBufferObject) ( int,  byteOrder) float32 {
	return math.Float32frombits(.getUint32(, ))
}

func ( *arrayBufferObject) ( int,  float32,  byteOrder) {
	.setUint32(, math.Float32bits(), )
}

func ( *arrayBufferObject) ( int,  byteOrder) float64 {
	return math.Float64frombits(.getUint64(, ))
}

func ( *arrayBufferObject) ( int,  float64,  byteOrder) {
	.setUint64(, math.Float64bits(), )
}

func ( *arrayBufferObject) ( int,  byteOrder) uint64 {
	var  []byte
	if  == nativeEndian {
		 = .data[ : +8]
	} else {
		 = make([]byte, 8)
		 := .data[ : +8]
		[0], [1], [2], [3], [4], [5], [6], [7] = [7], [6], [5], [4], [3], [2], [1], [0]
	}
	return *((*uint64)(unsafe.Pointer(&[0])))
}

func ( *arrayBufferObject) ( int,  uint64,  byteOrder) {
	if  == nativeEndian {
		*(*uint64)(unsafe.Pointer(&.data[])) = 
	} else {
		 := (*[8]byte)(unsafe.Pointer(&))
		 := .data[ : +8]
		[0], [1], [2], [3], [4], [5], [6], [7] = [7], [6], [5], [4], [3], [2], [1], [0]
	}
}

func ( *arrayBufferObject) ( int,  byteOrder) uint32 {
	var  []byte
	if  == nativeEndian {
		 = .data[ : +4]
	} else {
		 = make([]byte, 4)
		 := .data[ : +4]
		[0], [1], [2], [3] = [3], [2], [1], [0]
	}
	return *((*uint32)(unsafe.Pointer(&[0])))
}

func ( *arrayBufferObject) ( int,  uint32,  byteOrder) {
	.ensureNotDetached(true)
	if  == nativeEndian {
		*(*uint32)(unsafe.Pointer(&.data[])) = 
	} else {
		 := (*[4]byte)(unsafe.Pointer(&))
		 := .data[ : +4]
		[0], [1], [2], [3] = [3], [2], [1], [0]
	}
}

func ( *arrayBufferObject) ( int,  byteOrder) *big.Int {
	var  []byte
	if  == nativeEndian {
		 = .data[ : +8]
	} else {
		 = make([]byte, 8)
		 := .data[ : +8]
		[0], [1], [2], [3], [4], [5], [6], [7] = [7], [6], [5], [4], [3], [2], [1], [0]
	}
	return big.NewInt(*((*int64)(unsafe.Pointer(&[0]))))
}

func ( *arrayBufferObject) ( int,  byteOrder) *big.Int {
	var  []byte
	if  == nativeEndian {
		 = .data[ : +8]
	} else {
		 = make([]byte, 8)
		 := .data[ : +8]
		[0], [1], [2], [3], [4], [5], [6], [7] = [7], [6], [5], [4], [3], [2], [1], [0]
	}
	return new(big.Int).SetUint64(*((*uint64)(unsafe.Pointer(&[0]))))
}

func ( *arrayBufferObject) ( int,  *big.Int,  byteOrder) {
	if  == nativeEndian {
		*(*int64)(unsafe.Pointer(&.data[])) = .Int64()
	} else {
		 := .Int64()
		 := (*[8]byte)(unsafe.Pointer(&))
		 := .data[ : +8]
		[0], [1], [2], [3], [4], [5], [6], [7] = [7], [6], [5], [4], [3], [2], [1], [0]
	}
}

func ( *arrayBufferObject) ( int,  *big.Int,  byteOrder) {
	if  == nativeEndian {
		*(*uint64)(unsafe.Pointer(&.data[])) = .Uint64()
	} else {
		 := .Uint64()
		 := (*[8]byte)(unsafe.Pointer(&))
		 := .data[ : +8]
		[0], [1], [2], [3], [4], [5], [6], [7] = [7], [6], [5], [4], [3], [2], [1], [0]
	}
}

func ( *arrayBufferObject) ( int,  byteOrder) uint16 {
	var  []byte
	if  == nativeEndian {
		 = .data[ : +2]
	} else {
		 = make([]byte, 2)
		 := .data[ : +2]
		[0], [1] = [1], [0]
	}
	return *((*uint16)(unsafe.Pointer(&[0])))
}

func ( *arrayBufferObject) ( int,  uint16,  byteOrder) {
	if  == nativeEndian {
		*(*uint16)(unsafe.Pointer(&.data[])) = 
	} else {
		 := (*[2]byte)(unsafe.Pointer(&))
		 := .data[ : +2]
		[0], [1] = [1], [0]
	}
}

func ( *arrayBufferObject) ( int) uint8 {
	return .data[]
}

func ( *arrayBufferObject) ( int,  uint8) {
	.data[] = 
}

func ( *arrayBufferObject) ( int,  byteOrder) int32 {
	return int32(.getUint32(, ))
}

func ( *arrayBufferObject) ( int,  int32,  byteOrder) {
	.setUint32(, uint32(), )
}

func ( *arrayBufferObject) ( int,  byteOrder) int16 {
	return int16(.getUint16(, ))
}

func ( *arrayBufferObject) ( int,  int16,  byteOrder) {
	.setUint16(, uint16(), )
}

func ( *arrayBufferObject) ( int) int8 {
	return int8(.data[])
}

func ( *arrayBufferObject) ( int,  int8) {
	.setUint8(, uint8())
}

func ( *arrayBufferObject) () {
	.data = nil
	.detached = true
}

func ( *arrayBufferObject) () reflect.Type {
	return arrayBufferType
}

func ( *arrayBufferObject) (*objectExportCtx) interface{} {
	return ArrayBuffer{
		buf: ,
	}
}

func ( *arrayBufferObject) ( reflect.Value,  reflect.Type,  *objectExportCtx) error {
	if  == typeBytes {
		.Set(reflect.ValueOf(.data))
		return nil
	}
	return .baseObject.exportToArrayOrSlice(, , )
}

func ( *Runtime) ( *Object,  *Object) *arrayBufferObject {
	if  == nil {
		 = &Object{runtime: }
	}
	 := &arrayBufferObject{
		baseObject: baseObject{
			class:      classObject,
			val:        ,
			prototype:  ,
			extensible: true,
		},
	}
	.self = 
	.init()
	return 
}

func init() {
	 := [2]byte{}
	*(*uint16)(unsafe.Pointer(&[0])) = uint16(0xCAFE)

	switch  {
	case [2]byte{0xFE, 0xCA}:
		nativeEndian = littleEndian
	case [2]byte{0xCA, 0xFE}:
		nativeEndian = bigEndian
	default:
		panic("Could not determine native endianness.")
	}
}