Skip to content

Commit

Permalink
Fixed check BigInt64Array
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyk committed Aug 18, 2024
1 parent b230c59 commit 6017f8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 6 additions & 1 deletion builtin_typedarrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,12 @@ func (r *Runtime) typedArrayProto_with(call FunctionCall) Value {
panic(r.newError(r.getRangeError(), "Invalid typed array index"))
}

numericValue := toNumeric(call.Argument(1))
var numericValue Value
if ta.typedArray.exportType() == typeBigInt64Array {
numericValue = toBigInt(call.Argument(1))
} else {
numericValue = call.Argument(1).ToNumber()
}

a := r.typedArrayCreate(ta.defaultCtor, intToValue(int64(length)))
for k := 0; k < length; k++ {
Expand Down
9 changes: 4 additions & 5 deletions typedarrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,10 @@ func (a *bigInt64Array) export(offset int, length int) interface{} {
return ret
}

var typeBigIntArray = reflect.TypeOf(([]*big.Int)(nil))
var typeBigInt64Array = reflect.TypeOf(([]*big.Int)(nil))

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

func (a *bigUint64Array) toRaw(value Value) uint64 {
Expand Down Expand Up @@ -762,7 +762,7 @@ func (a *bigUint64Array) export(offset int, length int) interface{} {
}

func (a *bigUint64Array) exportType() reflect.Type {
return typeBigIntArray
return typeBigInt64Array
}

func (a *typedArrayObject) _getIdx(idx int) Value {
Expand Down Expand Up @@ -833,8 +833,7 @@ func (a *typedArrayObject) isValidIntegerIndex(idx int) bool {
}

func (a *typedArrayObject) _putIdx(idx int, v Value) {
if a.defaultCtor == a.val.runtime.global.BigInt64Array ||
a.defaultCtor == a.val.runtime.global.BigUint64Array {
if a.typedArray.exportType() == typeBigInt64Array {
v = toBigInt(v)
} else {
v = v.ToNumber()
Expand Down

0 comments on commit 6017f8f

Please sign in to comment.