!973 fix codeDex warning

Merge pull request !973 from zhaozhibo/master
This commit is contained in:
openharmony_ci 2022-04-12 08:41:37 +00:00 committed by Gitee
commit d3b388c723
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 248 additions and 193 deletions

View File

@ -269,9 +269,9 @@ bool JsonStringifier::CalculateNumberGap(JSTaggedValue gap)
bool JsonStringifier::CalculateStringGap(const JSHandle<EcmaString> &primString)
{
CString gapString = ConvertToString(*primString, StringConvertedUsage::LOGICOPERATION);
int gapLen = gapString.length();
uint32_t gapLen = gapString.length();
if (gapLen > 0) {
int gapLength = std::min(gapLen, GAP_MAX_LEN);
int gapLength = std::min(gapLen, static_cast<uint32_t>(GAP_MAX_LEN));
CString str = gapString.substr(0, gapLength);
gap_ += str;
gap_.append("\0");
@ -696,7 +696,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
JSHandle<JSHClass> jsHclass(thread_, obj->GetJSHClass());
JSTaggedValue enumCache = jsHclass->GetEnumCache();
if (!enumCache.IsNull()) {
int propsNumber = jsHclass->NumberOfProps();
int propsNumber = static_cast<int>(jsHclass->NumberOfProps());
JSHandle<TaggedArray> cache(thread_, enumCache);
uint32_t length = cache->GetLength();
for (uint32_t i = 0; i < length; i++) {
@ -711,8 +711,8 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
PropertyAttributes attr(layoutInfo->GetAttr(index));
ASSERT(static_cast<int>(attr.GetOffset()) == index);
value = attr.IsInlinedProps()
? obj->GetPropertyInlinedProps(index)
: propertiesArr->Get(index - jsHclass->GetInlinedProperties());
? obj->GetPropertyInlinedProps(static_cast<uint32_t>(index))
: propertiesArr->Get(static_cast<uint32_t>(index - jsHclass->GetInlinedProperties()));
if (UNLIKELY(value.IsAccessor())) {
value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()),
JSHandle<JSTaggedValue>(obj));
@ -723,11 +723,11 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
}
return hasContent;
}
int end = jsHclass->NumberOfProps();
int end = static_cast<int>(jsHclass->NumberOfProps());
if (end <= 0) {
return hasContent;
}
int propsNumber = jsHclass->NumberOfProps();
int propsNumber = static_cast<int>(jsHclass->NumberOfProps());
for (int i = 0; i < end; i++) {
LayoutInfo *layoutInfo = LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject());
JSTaggedValue key = layoutInfo->GetKey(i);
@ -738,8 +738,8 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
PropertyAttributes attr(layoutInfo->GetAttr(index));
ASSERT(static_cast<int>(attr.GetOffset()) == index);
value = attr.IsInlinedProps()
? obj->GetPropertyInlinedProps(index)
: propertiesArr->Get(index - jsHclass->GetInlinedProperties());
? obj->GetPropertyInlinedProps(static_cast<uint32_t>(index))
: propertiesArr->Get(static_cast<uint32_t>(index - jsHclass->GetInlinedProperties()));
if (UNLIKELY(value.IsAccessor())) {
value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()),
JSHandle<JSTaggedValue>(obj));

View File

