Fix the problem of mixing unsigned and signed numbers

Description:use the same number type

Issues:https://gitee.com/openharmony/ark_js_runtime/issues/I5C30M:wq

Signed-off-by: jiangkai43 <jiangkai43@huawei.com>
This commit is contained in:
jiangkai43 2022-06-13 19:59:21 +08:00
parent ee0b465e10
commit acbb7d82e6
5 changed files with 29 additions and 29 deletions

View File

@ -55,8 +55,8 @@ JSTaggedValue AtomicHelper::ValidateIntegerTypedArray(JSThread *thread, JSHandle
return bufferHandle.GetTaggedValue();
}
int32_t AtomicHelper::ValidateAtomicAccess(JSThread *thread, const JSHandle<JSTaggedValue> typedArray,
JSHandle<JSTaggedValue> requestIndex)
uint32_t AtomicHelper::ValidateAtomicAccess(JSThread *thread, const JSHandle<JSTaggedValue> typedArray,
JSHandle<JSTaggedValue> requestIndex)
{
// 1. Assert: typedArray is an Object that has a [[ViewedArrayBuffer]] internal slot.
ASSERT(typedArray->IsECMAObject() && typedArray->IsTypedArray());
@ -82,10 +82,10 @@ int32_t AtomicHelper::ValidateAtomicAccess(JSThread *thread, const JSHandle<JSTa
// 7. Let elementSize be the Element Size value specified in Table 60 for arrayTypeName.
// 8. Let offset be typedArray.[[ByteOffset]].
JSHandle<JSTaggedValue> arrayTypeName(thread, JSTypedArray::Cast(*typedArrayObj)->GetTypedArrayName());
int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, arrayTypeName);
uint32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, arrayTypeName);
uint32_t offset = srcObj->GetByteOffset();
// 9. Return (accessIndex × elementSize) + offset.
int32_t allOffset = index * elementSize + offset;
uint32_t allOffset = index * elementSize + offset;
return allOffset;
}
@ -124,7 +124,7 @@ JSTaggedValue AtomicHelper::AtomicLoad(JSThread *thread, const JSHandle<JSTagged
JSTaggedValue bufferValue = ValidateIntegerTypedArray(thread, typedArray);
JSHandle<JSTaggedValue> buffer(thread, bufferValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t indexedPosition = ValidateAtomicAccess(thread, typedArray, index);
uint32_t indexedPosition = ValidateAtomicAccess(thread, typedArray, index);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) {
THROW_TYPE_ERROR_AND_RETURN(thread, "The ArrayBuffer of this value is detached buffer.",

View File

@ -92,7 +92,7 @@ public:
static JSTaggedValue ValidateIntegerTypedArray(JSThread *thread, JSHandle<JSTaggedValue> typedArray,
bool waitable = false);
// 25.4.2.2 ValidateAtomicAccess ( typedArray, requestIndex )
static int32_t ValidateAtomicAccess(JSThread *thread, const JSHandle<JSTaggedValue> typedArray,
static uint32_t ValidateAtomicAccess(JSThread *thread, const JSHandle<JSTaggedValue> typedArray,
JSHandle<JSTaggedValue> requestIndex);
static JSTaggedValue AtomicStore(JSThread *thread, const JSHandle<JSTaggedValue> &typedArray,
JSHandle<JSTaggedValue> index, JSHandle<JSTaggedValue> &value);

View File

@ -176,7 +176,7 @@ JSTaggedValue BuiltinsAtomics::Wait(EcmaRuntimeCallInfo *argv)
}
// 3. Let indexedPosition be ? ValidateAtomicAccess(typedArray, index).
int32_t indexedPosition = AtomicHelper::ValidateAtomicAccess(thread, array, index);
uint32_t indexedPosition = AtomicHelper::ValidateAtomicAccess(thread, array, index);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 4. If typedArray.[[TypedArrayName]] is "BigInt64Array", let v be ? ToBigInt64(value).
@ -245,7 +245,7 @@ JSTaggedValue BuiltinsAtomics::Notify(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 2. Let indexedPosition be ? ValidateAtomicAccess(typedArray, index).
int32_t indexedPosition = AtomicHelper::ValidateAtomicAccess(thread, array, index);
uint32_t indexedPosition = AtomicHelper::ValidateAtomicAccess(thread, array, index);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 3. If count is undefined, let c be +∞.
@ -281,7 +281,7 @@ JSTaggedValue BuiltinsAtomics::AtomicReadModifyWrite(JSThread *thread, const JSH
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSTaggedValue> buffer(thread, bufferValue);
// 2. Let indexedPosition be ? ValidateAtomicAccess(typedArray, index).
int32_t indexedPosition = base::AtomicHelper::ValidateAtomicAccess(thread, typedArray, index);
uint32_t indexedPosition = base::AtomicHelper::ValidateAtomicAccess(thread, typedArray, index);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 3. Let arrayTypeName be typedArray.[[TypedArrayName]].
JSHandle<JSTaggedValue> arrayTypeName(thread,
@ -301,7 +301,7 @@ JSTaggedValue BuiltinsAtomics::AtomicReadModifyWrite(JSThread *thread, const JSH
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::AtomicReadModifyWriteCase(JSThread *thread, JSTaggedValue arrBuf,
DataViewType type, int32_t indexedPosition,
DataViewType type, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSArrayBuffer *jsArrayBuffer = JSArrayBuffer::Cast(arrBuf.GetTaggedObject());
@ -334,7 +334,7 @@ JSTaggedValue BuiltinsAtomics::AtomicReadModifyWriteCase(JSThread *thread, JSTag
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithUint8(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -354,7 +354,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithUint8(JSThread *thread, uint32_t size,
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithInt8(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -374,7 +374,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithInt8(JSThread *thread, uint32_t size, u
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithUint16(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -394,7 +394,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithUint16(JSThread *thread, uint32_t size,
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithInt16(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -414,7 +414,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithInt16(JSThread *thread, uint32_t size,
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithUint32(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -434,7 +434,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithUint32(JSThread *thread, uint32_t size,
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithInt32(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -454,7 +454,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithInt32(JSThread *thread, uint32_t size,
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithBigInt64(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
@ -477,7 +477,7 @@ JSTaggedValue BuiltinsAtomics::HandleWithBigInt64(JSThread *thread, uint32_t siz
template<typename callbackfun>
JSTaggedValue BuiltinsAtomics::HandleWithBigUint64(JSThread *thread, uint32_t size, uint8_t *block,
int32_t indexedPosition,
uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op)
{
JSHandle<JSTaggedValue> value = BuiltinsBase::GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);

View File

@ -61,31 +61,31 @@ private:
const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue AtomicReadModifyWriteCase(JSThread *thread, JSTaggedValue buffer, DataViewType type,
int32_t indexedPosition, EcmaRuntimeCallInfo *argv,
uint32_t indexedPosition, EcmaRuntimeCallInfo *argv,
const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithUint8(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithUint8(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithInt8(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithInt8(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithUint16(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithUint16(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithInt16(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithInt16(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithUint32(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithUint32(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithInt32(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithInt32(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithBigInt64(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithBigInt64(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
template<typename callbackfun>
static JSTaggedValue HandleWithBigUint64(JSThread *thread, uint32_t size, uint8_t *block, int32_t indexedPosition,
static JSTaggedValue HandleWithBigUint64(JSThread *thread, uint32_t size, uint8_t *block, uint32_t indexedPosition,
EcmaRuntimeCallInfo *argv, const callbackfun &op);
static constexpr int ARGS_NUMBER = 2;

View File

@ -565,11 +565,11 @@ JSHandle<BigInt> BigInt::Uint64ToBigInt(JSThread *thread, const uint64_t &number
int64_t BigInt::ToInt64()
{
int len = GetLength();
uint32_t len = GetLength();
ASSERT(len < 2); // The maximum length of the BigInt data is less 2
uint64_t value = 0;
uint32_t *addr = reinterpret_cast<uint32_t *>(&value);
for (int index = len - 1; index >= 0; --index) {
for (int32_t index = static_cast<int32_t>(len - 1); index >= 0; --index) {
*(addr + index) = GetDigit(index);
}
if (GetSign()) {