@ -238,7 +238,7 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const
break;
}
int currentBit = ToDigit(*p);
int currentBit = static_cast<int>(ToDigit(*p));
if (currentBit >= radix) {
isDone = true;
break;
@ -581,10 +581,10 @@ double NumberHelper::StringToDouble(const uint8_t *start, const uint8_t *end, ui
}
uint8_t digit;
while ((digit = ToDigit(*p)) < radix) {
if (additionalExponent > MAX_EXPONENT / radix) {
if (additionalExponent > static_cast<int>(MAX_EXPONENT / radix)) {
additionalExponent = MAX_EXPONENT;
} else {
additionalExponent = additionalExponent * radix + digit;
additionalExponent = static_cast<int>(additionalExponent * radix + digit);
}
if (++p == end) {
break;

View File

@ -81,7 +81,7 @@ EcmaString *StringHelper::Trim(JSThread *thread, const std::u16string &thisStr)
const char16_t *constChar16tData = tmpStr.data();
auto *char16tData = const_cast<char16_t *>(constChar16tData);
auto *uint16tData = reinterpret_cast<uint16_t *>(char16tData);
int32_t length = tmpStr.size();
uint32_t length = tmpStr.size();
return *factory->NewFromUtf16(uint16tData, length);
}
} // namespace panda::ecmascript::base

View File

@ -186,7 +186,7 @@ public:
static inline std::string Utf32ToString(uint32_t u32Data)
{
UChar32 charData = u32Data;
UChar32 charData = static_cast<int32_t>(u32Data);
icu::UnicodeString uString(charData);
std::string res;
uString.toUTF8String(res);

View File

@ -111,7 +111,7 @@ JSTaggedValue TypedArrayHelper::CreateFromOrdinaryObject(EcmaRuntimeCallInfo *ar
vec.push_back(nextValue);
}
}
int32_t len = vec.size();
int32_t len = static_cast<int32_t>(vec.size());
TypedArrayHelper::AllocateTypedArrayBuffer(thread, ecmaVm, obj, len);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// d. Let k be 0.
@ -276,11 +276,11 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv,
[[maybe_unused]] EcmaHandleScope handleScope(thread);
// 5. Let elementSize be the Element Size value specified in Table 61 for constructorName.
// 6. Let offset be ? ToIndex(byteOffset).
int32_t elementSize = TypedArrayHelper::GetSizeFromName(thread, constructorName);
uint32_t elementSize = static_cast<uint32_t>(TypedArrayHelper::GetSizeFromName(thread, constructorName));
JSHandle<JSTaggedValue> byteOffset = BuiltinsBase::GetCallArg(argv, 1);
JSTaggedNumber index = JSTaggedValue::ToIndex(thread, byteOffset);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
auto offset = static_cast<int32_t>(index.GetNumber());
auto offset = static_cast<uint32_t>(index.GetNumber());
// 7. If offset modulo elementSize ≠ 0, throw a RangeError exception.
if (offset % elementSize != 0) {
THROW_RANGE_ERROR_AND_RETURN(thread, "The offset cannot be an integral multiple of elementSize.",
@ -312,7 +312,7 @@ JSTaggedValue TypedArrayHelper::CreateFromArrayBuffer(EcmaRuntimeCallInfo *argv,
THROW_RANGE_ERROR_AND_RETURN(thread, "The bufferByteLength cannot be an integral multiple of elementSize.",
JSTaggedValue::Exception());
}
newByteLength = bufferByteLength - offset;
newByteLength = static_cast<int32_t>(bufferByteLength - offset);
if (newByteLength < 0) {
THROW_RANGE_ERROR_AND_RETURN(thread, "The newByteLength is less than 0.", JSTaggedValue::Exception());
}

View File

@ -207,7 +207,7 @@ std::pair<uint32_t, size_t> ConvertUtf8ToUtf16Pair(const uint8_t *data, bool com
if (combine) {
uint32_t lead = ((codePoint >> (utf::PAIR_ELEMENT_WIDTH - utf::DATA_WIDTH)) + utf::U16_LEAD);
uint32_t tail = ((codePoint & utf::MASK_10BIT) + utf::U16_TAIL) & utf::MASK_16BIT;
pair = U16_GET_SUPPLEMENTARY(lead, tail); // NOLINTNEXTLINE(hicpp-signed-bitwise)
pair = static_cast<uint32_t>(U16_GET_SUPPLEMENTARY(lead, tail)); // NOLINTNEXTLINE(hicpp-signed-bitwise)
} else {
pair |= ((codePoint >> (utf::PAIR_ELEMENT_WIDTH - utf::DATA_WIDTH)) + utf::U16_LEAD) << utf::PAIR_ELEMENT_WIDTH;
pair |= ((codePoint & utf::MASK_10BIT) + utf::U16_TAIL) & utf::MASK_16BIT;

View File

@ -1195,7 +1195,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv)
JSHandle<EcmaString> sepStringHandle = JSTaggedValue::ToString(thread, sepHandle);
// 7. ReturnIfAbrupt(sep).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t sepLen = sepStringHandle->GetLength();
uint32_t sepLen = sepStringHandle->GetLength();
std::u16string sepStr;
if (sepStringHandle->IsUtf16()) {
sepStr = base::StringHelper::Utf16ToU16String(sepStringHandle->GetDataUtf16(), sepLen);
@ -1228,7 +1228,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv)
if (!element->IsUndefined() && !element->IsNull()) {
JSHandle<EcmaString> nextStringHandle = JSTaggedValue::ToString(thread, element);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t nextLen = nextStringHandle->GetLength();
uint32_t nextLen = nextStringHandle->GetLength();
if (nextStringHandle->IsUtf16()) {
nextStr = base::StringHelper::Utf16ToU16String(nextStringHandle->GetDataUtf16(), nextLen);
} else {
@ -1247,7 +1247,7 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv)
const char16_t *constChar16tData = concatStr.data();
auto *char16tData = const_cast<char16_t *>(constChar16tData);
auto *uint16tData = reinterpret_cast<uint16_t *>(char16tData);
int32_t u16strSize = concatStr.size();
uint32_t u16strSize = concatStr.size();
return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue();
}

View File

@ -128,7 +128,7 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv)
THROW_TYPE_ERROR_AND_RETURN(thread, "this value IsDetachedBuffer", JSTaggedValue::Exception());
}
// 5. Let len be the value of Os [[ArrayBufferByteLength]] internal slot.
int32_t len = arrBuf->GetArrayBufferByteLength();
int32_t len = static_cast<int32_t>(arrBuf->GetArrayBufferByteLength());
JSHandle<JSTaggedValue> startHandle = GetCallArg(argv, 0);
// 6. Let relativeStart be ToInteger(start).
JSTaggedNumber relativeStart = JSTaggedValue::ToInteger(thread, startHandle);
@ -284,7 +284,7 @@ JSTaggedValue BuiltinsArrayBuffer::CloneArrayBuffer(JSThread *thread, const JSHa
// 5. Assert: srcByteOffset ≤ srcLength.
ASSERT(srcByteOffset <= srcLen);
// 6. Let cloneLength be srcLength srcByteOffset.
int32_t cloneLen = srcLen - srcByteOffset;
int32_t cloneLen = static_cast<int32_t>(srcLen - srcByteOffset);
// 8. Let targetBuffer be AllocateArrayBuffer(cloneConstructor, cloneLength).
JSTaggedValue taggedBuf = AllocateArrayBuffer(thread, constructor, cloneLen);
// 9. ReturnIfAbrupt(targetBuffer).
@ -559,7 +559,7 @@ void BuiltinsArrayBuffer::SetValueInBufferForUint8Clamped(double val, uint8_t *b
val = val >= UINT8_MAX ? UINT8_MAX : val;
constexpr double HALF = 0.5;
val = val == HALF ? 0 : std::round(val);
res = static_cast<int64_t>(val);
res = static_cast<uint64_t>(val);
SetTypeData(block, res, byteIndex);
}

View File

@ -56,7 +56,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv)
if (offsetInt < 0) {
THROW_RANGE_ERROR_AND_RETURN(thread, "Offset out of range", JSTaggedValue::Exception());
}
uint32_t offset = offsetInt;
uint32_t offset = static_cast<uint32_t>(offsetInt);
// 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
if (BuiltinsArrayBuffer::IsDetachedBuffer(bufferHandle.GetTaggedValue())) {
THROW_TYPE_ERROR_AND_RETURN(thread, "buffer is Detached Buffer", JSTaggedValue::Exception());
@ -78,7 +78,7 @@ JSTaggedValue BuiltinsDataView::DataViewConstructor(EcmaRuntimeCallInfo *argv)
JSTaggedNumber byteLen = JSTaggedValue::ToIndex(thread, byteLenHandle);
// ReturnIfAbrupt(viewByteLength).
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
viewByteLen = byteLen.ToInt32();
viewByteLen = static_cast<uint32_t>(byteLen.ToInt32());
// If offset+viewByteLength > bufferByteLength, throw a RangeError exception.
if (offset + viewByteLen > bufByteLen) {
THROW_RANGE_ERROR_AND_RETURN(thread, "offset + viewByteLen > bufByteLen", JSTaggedValue::Exception());
@ -347,7 +347,7 @@ JSTaggedValue BuiltinsDataView::GetViewValue(JSThread *thread, const JSHandle<JS
if (indexInt < 0) {
THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex < 0", JSTaggedValue::Exception());
}
uint32_t index = indexInt;
uint32_t index = static_cast<uint32_t>(indexInt);
// 7. Let isLittleEndian be ToBoolean(isLittleEndian).
bool isLittleEndian = false;
if (littleEndian.IsUndefined()) {
@ -424,11 +424,11 @@ JSTaggedValue BuiltinsDataView::SetViewValue(JSThread *thread, const JSHandle<JS
// 12. Let elementSize be the Number value of the Element Size value specified in Table 49 for Element Type type.
uint32_t elementSize = JSDataView::GetElementSize(type);
// 13. If getIndex +elementSize > viewSize, throw a RangeError exception.
if (index + elementSize > size) {
if (static_cast<uint32_t>(index) + elementSize > size) {
THROW_RANGE_ERROR_AND_RETURN(thread, "getIndex +elementSize > viewSize", JSTaggedValue::Exception());
}
// 14. Let bufferIndex be getIndex + viewOffset.
uint32_t bufferIndex = index + offset;
uint32_t bufferIndex = static_cast<uint32_t>(index) + offset;
// 15. Return SetValueFromBuffer(buffer, bufferIndex, type, value, isLittleEndian).
return BuiltinsArrayBuffer::SetValueInBuffer(thread, buffer, bufferIndex, type, numValueHandle, isLittleEndian);
}

View File

@ -201,7 +201,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle<EcmaString
// a. If k equals strLen, return R.
if (k == strLen) {
auto *uint16tData = reinterpret_cast<uint16_t *>(resStr.data());
int32_t resSize = resStr.size();
uint32_t resSize = resStr.size();
return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue();
}
@ -261,7 +261,7 @@ JSTaggedValue BuiltinsGlobal::Encode(JSThread *thread, const JSHandle<EcmaString
uint32_t length = oct.length();
std::stringstream tmpStr;
for (uint32_t j = 0; j < length; j++) {
uint8_t joct = oct.at(j);
uint8_t joct = static_cast<uint8_t>(oct.at(j));
tmpStr << '%' << hexStr.at((joct >> 4U) & BIT_MASK) // NOLINT
<< hexStr.at(joct & BIT_MASK); // 4: means shift right by 4 digits
}
@ -300,7 +300,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle<EcmaString
// a. If k equals strLen, return R.
if (k == strLen) {
auto *uint16tData = reinterpret_cast<uint16_t *>(resStr.data());
int32_t resSize = resStr.size();
uint32_t resSize = resStr.size();
return factory->NewFromUtf16Literal(uint16tData, resSize).GetTaggedValue();
}
@ -378,7 +378,7 @@ JSTaggedValue BuiltinsGlobal::Decode(JSThread *thread, const JSHandle<EcmaString
// b. Let H be ((((V 0x10000) >> 10) & 0x3FF) + 0xD800).
// c. Let S be the String containing the two code units H and L.
uint32_t n = 0;
while ((((bb << n) & BIT_MASK_ONE) != 0)) {
while ((((static_cast<uint32_t>(bb) << n) & BIT_MASK_ONE) != 0)) {
n++;
if (n > 4) // 4 : 4 means less than 4
break;

View File

@ -363,9 +363,9 @@ JSTaggedValue BuiltinsMath::Hypot(EcmaRuntimeCallInfo *argv)
[[maybe_unused]] EcmaHandleScope handleScope(thread);
double result = 0;
double value = 0;
int argLen = argv->GetArgsNumber();
uint32_t argLen = argv->GetArgsNumber();
auto numberValue = JSTaggedNumber(0);
for (int i = 0; i < argLen; i++) {
for (uint32_t i = 0; i < argLen; i++) {
JSHandle<JSTaggedValue> msg = GetCallArg(argv, i);
numberValue = JSTaggedValue::ToNumber(thread, msg);
value = numberValue.GetNumber();
@ -482,13 +482,13 @@ JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv)
BUILTINS_API_TRACE(argv->GetThread(), Math, Max);
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
int argLen = argv->GetArgsNumber();
uint32_t argLen = argv->GetArgsNumber();
auto numberValue = JSTaggedNumber(-base::POSITIVE_INFINITY);
// If no arguments are given, the result is -inf
auto result = JSTaggedNumber(-base::POSITIVE_INFINITY);
auto tmpMax = -base::POSITIVE_INFINITY;
auto value = -base::POSITIVE_INFINITY;
for (int i = 0; i < argLen; i++) {
for (uint32_t i = 0; i < argLen; i++) {
JSHandle<JSTaggedValue> msg = GetCallArg(argv, i);
numberValue = JSTaggedValue::ToNumber(thread, msg);
value = numberValue.GetNumber();
@ -516,13 +516,13 @@ JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv)
BUILTINS_API_TRACE(argv->GetThread(), Math, Min);
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
int argLen = argv->GetArgsNumber();
uint32_t argLen = argv->GetArgsNumber();
auto numberValue = JSTaggedNumber(base::POSITIVE_INFINITY);
// If no arguments are given, the result is inf
auto result = JSTaggedNumber(base::POSITIVE_INFINITY);
auto tmpMin = base::POSITIVE_INFINITY;
auto value = base::POSITIVE_INFINITY;
for (int i = 0; i < argLen; i++) {
for (uint32_t i = 0; i < argLen; i++) {
JSHandle<JSTaggedValue> msg = GetCallArg(argv, i);
numberValue = JSTaggedValue::ToNumber(thread, msg);
value = numberValue.GetNumber();

View File

@ -513,7 +513,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle<JSTag
JSTaggedValue thisIndex =
FastRuntimeStub::FastGetProperty(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue());
if (thisIndex.IsInt()) {
lastIndex = thisIndex.GetInt();
lastIndex = static_cast<uint32_t>(thisIndex.GetInt());
} else {
JSHandle<JSTaggedValue> thisIndexHandle(thread, thisIndex);
lastIndex = JSTaggedValue::ToLength(thread, thisIndexHandle).GetNumber();
@ -751,7 +751,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv)
thread, FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue()));
uint32_t thisIndex = 0;
if (thisIndexHandle->IsInt()) {
thisIndex = thisIndexHandle->GetInt();
thisIndex = static_cast<uint32_t>(thisIndexHandle->GetInt());
} else {
thisIndex = JSTaggedValue::ToLength(thread, thisIndexHandle).GetNumber();
// b. ReturnIfAbrupt(thisIndex).
@ -802,7 +802,7 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> positionHandle(thread, positionTag);
uint32_t position = 0;
if (positionHandle->IsInt()) {
position = positionHandle->GetInt();
position = static_cast<uint32_t>(positionHandle->GetInt());
} else {
position = JSTaggedValue::ToUint32(thread, positionHandle);
// h. ReturnIfAbrupt(position).
@ -1325,7 +1325,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle
JSHandle<EcmaString> flagsStr = JSTaggedValue::ToString(thread, flagsValue);
JSHandle<EcmaString> uString(globalConst->GetHandledUString());
[[maybe_unused]] bool fullUnicode = base::StringHelper::Contains(*flagsStr, *uString);
if (lastIndex > length) {
if (lastIndex > static_cast<int32_t>(length)) {
FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(),
JSTaggedValue(0));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -1742,7 +1742,7 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle<RegExpEx
} else if (cache->Match(entry, patternValue, flagsValue, inputValue, extend)) {
cache->UpdateResultArray(thread, entry, resultArray.GetTaggedValue(), type);
} else {
uint32_t entry2 = (entry + 1) & (cache->GetCacheLength() - 1);
uint32_t entry2 = (entry + 1) & static_cast<uint32_t>(cache->GetCacheLength() - 1);
uint32_t index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE;
JSHandle<JSTaggedValue> extendHandle(thread, extend);
if (cache->GetCacheLength() < DEFAULT_CACHE_NUMBER) {
@ -1753,7 +1753,7 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle<RegExpEx
inputValue = input.GetTaggedValue();
cache->SetCacheLength(thread, DEFAULT_CACHE_NUMBER);
entry2 = hash & (cache->GetCacheLength() - 1);
entry2 = hash & static_cast<uint32_t>(cache->GetCacheLength() - 1);
index2 = CACHE_TABLE_HEADER_SIZE + entry2 * ENTRY_SIZE;
}
JSTaggedValue extendValue = extendHandle.GetTaggedValue();

View File

@ -86,7 +86,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv)
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
int32_t argLength = argv->GetArgsNumber();
uint32_t argLength = argv->GetArgsNumber();
if (argLength == 0) {
return factory->GetEmptyString().GetTaggedValue();
}
@ -100,7 +100,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv)
std::u16string u16str = base::StringHelper::Utf16ToU16String(&codePointValue, 1);
CVector<uint16_t> valueTable;
valueTable.reserve(argLength - 1);
for (int32_t i = 1; i < argLength; i++) {
for (uint32_t i = 1; i < argLength; i++) {
JSHandle<JSTaggedValue> nextCp = BuiltinsString::GetCallArg(argv, i);
uint16_t nextCv = JSTaggedValue::ToUint16(thread, nextCp);
valueTable.emplace_back(nextCv);
@ -111,7 +111,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv)
const char16_t *constChar16tData = u16str.data();
auto *char16tData = const_cast<char16_t *>(constChar16tData);
auto *uint16tData = reinterpret_cast<uint16_t *>(char16tData);
int32_t u16strSize = u16str.size();
uint32_t u16strSize = u16str.size();
return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue();
}
@ -123,13 +123,13 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv)
JSThread *thread = argv->GetThread();
[[maybe_unused]] EcmaHandleScope handleScope(thread);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
int32_t argLength = argv->GetArgsNumber();
uint32_t argLength = argv->GetArgsNumber();
if (argLength == 0) {
return factory->GetEmptyString().GetTaggedValue();
}
std::u16string u16str;
int32_t u16strSize = argLength;
for (int i = 0; i < argLength; i++) {
uint32_t u16strSize = argLength;
for (uint32_t i = 0; i < argLength; i++) {
JSHandle<JSTaggedValue> nextCpTag = BuiltinsString::GetCallArg(argv, i);
JSTaggedNumber nextCpVal = JSTaggedValue::ToNumber(thread, nextCpTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -145,8 +145,10 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv)
return factory->NewFromUtf16Literal(data.data(), 1).GetTaggedValue();
}
if (cp > UINT16_MAX) {
uint16_t cu1 = std::floor((cp - ENCODE_SECOND_FACTOR) / ENCODE_FIRST_FACTOR) + ENCODE_LEAD_LOW;
uint16_t cu2 = ((cp - ENCODE_SECOND_FACTOR) % ENCODE_FIRST_FACTOR) + ENCODE_TRAIL_LOW;
uint16_t cu1 =
std::floor((static_cast<uint32_t>(cp) - ENCODE_SECOND_FACTOR) / ENCODE_FIRST_FACTOR) + ENCODE_LEAD_LOW;
uint16_t cu2 =
((static_cast<uint32_t>(cp) - ENCODE_SECOND_FACTOR) % ENCODE_FIRST_FACTOR) + ENCODE_TRAIL_LOW;
std::u16string nextU16str1 = base::StringHelper::Utf16ToU16String(&cu1, 1);
std::u16string nextU16str2 = base::StringHelper::Utf16ToU16String(&cu2, 1);
u16str = base::StringHelper::Append(u16str, nextU16str1);
@ -190,7 +192,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSTaggedNumber lengthNumber = JSTaggedValue::ToLength(thread, rawLen);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int length = lengthNumber.ToUint32();
int length = static_cast<int>(lengthNumber.ToUint32());
if (length <= 0) {
return factory->GetEmptyString().GetTaggedValue();
}
@ -242,7 +244,7 @@ JSTaggedValue BuiltinsString::CharAt(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t thisLen = static_cast<int32_t>(thisHandle->GetLength());
JSHandle<JSTaggedValue> posTag = BuiltinsString::GetCallArg(argv, 0);
int32_t pos;
if (posTag->IsUndefined()) {
@ -269,7 +271,7 @@ JSTaggedValue BuiltinsString::CharCodeAt(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t thisLen = static_cast<int32_t>(thisHandle->GetLength());
JSHandle<JSTaggedValue> posTag = BuiltinsString::GetCallArg(argv, 0);
int32_t pos;
if (posTag->IsUndefined()) {
@ -301,7 +303,7 @@ JSTaggedValue BuiltinsString::CodePointAt(EcmaRuntimeCallInfo *argv)
JSTaggedNumber posVal = JSTaggedValue::ToNumber(thread, posTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t pos = base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber());
int32_t thisLen = thisHandle->GetLength();
int32_t thisLen = static_cast<int32_t>(thisHandle->GetLength());
if (pos < 0 || pos >= thisLen) {
return JSTaggedValue::Undefined();
}
@ -328,8 +330,8 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t argLength = argv->GetArgsNumber();
uint32_t thisLen = thisHandle->GetLength();
uint32_t argLength = argv->GetArgsNumber();
if (argLength == 0) {
return thisHandle.GetTaggedValue();
}
@ -342,10 +344,10 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv)
} else {
u16strThis = base::StringHelper::Utf8ToU16String(thisHandle->GetDataUtf8(), thisLen);
}
for (int i = 0; i < argLength; i++) {
for (uint32_t i = 0; i < argLength; i++) {
JSHandle<JSTaggedValue> nextTag = BuiltinsString::GetCallArg(argv, i);
JSHandle<EcmaString> nextHandle = JSTaggedValue::ToString(thread, nextTag);
int32_t nextLen = nextHandle->GetLength();
uint32_t nextLen = nextHandle->GetLength();
if (nextHandle->IsUtf16()) {
u16strNext = base::StringHelper::Utf16ToU16String(nextHandle->GetDataUtf16(), nextLen);
canBeCompress = false;
@ -380,9 +382,9 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv)
}
JSHandle<EcmaString> searchHandle = JSTaggedValue::ToString(thread, searchTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t searchLen = searchHandle->GetLength();
int32_t pos;
uint32_t thisLen = thisHandle->GetLength();
uint32_t searchLen = searchHandle->GetLength();
uint32_t pos;
JSHandle<JSTaggedValue> posTag = BuiltinsString::GetCallArg(argv, 1);
if (posTag->IsUndefined()) {
pos = thisLen;
@ -391,8 +393,8 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
pos = posVal.ToInt32();
}
int32_t end = std::min(std::max(pos, 0), thisLen);
int32_t start = end - searchLen;
uint32_t end = std::min(std::max(pos, 0U), thisLen);
int32_t start = static_cast<int32_t>(end - searchLen);
if (start < 0) {
return BuiltinsString::GetTaggedBoolean(false);
}
@ -410,7 +412,7 @@ JSTaggedValue BuiltinsString::EndsWith(EcmaRuntimeCallInfo *argv)
const uint8_t *uint8Search = searchHandle->GetDataUtf8();
u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen);
}
int32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, start);
int32_t idx = static_cast<int32_t>(base::StringHelper::Find(u16strThis, u16strSearch, start));
if (idx == start) {
return BuiltinsString::GetTaggedBoolean(true);
}
@ -434,8 +436,8 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv)
}
JSHandle<EcmaString> searchHandle = JSTaggedValue::ToString(thread, searchTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t searchLen = searchHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
uint32_t searchLen = searchHandle->GetLength();
int32_t pos = 0;
JSHandle<JSTaggedValue> posTag = BuiltinsBase::GetCallArg(argv, 1);
if (argv->GetArgsNumber() == 1) {
@ -445,7 +447,7 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
pos = base::NumberHelper::DoubleInRangeInt32(posVal.GetNumber());
}
int32_t start = std::min(std::max(pos, 0), thisLen);
int32_t start = std::min(std::max(pos, 0), static_cast<int32_t>(thisLen));
std::u16string u16strThis;
std::u16string u16strSearch;
if (thisHandle->IsUtf16()) {
@ -460,7 +462,7 @@ JSTaggedValue BuiltinsString::Includes(EcmaRuntimeCallInfo *argv)
const uint8_t *uint8Search = searchHandle->GetDataUtf8();
u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen);
}
int32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, start);
uint32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, start);
if (idx < 0 || idx > thisLen) {
return BuiltinsString::GetTaggedBoolean(false);
}
@ -478,7 +480,7 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
JSHandle<EcmaString> searchHandle = JSTaggedValue::ToString(thread, searchTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t searchLen = searchHandle->GetLength();
@ -491,11 +493,11 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
pos = posVal.ToInt32();
}
pos = std::min(std::max(pos, 0), thisLen);
pos = std::min(std::max(pos, 0), static_cast<int32_t>(thisLen));
if (thisHandle->IsUtf8() && searchHandle->IsUtf8()) {
std::string thisString = base::StringHelper::Utf8ToString(thisHandle->GetDataUtf8(), thisLen);
std::string searchString = base::StringHelper::Utf8ToString(searchHandle->GetDataUtf8(), searchLen);
int32_t res = base::StringHelper::Find(thisString, searchString, pos);
uint32_t res = base::StringHelper::Find(thisString, searchString, pos);
if (res >= 0 && res < thisLen) {
return GetTaggedInt(res);
}
@ -515,7 +517,7 @@ JSTaggedValue BuiltinsString::IndexOf(EcmaRuntimeCallInfo *argv)
const uint8_t *uint8Search = searchHandle->GetDataUtf8();
u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen);
}
int32_t res = base::StringHelper::Find(u16strThis, u16strSearch, pos);
uint32_t res = base::StringHelper::Find(u16strThis, u16strSearch, pos);
if (res >= 0 && res < thisLen) {
return GetTaggedInt(res);
}
@ -533,11 +535,11 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
JSHandle<EcmaString> searchHandle = JSTaggedValue::ToString(thread, searchTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t searchLen = searchHandle->GetLength();
int32_t pos;
uint32_t searchLen = searchHandle->GetLength();
uint32_t pos;
if (argv->GetArgsNumber() == 1) {
pos = thisLen;
} else {
@ -547,10 +549,10 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv)
if (std::isnan(JSTaggedValue::ToNumber(thread, posTag).GetNumber())) {
pos = thisLen;
} else {
pos = posVal.ToInt32();
pos = static_cast<uint32_t>(posVal.ToInt32());
}
}
pos = std::min(std::max(pos, 0), thisLen);
pos = std::min(std::max(pos, 0U), thisLen);
std::u16string u16strThis;
std::u16string u16strSearch;
if (thisHandle->IsUtf16()) {
@ -565,7 +567,7 @@ JSTaggedValue BuiltinsString::LastIndexOf(EcmaRuntimeCallInfo *argv)
const uint8_t *uint8Search = searchHandle->GetDataUtf8();
u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen);
}
int32_t res = base::StringHelper::RFind(u16strThis, u16strSearch, pos);
uint32_t res = base::StringHelper::RFind(u16strThis, u16strSearch, pos);
if (res >= 0 && res < thisLen) {
return GetTaggedInt(res);
}
@ -707,7 +709,7 @@ JSTaggedValue BuiltinsString::Repeat(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
JSHandle<JSTaggedValue> countTag = BuiltinsString::GetCallArg(argv, 0);
JSTaggedNumber num = JSTaggedValue::ToInteger(thread, countTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -948,7 +950,7 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle<E
break;
case '\'': {
// $' - suffix
int32_t srcLength = srcString->GetLength();
int32_t srcLength = static_cast<int32_t>(srcString->GetLength());
if (tailPos < srcLength) {
EcmaString *sufffix = EcmaString::FastSubString(srcString, tailPos, srcLength - tailPos, ecmaVm);
if (sufffix->IsUtf16()) {
@ -973,15 +975,15 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle<E
case '7':
case '8':
case '9': {
int capturesLength = captureList->GetLength();
uint32_t capturesLength = captureList->GetLength();
// Valid indices are $1 .. $9, $01 .. $09 and $10 .. $99
int32_t scaledIndex = (peek - '0');
uint32_t scaledIndex = peek - '0';
int32_t advance = 1;
if (peekIndex + 1 < replaceLength) {
uint16_t nextPeek = replacement->At(peekIndex + 1);
if (nextPeek >= '0' && nextPeek <= '9') {
constexpr int32_t TEN_BASE = 10;
int32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0');
constexpr uint32_t TEN_BASE = 10;
uint32_t newScaledIndex = scaledIndex * TEN_BASE + (nextPeek - '0');
if (newScaledIndex <= capturesLength) {
scaledIndex = newScaledIndex;
advance = 2; // 2: 2 means from index needs to add two.
@ -1099,7 +1101,7 @@ JSTaggedValue BuiltinsString::Slice(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t thisLen = static_cast<int32_t>(thisHandle->GetLength());
JSHandle<JSTaggedValue> startTag = BuiltinsString::GetCallArg(argv, 0);
JSTaggedNumber startVal = JSTaggedValue::ToInteger(thread, startTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -1181,7 +1183,7 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv)
return resultArray.GetTaggedValue();
}
// Let s be the number of elements in S.
int32_t thisLength = thisString->GetLength();
int32_t thisLength = static_cast<int32_t>(thisString->GetLength());
JSHandle<EcmaString> seperatorString = JSTaggedValue::ToString(thread, seperatorTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (seperatorTag->IsUndefined()) {
@ -1234,8 +1236,8 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv)
int32_t BuiltinsString::SplitMatch(const JSHandle<EcmaString> &str, int32_t q, const JSHandle<EcmaString> &reg)
{
int32_t s = str->GetLength();
int32_t r = reg->GetLength();
int32_t s = static_cast<int32_t>(str->GetLength());
int32_t r = static_cast<int32_t>(reg->GetLength());
if (q + r > s) {
return -1;
}
@ -1267,8 +1269,8 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv)
JSHandle<EcmaString> searchHandle = JSTaggedValue::ToString(thread, searchTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
int32_t searchLen = searchHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
uint32_t searchLen = searchHandle->GetLength();
int32_t pos;
JSHandle<JSTaggedValue> posTag = BuiltinsString::GetCallArg(argv, 1);
if (posTag->IsUndefined()) {
@ -1278,8 +1280,8 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
pos = posVal.ToInt32();
}
pos = std::min(std::max(pos, 0), thisLen);
if (pos + searchLen > thisLen) {
pos = std::min(std::max(pos, 0), static_cast<int32_t>(thisLen));
if (static_cast<uint32_t>(pos + searchLen) > thisLen) {
return BuiltinsString::GetTaggedBoolean(false);
}
std::u16string u16strThis;
@ -1296,8 +1298,8 @@ JSTaggedValue BuiltinsString::StartsWith(EcmaRuntimeCallInfo *argv)
const uint8_t *uint8Search = searchHandle->GetDataUtf8();
u16strSearch = base::StringHelper::Utf8ToU16String(uint8Search, searchLen);
}
int32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, pos);
if (idx == pos) {
uint32_t idx = base::StringHelper::Find(u16strThis, u16strSearch, pos);
if (static_cast<int32_t>(idx) == pos) {
return BuiltinsString::GetTaggedBoolean(true);
}
return BuiltinsString::GetTaggedBoolean(false);
@ -1482,7 +1484,7 @@ JSTaggedValue BuiltinsString::ToLowerCase(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
std::u16string u16strThis;
if (thisHandle->IsUtf16()) {
u16strThis = base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen);
@ -1511,7 +1513,7 @@ JSTaggedValue BuiltinsString::ToUpperCase(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
std::u16string u16strThis;
if (thisHandle->IsUtf16()) {
u16strThis = base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen);
@ -1532,7 +1534,7 @@ JSTaggedValue BuiltinsString::Trim(EcmaRuntimeCallInfo *argv)
JSHandle<JSTaggedValue> thisTag(JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv)));
JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisTag);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int32_t thisLen = thisHandle->GetLength();
uint32_t thisLen = thisHandle->GetLength();
std::u16string u16strThis;
if (thisHandle->IsUtf16()) {
u16strThis = base::StringHelper::Utf16ToU16String(thisHandle->GetDataUtf16(), thisLen);
@ -1604,7 +1606,7 @@ JSTaggedValue BuiltinsString::SubStr(EcmaRuntimeCallInfo *argv)
end = lengthNumber.ToInt32();
}
// 8. Let size be the number of code units in S.
int32_t size = thisString->GetLength();
int32_t size = static_cast<int32_t>(thisString->GetLength());
// 9. If intStart < 0, let intStart be max(size + intStart,0).
if (start < 0) {
start = std::max(size + start, 0);

View File

@ -713,7 +713,8 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv)
THROW_TYPE_ERROR_AND_RETURN(argv->GetThread(), "This is not a TypedArray.", JSTaggedValue::Exception());
}
uint32_t length = TypedArrayHelper::GetArrayLength(thread, JSHandle<JSObject>::Cast(thisHandle));
uint32_t length =
static_cast<uint32_t>(TypedArrayHelper::GetArrayLength(thread, JSHandle<JSObject>::Cast(thisHandle)));
JSHandle<JSTaggedValue> sepHandle = GetCallArg(argv, 0);
int sep = ',';
@ -779,8 +780,8 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv)
current += sepLength;
}
JSHandle<EcmaString> nextStr = vec[k];
int nextLength = nextStr->GetLength();
newString->WriteData(*nextStr, current, allocateLength - current, nextLength);
int nextLength = static_cast<int>(nextStr->GetLength());
newString->WriteData(*nextStr, current, static_cast<size_t>(allocateLength - current), nextLength);
current += nextLength;
}
return JSTaggedValue(newString);

View File

@ -121,7 +121,7 @@ void BytecodeCircuitBuilder::CollectBytecodeBlockInfo(uint8_t *pc, std::vector<C
case EcmaOpcode::JNEZ_IMM16: {
std::vector<uint8_t *> temp;
temp.emplace_back(pc + BytecodeOffset::THREE); // first successor
int8_t offset = READ_INST_16_0();
int8_t offset = static_cast<int8_t>(READ_INST_16_0());
temp.emplace_back(pc + offset); // second successor
bytecodeBlockInfos.emplace_back(pc, SplitKind::END, temp);
bytecodeBlockInfos.emplace_back(pc + BytecodeOffset::THREE, SplitKind::START,
@ -457,17 +457,17 @@ void BytecodeCircuitBuilder::ComputeDominatorTree(BytecodeGraph &byteCodeGraph)
#endif
// compute immediate dominator
immDom[0] = doms[0].front();
immDom[0] = static_cast<int32_t>(doms[0].front());
for (size_t i = 1; i < doms.size(); i++) {
if (graph[i].isDead) {
continue;
}
auto it = std::remove(doms[i].begin(), doms[i].end(), i);
doms[i].resize(it - doms[i].begin());
immDom[i] = *std::max_element(
immDom[i] = static_cast<int32_t>(*std::max_element(
doms[i].begin(), doms[i].end(), [graph, bbIdToDfsTimestamp](size_t lhs, size_t rhs) -> bool {
return bbIdToDfsTimestamp.at(graph[lhs].id) < bbIdToDfsTimestamp.at(graph[rhs].id);
});
}));
}
#if ECMASCRIPT_ENABLE_TS_AOT_PRINT
@ -2006,7 +2006,7 @@ GateRef BytecodeCircuitBuilder::SetGateConstant(const BytecodeInfo &info)
gate = GetCommonArgByIndex(CommonArgIdx::FUNC);
break;
default:
abort();
UNREACHABLE();
}
return gate;
}
@ -2204,7 +2204,7 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph)
auto ifTrue = circuit_.NewGate(OpCode(OpCode::IF_TRUE), 0, {gate}, GateType::EMPTY);
auto ifFalse = circuit_.NewGate(OpCode(OpCode::IF_FALSE), 0, {gate}, GateType::EMPTY);
ASSERT(bb.succs.size() == 2); // 2 : 2 num of successors
int bitSet = 0;
uint32_t bitSet = 0;
for (auto &bbNext: bb.succs) {
if (bbNext->id == bb.id + 1) {
circuit_.NewIn(bbNext->stateStart, bbNext->statePredIndex, ifFalse);
@ -2270,7 +2270,7 @@ void BytecodeCircuitBuilder::BuildCircuit(BytecodeGraph &byteCodeGraph)
} else if (IsDiscarded(static_cast<EcmaOpcode>(bytecodeInfo.opcode))) {
continue;
} else {
abort();
UNREACHABLE();
}
}
}

View File

@ -137,7 +137,7 @@ void LLVMStackMapParser::PrintCallSiteInfo(const CallSiteInfo *infos, uintptr_t
bool LLVMStackMapParser::IsDeriveredPointer(int callsitetime) const
{
return callsitetime & 1;
return static_cast<uint32_t>(callsitetime) & 1;
}
bool LLVMStackMapParser::CollectStackMapSlots(uintptr_t callSiteAddr, uintptr_t frameFp,

View File

@ -211,7 +211,7 @@ void LLVMIRBuilder::Build()
for (size_t bbIdx = 0; bbIdx < schedule_->size(); bbIdx++) {
for (size_t instIdx = (*schedule_)[bbIdx].size(); instIdx > 0; instIdx--) {
GateId gateId = circuit_->GetId((*schedule_)[bbIdx][instIdx - 1]);
instIdMapBbId_[gateId] = bbIdx;
instIdMapBbId_[gateId] = static_cast<int>(bbIdx);
}
}
COMPILER_LOG(INFO) << "LLVM IR Builder Visit Gate...";
@ -511,7 +511,7 @@ void LLVMIRBuilder::HandleRuntimeCall(GateRef gate)
void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector<GateRef> &inList)
{
int paraStartIndex = 3;
size_t paraStartIndex = 3;
ASSERT(llvmModule_ != nullptr);
LLVMValueRef callee;
LLVMValueRef rtoffset;
@ -523,11 +523,11 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector<GateRef> &i
if (circuit_->GetFrameType() == FrameType::INTERPRETER_FRAME ||
circuit_->GetFrameType() == FrameType::OPTIMIZED_ENTRY_FRAME) {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) +
static_cast<int>(JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit())) +
(RTSTUB_ID(AsmIntCallRuntime)) * slotSize_, 0);
} else if (circuit_->GetFrameType() == FrameType::OPTIMIZED_FRAME) {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) +
static_cast<int>(JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit())) +
(RTSTUB_ID(OptimizedCallRuntime)) * slotSize_, 0);
} else {
abort();
@ -539,7 +539,7 @@ void LLVMIRBuilder::VisitRuntimeCall(GateRef gate, const std::vector<GateRef> &i
// 16 : params limit
LLVMValueRef params[16];
params[0] = glue;
int index = circuit_->GetBitField(inList[1]);
int index = static_cast<int>(circuit_->GetBitField(inList[1]));
params[1] = LLVMConstInt(LLVMInt64Type(), index, 0);
params[2] = LLVMConstInt(LLVMInt64Type(), inList.size() - paraStartIndex, 0); // 2 : 2 means third parameter
for (size_t paraIdx = paraStartIndex; paraIdx < inList.size(); ++paraIdx) {
@ -643,11 +643,11 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector<GateRef> &inList,
LLVMTypeRef glueType = LLVMTypeOf(glue);
// runtime case
if (op == OpCode::CALL) {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetCOStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0);
rtoffset = LLVMConstInt(glueType, JSThread::GlueData::GetCOStubEntriesOffset(compCfg_->Is32Bit()) +
index * static_cast<size_t>(slotSize_), 0);
} else {
rtoffset = LLVMConstInt(glueType,
JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) + index * slotSize_, 0);
rtoffset = LLVMConstInt(glueType, JSThread::GlueData::GetRTStubEntriesOffset(compCfg_->Is32Bit()) +
index * static_cast<size_t>(slotSize_), 0);
}
LLVMValueRef rtbaseoffset = LLVMBuildAdd(builder_, glue, rtoffset, "");
LLVMValueRef rtbaseAddr = LLVMBuildIntToPtr(builder_, rtbaseoffset, LLVMPointerType(glueType, 0), "");
@ -671,7 +671,7 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector<GateRef> &inList,
}
}
// then push the actual parameter for js function call
for (size_t paraIdx = paraStartIndex + 1; paraIdx < inList.size(); ++paraIdx) {
for (size_t paraIdx = static_cast<size_t>(paraStartIndex + 1); paraIdx < inList.size(); ++paraIdx) {
GateRef gateTmp = inList[paraIdx];
params[dstParaIndex++] = gateToLLVMMaps_[gateTmp];
}
@ -700,7 +700,7 @@ void LLVMIRBuilder::VisitCall(GateRef gate, const std::vector<GateRef> &inList,
void LLVMIRBuilder::VisitBytecodeCall(GateRef gate, const std::vector<GateRef> &inList)
{
int paraStartIndex = 3;
size_t paraStartIndex = 3;
LLVMValueRef opcodeOffset = gateToLLVMMaps_[inList[1]];
ASSERT(llvmModule_ != nullptr);
LLVMValueRef callee;
@ -767,7 +767,7 @@ void LLVMIRBuilder::VisitPhi(GateRef gate, const std::vector<GateRef> &srcGates)
int bbIdx = instIdMapBbId_[gateId];
COMPILER_LOG(DEBUG) << "srcGate: " << srcGates[i] << " dominated gateId:" << gateId << "dominated bbIdx: " <<
bbIdx;
int cnt = bbIdMapBb_.count(bbIdx);
int cnt = static_cast<int>(bbIdMapBb_.count(bbIdx));
// if cnt = 0 means bb with current bbIdx hasn't been created
if (cnt > 0) {
BasicBlock *bb = bbIdMapBb_[bbIdx].get();
@ -988,7 +988,7 @@ void LLVMIRBuilder::HandleParameter(GateRef gate)
void LLVMIRBuilder::VisitParameter(GateRef gate)
{
int argth = circuit_->LoadGatePtrConst(gate)->GetBitField();
int argth = static_cast<int>(circuit_->LoadGatePtrConst(gate)->GetBitField());
COMPILER_LOG(DEBUG) << " Parameter value" << argth;
if (callConv_ == CallSignature::CallConv::WebKitJSCallConv) {
if (compCfg_->Is32Bit() && argth > 0) {
@ -1078,19 +1078,19 @@ void LLVMIRBuilder::HandleSwitch(GateRef gate)
void LLVMIRBuilder::VisitSwitch(GateRef gate, GateRef input, const std::vector<GateRef> &outList)
{
LLVMValueRef cond = gateToLLVMMaps_[input];
unsigned caseNum = outList.size();
int caseNum = static_cast<int>(outList.size());
BasicBlock *curOutBB = nullptr;
LLVMBasicBlockRef llvmDefaultOutBB = nullptr;
for (int i = 0; i < static_cast<int>(caseNum); i++) {
for (int i = 0; i < caseNum; i++) {
curOutBB = EnsureBasicBlock(instIdMapBbId_[circuit_->GetId(outList[i])]);
EnsureBasicBlock(curOutBB);
if (circuit_->GetOpCode(outList[i]) == OpCode::DEFAULT_CASE) {
llvmDefaultOutBB = curOutBB->GetImpl<LLVMTFBuilderBasicBlockImpl>()->llvm_bb_;
}
}
LLVMValueRef result = LLVMBuildSwitch(builder_, cond, llvmDefaultOutBB, caseNum - 1);
LLVMValueRef result = LLVMBuildSwitch(builder_, cond, llvmDefaultOutBB, static_cast<uint32_t>(caseNum - 1));
LLVMBasicBlockRef llvmCurOutBB = nullptr;
for (int i = 0; i < static_cast<int>(caseNum); i++) {
for (int i = 0; i < caseNum; i++) {
if (circuit_->GetOpCode(outList[i]) == OpCode::DEFAULT_CASE) {
continue;
}
@ -1903,19 +1903,23 @@ LLVMTypeRef LLVMModule::GetFuncType(const CallSignature *stubDescriptor)
auto paramsType = stubDescriptor->GetParametersType();
ASSERT(paramCount > 0);
// first argument is glue
LLVMTypeRef glueType = ConvertLLVMTypeFromVariableType(paramsType[0]);
paramTys.push_back(glueType);
if (cfg_.Is32Bit() && stubDescriptor->GetTargetKind() != CallSignature::TargetKind::RUNTIME_STUB) {
if (stubDescriptor->GetCallConv() == CallSignature::CallConv::WebKitJSCallConv) {
for (int i = 0; i < CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32; i++) {
paramTys.push_back(glueType); // fake paramter's type is same with glue type
if (paramsType != nullptr) {
LLVMTypeRef glueType = ConvertLLVMTypeFromVariableType(paramsType[0]);
paramTys.push_back(glueType);
if (cfg_.Is32Bit() && stubDescriptor->GetTargetKind() != CallSignature::TargetKind::RUNTIME_STUB) {
if (stubDescriptor->GetCallConv() == CallSignature::CallConv::WebKitJSCallConv) {
for (int i = 0; i < CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32; i++) {
paramTys.push_back(glueType); // fake paramter's type is same with glue type
}
extraParameterCnt += CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32;
}
extraParameterCnt += CompilationConfig::FAKE_REGISTER_PARAMTERS_ARM32;
}
}
for (int i = 1; i < paramCount; i++) {
paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType[i]));
for (int i = 1; i < paramCount; i++) {
paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType[i]));
}
} else {
UNREACHABLE();
}
auto functype = LLVMFunctionType(returnType, paramTys.data(), paramCount + extraParameterCnt,
stubDescriptor->GetVariableArgs());

View File

@ -1591,7 +1591,7 @@ inline void Stub::SetNumberOfPropsToHClass(GateRef glue, GateRef hClass, GateRef
{
GateRef bitfield1 = Load(VariableType::INT32(), hClass, IntPtr(JSHClass::BIT_FIELD1_OFFSET));
GateRef oldWithMask = Int32And(bitfield1,
Int32(~static_cast<int32_t>(JSHClass::NumberOfPropsBits::Mask())));
Int32(~static_cast<uint32_t>(JSHClass::NumberOfPropsBits::Mask())));
GateRef newValue = UInt32LSR(value, Int32(JSHClass::NumberOfPropsBits::START_BIT));
Store(VariableType::INT32(), glue, hClass, IntPtr(JSHClass::BIT_FIELD1_OFFSET),
Int32Or(oldWithMask, newValue));

View File

@ -285,6 +285,7 @@ Stub::Environment::Environment(size_t arguments, Circuit *circuit)
currentLabel_->Seal();
auto depend_entry = Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY));
currentLabel_->SetDepend(depend_entry);
compCfg_ = nullptr;
}
Stub::Environment::~Environment()

View File

@ -348,7 +348,7 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv)
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret);
// check entries should be update, size will be update in tmap set or remove.
if (tmap->GetSize() != length) {
if (tmap->GetSize() != static_cast<int>(length)) {
iteratedMap.Update(tmap->GetTreeMap());
entries.Update(TaggedTreeMap::GetArrayFromMap(thread, iteratedMap).GetTaggedValue());
elements = iteratedMap->NumberOfElements();

View File

@ -301,7 +301,7 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv)
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret);
// check entries should be update, size will be update by set add and remove.
if (tset->GetSize() != length) {
if (tset->GetSize() != static_cast<int>(length)) {
iteratedSet.Update(tset->GetTreeSet());
entries.Update(TaggedTreeSet::GetArrayFromSet(thread, iteratedSet).GetTaggedValue());
elements = iteratedSet->NumberOfElements();

View File

@ -166,10 +166,14 @@ void CpuProfiler::GetCurrentProcessInfo(struct CurrentProcessInfo &currentProces
{
currentProcessInfo.nowTimeStamp = ProfileProcessor::GetMicrosecondsTimeStamp() % TIME_CHANGE;
currentProcessInfo.pid = getpid();
tid_ = currentProcessInfo.tid = syscall(SYS_gettid);
if (syscall(SYS_gettid) == -1) {
LOG_ECMA(FATAL) << "syscall failed";
UNREACHABLE();
}
tid_ = currentProcessInfo.tid = static_cast<pthread_t>(syscall(SYS_gettid));
struct timespec time = {0, 0};
clock_gettime(CLOCK_MONOTONIC, &time);
currentProcessInfo.tts = time.tv_nsec / 1000; // 1000:Nanoseconds to milliseconds.
currentProcessInfo.tts = static_cast<uint64_t>(time.tv_nsec) / 1000; // 1000:Nanoseconds to milliseconds.
}
void CpuProfiler::GetFrameStack(JSThread *thread)
@ -218,7 +222,7 @@ void CpuProfiler::ParseMethodInfo(JSMethod *method, InterpretedFrameHandler fram
auto iter = scriptIdMap_.find(codeEntry.url);
if (iter == scriptIdMap_.end()) {
scriptIdMap_.insert(std::make_pair(codeEntry.url, scriptIdMap_.size() + 1));
codeEntry.scriptId = scriptIdMap_.size();
codeEntry.scriptId = static_cast<int>(scriptIdMap_.size());
} else {
codeEntry.scriptId = iter->second;
}

View File

@ -49,7 +49,7 @@ void ProfileGenerator::AddSample(CVector<JSMethod *> sample, uint64_t sampleTime
methodNode.parentId = methodkey.parentId = PreviousId;
auto result = methodMap_.find(methodkey);
if (result == methodMap_.end()) {
methodNode.id = methodMap_.size() + 1;
methodNode.id = static_cast<int>(methodMap_.size() + 1);
methodMap_.insert(std::make_pair(methodkey, methodNode.id));
methodNode.codeEntry = GetGcInfo();
stackTopLines_.push_back(0);
@ -69,7 +69,7 @@ void ProfileGenerator::AddSample(CVector<JSMethod *> sample, uint64_t sampleTime
}
auto result = methodMap_.find(methodkey);
if (result == methodMap_.end()) {
int id = methodMap_.size() + 1;
int id = static_cast<int>(methodMap_.size() + 1);
methodMap_.insert(std::make_pair(methodkey, id));
PreviousId = methodNode.id = id;
methodNode.codeEntry = GetMethodInfo(methodkey.method);
@ -161,12 +161,12 @@ void ProfileGenerator::WriteMethodsAndSampleInfo(bool timeEnd)
sampleData_ += "\"cat\":\"disabled-by-default-ark.cpu_profiler\",\"id\":"
"\"0x2\",\"name\":\"ProfileChunk\",\"ph\":\"P\",\"pid\":";
pid_t pid = getpid();
pthread_t tid = syscall(SYS_gettid);
int64_t tid = syscall(SYS_gettid);
uint64_t ts = ProfileProcessor::GetMicrosecondsTimeStamp();
ts = ts % TIME_CHANGE;
struct timespec time = {0, 0};
clock_gettime(CLOCK_MONOTONIC, &time);
uint64_t tts = time.tv_nsec / 1000; // 1000:Nanoseconds to milliseconds.
uint64_t tts = static_cast<uint64_t>(time.tv_nsec) / 1000; // 1000:Nanoseconds to milliseconds.
sampleData_ += std::to_string(pid) + ",\"tid\":" +
std::to_string(tid) + ",\"ts\":" +
std::to_string(ts) + ",\"tts\":" +

View File

@ -131,6 +131,10 @@ CString HeapProfiler::GetTimeStamp()
struct tm tm {
};
struct tm *timeData = localtime_r(&timeSource, &tm);
if (timeData == nullptr) {
LOG_ECMA(FATAL) << "localtime_r failed";
UNREACHABLE();
}
CString stamp;
const int TIME_START = 1900;
stamp.append(ToCString(timeData->tm_year + TIME_START))

View File

@ -133,7 +133,7 @@ void HeapSnapShot::MoveNode(uintptr_t address, uintptr_t forward_address)
int sequenceId = -1;
Node *node = entryMap_.FindAndEraseNode(address);
if (node != nullptr) {
sequenceId = node->GetId();
sequenceId = static_cast<int>(node->GetId());
EraseNodeUnique(node);
}
GenerateNode(JSTaggedValue(forward_address), sequenceId);
@ -705,18 +705,18 @@ CString EntryVisitor::ConvertKey(JSTaggedValue key)
keyString = EcmaString::Cast(symbol->GetDescription().GetTaggedObject());
}
// convert, expensive but safe
int length = 0;
uint32_t length = 0;
if (keyString->IsUtf8()) {
length = keyString->GetUtf8Length();
std::vector<uint8_t> buffer(length);
[[maybe_unused]] int size = keyString->CopyDataUtf8(buffer.data(), length);
[[maybe_unused]] size_t size = keyString->CopyDataUtf8(buffer.data(), length);
ASSERT(size == length);
CString keyCopy(reinterpret_cast<char *>(buffer.data()));
return keyCopy;
} else { // NOLINT(readability-else-after-return)
length = keyString->GetLength();
std::vector<uint16_t> buffer(length);
[[maybe_unused]] int size = keyString->CopyDataUtf16(buffer.data(), length);
[[maybe_unused]] size_t size = keyString->CopyDataUtf16(buffer.data(), length);
ASSERT(size == length);
CString keyCopy(reinterpret_cast<char *>(buffer.data()));
return keyCopy;

View File

@ -272,11 +272,11 @@ public:
}
void AccumulateNodeSize(size_t size)
{
totalNodesSize_ += size;
totalNodesSize_ += static_cast<int>(size);
}
void DecreaseNodeSize(size_t size)
{
totalNodesSize_ -= size;
totalNodesSize_ -= static_cast<int>(size);
}
CString *GenerateNodeName(TaggedObject *entry);
NodeType GenerateNodeType(TaggedObject *entry);

View File

@ -49,7 +49,7 @@ CString *StringHashMap::GetStringByKey(StringKey key) const
CString *StringHashMap::FormatString(CString *string) const
{
// remove "\"" | "\r\n" | "\\" | "\t" | "\f"
int length = string->length();
int length = static_cast<int>(string->length());
char *charSeq = const_cast<char *>(string->c_str());
for (int i = 0; i < length; i++) {
if (charSeq[i] == '\"') { // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)

View File

@ -991,7 +991,7 @@ void JSObject::Dump(std::ostream &os) const
}
LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject());
int propNumber = jshclass->NumberOfProps();
int propNumber = static_cast<int>(jshclass->NumberOfProps());
os << " <LayoutInfo[" << std::dec << propNumber << "]>\n";
for (int i = 0; i < propNumber; i++) {
JSTaggedValue key = layoutInfo->GetKey(i);
@ -1004,7 +1004,7 @@ void JSObject::Dump(std::ostream &os) const
if (attr.IsInlinedProps()) {
val = GetPropertyInlinedProps(i);
} else {
val = properties->Get(i - jshclass->GetInlinedProperties());
val = properties->Get(i - static_cast<int>(jshclass->GetInlinedProperties()));
}
val.DumpTaggedValue(os);
os << ") ";
@ -3143,7 +3143,7 @@ void JSObject::DumpForSnapshot(std::vector<std::pair<CString, JSTaggedValue>> &v
}
LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetTaggedObject());
int propNumber = jshclass->NumberOfProps();
int propNumber = static_cast<int>(jshclass->NumberOfProps());
for (int i = 0; i < propNumber; i++) {
JSTaggedValue key = layoutInfo->GetKey(i);
PropertyAttributes attr = layoutInfo->GetAttr(i);
@ -3152,7 +3152,7 @@ void JSObject::DumpForSnapshot(std::vector<std::pair<CString, JSTaggedValue>> &v
if (attr.IsInlinedProps()) {
val = GetPropertyInlinedProps(i);
} else {
val = properties->Get(i - jshclass->GetInlinedProperties());
val = properties->Get(i - static_cast<int>(jshclass->GetInlinedProperties()));
}
CString str;

View File

@ -100,7 +100,7 @@ inline EcmaString *EcmaString::CreateFromUtf16(const uint16_t *utf16Data, uint32
template<bool verify>
inline uint16_t EcmaString::At(int32_t index) const
{
int32_t length = GetLength();
int32_t length = static_cast<int32_t>(GetLength());
if (verify) {
if ((index < 0) || (index >= length)) {
return 0;

View File

@ -127,8 +127,8 @@ int32_t EcmaString::Compare(const EcmaString *rhs) const
if (lhs == rhs) {
return 0;
}
int32_t lhsCount = lhs->GetLength();
int32_t rhsCount = rhs->GetLength();
int32_t lhsCount = static_cast<int32_t>(lhs->GetLength());
int32_t rhsCount = static_cast<int32_t>(rhs->GetLength());
int32_t countDiff = lhsCount - rhsCount;
int32_t minCount = (countDiff < 0) ? lhsCount : rhsCount;
if (!lhs->IsUtf16() && !rhs->IsUtf16()) {
@ -199,8 +199,8 @@ int32_t EcmaString::IndexOf(const EcmaString *rhs, int32_t pos) const
return -1;
}
const EcmaString *lhs = this;
int32_t lhsCount = lhs->GetLength();
int32_t rhsCount = rhs->GetLength();
int32_t lhsCount = static_cast<int32_t>(lhs->GetLength());
int32_t rhsCount = static_cast<int32_t>(rhs->GetLength());
if (rhsCount == 0) {
return pos;
}
@ -433,7 +433,7 @@ static int32_t ComputeHashForUtf8(const uint8_t *utf8Data)
uint32_t EcmaString::ComputeHashcode(uint32_t hashSeed) const
{
uint32_t hash;
int32_t hash;
if (compressedStringsEnabled) {
if (!IsUtf16()) {
hash = ComputeHashForData(GetDataUtf8(), GetLength(), hashSeed);
@ -444,13 +444,13 @@ uint32_t EcmaString::ComputeHashcode(uint32_t hashSeed) const
ASSERT(static_cast<size_t>(GetLength())<(std::numeric_limits<size_t>::max()>>1U));
hash = ComputeHashForData(GetDataUtf16(), GetLength(), hashSeed);
}
return hash;
return static_cast<uint32_t>(hash);
}
/* static */
uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len, bool canBeCompress)
{
uint32_t hash;
int32_t hash;
if (canBeCompress) {
hash = ComputeHashForUtf8(utf8Data);
} else {
@ -461,7 +461,7 @@ uint32_t EcmaString::ComputeHashcodeUtf8(const uint8_t *utf8Data, size_t utf8Len
ASSERT(len == utf16Len);
hash = ComputeHashForData(tmpBuffer.data(), utf16Len, 0);
}
return hash;
return static_cast<uint32_t>(hash);
}
/* static */

View File

@ -107,8 +107,12 @@ EcmaVM *EcmaVM::Create(Runtime *runtime)
{
EcmaVM *vm = runtime->GetInternalAllocator()->New<EcmaVM>();
auto jsThread = ecmascript::JSThread::Create(runtime, vm);
vm->thread_ = jsThread;
return vm;
if (vm == nullptr) {
return nullptr;
} else {
vm->thread_ = jsThread;
return vm;
}
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)

View File

@ -159,7 +159,7 @@ void GlobalDictionary::InvalidatePropertyBox(JSThread *thread, const JSHandle<Gl
PropertyAttributes newAttr(metaData);
ASSERT(!box->GetValue().IsHole());
int index = originAttr.GetDictionaryOrder();
int index = static_cast<int>(originAttr.GetDictionaryOrder());
JSHandle<JSTaggedValue> oldValue(thread, box->GetValue());
GlobalDictionary::InvalidateAndReplaceEntry(thread, dictHandle, index, oldValue);
dictHandle->SetAttributes(thread, entry, newAttr);

View File

@ -183,7 +183,7 @@ public:
template<typename T> \
inline void Set##name(const JSThread *thread, JSHandle<T> value, BarrierMode mode = WRITE_BARRIER) \
{ \
int offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \
uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \
if (mode == WRITE_BARRIER && value.GetTaggedValue().IsHeapObject()) { \
Barriers::SetDynObject<true>(thread, this, offset, value.GetTaggedValue().GetRawData()); \
} else { \
@ -192,7 +192,7 @@ public:
} \
inline void Set##name(const JSThread *thread, type value, BarrierMode mode = WRITE_BARRIER) \
{ \
int offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \
uint32_t offset = HEADER_SIZE + index * JSTaggedValue::TaggedTypeSize(); \
if (mode == WRITE_BARRIER && value.IsHeapObject()) { \
Barriers::SetDynObject<true>(thread, this, offset, value.GetRawData()); \
} else { \

View File

@ -47,7 +47,7 @@ inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSHandle<T> val
inline uintptr_t GlobalEnvConstants::GetGlobalConstantAddr(ConstantIndex index) const
{
return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast<int>(index);
return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast<uint32_t>(index);
}
// clang-format off

View File

@ -240,12 +240,12 @@ void ICRuntimeStub::StoreWithTransition(JSThread *thread, JSObject *receiver, JS
TransitionHandler *transitionHandler = TransitionHandler::Cast(handler.GetTaggedObject());
JSHClass *newHClass = JSHClass::Cast(transitionHandler->GetTransitionHClass().GetTaggedObject());
receiver->SetClass(newHClass);
uint32_t handlerInfo = transitionHandler->GetHandlerInfo().GetInt();
uint32_t handlerInfo = static_cast<uint32_t>(transitionHandler->GetHandlerInfo().GetInt());
ASSERT(HandlerBase::IsField(handlerInfo));
if (!HandlerBase::IsInlinedProps(handlerInfo)) {
TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject());
int capacity = array->GetLength();
int capacity = static_cast<int>(array->GetLength());
int index = HandlerBase::GetOffset(handlerInfo);
if (index >= capacity) {
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
@ -275,7 +275,7 @@ ARK_INLINE void ICRuntimeStub::StoreField(JSThread *thread, JSObject *receiver,
INTERPRETER_TRACE(thread, StoreField);
int index = HandlerBase::GetOffset(handler);
if (HandlerBase::IsInlinedProps(handler)) {
SET_VALUE_WITH_BARRIER(thread, receiver, index * JSTaggedValue::TaggedTypeSize(), value);
SET_VALUE_WITH_BARRIER(thread, receiver, static_cast<uint32_t>(index) * JSTaggedValue::TaggedTypeSize(), value);
return;
}
TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject());
@ -287,7 +287,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadFromField(JSObject *receiver, uint32
{
int index = HandlerBase::GetOffset(handlerInfo);
if (HandlerBase::IsInlinedProps(handlerInfo)) {
return JSTaggedValue(GET_VALUE(receiver, index * JSTaggedValue::TaggedTypeSize()));
return JSTaggedValue(GET_VALUE(receiver, static_cast<size_t>(index) * JSTaggedValue::TaggedTypeSize()));
}
return TaggedArray::Cast(receiver->GetProperties().GetHeapObject())->Get(index);
}
@ -363,7 +363,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadElement(JSObject *receiver, JSTagged
if (index < 0) {
return JSTaggedValue::Hole();
}
uint32_t elementIndex = index;
uint32_t elementIndex = static_cast<uint32_t>(index);
TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetHeapObject());
if (elements->GetLength() <= elementIndex) {
return JSTaggedValue::Hole();
@ -382,7 +382,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver,
if (index < 0) {
return JSTaggedValue::Hole();
}
uint32_t elementIndex = index;
uint32_t elementIndex = static_cast<uint32_t>(index);
if (handler.IsInt()) {
auto handlerInfo = static_cast<uint32_t>(handler.GetInt());
if (HandlerBase::IsJSArray(handlerInfo)) {

View File

@ -126,55 +126,55 @@ uint32_t LinkedHashTable<Derived, HashObject>::BucketToIndex(uint32_t bucket)
template<typename Derived, typename HashObject>
uint32_t LinkedHashTable<Derived, HashObject>::EntryToIndex(uint32_t entry) const
{
return ELEMENTS_START_INDEX + Capacity() + entry * (HashObject::ENTRY_SIZE + 1);
return ELEMENTS_START_INDEX + Capacity() + static_cast<int>(entry) * (HashObject::ENTRY_SIZE + 1);
}
template<typename Derived, typename HashObject>
void LinkedHashTable<Derived, HashObject>::SetKey(const JSThread *thread, int entry, JSTaggedValue key)
{
int index = EntryToIndex(entry);
int index = static_cast<int>(EntryToIndex(entry));
SetElement(thread, index, key);
}
template<typename Derived, typename HashObject>
JSTaggedValue LinkedHashTable<Derived, HashObject>::GetKey(int entry) const
{
int index = EntryToIndex(entry);
int index = static_cast<int>(EntryToIndex(entry));
return GetElement(index);
}
template<typename Derived, typename HashObject>
JSTaggedValue LinkedHashTable<Derived, HashObject>::GetValue(int entry) const
{
int index = EntryToIndex(entry) + HashObject::ENTRY_VALUE_INDEX;
int index = static_cast<int>(EntryToIndex(entry)) + HashObject::ENTRY_VALUE_INDEX;
return GetElement(index);
}
template<typename Derived, typename HashObject>
void LinkedHashTable<Derived, HashObject>::SetValue(const JSThread *thread, int entry, JSTaggedValue value)
{
int index = EntryToIndex(entry) + HashObject::ENTRY_VALUE_INDEX;
int index = static_cast<int>(EntryToIndex(entry)) + HashObject::ENTRY_VALUE_INDEX;
SetElement(thread, index, value);
}
template<typename Derived, typename HashObject>
JSTaggedValue LinkedHashTable<Derived, HashObject>::GetNextEntry(int entry) const
{
int index = EntryToIndex(entry) + HashObject::ENTRY_SIZE;
int index = static_cast<int>(EntryToIndex(entry)) + HashObject::ENTRY_SIZE;
return GetElement(index);
}
template<typename Derived, typename HashObject>
void LinkedHashTable<Derived, HashObject>::SetNextEntry(const JSThread *thread, int entry, JSTaggedValue nextEntry)
{
int index = EntryToIndex(entry) + HashObject::ENTRY_SIZE;
int index = static_cast<int>(EntryToIndex(entry)) + HashObject::ENTRY_SIZE;
SetElement(thread, index, nextEntry);
}
template<typename Derived, typename HashObject>
void LinkedHashTable<Derived, HashObject>::InsertNewEntry(const JSThread *thread, int bucket, int entry)
{
int bucketIndex = BucketToIndex(bucket);
int bucketIndex = static_cast<int>(BucketToIndex(bucket));
JSTaggedValue previousEntry = GetElement(bucketIndex);
SetNextEntry(thread, entry, previousEntry);
SetElement(thread, bucketIndex, JSTaggedValue(entry));
@ -186,7 +186,7 @@ int LinkedHashTable<Derived, HashObject>::FindElement(JSTaggedValue key) const
if (!IsKey(key)) {
return -1;
}
int hash = LinkedHash::Hash(key);
int hash = static_cast<int>(LinkedHash::Hash(key));
int bucket = HashToBucket(hash);
for (JSTaggedValue entry = GetElement(BucketToIndex(bucket)); !entry.IsHole();
entry = GetNextEntry(entry.GetInt())) {
@ -237,7 +237,7 @@ template<typename Derived, typename HashObject>
void LinkedHashTable<Derived, HashObject>::RemoveEntry(const JSThread *thread, int entry)
{
ASSERT_PRINT(entry >= 0 && entry < Capacity(), "entry must be a non-negative integer less than capacity");
int index = EntryToIndex(entry);
int index = static_cast<int>(EntryToIndex(entry));
for (int i = 0; i < HashObject::ENTRY_SIZE; i++) {
SetElement(thread, index + i, JSTaggedValue::Hole());
}

View File

@ -21,6 +21,10 @@
namespace panda::ecmascript {
void AotCodeInfo::SerializeForStub(const std::string &filename)
{
if (!VerifyFilePath(filename.c_str())) {
LOG_ECMA(FATAL) << "file path illegal !";
UNREACHABLE();
}
std::ofstream modulefile(filename.c_str(), std::ofstream::binary);
SetStubNum(stubEntries_.size());
/* write stub entries offset */
@ -43,6 +47,10 @@ bool AotCodeInfo::DeserializeForStub(JSThread *thread, const std::string &filena
// by calling NewMachineCodeObject.
// then MachineCode will support movable, code is saved to MachineCode and stackmap is saved
// to different heap which will be freed when stackmap is parsed by EcmaVM is started.
if (!VerifyFilePath(filename.c_str())) {
LOG_ECMA(FATAL) << "file path illegal !";
UNREACHABLE();
}
std::ifstream modulefile(filename.c_str(), std::ofstream::binary);
if (!modulefile.good()) {
modulefile.close();
@ -79,6 +87,10 @@ bool AotCodeInfo::DeserializeForStub(JSThread *thread, const std::string &filena
void AotCodeInfo::Serialize(const std::string &filename)
{
if (!VerifyFilePath(filename.c_str())) {
LOG_ECMA(FATAL) << "file path illegal !";
UNREACHABLE();
}
std::ofstream moduleFile(filename.c_str(), std::ofstream::binary);
uint32_t funcNum = aotFuncEntryOffsets_.size();
moduleFile.write(reinterpret_cast<char *>(&funcNum), sizeof(funcNum));
@ -102,6 +114,10 @@ void AotCodeInfo::Serialize(const std::string &filename)
bool AotCodeInfo::Deserialize(EcmaVM *vm, const std::string &filename)
{
if (!VerifyFilePath(filename.c_str())) {
LOG_ECMA(FATAL) << "file path illegal !";
UNREACHABLE();
}
std::ifstream moduleFile(filename.c_str(), std::ofstream::binary);
if (!moduleFile.good()) {
moduleFile.close();
@ -149,4 +165,22 @@ void AotCodeInfo::Iterate(const RootVisitor &v)
{
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&code_)));
}
bool AotCodeInfo::VerifyFilePath(const CString &filePath) const
{
#ifndef PANDA_TARGET_WINDOWS
if (filePath.size() > PATH_MAX) {
return false;
}
CVector<char> resolvedPath(PATH_MAX);
auto result = realpath(filePath.c_str(), resolvedPath.data());
if (result == nullptr) {
return false;
}
return true;
#else
return false;
#endif
}
} // panda::ecmascript

View File

@ -85,6 +85,7 @@ public:
void Serialize(const std::string &filename);
bool DeserializeForStub(JSThread *thread, const std::string &filename);
bool Deserialize(EcmaVM *vm, const std::string &filename);
bool VerifyFilePath(const CString &filePath) const;
struct StubDes {
uint64_t codeAddr_;
@ -215,7 +216,7 @@ public:
{
StubDes des;
des.kind_ = kind;
des.indexInKind_ = indexInKind;
des.indexInKind_ = static_cast<uint32_t>(indexInKind);
des.codeAddr_ = offset;
stubEntries_.emplace_back(des);
}