From 839f39e500d02dd619f074b426918984821f249b Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Fri, 14 Jan 2022 21:50:26 +0800 Subject: [PATCH] modify ACCESSOR for EcmaString and TaggedArray Signed-off-by: wengchangcheng Change-Id: I2995dc75ed34e8eb2bf249f2cced62ec9d91250e --- ecmascript/base/builtins_base.cpp | 4 +- ecmascript/base/json_parser.cpp | 8 +- ecmascript/base/json_stringifier.cpp | 18 ++-- ecmascript/builtins/builtins_array.cpp | 22 ++--- ecmascript/builtins/builtins_function.cpp | 6 +- ecmascript/builtins/builtins_json.cpp | 4 +- ecmascript/builtins/builtins_object.cpp | 18 ++-- ecmascript/builtins/builtins_promise.cpp | 2 +- ecmascript/builtins/builtins_typedarray.cpp | 2 +- .../builtins/tests/builtins_array_test.cpp | 8 +- .../builtins/tests/builtins_function_test.cpp | 2 +- .../builtins/tests/builtins_json_test.cpp | 6 +- .../builtins/tests/builtins_proxy_test.cpp | 2 +- .../builtins/tests/builtins_reflect_test.cpp | 2 +- .../tests/builtins_typedarray_test.cpp | 10 +- .../class_linker/panda_file_translator.cpp | 6 +- ecmascript/compiler/stub-inl.h | 12 +-- ecmascript/compiler/stub.cpp | 18 ++-- ecmascript/dump.cpp | 8 +- ecmascript/ecma_macros.h | 92 ++++++++++--------- ecmascript/ecma_runtime_call_info.h | 2 +- ecmascript/ecma_string-inl.h | 8 +- ecmascript/ecma_string.h | 71 +++++++------- ecmascript/ecma_vm.cpp | 2 +- ecmascript/global_dictionary-inl.h | 2 +- ecmascript/global_dictionary.h | 2 +- ecmascript/global_env.h | 7 +- ecmascript/ic/ic_runtime_stub-inl.h | 4 +- ecmascript/ic/invoke_cache.cpp | 6 +- ecmascript/ic/profile_type_info.cpp | 20 ++-- ecmascript/ic/profile_type_info.h | 2 +- ecmascript/ic/proto_change_details.cpp | 14 +-- ecmascript/ic/proto_change_details.h | 6 +- ecmascript/internal_call_params.cpp | 18 ++-- .../interpreter/fast_runtime_stub-inl.h | 6 +- .../interpreter/slow_runtime_helper.cpp | 14 +-- ecmascript/interpreter/slow_runtime_stub.cpp | 18 ++-- ecmascript/js_arraylist.cpp | 18 ++-- ecmascript/js_arraylist.h | 6 +- ecmascript/js_date_time_format.cpp | 16 ++-- ecmascript/js_for_in_iterator.cpp | 8 +- ecmascript/js_hclass.cpp | 6 +- ecmascript/js_locale.cpp | 34 +++---- ecmascript/js_locale.h | 8 +- ecmascript/js_object.cpp | 32 +++---- ecmascript/js_object.h | 12 +-- ecmascript/js_proxy.cpp | 22 ++--- ecmascript/js_stable_array.cpp | 36 ++++---- ecmascript/js_tagged_value-inl.h | 6 +- ecmascript/js_tagged_value.h | 2 +- ecmascript/js_typed_array.cpp | 14 +-- ecmascript/layout_info-inl.h | 18 ++-- ecmascript/layout_info.cpp | 4 +- ecmascript/layout_info.h | 20 ++-- ecmascript/lexical_env.h | 4 +- ecmascript/literal_data_extractor.cpp | 8 +- ecmascript/napi/jsnapi.cpp | 14 +-- ecmascript/object_factory.cpp | 42 ++++----- ecmascript/object_factory.h | 16 ++-- .../snapshot/mem/snapshot_serialize.cpp | 8 +- ecmascript/tagged_array-inl.h | 55 +++++------ ecmascript/tagged_array.h | 73 +++++---------- ecmascript/tagged_dictionary.cpp | 8 +- ecmascript/tagged_dictionary.h | 4 +- ecmascript/tagged_queue-inl.h | 8 +- ecmascript/tagged_queue.h | 48 +++++----- ecmascript/tests/concurrent_marking_test.cpp | 22 ++--- ecmascript/tests/ecma_string_test.cpp | 16 ++-- ecmascript/tests/js_object_test.cpp | 2 +- ecmascript/tests/test_helper.h | 2 +- ecmascript/tooling/agent/js_backend.cpp | 4 +- ecmascript/tooling/base/pt_params.cpp | 6 +- ecmascript/weak_vector-inl.h | 10 +- ecmascript/weak_vector.cpp | 16 ++-- ecmascript/weak_vector.h | 30 +++--- 75 files changed, 538 insertions(+), 572 deletions(-) diff --git a/ecmascript/base/builtins_base.cpp b/ecmascript/base/builtins_base.cpp index bdcef5dc50..3648792b71 100644 --- a/ecmascript/base/builtins_base.cpp +++ b/ecmascript/base/builtins_base.cpp @@ -22,9 +22,9 @@ JSHandle BuiltinsBase::GetArgsArray(EcmaRuntimeCallInfo *msg) { JSThread *thread = msg->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t length = msg->GetArgsNumber(); + uint32_t length = msg->GetArgsNumber(); JSHandle array = factory->NewTaggedArray(length); - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { array->Set(thread, i, GetCallArg(msg, i).GetTaggedValue()); } return array; diff --git a/ecmascript/base/json_parser.cpp b/ecmascript/base/json_parser.cpp index ec31ca0f6f..dbd130acff 100644 --- a/ecmascript/base/json_parser.cpp +++ b/ecmascript/base/json_parser.cpp @@ -31,10 +31,10 @@ JSHandle Internalize::InternalizeJsonProperty(JSThread *thread, c RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread, lenResult); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - array_size_t length = lenNumber.ToUint32(); + uint32_t length = lenNumber.ToUint32(); JSMutableHandle keyUnknow(thread, JSTaggedValue::Undefined()); JSMutableHandle keyName(thread, JSTaggedValue::Undefined()); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { // Let prop be ! ToString((I)). keyUnknow.Update(JSTaggedValue(i)); keyName.Update(JSTaggedValue::ToString(thread, keyUnknow).GetTaggedValue()); @@ -44,9 +44,9 @@ JSHandle Internalize::InternalizeJsonProperty(JSThread *thread, c // Let keys be ? EnumerableOwnPropertyNames(val, key). JSHandle ownerNames(JSObject::EnumerableOwnNames(thread, obj)); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); - array_size_t namesLength = ownerNames->GetLength(); + uint32_t namesLength = ownerNames->GetLength(); JSMutableHandle keyName(thread, JSTaggedValue::Undefined()); - for (array_size_t i = 0; i < namesLength; i++) { + for (uint32_t i = 0; i < namesLength; i++) { keyName.Update(JSTaggedValue::GetProperty(thread, JSHandle(ownerNames), i) .GetValue().GetTaggedValue()); RecurseAndApply(thread, obj, keyName, receiver); diff --git a/ecmascript/base/json_stringifier.cpp b/ecmascript/base/json_stringifier.cpp index e59bfa92bb..12039792a8 100644 --- a/ecmascript/base/json_stringifier.cpp +++ b/ecmascript/base/json_stringifier.cpp @@ -165,7 +165,7 @@ JSHandle JsonStringifier::Stringify(const JSHandle if (len > 0) { JSMutableHandle propHandle(thread_, JSTaggedValue::Undefined()); // Repeat while k JsonStringifier::Stringify(const JSHandle void JsonStringifier::AddDeduplicateProp(const JSHandle &property) { - array_size_t propLen = propList_.size(); - for (array_size_t i = 0; i < propLen; i++) { + uint32_t propLen = propList_.size(); + for (uint32_t i = 0; i < propLen; i++) { if (JSTaggedValue::SameValue(propList_[i], property)) { return; } @@ -414,9 +414,9 @@ void JsonStringifier::SerializeObjectKey(const JSHandle &key, boo bool JsonStringifier::PushValue(const JSHandle &value) { - array_size_t thisLen = stack_.size(); + uint32_t thisLen = stack_.size(); - for (array_size_t i = 0; i < thisLen; i++) { + for (uint32_t i = 0; i < thisLen; i++) { bool equal = JSTaggedValue::SameValue(stack_[i].GetTaggedValue(), value.GetTaggedValue()); if (equal) { return true; @@ -458,8 +458,8 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle &value, RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); } } else { - array_size_t propLen = propList_.size(); - for (array_size_t i = 0; i < propLen; i++) { + uint32_t propLen = propList_.size(); + for (uint32_t i = 0; i < propLen; i++) { JSTaggedValue tagVal = FastRuntimeStub::FastGetPropertyByValue(thread_, obj.GetTaggedValue(), propList_[i].GetTaggedValue()); handleValue_.Update(tagVal); @@ -511,7 +511,7 @@ bool JsonStringifier::SerializeJSProxy(const JSHandle &object, co JSTaggedNumber lenNumber = JSTaggedValue::ToLength(thread_, lenghHandle); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); uint32_t length = lenNumber.ToUint32(); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { handleKey_.Update(JSTaggedValue(i)); JSHandle valHandle = JSProxy::GetProperty(thread_, proxy, handleKey_).GetValue(); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false); @@ -559,7 +559,7 @@ bool JsonStringifier::SerializeJSArray(const JSHandle &value, con JSHandle jsArr(value); uint32_t len = jsArr->GetArrayLength(); if (len > 0) { - for (array_size_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { JSTaggedValue tagVal = FastRuntimeStub::FastGetPropertyByIndex(thread_, value.GetTaggedValue(), i); if (UNLIKELY(tagVal.IsAccessor())) { tagVal = JSObject::CallGetter(thread_, AccessorData::Cast(tagVal.GetTaggedObject()), value); diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index 346e2856e2..8e21c86047 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -49,7 +49,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // 1. Let numberOfArgs be the number of arguments passed to this function call. - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 3. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. JSHandle constructor = GetConstructor(argv); @@ -328,7 +328,7 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) JSHandle lengthKey = globalConst->GetHandledLengthString(); // 1. Let len be the actual number of arguments passed to this function. - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 3. Let C be the this value. JSHandle thisHandle = GetThis(argv); @@ -391,7 +391,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Array, Concat); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1067,7 +1067,7 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1255,7 +1255,7 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1464,7 +1464,7 @@ JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) return JSStableArray::Push(JSHandle::Cast(thisHandle), argv); } // 6. Let argCount be the number of elements in items. - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -1517,7 +1517,7 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -1618,7 +1618,7 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1969,7 +1969,7 @@ JSTaggedValue BuiltinsArray::Slice(EcmaRuntimeCallInfo *argv) TaggedArray *destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, count); TaggedArray *srcElements = TaggedArray::Cast(thisObjHandle->GetElements().GetTaggedObject()); - for (array_size_t idx = 0; idx < count; idx++) { + for (uint32_t idx = 0; idx < count; idx++) { destElements->Set(thread, idx, srcElements->Get(k + idx)); } @@ -2156,7 +2156,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Array, Splice); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -2493,7 +2493,7 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); // 5. Let argCount be the number of actual arguments. - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); diff --git a/ecmascript/builtins/builtins_function.cpp b/ecmascript/builtins/builtins_function.cpp index 50ab74e6b3..bd04a083f2 100644 --- a/ecmascript/builtins/builtins_function.cpp +++ b/ecmascript/builtins/builtins_function.cpp @@ -122,7 +122,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) } JSHandle thisArg = GetCallArg(argv, 0); - array_size_t argsLength = 0; + uint32_t argsLength = 0; if (argv->GetArgsNumber() > 1) { argsLength = argv->GetArgsNumber() - 1; } @@ -130,7 +130,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) // 3. Let args be a new (possibly empty) List consisting of all of the argument // values provided after thisArg in order. JSHandle argsArray = factory->NewTaggedArray(argsLength); - for (array_size_t index = 0; index < argsLength; ++index) { + for (uint32_t index = 0; index < argsLength; ++index) { argsArray->Set(thread, index, GetCallArg(argv, index + 1)); } // 4. Let F be BoundFunctionCreate(Target, thisArg, args). @@ -212,7 +212,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) JSHandle func = GetThis(argv); JSHandle thisArg = GetCallArg(argv, 0); - array_size_t argsLength = 0; + uint32_t argsLength = 0; if (argv->GetArgsNumber() > 1) { argsLength = argv->GetArgsNumber() - 1; } diff --git a/ecmascript/builtins/builtins_json.cpp b/ecmascript/builtins/builtins_json.cpp index 703581abe1..44b82bb5d3 100644 --- a/ecmascript/builtins/builtins_json.cpp +++ b/ecmascript/builtins/builtins_json.cpp @@ -35,7 +35,7 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc == 0) { JSHandle syntaxError = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, "arg is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); @@ -83,7 +83,7 @@ JSTaggedValue BuiltinsJson::Stringify(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); JSTaggedValue value = GetCallArg(argv, 0).GetTaggedValue(); JSTaggedValue replacer = JSTaggedValue::Undefined(); JSTaggedValue gap = JSTaggedValue::Undefined(); diff --git a/ecmascript/builtins/builtins_object.cpp b/ecmascript/builtins/builtins_object.cpp index df920725d8..e74ee5f505 100644 --- a/ecmascript/builtins/builtins_object.cpp +++ b/ecmascript/builtins/builtins_object.cpp @@ -81,7 +81,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // ii.Let keys be from.[[OwnPropertyKeys]](). // iii.ReturnIfAbrupt(keys). JSMutableHandle key(thread, JSTaggedValue::Undefined()); - for (array_size_t i = 1; i < numArgs; i++) { + for (uint32_t i = 1; i < numArgs; i++) { JSHandle source = GetCallArg(argv, i); if (!source->IsNull() && !source->IsUndefined()) { JSHandle from = JSTaggedValue::ToObject(thread, source); @@ -99,8 +99,8 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // 2.ReturnIfAbrupt(propValue). // 3.Let status be Set(to, nextKey, propValue, true). // 4.ReturnIfAbrupt(status). - array_size_t keysLen = keys->GetLength(); - for (array_size_t j = 0; j < keysLen; j++) { + uint32_t keysLen = keys->GetLength(); + for (uint32_t j = 0; j < keysLen; j++) { PropertyDescriptor desc(thread); key.Update(keys->Get(j)); bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle::Cast(from), key, desc); @@ -152,7 +152,7 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH // 6.Let descriptors be an empty List. // new an empty array and append - array_size_t length = handleKeys->GetLength(); + uint32_t length = handleKeys->GetLength(); [[maybe_unused]] JSHandle descriptors = factory->NewTaggedArray(2 * length); // 2: 2 means two element list @@ -166,7 +166,7 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH // iv.ReturnIfAbrupt(desc). // v.Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors. JSMutableHandle handleKey(thread, JSTaggedValue::Undefined()); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { PropertyDescriptor propDesc(thread); handleKey.Update(handleKeys->Get(i)); @@ -364,14 +364,14 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl // 5.Let nameList be a new empty List. // new an empty array and append - array_size_t length = handleKeys->GetLength(); + uint32_t length = handleKeys->GetLength(); JSHandle nameList = factory->NewTaggedArray(length); // 6.Repeat for each element nextKey of keys in List order, - array_size_t copyLength = 0; + uint32_t copyLength = 0; switch (type) { case KeyType::STRING_TYPE: { - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { JSTaggedValue key = handleKeys->Get(i); if (key.IsString()) { nameList->Set(thread, copyLength, key); @@ -381,7 +381,7 @@ JSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandl break; } case KeyType::SYMBOL_TYPE: { - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { JSTaggedValue key = handleKeys->Get(i); if (key.IsSymbol()) { nameList->Set(thread, copyLength, key); diff --git a/ecmascript/builtins/builtins_promise.cpp b/ecmascript/builtins/builtins_promise.cpp index e1f25d5845..58242c48b3 100644 --- a/ecmascript/builtins/builtins_promise.cpp +++ b/ecmascript/builtins/builtins_promise.cpp @@ -451,7 +451,7 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, JSHandle remainCnt = factory->NewPromiseRecord(); remainCnt->SetValue(thread, JSTaggedNumber(1)); // 5. Let index be 0. - array_size_t index = 0; + uint32_t index = 0; // 6. Repeat JSHandle itor(thread, itRecord->GetIterator()); JSMutableHandle next(thread, globalConst->GetUndefined()); diff --git a/ecmascript/builtins/builtins_typedarray.cpp b/ecmascript/builtins/builtins_typedarray.cpp index 9aaa5e38c3..1edc760cad 100644 --- a/ecmascript/builtins/builtins_typedarray.cpp +++ b/ecmascript/builtins/builtins_typedarray.cpp @@ -268,7 +268,7 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let len be the actual number of arguments passed to this function. - array_size_t len = argv->GetArgsNumber(); + uint32_t len = argv->GetArgsNumber(); // 2. Let items be the List of arguments passed to this function. // 3. Let C be the this value. JSHandle thisHandle = GetThis(argv); diff --git a/ecmascript/builtins/tests/builtins_array_test.cpp b/ecmascript/builtins/tests/builtins_array_test.cpp index 0e9a9c1e35..19c44c3281 100644 --- a/ecmascript/builtins/tests/builtins_array_test.cpp +++ b/ecmascript/builtins/tests/builtins_array_test.cpp @@ -81,7 +81,7 @@ public: static JSTaggedValue TestEveryFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { if (GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case return GetTaggedBoolean(true); @@ -99,7 +99,7 @@ public: static JSTaggedValue TestFindFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -111,7 +111,7 @@ public: static JSTaggedValue TestFindIndexFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -137,7 +137,7 @@ public: static JSTaggedValue TestSomeFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { if (GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case return GetTaggedBoolean(true); diff --git a/ecmascript/builtins/tests/builtins_function_test.cpp b/ecmascript/builtins/tests/builtins_function_test.cpp index d3de7245e9..4190b4ee3f 100644 --- a/ecmascript/builtins/tests/builtins_function_test.cpp +++ b/ecmascript/builtins/tests/builtins_function_test.cpp @@ -68,7 +68,7 @@ JSTaggedValue TestFunctionApplyAndCall(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; - for (array_size_t index = 0; index < argv->GetArgsNumber(); ++index) { + for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += BuiltinsBase::GetCallArg(argv, index)->GetInt(); } JSHandle thisValue(BuiltinsBase::GetThis(argv)); diff --git a/ecmascript/builtins/tests/builtins_json_test.cpp b/ecmascript/builtins/tests/builtins_json_test.cpp index 8714bb243b..5f5f035747 100644 --- a/ecmascript/builtins/tests/builtins_json_test.cpp +++ b/ecmascript/builtins/tests/builtins_json_test.cpp @@ -70,7 +70,7 @@ public: public: static JSTaggedValue TestForParse(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { } JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); @@ -87,7 +87,7 @@ public: static JSTaggedValue TestForParse1(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { } return JSTaggedValue::Undefined(); @@ -95,7 +95,7 @@ public: static JSTaggedValue TestForStringfy(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); if (key.IsUndefined()) { diff --git a/ecmascript/builtins/tests/builtins_proxy_test.cpp b/ecmascript/builtins/tests/builtins_proxy_test.cpp index 20e200f067..cccd7d1fc9 100644 --- a/ecmascript/builtins/tests/builtins_proxy_test.cpp +++ b/ecmascript/builtins/tests/builtins_proxy_test.cpp @@ -120,7 +120,7 @@ HWTEST_F_L0(BuiltinsProxyTest, Revocable) JSHandle keys = JSObject::GetOwnPropertyKeys(thread, resultHandle); bool pflag = false; bool rflag = false; - for (array_size_t i = 0; i < keys->GetLength(); i++) { + for (uint32_t i = 0; i < keys->GetLength(); i++) { if (JSTaggedValue::SameValue(keys->Get(i), proxyKey.GetTaggedValue())) { pflag = true; } diff --git a/ecmascript/builtins/tests/builtins_reflect_test.cpp b/ecmascript/builtins/tests/builtins_reflect_test.cpp index d630efc9cb..fd03fdf49c 100644 --- a/ecmascript/builtins/tests/builtins_reflect_test.cpp +++ b/ecmascript/builtins/tests/builtins_reflect_test.cpp @@ -74,7 +74,7 @@ JSTaggedValue TestReflectApply(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; - for (array_size_t index = 0; index < argv->GetArgsNumber(); ++index) { + for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += BuiltinsBase::GetCallArg(argv, index).GetTaggedValue().GetInt(); } JSHandle thisValue = BuiltinsBase::GetThis(argv); diff --git a/ecmascript/builtins/tests/builtins_typedarray_test.cpp b/ecmascript/builtins/tests/builtins_typedarray_test.cpp index 7cab6934fb..688d81615f 100644 --- a/ecmascript/builtins/tests/builtins_typedarray_test.cpp +++ b/ecmascript/builtins/tests/builtins_typedarray_test.cpp @@ -90,7 +90,7 @@ protected: static JSTaggedValue TestEveryFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { [[maybe_unused]] int aaa = GetCallArg(argv, 0)->GetInt(); // 10 : test case @@ -104,7 +104,7 @@ protected: static JSTaggedValue TestFilterFunc(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -123,7 +123,7 @@ protected: static JSTaggedValue TestFindFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -135,7 +135,7 @@ protected: static JSTaggedValue TestFindIndexFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -161,7 +161,7 @@ protected: static JSTaggedValue TestSomeFunc(EcmaRuntimeCallInfo *argv) { - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { diff --git a/ecmascript/class_linker/panda_file_translator.cpp b/ecmascript/class_linker/panda_file_translator.cpp index f5606e2a2e..be50cd14de 100644 --- a/ecmascript/class_linker/panda_file_translator.cpp +++ b/ecmascript/class_linker/panda_file_translator.cpp @@ -237,7 +237,7 @@ Program *PandaFileTranslator::GenerateProgram(const panda_file::File &pf) size_t index = it.first; JSHandle literal = LiteralDataExtractor::GetDatasIgnoreType(thread_, &pf, static_cast(index)); - array_size_t length = literal->GetLength(); + uint32_t length = literal->GetLength(); JSHandle arr(JSArray::ArrayCreate(thread_, JSTaggedNumber(length))); arr->SetElements(thread_, literal); @@ -580,8 +580,8 @@ JSHandle PandaFileTranslator::DefineMethodInLiteral(JSThread *thread void PandaFileTranslator::DefineClassInConstPool(const JSHandle &constpool) const { - array_size_t length = constpool->GetLength(); - array_size_t index = 0; + uint32_t length = constpool->GetLength(); + uint32_t index = 0; while (index < length - 1) { JSTaggedValue value = constpool->Get(index); if (!value.IsClassInfoExtractor()) { diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index 5c2a26659f..c444576c3f 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -862,7 +862,7 @@ void Stub::SetPropertiesArray(GateRef glue, GateRef object, GateRef propsArray) GateRef Stub::GetLengthofTaggedArray(GateRef array) { - return Load(MachineType::UINT32, array, GetArchRelateConstant(TaggedArray::GetLengthOffset())); + return Load(MachineType::UINT32, array, GetArchRelateConstant(TaggedArray::LENGTH_OFFSET)); } GateRef Stub::IsJSHClass(GateRef obj) @@ -1348,7 +1348,7 @@ void Stub::SetValueToTaggedArray(MachineType valType, GateRef glue, GateRef arra // NOTE: need to translate MarkingBarrier GateRef offset = ArchRelatePtrMul(ChangeInt32ToUintPtr(index), GetArchRelateConstant(JSTaggedValue::TaggedTypeSize())); - GateRef dataOffset = PtrAdd(offset, GetArchRelateConstant(TaggedArray::GetDataOffset())); + GateRef dataOffset = PtrAdd(offset, GetArchRelateConstant(TaggedArray::DATA_OFFSET)); Store(valType, glue, array, dataOffset, val); } @@ -1356,7 +1356,7 @@ GateRef Stub::GetValueFromTaggedArray(MachineType returnType, GateRef array, Gat { GateRef offset = ArchRelatePtrMul(ChangeInt32ToUintPtr(index), GetArchRelateConstant(JSTaggedValue::TaggedTypeSize())); - GateRef dataOffset = PtrAdd(offset, GetArchRelateConstant(TaggedArray::GetDataOffset())); + GateRef dataOffset = PtrAdd(offset, GetArchRelateConstant(TaggedArray::DATA_OFFSET)); return Load(returnType, array, dataOffset); } @@ -1372,7 +1372,7 @@ void Stub::UpdateValueAndAttributes(GateRef glue, GateRef elements, GateRef inde SetValueToTaggedArray(MachineType::TAGGED, glue, elements, valueIndex, value); GateRef attroffset = ArchRelatePtrMul(ChangeInt32ToUintPtr(attributesIndex), GetArchRelateConstant(JSTaggedValue::TaggedTypeSize())); - GateRef dataOffset = PtrAdd(attroffset, GetArchRelateConstant(TaggedArray::GetDataOffset())); + GateRef dataOffset = PtrAdd(attroffset, GetArchRelateConstant(TaggedArray::DATA_OFFSET)); Store(MachineType::INT64, glue, elements, dataOffset, IntBuildTaggedWithNoGC(attr)); } @@ -1429,7 +1429,7 @@ GateRef Stub::GetKeyFromDictionary(MachineType returnType, GateRef elements, Gat Label gtLength(env); Label notGtLength(env); GateRef dictionaryLength = - Load(MachineType::INT32, elements, GetArchRelateConstant(panda::coretypes::Array::GetLengthOffset())); + Load(MachineType::INT32, elements, GetArchRelateConstant(TaggedArray::LENGTH_OFFSET)); GateRef arrayIndex = Int32Add(GetInt32Constant(DictionaryT::TABLE_HEADER_SIZE), Int32Mul(entry, GetInt32Constant(DictionaryT::ENTRY_SIZE))); @@ -1474,7 +1474,7 @@ GateRef Stub::GetPropertiesAddrFromLayoutInfo(GateRef layout) { GateRef eleStartIdx = ArchRelatePtrMul(GetArchRelateConstant(LayoutInfo::ELEMENTS_START_INDEX), GetArchRelateConstant(JSTaggedValue::TaggedTypeSize())); - return PtrAdd(layout, PtrAdd(GetArchRelateConstant(TaggedArray::GetDataOffset()), eleStartIdx)); + return PtrAdd(layout, PtrAdd(GetArchRelateConstant(TaggedArray::DATA_OFFSET), eleStartIdx)); } GateRef Stub::TaggedCastToInt64(GateRef x) diff --git a/ecmascript/compiler/stub.cpp b/ecmascript/compiler/stub.cpp index 4535c3396d..ce39e1144f 100644 --- a/ecmascript/compiler/stub.cpp +++ b/ecmascript/compiler/stub.cpp @@ -440,7 +440,7 @@ GateRef Stub::FindElementFromNumberDictionary(GateRef glue, GateRef elements, Ga GateRef capcityoffset = ArchRelatePtrMul(GetArchRelateConstant(JSTaggedValue::TaggedTypeSize()), GetArchRelateConstant(TaggedHashTable::SIZE_INDEX)); - GateRef dataoffset = GetArchRelateConstant(TaggedArray::GetDataOffset()); + GateRef dataoffset = GetArchRelateConstant(TaggedArray::DATA_OFFSET); GateRef capacity = TaggedCastToInt32(Load(MachineType::UINT64, elements, ArchRelateAdd(dataoffset, capcityoffset))); DEFVARIABLE(count, MachineType::INT32, GetInt32Constant(1)); @@ -538,7 +538,7 @@ GateRef Stub::FindEntryFromNameDictionary(GateRef glue, GateRef elements, GateRe GateRef capcityoffset = ArchRelatePtrMul(GetArchRelateConstant(JSTaggedValue::TaggedTypeSize()), GetArchRelateConstant(TaggedHashTable::SIZE_INDEX)); - GateRef dataoffset = GetArchRelateConstant(TaggedArray::GetDataOffset()); + GateRef dataoffset = GetArchRelateConstant(TaggedArray::DATA_OFFSET); GateRef capacity = TaggedCastToInt32(Load(MachineType::UINT64, elements, PtrAdd(dataoffset, capcityoffset))); DEFVARIABLE(count, MachineType::INT32, GetInt32Constant(1)); DEFVARIABLE(hash, MachineType::INT32, GetInt32Constant(0)); @@ -648,7 +648,7 @@ GateRef Stub::FindEntryFromTransitionDictionary(GateRef glue, GateRef elements, GateRef capcityoffset = ArchRelatePtrMul(GetArchRelateConstant(JSTaggedValue::TaggedTypeSize()), GetArchRelateConstant(TaggedHashTable::SIZE_INDEX)); - GateRef dataoffset = GetArchRelateConstant(TaggedArray::GetDataOffset()); + GateRef dataoffset = GetArchRelateConstant(TaggedArray::DATA_OFFSET); GateRef capacity = TaggedCastToInt32(Load(MachineType::UINT64, elements, PtrAdd(dataoffset, capcityoffset))); DEFVARIABLE(count, MachineType::INT32, GetInt32Constant(1)); DEFVARIABLE(hash, MachineType::INT32, GetInt32Constant(0)); @@ -1242,7 +1242,7 @@ GateRef Stub::TaggedIsStringOrSymbol(GateRef obj) GateRef Stub::IsUtf16String(GateRef string) { // compressedStringsEnabled fixed to true constant - GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::GetLengthOffset())); + GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::MIX_LENGTH_OFFSET)); return Word32Equal( Word32And(len, GetInt32Constant(EcmaString::STRING_COMPRESSED_BIT)), GetInt32Constant(EcmaString::STRING_UNCOMPRESSED)); @@ -1251,7 +1251,7 @@ GateRef Stub::IsUtf16String(GateRef string) GateRef Stub::IsUtf8String(GateRef string) { // compressedStringsEnabled fixed to true constant - GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::GetLengthOffset())); + GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::MIX_LENGTH_OFFSET)); return Word32Equal( Word32And(len, GetInt32Constant(EcmaString::STRING_COMPRESSED_BIT)), GetInt32Constant(EcmaString::STRING_COMPRESSED)); @@ -1260,7 +1260,7 @@ GateRef Stub::IsUtf8String(GateRef string) GateRef Stub::IsInternalString(GateRef string) { // compressedStringsEnabled fixed to true constant - GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::GetLengthOffset())); + GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::MIX_LENGTH_OFFSET)); return Word32NotEqual( Word32And(len, GetInt32Constant(EcmaString::STRING_INTERN_BIT)), GetInt32Constant(0)); @@ -1282,14 +1282,14 @@ GateRef Stub::StringToElementIndex(GateRef string) DEFVARIABLE(result, MachineType::INT32, GetInt32Constant(-1)); Label greatThanZero(env); Label inRange(env); - GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::GetLengthOffset())); + GateRef len = Load(MachineType::UINT32, string, GetArchRelateConstant(EcmaString::MIX_LENGTH_OFFSET)); len = Word32LSR(len, GetInt32Constant(2)); // 2 : 2 means len must be right shift 2 bits Branch(Word32Equal(len, GetInt32Constant(0)), &exit, &greatThanZero); Bind(&greatThanZero); Branch(Int32GreaterThan(len, GetInt32Constant(MAX_INDEX_LEN)), &exit, &inRange); Bind(&inRange); { - GateRef dataUtf16 = PtrAdd(string, GetArchRelateConstant(EcmaString::GetDataOffset())); + GateRef dataUtf16 = PtrAdd(string, GetArchRelateConstant(EcmaString::DATA_OFFSET)); DEFVARIABLE(c, MachineType::UINT32, GetInt32Constant(0)); Label isUtf16(env); Label isUtf8(env); @@ -1865,7 +1865,7 @@ void Stub::StoreWithTransition(GateRef glue, GateRef receiver, GateRef value, Ga } Bind(&indexLessCapacity); { - Store(MachineType::UINT64, glue, ArchRelateAdd(array, GetArchRelateConstant(TaggedArray::GetDataOffset())), + Store(MachineType::UINT64, glue, ArchRelateAdd(array, GetArchRelateConstant(TaggedArray::DATA_OFFSET)), ArchRelatePtrMul(ChangeInt32ToUintPtr(index), GetArchRelateConstant(JSTaggedValue::TaggedTypeSize())), value); Jump(&exit); diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 6fd511ec8d..445728c7da 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -267,9 +267,9 @@ CString JSHClass::DumpJSType(JSType type) static void DumpArrayClass(JSThread *thread, const TaggedArray *arr, std::ostream &os) { DISALLOW_GARBAGE_COLLECTION; - array_size_t len = arr->GetLength(); + uint32_t len = arr->GetLength(); os << " \n"; - for (array_size_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { JSTaggedValue val(arr->Get(i)); if (!val.IsHole()) { os << std::right << std::setw(DUMP_PROPERTY_OFFSET) << i << ": "; @@ -1943,8 +1943,8 @@ static void DumpArrayClass([[maybe_unused]] JSThread *thread, const TaggedArray std::vector> &vec) { DISALLOW_GARBAGE_COLLECTION; - array_size_t len = arr->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = arr->GetLength(); + for (uint32_t i = 0; i < len; i++) { JSTaggedValue val(arr->Get(i)); CString str = ToCString(i); vec.push_back(std::make_pair(str, val)); diff --git a/ecmascript/ecma_macros.h b/ecmascript/ecma_macros.h index f4b4ab38d5..2624bef433 100644 --- a/ecmascript/ecma_macros.h +++ b/ecmascript/ecma_macros.h @@ -60,7 +60,7 @@ /* dynamically-typed languages like JavaScript. So we simply skip the read-barrier. */ \ return JSTaggedValue(Barriers::GetDynValue(this, offset)); \ } \ - template \ + template \ void Set##name(const JSThread *thread, JSHandle value, BarrierMode mode = WRITE_BARRIER) \ { \ if (mode == WRITE_BARRIER) { \ @@ -87,7 +87,7 @@ } \ void Set##name(JSTaggedValue value) \ { \ - Barriers::SetDynPrimitive(this, offset, value.GetRawData()); \ + Barriers::SetDynPrimitive(this, offset, value.GetRawData()); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -235,19 +235,19 @@ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DATE_STRING(name) \ - static JSTaggedValue name(EcmaRuntimeCallInfo *argv) \ - { \ - ASSERT(argv); \ - JSThread *thread = argv->GetThread(); \ - JSHandle msg = GetThis(argv); \ - if (!msg->IsDate()) { \ - THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ - } \ - if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ +#define DATE_STRING(name) \ + static JSTaggedValue name(EcmaRuntimeCallInfo *argv) \ + { \ + ASSERT(argv); \ + JSThread *thread = argv->GetThread(); \ + JSHandle msg = GetThis(argv); \ + if (!msg->IsDate()) { \ + THROW_TYPE_ERROR_AND_RETURN(thread, "Not a Date Object", JSTaggedValue::Exception()); \ + } \ + if (std::isnan(JSDate::Cast(msg->GetTaggedObject())->GetTimeValue().GetDouble())) { \ return thread->GetEcmaVM()->GetFactory()->NewFromCanBeCompressString("Invalid Date").GetTaggedValue(); \ - } \ - return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ + } \ + return JSDate::Cast(msg->GetTaggedObject())->name(thread); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -350,13 +350,13 @@ } while (false) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define RETURN_COMPLETION_IF_ABRUPT(thread, value) \ - do { \ - if (thread->HasPendingException()) { \ - JSHandle completionRecord = \ - factory->NewCompletionRecord(CompletionRecord::THROW, value); \ - return (completionRecord); \ - } \ +#define RETURN_COMPLETION_IF_ABRUPT(thread, value) \ + do { \ + if (thread->HasPendingException()) { \ + JSHandle completionRecord = \ + factory->NewCompletionRecord(CompletionRecord::THROW, value); \ + return (completionRecord); \ + } \ } while (false) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -379,30 +379,38 @@ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECL_VISIT_OBJECT(BEGIN_OFFSET, SIZE) \ - void VisitRangeSlot(const EcmaObjectRangeVisitor &visitor) \ - { \ - visitor(this, ObjectSlot(ToUintPtr(this) + BEGIN_OFFSET), ObjectSlot(ToUintPtr(this) + SIZE)); \ +#define DECL_VISIT_ARRAY(BEGIN_OFFSET, LENGTH) \ + void VisitRangeSlot(const EcmaObjectRangeVisitor &visitor) \ + { \ + size_t endOffset = (BEGIN_OFFSET) + (LENGTH) * JSTaggedValue::TaggedTypeSize(); \ + visitor(this, ObjectSlot(ToUintPtr(this) + (BEGIN_OFFSET)), ObjectSlot(ToUintPtr(this) + endOffset)); \ + } + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DECL_VISIT_OBJECT(BEGIN_OFFSET, END_OFFSET) \ + void VisitRangeSlot(const EcmaObjectRangeVisitor &visitor) \ + { \ + visitor(this, ObjectSlot(ToUintPtr(this) + (BEGIN_OFFSET)), ObjectSlot(ToUintPtr(this) + (END_OFFSET))); \ } // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DECL_VISIT_OBJECT_FOR_JS_OBJECT(PARENTCLASS, BEGIN_OFFSET, SIZE) \ - void VisitRangeSlot(const EcmaObjectRangeVisitor &visitor) \ - { \ - VisitObjects(visitor); \ - /* visit in object fields */ \ - auto objSize = this->GetClass()->GetObjectSize(); \ - if (objSize > SIZE) { \ - visitor(this, ObjectSlot(ToUintPtr(this) + SIZE), ObjectSlot(ToUintPtr(this) + objSize)); \ - } \ - } \ - void VisitObjects(const EcmaObjectRangeVisitor &visitor) \ - { \ - PARENTCLASS::VisitObjects(visitor); \ - if (BEGIN_OFFSET == SIZE) { \ - return; \ - } \ - visitor(this, ObjectSlot(ToUintPtr(this) + BEGIN_OFFSET), ObjectSlot(ToUintPtr(this) + SIZE)); \ +#define DECL_VISIT_OBJECT_FOR_JS_OBJECT(PARENTCLASS, BEGIN_OFFSET, END_OFFSET) \ + void VisitRangeSlot(const EcmaObjectRangeVisitor &visitor) \ + { \ + VisitObjects(visitor); \ + /* visit in object fields */ \ + auto objSize = this->GetClass()->GetObjectSize(); \ + if (objSize > (END_OFFSET)) { \ + visitor(this, ObjectSlot(ToUintPtr(this) + (END_OFFSET)), ObjectSlot(ToUintPtr(this) + objSize)); \ + } \ + } \ + void VisitObjects(const EcmaObjectRangeVisitor &visitor) \ + { \ + PARENTCLASS::VisitObjects(visitor); \ + if ((BEGIN_OFFSET) == (END_OFFSET)) { \ + return; \ + } \ + visitor(this, ObjectSlot(ToUintPtr(this) + (BEGIN_OFFSET)), ObjectSlot(ToUintPtr(this) + (END_OFFSET))); \ } #if ECMASCRIPT_ENABLE_CAST_CHECK diff --git a/ecmascript/ecma_runtime_call_info.h b/ecmascript/ecma_runtime_call_info.h index c7c557efb4..3f7eb895e3 100644 --- a/ecmascript/ecma_runtime_call_info.h +++ b/ecmascript/ecma_runtime_call_info.h @@ -93,7 +93,7 @@ public: * The number of arguments pairs excluding the 'func', 'new.target' and 'this'. For instance: * for code fragment: " foo(v1); ", GetArgsNumber() returns 1 */ - inline array_size_t GetArgsNumber() const + inline uint32_t GetArgsNumber() const { return numArgs_ - NUM_MANDATORY_JSFUNC_ARGS; } diff --git a/ecmascript/ecma_string-inl.h b/ecmascript/ecma_string-inl.h index 5cffa1c1b1..c4168cf03c 100644 --- a/ecmascript/ecma_string-inl.h +++ b/ecmascript/ecma_string-inl.h @@ -40,9 +40,9 @@ inline const EcmaString *EcmaString::ConstCast(const TaggedObject *object) /* static */ inline EcmaString *EcmaString::CreateEmptyString(const EcmaVM *vm) { - auto string = vm->GetFactory()->AllocNonMovableStringObject(sizeof(EcmaString)); + auto string = vm->GetFactory()->AllocNonMovableStringObject(EcmaString::SIZE); string->SetLength(0, GetCompressedStringsEnabled()); - string->SetHashcode(0); + string->SetRawHashcode(0); return string; } @@ -120,9 +120,10 @@ inline EcmaString *EcmaString::AllocStringObject(size_t length, bool compressed, size_t size = compressed ? ComputeSizeUtf8(length) : ComputeSizeUtf16(length); auto string = reinterpret_cast(vm->GetFactory()->AllocStringObject(size)); string->SetLength(length, compressed); - string->SetHashcode(0); + string->SetRawHashcode(0); return reinterpret_cast(string); } + void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, uint32_t length) { if (IsUtf8()) { @@ -147,6 +148,7 @@ void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, u } } } + void EcmaString::WriteData(char src, uint32_t start) { if (IsUtf8()) { diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index 453b2d1250..73ed4a0340 100644 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -59,17 +59,17 @@ public: bool IsUtf16() const { - return compressedStringsEnabled ? ((length_ & STRING_COMPRESSED_BIT) == STRING_UNCOMPRESSED) : true; + return compressedStringsEnabled ? ((GetMixLength() & STRING_COMPRESSED_BIT) == STRING_UNCOMPRESSED) : true; } bool IsUtf8() const { - return compressedStringsEnabled ? ((length_ & STRING_COMPRESSED_BIT) == STRING_COMPRESSED) : false; + return compressedStringsEnabled ? ((GetMixLength() & STRING_COMPRESSED_BIT) == STRING_COMPRESSED) : false; } static size_t ComputeDataSizeUtf16(uint32_t length) { - return length * sizeof(dataUtf16_[0]); + return length * sizeof(uint16_t); } /** @@ -77,13 +77,18 @@ public: */ static size_t ComputeSizeUtf16(uint32_t utf16Len) { - return sizeof(EcmaString) + ComputeDataSizeUtf16(utf16Len); + return DATA_OFFSET + ComputeDataSizeUtf16(utf16Len); + } + + inline uint16_t *GetData() const + { + return reinterpret_cast(ToUintPtr(this) + DATA_OFFSET); } const uint16_t *GetDataUtf16() const { LOG_IF(!IsUtf16(), FATAL, RUNTIME) << "EcmaString: Read data as utf16 for utf8 string"; - return dataUtf16_; + return GetData(); } /** @@ -91,7 +96,7 @@ public: */ static size_t ComputeSizeUtf8(uint32_t utf8Len) { - return sizeof(EcmaString) + utf8Len; + return DATA_OFFSET + utf8Len; } /** @@ -100,7 +105,7 @@ public: const uint8_t *GetDataUtf8() const { LOG_IF(IsUtf16(), FATAL, RUNTIME) << "EcmaString: Read data as utf8 for utf16 string"; - return reinterpret_cast(dataUtf16_); + return reinterpret_cast(GetData()); } size_t GetUtf8Length() const @@ -108,7 +113,7 @@ public: if (!IsUtf16()) { return GetLength() + 1; // add place for zero in the end } - return base::utf_helper::Utf16ToUtf8Size(dataUtf16_, GetLength()); + return base::utf_helper::Utf16ToUtf8Size(GetData(), GetLength()); } size_t GetUtf16Length() const @@ -188,17 +193,17 @@ public: inline void WriteData(char src, uint32_t start); uint32_t GetLength() const { - return length_ >> 2U; + return GetMixLength() >> 2U; } void SetIsInternString() { - length_ |= STRING_INTERN_BIT; + SetMixLength(GetMixLength() | STRING_INTERN_BIT); } bool IsInternString() const { - return (length_ & STRING_INTERN_BIT) != 0; + return (GetMixLength() & STRING_INTERN_BIT) != 0; } size_t ObjectSize() const @@ -209,24 +214,16 @@ public: uint32_t GetHashcode() { - if (hashcode_ == 0) { - hashcode_ = ComputeHashcode(); + uint32_t hashcode = GetRawHashcode(); + if (hashcode == 0) { + hashcode = ComputeHashcode(); + SetRawHashcode(hashcode); } - return hashcode_; + return hashcode; } int32_t IndexOf(const EcmaString *rhs, int pos = 0) const; - static constexpr uint32_t GetLengthOffset() - { - return MEMBER_OFFSET(EcmaString, length_); - } - - static constexpr uint32_t GetDataOffset() - { - return MEMBER_OFFSET(EcmaString, dataUtf16_); - } - static constexpr uint32_t GetStringCompressionMask() { return STRING_COMPRESSED_BIT; @@ -263,29 +260,32 @@ public: static bool CanBeCompressed(const uint8_t *utf8Data); static bool CanBeCompressed(const uint16_t *utf16Data, uint32_t utf16Len); + static constexpr size_t MIX_LENGTH_OFFSET = TaggedObjectSize(); + // In last bit of mix_length we store if this string is compressed or not. + SET_GET_PRIMITIVE_FIELD(MixLength, uint32_t, MIX_LENGTH_OFFSET, HASHCODE_OFFSET); + SET_GET_PRIMITIVE_FIELD(RawHashcode, uint32_t, HASHCODE_OFFSET, DATA_OFFSET); + // DATA_OFFSET: the string data stored after the string header. + // Data can be stored in utf8 or utf16 form according to compressed bit. + static constexpr size_t SIZE = DATA_OFFSET; // Empty String size + private: void SetLength(uint32_t length, bool compressed = false) { ASSERT(length < 0x40000000U); // Use 0u for compressed/utf8 expression - length_ = (length << 2U) | (compressed ? STRING_COMPRESSED : STRING_UNCOMPRESSED); - } - - void SetHashcode(uint32_t hashcode) - { - hashcode_ = hashcode; + SetMixLength((length << 2U) | (compressed ? STRING_COMPRESSED : STRING_UNCOMPRESSED)); } uint16_t *GetDataUtf16Writable() { LOG_IF(!IsUtf16(), FATAL, RUNTIME) << "EcmaString: Read data as utf16 for utf8 string"; - return dataUtf16_; + return GetData(); } uint8_t *GetDataUtf8Writable() { LOG_IF(IsUtf16(), FATAL, RUNTIME) << "EcmaString: Read data as utf8 for utf16 string"; - return reinterpret_cast(dataUtf16_); + return reinterpret_cast(GetData()); } uint32_t ComputeHashcode() const; @@ -319,13 +319,6 @@ private: template static int32_t IndexOf(Span &lhsSp, Span &rhsSp, int32_t pos, int32_t max); - - // In last bit of length_ we store if this string is compressed or not. - uint32_t length_; - uint32_t hashcode_; - // A pointer to the string data stored after the string header. - // Data can be stored in utf8 or utf16 form according to compressed bit. - __extension__ uint16_t dataUtf16_[0]; // NOLINT(modernize-avoid-c-arrays) }; } // namespace ecmascript } // namespace panda diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index ee5957586a..adceb54a10 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -461,7 +461,7 @@ Expected EcmaVM::InvokeEcmaEntrypoint(const panda_file::Fil JSHandle global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject(); JSHandle newTarget(thread_, JSTaggedValue::Undefined()); JSHandle jsargs = factory_->NewTaggedArray(args.size()); - array_size_t i = 0; + uint32_t i = 0; for (const std::string &str : args) { JSHandle strobj(factory_->NewFromStdString(str)); jsargs->Set(thread_, i++, strobj); diff --git a/ecmascript/global_dictionary-inl.h b/ecmascript/global_dictionary-inl.h index f53ceed58f..f843df6fd8 100644 --- a/ecmascript/global_dictionary-inl.h +++ b/ecmascript/global_dictionary-inl.h @@ -119,7 +119,7 @@ void GlobalDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArra } void GlobalDictionary::GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, - array_size_t *keys) const + uint32_t *keys) const { ASSERT_PRINT(offset + EntriesCount() <= static_cast(keyArray->GetLength()), "keyArray capacity is not enough for dictionary"); diff --git a/ecmascript/global_dictionary.h b/ecmascript/global_dictionary.h index bbbda1709e..8f13113c1c 100644 --- a/ecmascript/global_dictionary.h +++ b/ecmascript/global_dictionary.h @@ -73,7 +73,7 @@ public: inline void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const; - inline void GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, array_size_t *keys) const; + inline void GetEnumAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const; static bool inline CompKey(const std::pair &a, const std::pair &b); diff --git a/ecmascript/global_env.h b/ecmascript/global_env.h index 2181d1fdfc..04988f5491 100644 --- a/ecmascript/global_env.h +++ b/ecmascript/global_env.h @@ -200,12 +200,9 @@ public: static constexpr size_t HEADER_SIZE = TaggedObjectSize(); static constexpr size_t SIZE = HEADER_SIZE + FINAL_INDEX * JSTaggedValue::TaggedTypeSize(); - DECL_DUMP() + DECL_VISIT_OBJECT(HEADER_SIZE, SIZE); - inline void VisitRangeSlot(const EcmaObjectRangeVisitor &v) - { - v(this, ObjectSlot(ToUintPtr(this) + HEADER_SIZE), ObjectSlot(ToUintPtr(this) + SIZE)); - } + DECL_DUMP() }; } // namespace panda::ecmascript diff --git a/ecmascript/ic/ic_runtime_stub-inl.h b/ecmascript/ic/ic_runtime_stub-inl.h index 5ba5fcef22..fdd6e667a1 100644 --- a/ecmascript/ic/ic_runtime_stub-inl.h +++ b/ecmascript/ic/ic_runtime_stub-inl.h @@ -86,8 +86,8 @@ JSTaggedValue ICRuntimeStub::CheckPolyHClass(JSTaggedValue cachedValue, JSHClass if (!cachedValue.IsWeak()) { ASSERT(cachedValue.IsTaggedArray()); TaggedArray *array = TaggedArray::Cast(cachedValue.GetHeapObject()); - array_size_t length = array->GetLength(); - for (array_size_t i = 0; i < length; i += 2) { // 2 means one ic, two slot + uint32_t length = array->GetLength(); + for (uint32_t i = 0; i < length; i += 2) { // 2 means one ic, two slot auto result = array->Get(i); if (result != JSTaggedValue::Undefined() && result.GetWeakReferent() == hclass) { return array->Get(i + 1); diff --git a/ecmascript/ic/invoke_cache.cpp b/ecmascript/ic/invoke_cache.cpp index af4c6dee0a..de27342349 100644 --- a/ecmascript/ic/invoke_cache.cpp +++ b/ecmascript/ic/invoke_cache.cpp @@ -63,8 +63,8 @@ JSTaggedValue InvokeCache::CheckPolyInvokeCache(JSTaggedValue cachedArray, JSTag { ASSERT(cachedArray.IsTaggedArray()); TaggedArray *array = TaggedArray::Cast(cachedArray.GetHeapObject()); - array_size_t length = array->GetLength(); - for (array_size_t index = 0; index < length; index += 2) { // 2: means one ic, two slot + uint32_t length = array->GetLength(); + for (uint32_t index = 0; index < length; index += 2) { // 2: means one ic, two slot auto result = array->Get(index); if (JSFunction::Cast(result.GetTaggedObject())->GetMethod() == JSFunction::Cast(func.GetTaggedObject())->GetMethod()) { @@ -114,7 +114,7 @@ JSTaggedValue InvokeCache::Construct(JSThread *thread, JSTaggedValue firstValue, params.newTarget = newTgt.GetTaggedType(); params.thisArg = obj.GetTaggedType(); params.argc = length; - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { JSTaggedValue value = frameHandler.GetVRegValue(firstArgIdx + i); values.emplace_back(value.GetRawData()); } diff --git a/ecmascript/ic/profile_type_info.cpp b/ecmascript/ic/profile_type_info.cpp index cddfcff97d..dddb296410 100644 --- a/ecmascript/ic/profile_type_info.cpp +++ b/ecmascript/ic/profile_type_info.cpp @@ -55,8 +55,8 @@ void ProfileTypeAccessor::AddHandlerWithoutKey(JSHandle dynclass, if (!profileData.IsWeak() && profileData.IsTaggedArray()) { // POLY ASSERT(profileTypeInfo_->Get(index + 1) == JSTaggedValue::Hole()); JSHandle arr(thread_, profileData); - const array_size_t step = 2; - array_size_t newLen = arr->GetLength() + step; + const uint32_t step = 2; + uint32_t newLen = arr->GetLength() + step; if (newLen > CACHE_MAX_LEN) { profileTypeInfo_->Set(thread_, index, JSTaggedValue::Hole()); profileTypeInfo_->Set(thread_, index + 1, JSTaggedValue::Hole()); @@ -64,7 +64,7 @@ void ProfileTypeAccessor::AddHandlerWithoutKey(JSHandle dynclass, } auto factory = thread_->GetEcmaVM()->GetFactory(); JSHandle newArr = factory->NewTaggedArray(newLen); - array_size_t i = 0; + uint32_t i = 0; for (; i < arr->GetLength(); i += step) { newArr->Set(thread_, i, arr->Get(i)); newArr->Set(thread_, i + 1, arr->Get(i + 1)); @@ -78,7 +78,7 @@ void ProfileTypeAccessor::AddHandlerWithoutKey(JSHandle dynclass, // MONO to POLY auto factory = thread_->GetEcmaVM()->GetFactory(); JSHandle newArr = factory->NewTaggedArray(POLY_CASE_NUM); - array_size_t arrIndex = 0; + uint32_t arrIndex = 0; newArr->Set(thread_, arrIndex++, profileTypeInfo_->Get(index)); newArr->Set(thread_, arrIndex++, profileTypeInfo_->Get(index + 1)); newArr->Set(thread_, arrIndex++, GetWeakRef(dynclass.GetTaggedValue())); @@ -117,9 +117,9 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl JSTaggedValue patchValue = profileTypeInfo_->Get(index + 1); ASSERT(patchValue.IsTaggedArray()); JSHandle arr(thread_, patchValue); - const array_size_t step = 2; + const uint32_t step = 2; if (arr->GetLength() > step) { // POLY - array_size_t newLen = arr->GetLength() + step; + uint32_t newLen = arr->GetLength() + step; if (newLen > CACHE_MAX_LEN) { profileTypeInfo_->Set(thread_, index, JSTaggedValue::Hole()); profileTypeInfo_->Set(thread_, index + 1, JSTaggedValue::Hole()); @@ -129,7 +129,7 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl JSHandle newArr = factory->NewTaggedArray(newLen); newArr->Set(thread_, 0, GetWeakRef(dynclass.GetTaggedValue())); newArr->Set(thread_, 1, handler.GetTaggedValue()); - for (array_size_t i = 0; i < arr->GetLength(); i += step) { + for (uint32_t i = 0; i < arr->GetLength(); i += step) { newArr->Set(thread_, i + step, arr->Get(i)); newArr->Set(thread_, i + step + 1, arr->Get(i + 1)); } @@ -139,7 +139,7 @@ void ProfileTypeAccessor::AddHandlerWithKey(JSHandle key, JSHandl // MONO auto factory = thread_->GetEcmaVM()->GetFactory(); JSHandle newArr = factory->NewTaggedArray(POLY_CASE_NUM); - array_size_t arrIndex = 0; + uint32_t arrIndex = 0; newArr->Set(thread_, arrIndex++, arr->Get(0)); newArr->Set(thread_, arrIndex++, arr->Get(1)); newArr->Set(thread_, arrIndex++, GetWeakRef(dynclass.GetTaggedValue())); @@ -163,7 +163,7 @@ void ProfileTypeAccessor::AddGlobalHandlerKey(JSHandle key, JSHan } ASSERT(indexVal.IsTaggedArray()); JSHandle arr(thread_, indexVal); - array_size_t newLen = arr->GetLength() + step; + uint32_t newLen = arr->GetLength() + step; if (newLen > CACHE_MAX_LEN) { profileTypeInfo_->Set(thread_, index, JSTaggedValue::Hole()); return; @@ -173,7 +173,7 @@ void ProfileTypeAccessor::AddGlobalHandlerKey(JSHandle key, JSHan newArr->Set(thread_, 0, GetWeakRef(key.GetTaggedValue())); newArr->Set(thread_, 1, handler.GetTaggedValue()); - for (array_size_t i = 0; i < arr->GetLength(); i += step) { + for (uint32_t i = 0; i < arr->GetLength(); i += step) { newArr->Set(thread_, i + step, arr->Get(i)); newArr->Set(thread_, i + step + 1, arr->Get(i + 1)); } diff --git a/ecmascript/ic/profile_type_info.h b/ecmascript/ic/profile_type_info.h index 4e0b327af7..e40bcdfa6a 100644 --- a/ecmascript/ic/profile_type_info.h +++ b/ecmascript/ic/profile_type_info.h @@ -80,7 +80,7 @@ std::string ICKindToString(ICKind kind); class ProfileTypeInfo : public TaggedArray { public: - static const array_size_t MAX_FUNC_CACHE_INDEX = std::numeric_limits::max(); + static const uint32_t MAX_FUNC_CACHE_INDEX = std::numeric_limits::max(); static constexpr uint32_t INVALID_SLOT_INDEX = 0xFF; static ProfileTypeInfo *Cast(TaggedObject *object) diff --git a/ecmascript/ic/proto_change_details.cpp b/ecmascript/ic/proto_change_details.cpp index dc8d0b972c..de8a0c5458 100644 --- a/ecmascript/ic/proto_change_details.cpp +++ b/ecmascript/ic/proto_change_details.cpp @@ -18,12 +18,12 @@ namespace panda::ecmascript { JSHandle ChangeListener::Add(const JSThread *thread, const JSHandle &array, - const JSHandle &value, array_size_t *index) + const JSHandle &value, uint32_t *index) { JSTaggedValue weakValue; if (!array->Full()) { weakValue = JSTaggedValue(value.GetTaggedValue().CreateAndGetWeakRef()); - array_size_t arrayIndex = array->PushBack(thread, weakValue); + uint32_t arrayIndex = array->PushBack(thread, weakValue); if (arrayIndex != TaggedArray::MAX_ARRAY_INDEX) { if (index != nullptr) { *index = arrayIndex; @@ -33,7 +33,7 @@ JSHandle ChangeListener::Add(const JSThread *thread, const JSHan UNREACHABLE(); } // if exist hole, use it. - array_size_t holeIndex = CheckHole(array); + uint32_t holeIndex = CheckHole(array); if (holeIndex != TaggedArray::MAX_ARRAY_INDEX) { weakValue = JSTaggedValue(value.GetTaggedValue().CreateAndGetWeakRef()); array->Set(thread, holeIndex, weakValue); @@ -45,7 +45,7 @@ JSHandle ChangeListener::Add(const JSThread *thread, const JSHan // the vector is full and no hole exists. JSHandle newArray = WeakVector::Grow(thread, JSHandle(array), array->GetCapacity() + 1); weakValue = JSTaggedValue(value.GetTaggedValue().CreateAndGetWeakRef()); - array_size_t arrayIndex = newArray->PushBack(thread, weakValue); + uint32_t arrayIndex = newArray->PushBack(thread, weakValue); ASSERT(arrayIndex != TaggedArray::MAX_ARRAY_INDEX); if (index != nullptr) { *index = arrayIndex; @@ -53,9 +53,9 @@ JSHandle ChangeListener::Add(const JSThread *thread, const JSHan return JSHandle(newArray); } -array_size_t ChangeListener::CheckHole(const JSHandle &array) +uint32_t ChangeListener::CheckHole(const JSHandle &array) { - for (array_size_t i = 0; i < array->GetEnd(); i++) { + for (uint32_t i = 0; i < array->GetEnd(); i++) { JSTaggedValue value = array->Get(i); if (value == JSTaggedValue::Hole() || value == JSTaggedValue::Undefined()) { return i; @@ -64,7 +64,7 @@ array_size_t ChangeListener::CheckHole(const JSHandle &array) return TaggedArray::MAX_ARRAY_INDEX; } -JSTaggedValue ChangeListener::Get(array_size_t index) +JSTaggedValue ChangeListener::Get(uint32_t index) { JSTaggedValue value = WeakVector::Get(index); if (!value.IsHeapObject()) { diff --git a/ecmascript/ic/proto_change_details.h b/ecmascript/ic/proto_change_details.h index 8ddeb5fc36..91022c74fe 100644 --- a/ecmascript/ic/proto_change_details.h +++ b/ecmascript/ic/proto_change_details.h @@ -63,11 +63,11 @@ public: } static JSHandle Add(const JSThread *thread, const JSHandle &array, - const JSHandle &value, array_size_t *index); + const JSHandle &value, uint32_t *index); - static array_size_t CheckHole(const JSHandle &array); + static uint32_t CheckHole(const JSHandle &array); - JSTaggedValue Get(array_size_t index); + JSTaggedValue Get(uint32_t index); }; } // namespace ecmascript } // namespace panda diff --git a/ecmascript/internal_call_params.cpp b/ecmascript/internal_call_params.cpp index 268e1a8326..515fa0b222 100644 --- a/ecmascript/internal_call_params.cpp +++ b/ecmascript/internal_call_params.cpp @@ -22,14 +22,14 @@ void InternalCallParams::MakeArgv(const EcmaRuntimeCallInfo *info, uint32_t posi uint32_t length = mayLenth > 0 ? mayLenth : 0; if (LIKELY(length <= InternalCallParams::RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH)) { EnableFixedModeAndSetLength(length); - for (array_size_t index = 0; index < length; ++index) { + for (uint32_t index = 0; index < length; ++index) { SetFixedBuffer(index, info->GetCallArg(index + position)); } return; } EnableVariableModeAndSetLength(length); - for (array_size_t index = 0; index < length; ++index) { + for (uint32_t index = 0; index < length; ++index) { SetVariableBuffer(index, info->GetCallArg(index + position)); } } @@ -42,7 +42,7 @@ void InternalCallParams::MakeArgListWithHole(const TaggedArray *argv, uint32_t l ASSERT(length <= argv->GetLength()); if (LIKELY(length <= InternalCallParams::RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH)) { EnableFixedModeAndSetLength(length); - for (array_size_t index = 0; index < length; ++index) { + for (uint32_t index = 0; index < length; ++index) { auto value = argv->Get(index); SetFixedBuffer(index, value.IsHole() ? JSTaggedValue::Undefined() : value); } @@ -50,7 +50,7 @@ void InternalCallParams::MakeArgListWithHole(const TaggedArray *argv, uint32_t l } EnableVariableModeAndSetLength(length); - for (array_size_t index = 0; index < length; ++index) { + for (uint32_t index = 0; index < length; ++index) { auto value = argv->Get(index); SetVariableBuffer(index, value.IsHole() ? JSTaggedValue::Undefined() : value); } @@ -61,14 +61,14 @@ void InternalCallParams::MakeArgList(const TaggedArray *argv) uint32_t length = argv->GetLength(); if (LIKELY(length <= InternalCallParams::RESERVE_INTERNAL_CALL_PARAMS_FIXED_LENGTH)) { EnableFixedModeAndSetLength(length); - for (array_size_t index = 0; index < length; ++index) { + for (uint32_t index = 0; index < length; ++index) { SetFixedBuffer(index, argv->Get(index)); } return; } EnableVariableModeAndSetLength(length); - for (array_size_t index = 0; index < length; ++index) { + for (uint32_t index = 0; index < length; ++index) { SetVariableBuffer(index, argv->Get(index)); } } @@ -87,7 +87,7 @@ void InternalCallParams::MakeBoundArgv(const JSThread *thread, const JSHandleGet(index)); } return; @@ -97,11 +97,11 @@ void InternalCallParams::MakeBoundArgv(const JSThread *thread, const JSHandleGet(index)); } - for (array_size_t index = boundLength; index < length; ++index) { + for (uint32_t index = boundLength; index < length; ++index) { SetVariableBuffer(index, GetFixedBuffer(index - boundLength)); } return; diff --git a/ecmascript/interpreter/fast_runtime_stub-inl.h b/ecmascript/interpreter/fast_runtime_stub-inl.h index d3d40c49ea..eb5f911cdd 100644 --- a/ecmascript/interpreter/fast_runtime_stub-inl.h +++ b/ecmascript/interpreter/fast_runtime_stub-inl.h @@ -248,7 +248,7 @@ PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle } JSMutableHandle array(thread, objHandle->GetProperties()); - array_size_t length = array->GetLength(); + uint32_t length = array->GetLength(); if (length == 0) { length = JSObject::MIN_PROPERTIES_LENGTH; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -259,7 +259,7 @@ PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle if (!array->IsDictionaryMode()) { attr.SetIsInlinedProps(false); - array_size_t nonInlinedProps = objHandle->GetJSHClass()->GetNextNonInlinedPropsIndex(); + uint32_t nonInlinedProps = objHandle->GetJSHClass()->GetNextNonInlinedPropsIndex(); ASSERT(length >= nonInlinedProps); // if array is full, grow array or change to dictionary mode if (length == nonInlinedProps) { @@ -273,7 +273,7 @@ PropertyAttributes FastRuntimeStub::AddPropertyByName(JSThread *thread, JSHandle return attr; } // Grow properties array size - array_size_t capacity = JSObject::ComputePropertyCapacity(length); + uint32_t capacity = JSObject::ComputePropertyCapacity(length); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); array.Update(factory->CopyArray(array, length, capacity).GetTaggedValue()); objHandle->SetProperties(thread, array.GetTaggedValue()); diff --git a/ecmascript/interpreter/slow_runtime_helper.cpp b/ecmascript/interpreter/slow_runtime_helper.cpp index 1d9a9a8096..02363321bf 100644 --- a/ecmascript/interpreter/slow_runtime_helper.cpp +++ b/ecmascript/interpreter/slow_runtime_helper.cpp @@ -112,7 +112,7 @@ JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHa obj = JSHandle(factory->NewJSObjectByConstructor(ctor, newTgt)); } uint32_t preArgsSize = preArgs->IsUndefined() ? 0 : JSHandle::Cast(preArgs)->GetLength(); - const array_size_t size = preArgsSize + argsCount; + const uint32_t size = preArgsSize + argsCount; CVector values; values.reserve(size); @@ -131,17 +131,17 @@ JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHa // add preArgs when boundfunction is encountered if (preArgsSize > 0) { JSHandle tgaPreArgs = JSHandle::Cast(preArgs); - for (array_size_t i = 0; i < preArgsSize; ++i) { + for (uint32_t i = 0; i < preArgsSize; ++i) { JSTaggedValue value = tgaPreArgs->Get(i); values.emplace_back(value.GetRawData()); } - for (array_size_t i = 0; i < argsCount; ++i) { + for (uint32_t i = 0; i < argsCount; ++i) { JSTaggedValue value = frameHandler.GetVRegValue(baseArgLocation + i); values.emplace_back(value.GetRawData()); } params.argv = values.data(); } else { - for (array_size_t i = 0; i < argsCount; ++i) { + for (uint32_t i = 0; i < argsCount; ++i) { JSTaggedValue value = frameHandler.GetVRegValue(baseArgLocation + i); values.emplace_back(value.GetRawData()); } @@ -212,17 +212,17 @@ JSTaggedValue ConstructProxy(JSThread *thread, JSHandle ctor, JSHandle< // 8.Let argArray be CreateArrayFromList(argumentsList). uint32_t preArgsSize = preArgs->IsUndefined() ? 0 : JSHandle::Cast(preArgs)->GetLength(); - const array_size_t size = preArgsSize + argsCount; + const uint32_t size = preArgsSize + argsCount; JSHandle args = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(size); JSHandle tgaPreArgs = JSHandle::Cast(preArgs); if (preArgsSize > 0) { - for (array_size_t i = 0; i < preArgsSize; ++i) { + for (uint32_t i = 0; i < preArgsSize; ++i) { JSTaggedValue value = tgaPreArgs->Get(i); args->Set(thread, i, value); } } InterpretedFrameHandler frameHandler(thread); - for (array_size_t i = 0; i < argsCount; ++i) { + for (uint32_t i = 0; i < argsCount; ++i) { JSTaggedValue value = frameHandler.GetVRegValue(baseArgLocation + i); args->Set(thread, i + preArgsSize, value); } diff --git a/ecmascript/interpreter/slow_runtime_stub.cpp b/ecmascript/interpreter/slow_runtime_stub.cpp index ae575dc0e7..ac87931cb7 100644 --- a/ecmascript/interpreter/slow_runtime_stub.cpp +++ b/ecmascript/interpreter/slow_runtime_stub.cpp @@ -445,14 +445,14 @@ JSTaggedValue SlowRuntimeStub::CreateObjectWithExcludedKeys(JSThread *thread, ui ASSERT(objVal.IsJSObject()); JSHandle obj(thread, objVal); - array_size_t numExcludedKeys = 0; + uint32_t numExcludedKeys = 0; JSHandle excludedKeys = factory->NewTaggedArray(numKeys + 1); InterpretedFrameHandler frameHandler(thread); JSTaggedValue excludedKey = frameHandler.GetVRegValue(firstArgRegIdx); if (!excludedKey.IsUndefined()) { numExcludedKeys = numKeys + 1; excludedKeys->Set(thread, 0, excludedKey); - for (array_size_t i = 1; i < numExcludedKeys; i++) { + for (uint32_t i = 1; i < numExcludedKeys; i++) { excludedKey = frameHandler.GetVRegValue(firstArgRegIdx + i); excludedKeys->Set(thread, i, excludedKey); } @@ -672,7 +672,7 @@ JSTaggedValue SlowRuntimeStub::NewObjSpreadDyn(JSThread *thread, JSTaggedValue f uint32_t length = JSHandle::Cast(jsArray)->GetArrayLength(); JSHandle argsArray = factory->NewTaggedArray(length); - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { auto prop = JSTaggedValue::GetProperty(thread, jsArray, i).GetValue(); argsArray->Set(thread, i, prop); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1060,8 +1060,8 @@ JSTaggedValue SlowRuntimeStub::CopyDataProperties(JSThread *thread, JSTaggedValu RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSMutableHandle key(thread, JSTaggedValue::Undefined()); - array_size_t keysLen = keys->GetLength(); - for (array_size_t i = 0; i < keysLen; i++) { + uint32_t keysLen = keys->GetLength(); + for (uint32_t i = 0; i < keysLen; i++) { PropertyDescriptor desc(thread); key.Update(keys->Get(i)); bool success = JSTaggedValue::GetOwnProperty(thread, srcHandle, key, desc); @@ -1102,7 +1102,7 @@ JSTaggedValue SlowRuntimeStub::GetUnmapedArgs(JSThread *thread, JSTaggedType *sp ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle argumentsList = factory->NewTaggedArray(actualNumArgs); - for (array_size_t i = 0; i < actualNumArgs; ++i) { + for (uint32_t i = 0; i < actualNumArgs; ++i) { argumentsList->Set(thread, i, JSTaggedValue(sp[startIdx + i])); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } @@ -1495,9 +1495,9 @@ JSTaggedValue SlowRuntimeStub::StArraySpread(JSThread *thread, JSTaggedValue dst if (srcHandle->IsString()) { JSHandle srcString = JSTaggedValue::ToString(thread, srcHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - array_size_t dstLen = index.GetInt(); - array_size_t strLen = srcString->GetLength(); - for (array_size_t i = 0; i < strLen; i++) { + uint32_t dstLen = index.GetInt(); + uint32_t strLen = srcString->GetLength(); + for (uint32_t i = 0; i < strLen; i++) { uint16_t res = srcString->At(i); JSHandle strValue(factory->NewFromUtf16Literal(&res, 1)); JSTaggedValue::SetProperty(thread, dstHandle, dstLen + i, strValue, true); diff --git a/ecmascript/js_arraylist.cpp b/ecmascript/js_arraylist.cpp index 01094a91d7..02d2f54cae 100644 --- a/ecmascript/js_arraylist.cpp +++ b/ecmascript/js_arraylist.cpp @@ -22,7 +22,7 @@ namespace panda::ecmascript { void JSArrayList::Add(JSThread *thread, const JSHandle &arrayList, const JSHandle &value) { // GrowCapacity - array_size_t length = arrayList->GetLength().GetArrayLength(); + uint32_t length = arrayList->GetLength().GetArrayLength(); JSHandle elements = GrowCapacity(thread, arrayList, length + 1); ASSERT(!elements->IsDictionaryMode()); @@ -31,14 +31,14 @@ void JSArrayList::Add(JSThread *thread, const JSHandle &arrayList, } JSHandle JSArrayList::GrowCapacity(const JSThread *thread, const JSHandle &obj, - array_size_t capacity) + uint32_t capacity) { JSHandle oldElements(thread, obj->GetElements()); - array_size_t oldLength = oldElements->GetLength(); + uint32_t oldLength = oldElements->GetLength(); if (capacity < oldLength) { return oldElements; } - array_size_t newCapacity = ComputeCapacity(capacity); + uint32_t newCapacity = ComputeCapacity(capacity); JSHandle newElements = thread->GetEcmaVM()->GetFactory()->CopyArray(oldElements, oldLength, newCapacity); @@ -73,12 +73,12 @@ bool JSArrayList::Delete(JSThread *thread, const JSHandle &obj, con if (UNLIKELY(JSTaggedValue::ToElementIndex(key.GetTaggedValue(), &index))) { THROW_TYPE_ERROR_AND_RETURN(thread, "Can not delete a type other than number", false); } - array_size_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength().GetArrayLength(); if (index < 0 || index >= length) { THROW_RANGE_ERROR_AND_RETURN(thread, "Delete property index out-of-bounds", false); } TaggedArray *elements = TaggedArray::Cast(obj->GetElements().GetTaggedObject()); - for (array_size_t i = 0; i < length - 1; i++) { + for (uint32_t i = 0; i < length - 1; i++) { elements->Set(thread, i, elements->Get(i + 1)); } obj->SetLength(thread, JSTaggedValue(--length)); @@ -93,11 +93,11 @@ bool JSArrayList::Has(JSTaggedValue value) const JSHandle JSArrayList::OwnKeys(JSThread *thread, const JSHandle &obj) { - array_size_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength().GetArrayLength(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle keys = factory->NewTaggedArray(length); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { keys->Set(thread, i, JSTaggedValue(i)); } @@ -112,7 +112,7 @@ bool JSArrayList::GetOwnProperty(JSThread *thread, const JSHandle & THROW_TYPE_ERROR_AND_RETURN(thread, "Can not get property whose type is not number", false); } - array_size_t length = obj->GetLength().GetArrayLength(); + uint32_t length = obj->GetLength().GetArrayLength(); if (index < 0 || index >= length) { THROW_RANGE_ERROR_AND_RETURN(thread, "Get property index out-of-bounds", false); } diff --git a/ecmascript/js_arraylist.h b/ecmascript/js_arraylist.h index 3a48e7c2ff..8c2d46c0ec 100644 --- a/ecmascript/js_arraylist.h +++ b/ecmascript/js_arraylist.h @@ -51,13 +51,13 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LENGTH_OFFSET, SIZE) DECL_DUMP() private: - inline static array_size_t ComputeCapacity(array_size_t oldCapacity) + inline static uint32_t ComputeCapacity(uint32_t oldCapacity) { - array_size_t newCapacity = oldCapacity + (oldCapacity >> 1U); + uint32_t newCapacity = oldCapacity + (oldCapacity >> 1U); return newCapacity > DEFAULT_CAPACITY_LENGTH ? newCapacity : DEFAULT_CAPACITY_LENGTH; } static JSHandle GrowCapacity(const JSThread *thread, const JSHandle &obj, - array_size_t capacity); + uint32_t capacity); }; } // namespace panda::ecmascript diff --git a/ecmascript/js_date_time_format.cpp b/ecmascript/js_date_time_format.cpp index bcd2037859..6d98d01441 100644 --- a/ecmascript/js_date_time_format.cpp +++ b/ecmascript/js_date_time_format.cpp @@ -503,8 +503,8 @@ JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const J array->Set(thread, 2, globalConst->GetHandledMonthString()); // 2 means the third slot array->Set(thread, 3, globalConst->GetHandledDayString()); // 3 means the fourth slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); - array_size_t len = array->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = array->GetLength(); + for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); OperationResult operationResult = JSObject::GetProperty(thread, optionsResult, key); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); @@ -527,8 +527,8 @@ JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const J array->Set(thread, 3, globalConst->GetHandledSecondString()); // 3 means the third slot array->Set(thread, 4, globalConst->GetHandledFractionalSecondDigitsString()); // 4 means the fourth slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); - array_size_t len = array->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = array->GetLength(); + for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); OperationResult operationResult = JSObject::GetProperty(thread, optionsResult, key); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); @@ -570,8 +570,8 @@ JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const J array->Set(thread, 1, globalConst->GetHandledMonthString()); array->Set(thread, 2, globalConst->GetHandledDayString()); // 2 means the third slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); - array_size_t len = array->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = array->GetLength(); + for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); JSObject::CreateDataPropertyOrThrow(thread, optionsResult, key, globalConst->GetHandledNumericString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); @@ -587,8 +587,8 @@ JSHandle JSDateTimeFormat::ToDateTimeOptions(JSThread *thread, const J array->Set(thread, 1, globalConst->GetHandledMinuteString()); array->Set(thread, 2, globalConst->GetHandledSecondString()); // 2 means the third slot JSMutableHandle key(thread, JSTaggedValue::Undefined()); - array_size_t len = array->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = array->GetLength(); + for (uint32_t i = 0; i < len; i++) { key.Update(array->Get(thread, i)); JSObject::CreateDataPropertyOrThrow(thread, optionsResult, key, globalConst->GetHandledNumericString()); RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSObject, thread); diff --git a/ecmascript/js_for_in_iterator.cpp b/ecmascript/js_for_in_iterator.cpp index 5842f6934c..fccb34509d 100644 --- a/ecmascript/js_for_in_iterator.cpp +++ b/ecmascript/js_for_in_iterator.cpp @@ -193,8 +193,8 @@ void JSForInIterator::SlowGetAllEnumKeys(JSThread *thread, const JSHandle value(thread, JSTaggedValue::Undefined()); JSMutableHandle remaining(thread, it->GetRemainingKeys()); JSHandle arr = JSTaggedValue::GetOwnPropertyKeys(thread, object); - array_size_t len = arr->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = arr->GetLength(); + for (uint32_t i = 0; i < len; i++) { value.Update(arr->Get(i)); if (value->IsString()) { TaggedQueue *newQueue = TaggedQueue::Push(thread, remaining, value); @@ -232,8 +232,8 @@ std::pair JSForInIterator::NextInternal(JSThread *thread, c } JSHandle key(thread, r); bool has_same = false; - array_size_t len = visited->Size(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = visited->Size(); + for (uint32_t i = 0; i < len; i++) { if (JSTaggedValue::SameValue(r, visited->Get(i))) { has_same = true; break; diff --git a/ecmascript/js_hclass.cpp b/ecmascript/js_hclass.cpp index b3ef03ea2c..e32641a3ca 100644 --- a/ecmascript/js_hclass.cpp +++ b/ecmascript/js_hclass.cpp @@ -381,7 +381,7 @@ void JSHClass::RegisterOnProtoChain(const JSThread *thread, const JSHandle(thread, listeners); } - array_size_t registerIndex = 0; + uint32_t registerIndex = 0; JSHandle newListeners = ChangeListener::Add(thread, listenersHandle, user, ®isterIndex); userDetails->SetRegisterIndex(thread, JSTaggedValue(registerIndex)); protoDetails->SetChangeListener(thread, newListeners.GetTaggedValue()); @@ -402,7 +402,7 @@ bool JSHClass::UnregisterOnProtoChain(const JSThread *thread, const JSHandle currentDetails = GetProtoChangeDetails(thread, jshclass); - array_size_t index = currentDetails->GetRegisterIndex().GetArrayLength(); + uint32_t index = currentDetails->GetRegisterIndex().GetArrayLength(); if (JSTaggedValue(index) == JSTaggedValue(ProtoChangeDetails::UNREGISTERED)) { return false; } @@ -457,7 +457,7 @@ void JSHClass::NoticeThroughChain(const JSThread *thread, const JSHandleGetEnd(); i++) { + for (uint32_t i = 0; i < listeners->GetEnd(); i++) { JSTaggedValue temp = listeners->Get(i); if (temp.IsJSHClass()) { NoticeThroughChain(thread, JSHandle(thread, listeners->Get(i).GetTaggedObject())); diff --git a/ecmascript/js_locale.cpp b/ecmascript/js_locale.cpp index 313c911c91..c34157f4e5 100644 --- a/ecmascript/js_locale.cpp +++ b/ecmascript/js_locale.cpp @@ -232,7 +232,7 @@ JSHandle JSLocale::CanonicalizeHelper(JSThread *thread, const JSHan // 7. Repeat, while k < len JSMutableHandle pk(thread, JSTaggedValue::Undefined()); JSMutableHandle tag(thread, JSTaggedValue::Undefined()); - array_size_t index = 0; + uint32_t index = 0; JSHandle objTagged = JSHandle::Cast(obj); for (uint32_t k = 0; k < requestedLocalesLen; k++) { // a. Let Pk be ToString(k). @@ -271,8 +271,8 @@ JSHandle JSLocale::CanonicalizeHelper(JSThread *thread, const JSHan } // vii. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen. bool isExist = false; - array_size_t len = seen->GetLength(); - for (array_size_t i = 0; i < len; i++) { + uint32_t len = seen->GetLength(); + for (uint32_t i = 0; i < len; i++) { if (JSTaggedValue::SameValue(seen->Get(thread, i), tag.GetTaggedValue())) { isExist = true; } @@ -297,11 +297,11 @@ std::string JSLocale::BestAvailableLocale(JSThread *thread, const JSHandleGetLength(); + uint32_t length = availableLocales->GetLength(); JSMutableHandle item(thread, JSTaggedValue::Undefined()); while (true) { // a. If availableLocales contains an element equal to candidate, return candidate. - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { item.Update(availableLocales->Get(thread, i)); std::string itemStr = ConvertToStdString(item); if (itemStr == localeCandidate) { @@ -331,9 +331,9 @@ JSHandle JSLocale::LookupMatcher(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); // 1. Let result be a new Record. // 2. For each element locale of requestedLocales in List order, do - array_size_t length = requestedLocales->GetLength(); + uint32_t length = requestedLocales->GetLength(); JSMutableHandle locale(thread, JSTaggedValue::Undefined()); - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { locale.Update(requestedLocales->Get(thread, i)); // 2. a. Let noExtensionsLocale be the String value that is locale // with all Unicode locale extension sequences removed. @@ -366,7 +366,7 @@ JSHandle JSLocale::LookupMatcher(JSThread *thread, const JSHandleNewFromStdString(result.locale); } -icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, array_size_t *availableLength, UErrorCode *status, +icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, uint32_t *availableLength, UErrorCode *status, const JSHandle &availableLocales) { std::string locale = JSLocale::ConvertToStdString(JSLocale::DefaultLocale(thread)); @@ -374,7 +374,7 @@ icu::LocaleMatcher BuildLocaleMatcher(JSThread *thread, array_size_t *availableL ASSERT_PRINT(U_SUCCESS(*status), "icu::Locale::forLanguageTag failed"); icu::LocaleMatcher::Builder builder; builder.setDefaultLocale(&defaultLocale); - array_size_t length = availableLocales->GetLength(); + uint32_t length = availableLocales->GetLength(); JSMutableHandle item(thread, JSTaggedValue::Undefined()); for (*availableLength = 0; *availableLength < length; ++(*availableLength)) { @@ -397,11 +397,11 @@ JSHandle JSLocale::BestFitMatcher(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); UErrorCode status = U_ZERO_ERROR; - array_size_t availableLength = availableLocales->GetLength(); + uint32_t availableLength = availableLocales->GetLength(); icu::LocaleMatcher matcher = BuildLocaleMatcher(thread, &availableLength, &status, availableLocales); ASSERT(U_SUCCESS(status)); - array_size_t requestedLocalesLength = requestedLocales->GetLength(); + uint32_t requestedLocalesLength = requestedLocales->GetLength(); JSIntlIterator iter(requestedLocales, requestedLocalesLength); auto bestFit = matcher.getBestMatch(iter, status)->toLanguageTag(status); @@ -409,7 +409,7 @@ JSHandle JSLocale::BestFitMatcher(JSThread *thread, const JSHandle(thread, requestedLocales->Get(thread, i)); } @@ -423,7 +423,7 @@ JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const J { uint32_t index = 0; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t length = requestedLocales->GetLength(); + uint32_t length = requestedLocales->GetLength(); // 1. Let subset be a new empty List. JSHandle subset = factory->NewTaggedArray(length); JSMutableHandle item(thread, JSTaggedValue::Undefined()); @@ -432,7 +432,7 @@ JSHandle JSLocale::LookupSupportedLocales(JSThread *thread, const J // removed. // b. Let availableLocale be BestAvailableLocale(availableLocales, noExtensionsLocale). // c. If availableLocale is not undefined, append locale to the end of subset. - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { item.Update(requestedLocales->Get(thread, i)); ParsedLocale foundationResult = HandleLocale(item); std::string availableLocale = BestAvailableLocale(thread, availableLocales, foundationResult.base); @@ -449,8 +449,8 @@ JSHandle JSLocale::BestFitSupportedLocales(JSThread *thread, const const JSHandle &requestedLocales) { UErrorCode status = U_ZERO_ERROR; - array_size_t requestLength = requestedLocales->GetLength(); - array_size_t availableLength = availableLocales->GetLength(); + uint32_t requestLength = requestedLocales->GetLength(); + uint32_t availableLength = availableLocales->GetLength(); icu::LocaleMatcher matcher = BuildLocaleMatcher(thread, &availableLength, &status, availableLocales); ASSERT(U_SUCCESS(status)); @@ -460,7 +460,7 @@ JSHandle JSLocale::BestFitSupportedLocales(JSThread *thread, const uint32_t index = 0; JSMutableHandle locale(thread, JSTaggedValue::Undefined()); - for (array_size_t i = 0; i < requestLength; ++i) { + for (uint32_t i = 0; i < requestLength; ++i) { locale.Update(requestedLocales->Get(thread, i)); if (EcmaString::StringsAreEqual(*locale, *defaultLocale)) { result->Set(thread, index++, locale.GetTaggedValue()); diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index 69f08de780..e50929e77d 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -77,9 +77,9 @@ constexpr uint8_t INTL_INDEX_EIGHT = 8; class JSIntlIterator : public icu::Locale::Iterator { public: - JSIntlIterator(const JSHandle &data, array_size_t length) : length_(length), curIdx_(0) + JSIntlIterator(const JSHandle &data, uint32_t length) : length_(length), curIdx_(0) { - for (array_size_t idx = 0; idx < length; idx++) { + for (uint32_t idx = 0; idx < length; idx++) { std::string str = base::StringHelper::ToStdString(EcmaString::Cast(data->Get(idx).GetTaggedObject())); data_.emplace_back(str); } @@ -112,8 +112,8 @@ public: private: std::vector data_{}; - array_size_t length_{0}; - array_size_t curIdx_{0}; + uint32_t length_{0}; + uint32_t curIdx_{0}; icu::Locale locale_{}; }; diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index 5ea96e3b8d..5a8fa214cd 100644 --- a/ecmascript/js_object.cpp +++ b/ecmascript/js_object.cpp @@ -72,7 +72,7 @@ JSHandle JSObject::GrowElementsCapacity(const JSThread *thread, con uint32_t newCapacity = ComputeElementCapacity(capacity); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle oldElements(thread, obj->GetElements()); - array_size_t oldLength = oldElements->GetLength(); + uint32_t oldLength = oldElements->GetLength(); JSHandle newElements = factory->CopyArray(oldElements, oldLength, newCapacity); obj->SetElements(thread, newElements); @@ -136,7 +136,7 @@ JSHandle JSObject::TransitionToDictionary(const JSThread *thread // trim in-obj properties space if (numberInlinedProps > 0) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t newSize = receiver->GetClass()->GetObjectSize(); + uint32_t newSize = receiver->GetClass()->GetObjectSize(); size_t trimBytes = numberInlinedProps * JSTaggedValue::TaggedTypeSize(); factory->FillFreeObject(ToUintPtr(*receiver) + newSize, trimBytes, RemoveSlots::YES); } @@ -294,7 +294,7 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, } JSHandle JSObject::GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - uint32_t numOfKeys, array_size_t *keys) + uint32_t numOfKeys, uint32_t *keys) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); if (obj->IsJSGlobalObject()) { @@ -376,7 +376,7 @@ void JSObject::GetALLElementKeysIntoVector(const JSThread *thread, const JSHandl } JSHandle JSObject::GetEnumElementKeys(JSThread *thread, const JSHandle &obj, int offset, - uint32_t numOfElements, array_size_t *keys) + uint32_t numOfElements, uint32_t *keys) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle elementArray = factory->NewTaggedArray(numOfElements); @@ -1195,13 +1195,13 @@ bool JSObject::SetIntegrityLevel(JSThread *thread, const JSHandle &obj descNoConfWrite.SetConfigurable(false); if (level == IntegrityLevel::SEALED) { - array_size_t length = jshandleKeys->GetLength(); + uint32_t length = jshandleKeys->GetLength(); if (length == 0) { return true; } auto key = jshandleKeys->Get(0); JSMutableHandle handleKey(thread, key); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); handleKey.Update(taggedKey); [[maybe_unused]] bool success = @@ -1209,13 +1209,13 @@ bool JSObject::SetIntegrityLevel(JSThread *thread, const JSHandle &obj RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); } } else { - array_size_t length = jshandleKeys->GetLength(); + uint32_t length = jshandleKeys->GetLength(); if (length == 0) { return true; } auto key = jshandleKeys->Get(0); JSMutableHandle handleKey(thread, key); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); handleKey.Update(taggedKey); PropertyDescriptor currentDesc(thread); @@ -1247,13 +1247,13 @@ bool JSObject::TestIntegrityLevel(JSThread *thread, const JSHandle &ob JSHandle jshandleKeys = GetOwnPropertyKeys(thread, obj); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - array_size_t length = jshandleKeys->GetLength(); + uint32_t length = jshandleKeys->GetLength(); if (length == 0) { return true; } auto key = jshandleKeys->Get(0); JSMutableHandle handleKey(thread, key); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { auto taggedKey = JSTaggedValue(jshandleKeys->Get(i)); handleKey.Update(taggedKey); PropertyDescriptor currentDesc(thread); @@ -1278,7 +1278,7 @@ JSHandle JSObject::EnumerableOwnNames(JSThread *thread, const JSHan ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle keys; JSHandle tagObj(obj); - array_size_t copyLength = 0; + uint32_t copyLength = 0; // fast mode if (tagObj->IsJSObject() && !tagObj->IsTypedArray()) { uint32_t numOfKeys = obj->GetNumberOfKeys(); @@ -1307,10 +1307,10 @@ JSHandle JSObject::EnumerableOwnNames(JSThread *thread, const JSHan keys = JSTaggedValue::GetOwnPropertyKeys(thread, tagObj); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); - array_size_t length = keys->GetLength(); + uint32_t length = keys->GetLength(); JSHandle names = factory->NewTaggedArray(length); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { JSTaggedValue key(keys->Get(i)); if (key.IsString()) { PropertyDescriptor desc(thread); @@ -1338,7 +1338,7 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); // 3. Let properties be a new empty List. - array_size_t length = ownKeys->GetLength(); + uint32_t length = ownKeys->GetLength(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle properties = factory->NewTaggedArray(length); @@ -1355,8 +1355,8 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con // ii. Let entry be ! CreateArrayFromList(« key, value »). // iii. Append entry to properties. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - array_size_t index = 0; - for (array_size_t i = 0; i < length; i++) { + uint32_t index = 0; + for (uint32_t i = 0; i < length; i++) { key.Update(ownKeys->Get(thread, i)); if (key->IsString()) { PropertyDescriptor desc(thread); diff --git a/ecmascript/js_object.h b/ecmascript/js_object.h index baa92b6244..d143f1a491 100644 --- a/ecmascript/js_object.h +++ b/ecmascript/js_object.h @@ -352,13 +352,9 @@ public: int32_t GetNativePointerFieldCount() const; void SetNativePointerFieldCount(int32_t count); - void VisitRangeSlot(const EcmaObjectRangeVisitor &visitor) const - { - TaggedObject *object = const_cast(reinterpret_cast(this)); - visitor(object, ObjectSlot(ToUintPtr(this) + HASH_OFFSET), ObjectSlot(ToUintPtr(this) + SIZE)); - } + DECL_VISIT_OBJECT(HASH_OFFSET, SIZE); - void VisitObjects([[maybe_unused]] const EcmaObjectRangeVisitor &visitor) const + void VisitObjects(const EcmaObjectRangeVisitor &visitor) { // no field in this object VisitRangeSlot(visitor); @@ -572,9 +568,9 @@ public: uint32_t GetNumberOfElements(); static JSHandle GetEnumElementKeys(JSThread *thread, const JSHandle &obj, int offset, - uint32_t numOfElements, array_size_t *keys); + uint32_t numOfElements, uint32_t *keys); static JSHandle GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - uint32_t numOfKeys, array_size_t *keys); + uint32_t numOfKeys, uint32_t *keys); static void AddAccessor(JSThread *thread, const JSHandle &obj, const JSHandle &key, const JSHandle &value, PropertyAttributes attr); diff --git a/ecmascript/js_proxy.cpp b/ecmascript/js_proxy.cpp index 2fb989a09d..ef08bbe860 100644 --- a/ecmascript/js_proxy.cpp +++ b/ecmascript/js_proxy.cpp @@ -744,13 +744,13 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // i.Append key as an element of targetNonconfigurableKeys. // d.Else, // i.Append key as an element of targetConfigurableKeys. - array_size_t length = targetKeys->GetLength(); + uint32_t length = targetKeys->GetLength(); JSHandle tgtCfigKeys = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); JSHandle tgtNoCfigKeys = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length); - array_size_t cfigLength = 0; - array_size_t noCfigLength = 0; - for (array_size_t i = 0; i < length; i++) { + uint32_t cfigLength = 0; + uint32_t noCfigLength = 0; + for (uint32_t i = 0; i < length; i++) { JSHandle targetKey(thread, targetKeys->Get(i)); ASSERT(targetKey->IsStringOrSymbol()); @@ -776,13 +776,13 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // 20.Let uncheckedResultKeys be a new List which is a copy of trapResult. JSHandle uncheckFesKeys = thread->GetEcmaVM()->GetFactory()->CopyArray(trapRes, trapRes->GetLength(), trapRes->GetLength()); - array_size_t uncheckLength = uncheckFesKeys->GetLength(); + uint32_t uncheckLength = uncheckFesKeys->GetLength(); // 21.Repeat, for each key that is an element of targetNonconfigurableKeys, // a.If key is not an element of uncheckedResultKeys, throw a TypeError exception. // b.Remove key from uncheckedResultKeys - for (array_size_t i = 0; i < noCfigLength; i++) { - array_size_t idx = uncheckFesKeys->GetIdx(tgtNoCfigKeys->Get(i)); + for (uint32_t i = 0; i < noCfigLength; i++) { + uint32_t idx = uncheckFesKeys->GetIdx(tgtNoCfigKeys->Get(i)); if (idx == TaggedArray::MAX_ARRAY_INDEX) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: key is not an element of uncheckedResultKeys", JSHandle(thread, JSTaggedValue::Exception())); @@ -799,8 +799,8 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // 23.Repeat, for each key that is an element of targetConfigurableKeys, // a.If key is not an element of uncheckedResultKeys, throw a TypeError exception. // b.Remove key from uncheckedResultKeys - for (array_size_t i = 0; i < cfigLength; i++) { - array_size_t idx = uncheckFesKeys->GetIdx(tgtCfigKeys->Get(i)); + for (uint32_t i = 0; i < cfigLength; i++) { + uint32_t idx = uncheckFesKeys->GetIdx(tgtCfigKeys->Get(i)); if (idx == TaggedArray::MAX_ARRAY_INDEX) { THROW_TYPE_ERROR_AND_RETURN(thread, "OwnPropertyKeys: key is not an element of uncheckedResultKeys", JSHandle(thread, JSTaggedValue::Exception())); @@ -846,7 +846,7 @@ JSTaggedValue JSProxy::CallInternal(JSThread *thread, const JSHandle &p // 8.Let argArray be CreateArrayFromList(argumentsList). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle taggedArray = factory->NewTaggedArray(argc); - for (array_size_t index = 0; index < argc; ++index) { + for (uint32_t index = 0; index < argc; ++index) { taggedArray->Set(thread, index, JSTaggedValue(argv[index])); } JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); @@ -886,7 +886,7 @@ JSTaggedValue JSProxy::ConstructInternal(JSThread *thread, const JSHandleGetEcmaVM()->GetFactory(); JSHandle taggedArray = factory->NewTaggedArray(argc); - for (array_size_t index = 0; index < argc; ++index) { + for (uint32_t index = 0; index < argc; ++index) { taggedArray->Set(thread, index, JSTaggedValue(argv[index])); } JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); diff --git a/ecmascript/js_stable_array.cpp b/ecmascript/js_stable_array.cpp index fb7723a052..23cdff3020 100644 --- a/ecmascript/js_stable_array.cpp +++ b/ecmascript/js_stable_array.cpp @@ -28,16 +28,16 @@ namespace panda::ecmascript { JSTaggedValue JSStableArray::Push(JSHandle receiver, EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); uint32_t oldLength = receiver->GetArrayLength(); - array_size_t newLength = argc + oldLength; + uint32_t newLength = argc + oldLength; TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); if (newLength > elements->GetLength()) { elements = *JSObject::GrowElementsCapacity(thread, JSHandle::Cast(receiver), newLength); } - for (array_size_t k = 0; k < argc; k++) { + for (uint32_t k = 0; k < argc; k++) { JSHandle value = argv->GetCallArg(k); elements->Set(thread, oldLength + k, value.GetTaggedValue()); } @@ -56,8 +56,8 @@ JSTaggedValue JSStableArray::Pop(JSHandle receiver, EcmaRuntimeCallInfo } TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); - array_size_t capacity = elements->GetLength(); - array_size_t index = length - 1; + uint32_t capacity = elements->GetLength(); + uint32_t index = length - 1; auto result = elements->Get(index); if (TaggedArray::ShouldTrim(thread, capacity, index)) { elements->Trim(thread, index); @@ -73,7 +73,7 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallI { JSThread *thread = argv->GetThread(); uint32_t len = receiver->GetArrayLength(); - array_size_t argc = argv->GetArgsNumber(); + uint32_t argc = argv->GetArgsNumber(); JSHandle thisObjHandle(receiver); JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(actualDeleteCount)); @@ -90,7 +90,7 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallI destElements = *JSObject::GrowElementsCapacity(thread, newArrayHandle, actualDeleteCount); } - for (array_size_t idx = 0; idx < actualDeleteCount; idx++) { + for (uint32_t idx = 0; idx < actualDeleteCount; idx++) { destElements->Set(thread, idx, srcElementsHandle->Get(start + idx)); } JSHandle::Cast(newArrayHandle)->SetArrayLength(thread, actualDeleteCount); @@ -122,10 +122,10 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallI RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - array_size_t oldCapacity = srcElementsHandle->GetLength(); - array_size_t newCapacity = len - actualDeleteCount + insertCount; + uint32_t oldCapacity = srcElementsHandle->GetLength(); + uint32_t newCapacity = len - actualDeleteCount + insertCount; if (insertCount < actualDeleteCount) { - for (array_size_t idx = start; idx < len - actualDeleteCount; idx++) { + for (uint32_t idx = start; idx < len - actualDeleteCount; idx++) { auto element = srcElementsHandle->Get(idx + actualDeleteCount); element = element.IsHole() ? JSTaggedValue::Undefined() : element; srcElementsHandle->Set(thread, idx + insertCount, element); @@ -134,7 +134,7 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallI if (TaggedArray::ShouldTrim(thread, oldCapacity, newCapacity)) { srcElementsHandle->Trim(thread, newCapacity); } else { - for (array_size_t idx = newCapacity; idx < len; idx++) { + for (uint32_t idx = newCapacity; idx < len; idx++) { srcElementsHandle->Set(thread, idx, JSTaggedValue::Hole()); } } @@ -142,14 +142,14 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallI if (newCapacity > oldCapacity) { srcElementsHandle = JSObject::GrowElementsCapacity(thread, thisObjHandle, newCapacity); } - for (array_size_t idx = len - actualDeleteCount; idx > start; idx--) { + for (uint32_t idx = len - actualDeleteCount; idx > start; idx--) { auto element = srcElementsHandle->Get(idx + actualDeleteCount - 1); element = element.IsHole() ? JSTaggedValue::Undefined() : element; srcElementsHandle->Set(thread, idx + insertCount - 1, element); } } - for (array_size_t i = 2, idx = start; i < argc; i++, idx++) { + for (uint32_t i = 2, idx = start; i < argc; i++, idx++) { srcElementsHandle->Set(thread, idx, argv->GetCallArg(i)); } @@ -170,7 +170,7 @@ JSTaggedValue JSStableArray::Shift(JSHandle receiver, EcmaRuntimeCallIn TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); auto result = elements->Get(0); - for (array_size_t k = 1; k < length; k++) { + for (uint32_t k = 1; k < length; k++) { auto kValue = elements->Get(k); if (kValue.IsHole()) { elements->Set(thread, k - 1, JSTaggedValue::Undefined()); @@ -178,8 +178,8 @@ JSTaggedValue JSStableArray::Shift(JSHandle receiver, EcmaRuntimeCallIn elements->Set(thread, k - 1, kValue); } } - array_size_t capacity = elements->GetLength(); - array_size_t index = length - 1; + uint32_t capacity = elements->GetLength(); + uint32_t index = length - 1; if (TaggedArray::ShouldTrim(thread, capacity, index)) { elements->Trim(thread, index); } else { @@ -225,7 +225,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInf CVector> vec; JSMutableHandle elementHandle(thread, JSTaggedValue::Undefined()); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - for (array_size_t k = 0; k < length; k++) { + for (uint32_t k = 0; k < length; k++) { JSTaggedValue element = elements->Get(k); if (!element.IsUndefinedOrNull() && !element.IsHole()) { if (!element.IsString()) { @@ -248,7 +248,7 @@ JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInf auto newString = EcmaString::AllocStringObject(allocateLength, isOneByte, thread->GetEcmaVM()); int current = 0; DISALLOW_GARBAGE_COLLECTION; - for (array_size_t k = 0; k < length; k++) { + for (uint32_t k = 0; k < length; k++) { if (k > 0) { if (sep >= 0) { newString->WriteData(static_cast(sep), current); diff --git a/ecmascript/js_tagged_value-inl.h b/ecmascript/js_tagged_value-inl.h index 3e02edef54..a1137e7780 100644 --- a/ecmascript/js_tagged_value-inl.h +++ b/ecmascript/js_tagged_value-inl.h @@ -883,15 +883,15 @@ inline bool JSTaggedValue::ToArrayLength(JSThread *thread, const JSHandle(GetInt()); + return static_cast(GetInt()); } if (IsDouble()) { ASSERT(GetDouble() <= TaggedArray::MAX_ARRAY_INDEX); - return static_cast(GetDouble()); + return static_cast(GetDouble()); } UNREACHABLE(); } diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index f26f15f48a..f64bbadcc7 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -163,7 +163,7 @@ public: static bool ToArrayLength(JSThread *thread, const JSHandle &tagged, uint32_t *output); static bool ToElementIndex(JSTaggedValue key, uint32_t *output); static bool StringToElementIndex(JSTaggedValue key, uint32_t *output); - array_size_t GetArrayLength() const; + uint32_t GetArrayLength() const; // ecma6 7.2 Testing and Comparison Operations bool IsCallable() const; diff --git a/ecmascript/js_typed_array.cpp b/ecmascript/js_typed_array.cpp index 7448257757..14edaec997 100644 --- a/ecmascript/js_typed_array.cpp +++ b/ecmascript/js_typed_array.cpp @@ -256,16 +256,16 @@ JSHandle JSTypedArray::OwnPropertyKeys(JSThread *thread, const JSHa // 3. Let len be the value of O’s [[ArrayLength]] internal slot. JSHandle arrayObj(typedarray); JSHandle objKeys = JSObject::GetOwnPropertyKeys(thread, arrayObj); - array_size_t objKeysLen = objKeys->GetLength(); - array_size_t bufferKeysLen = TypedArrayHelper::GetArrayLength(thread, arrayObj); - array_size_t length = objKeysLen + bufferKeysLen; + uint32_t objKeysLen = objKeys->GetLength(); + uint32_t bufferKeysLen = TypedArrayHelper::GetArrayLength(thread, arrayObj); + uint32_t length = objKeysLen + bufferKeysLen; JSHandle nameList = factory->NewTaggedArray(length); // 4. For each integer i starting with 0 such that i < len, in ascending order, // a. Add ToString(i) as the last element of keys. - array_size_t copyLength = 0; + uint32_t copyLength = 0; JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); - for (array_size_t k = 0; k < bufferKeysLen; k++) { + for (uint32_t k = 0; k < bufferKeysLen; k++) { tKey.Update(JSTaggedValue(k)); JSHandle sKey(JSTaggedValue::ToString(thread, tKey)); nameList->Set(thread, copyLength, sKey.GetTaggedValue()); @@ -275,7 +275,7 @@ JSHandle JSTypedArray::OwnPropertyKeys(JSThread *thread, const JSHa // 5. For each own property key P of O such that Type(P) is String and P is not an integer index, in // property creation order // a. Add P as the last element of keys. - for (array_size_t i = 0; i < objKeysLen; i++) { + for (uint32_t i = 0; i < objKeysLen; i++) { JSTaggedValue key = objKeys->Get(i); if (JSTaggedValue(key).IsString()) { nameList->Set(thread, copyLength, key); @@ -285,7 +285,7 @@ JSHandle JSTypedArray::OwnPropertyKeys(JSThread *thread, const JSHa // 6. For each own property key P of O such that Type(P) is Symbol, in property creation order // a. Add P as the last element of keys. - for (array_size_t i = 0; i < objKeysLen; i++) { + for (uint32_t i = 0; i < objKeysLen; i++) { JSTaggedValue key = objKeys->Get(i); if (JSTaggedValue(key).IsSymbol()) { nameList->Set(thread, copyLength, key); diff --git a/ecmascript/layout_info-inl.h b/ecmascript/layout_info-inl.h index 954c489777..065eda9da5 100644 --- a/ecmascript/layout_info-inl.h +++ b/ecmascript/layout_info-inl.h @@ -36,12 +36,12 @@ inline void LayoutInfo::SetNumberOfElements(const JSThread *thread, int properti return TaggedArray::Set(thread, NUMBER_OF_PROPERTIES_INDEX, JSTaggedValue(properties)); } -inline array_size_t LayoutInfo::GetKeyIndex(int index) const +inline uint32_t LayoutInfo::GetKeyIndex(int index) const { return ELEMENTS_START_INDEX + (static_cast(index) << 1U); } -inline array_size_t LayoutInfo::GetAttrIndex(int index) const +inline uint32_t LayoutInfo::GetAttrIndex(int index) const { return ELEMENTS_START_INDEX + (static_cast(index) << 1U) + 1; } @@ -49,14 +49,14 @@ inline array_size_t LayoutInfo::GetAttrIndex(int index) const inline void LayoutInfo::SetPropertyInit(const JSThread *thread, int index, const JSTaggedValue &key, const PropertyAttributes &attr) { - array_size_t fixed_idx = GetKeyIndex(index); + uint32_t fixed_idx = GetKeyIndex(index); TaggedArray::Set(thread, fixed_idx, key); TaggedArray::Set(thread, fixed_idx + 1, attr.GetNormalTagged()); } inline void LayoutInfo::SetNormalAttr(const JSThread *thread, int index, const PropertyAttributes &attr) { - array_size_t fixed_idx = GetAttrIndex(index); + uint32_t fixed_idx = GetAttrIndex(index); PropertyAttributes oldAttr(TaggedArray::Get(fixed_idx)); oldAttr.SetNormalAttr(attr.GetNormalAttr()); TaggedArray::Set(thread, fixed_idx, oldAttr.GetTaggedValue()); @@ -64,30 +64,30 @@ inline void LayoutInfo::SetNormalAttr(const JSThread *thread, int index, const P inline JSTaggedValue LayoutInfo::GetKey(int index) const { - array_size_t fixed_idx = GetKeyIndex(index); + uint32_t fixed_idx = GetKeyIndex(index); return TaggedArray::Get(fixed_idx); } inline PropertyAttributes LayoutInfo::GetAttr(int index) const { - array_size_t fixed_idx = GetAttrIndex(index); + uint32_t fixed_idx = GetAttrIndex(index); return PropertyAttributes(TaggedArray::Get(fixed_idx)); } inline JSTaggedValue LayoutInfo::GetSortedKey(int index) const { - array_size_t fixed_idx = GetSortedIndex(index); + uint32_t fixed_idx = GetSortedIndex(index); return GetKey(fixed_idx); } -inline array_size_t LayoutInfo::GetSortedIndex(int index) const +inline uint32_t LayoutInfo::GetSortedIndex(int index) const { return GetAttr(index).GetSortedIndex(); } inline void LayoutInfo::SetSortedIndex(const JSThread *thread, int index, int sortedIndex) { - array_size_t fixed_idx = GetAttrIndex(index); + uint32_t fixed_idx = GetAttrIndex(index); PropertyAttributes attr(TaggedArray::Get(fixed_idx)); attr.SetSortedIndex(sortedIndex); TaggedArray::Set(thread, fixed_idx, attr.GetTaggedValue()); diff --git a/ecmascript/layout_info.cpp b/ecmascript/layout_info.cpp index f3d5bf8ea1..03f45f010c 100644 --- a/ecmascript/layout_info.cpp +++ b/ecmascript/layout_info.cpp @@ -83,7 +83,7 @@ void LayoutInfo::GetAllKeys(const JSThread *thread, int end, std::vector(keyArray->GetLength()), @@ -102,7 +102,7 @@ void LayoutInfo::GetAllEnumKeys(const JSThread *thread, int end, int offset, Tag } void LayoutInfo::GetAllNames(const JSThread *thread, int end, const JSHandle &keyArray, - array_size_t *length) + uint32_t *length) { DISALLOW_GARBAGE_COLLECTION; int arrayIndex = 0; diff --git a/ecmascript/layout_info.h b/ecmascript/layout_info.h index 9753ff8804..5fdb17b7b4 100644 --- a/ecmascript/layout_info.h +++ b/ecmascript/layout_info.h @@ -42,37 +42,37 @@ public: int GetPropertiesCapacity() const; int NumberOfElements() const; void SetNumberOfElements(const JSThread *thread, int properties); - array_size_t GetKeyIndex(int index) const; - array_size_t GetAttrIndex(int index) const; + uint32_t GetKeyIndex(int index) const; + uint32_t GetAttrIndex(int index) const; void SetPropertyInit(const JSThread *thread, int index, const JSTaggedValue &key, const PropertyAttributes &attr); void SetKey(const JSThread *thread, int index, const JSTaggedValue &key); void SetNormalAttr(const JSThread *thread, int index, const PropertyAttributes &attr); JSTaggedValue GetKey(int index) const; PropertyAttributes GetAttr(int index) const; JSTaggedValue GetSortedKey(int index) const; - array_size_t GetSortedIndex(int index) const; + uint32_t GetSortedIndex(int index) const; void SetSortedIndex(const JSThread *thread, int index, int sortedIndex); void AddKey(const JSThread *thread, int index, const JSTaggedValue &key, const PropertyAttributes &attr); - inline array_size_t GetLength() const + inline uint32_t GetLength() const { return TaggedArray::GetLength(); } inline Properties *GetProperties() const { - return reinterpret_cast(reinterpret_cast(this) + TaggedArray::GetDataOffset() + + return reinterpret_cast(reinterpret_cast(this) + TaggedArray::DATA_OFFSET + ELEMENTS_START_INDEX * JSTaggedValue::TaggedTypeSize()); } - static inline array_size_t ComputeArrayLength(array_size_t properties_number) + static inline uint32_t ComputeArrayLength(uint32_t properties_number) { return (properties_number << 1U) + ELEMENTS_START_INDEX; } - static inline array_size_t ComputeGrowCapacity(uint32_t old_capacity) + static inline uint32_t ComputeGrowCapacity(uint32_t old_capacity) { - array_size_t new_capacity = old_capacity + MIN_PROPERTIES_LENGTH; + uint32_t new_capacity = old_capacity + MIN_PROPERTIES_LENGTH; return new_capacity > MAX_PROPERTIES_LENGTH ? MAX_PROPERTIES_LENGTH : new_capacity; } @@ -81,8 +81,8 @@ public: int BinarySearch(JSTaggedValue key, int propertiesNumber); void GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray); void GetAllKeys(const JSThread *thread, int end, std::vector &keyVector); - void GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, array_size_t *keys); - void GetAllNames(const JSThread *thread, int end, const JSHandle &keyArray, array_size_t *length); + void GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, uint32_t *keys); + void GetAllNames(const JSThread *thread, int end, const JSHandle &keyArray, uint32_t *length); DECL_DUMP() }; diff --git a/ecmascript/lexical_env.h b/ecmascript/lexical_env.h index cedda236d5..b1c0b3c5e8 100644 --- a/ecmascript/lexical_env.h +++ b/ecmascript/lexical_env.h @@ -21,8 +21,8 @@ namespace panda::ecmascript { class LexicalEnv : public TaggedArray { public: - static constexpr array_size_t PARENT_ENV_INDEX = 0; - static constexpr array_size_t RESERVED_ENV_LENGTH = 1; + static constexpr uint32_t PARENT_ENV_INDEX = 0; + static constexpr uint32_t RESERVED_ENV_LENGTH = 1; static LexicalEnv *Cast(ObjectHeader *object) { diff --git a/ecmascript/literal_data_extractor.cpp b/ecmascript/literal_data_extractor.cpp index 15fb9bd39c..31ef37290e 100644 --- a/ecmascript/literal_data_extractor.cpp +++ b/ecmascript/literal_data_extractor.cpp @@ -39,8 +39,8 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half elements.Update(factory->NewTaggedArray(num).GetTaggedValue()); properties.Update(factory->NewTaggedArray(num).GetTaggedValue()); - array_size_t epos = 0; - array_size_t ppos = 0; + uint32_t epos = 0; + uint32_t ppos = 0; const uint8_t pairSize = 2; uint32_t methodId; FunctionKind kind; @@ -125,7 +125,7 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, uint32_t num = lda.GetLiteralValsNum(index) / 2; // 2: half JSHandle literals = factory->NewTaggedArray(num); - array_size_t pos = 0; + uint32_t pos = 0; uint32_t methodId; FunctionKind kind; lda.EnumerateLiteralVals( @@ -186,7 +186,7 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, if (tag != LiteralTag::METHOD && tag != LiteralTag::GENERATORMETHOD) { literals->Set(thread, pos++, jt); } else { - array_size_t oldLength = literals->GetLength(); + uint32_t oldLength = literals->GetLength(); literals->Trim(thread, oldLength - 1); } }); diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index 612d04fa2d..e37dcf0ff8 100755 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -1276,7 +1276,7 @@ Local TypedArrayRef::GetArrayBuffer(const EcmaVM *vm) JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(buffer)); \ ecmascript::InternalCallParams *argv = thread->GetInternalCallParams(); \ argv->MakeArgv(arrayBuffer.GetTaggedValue(), JSTaggedValue(byteOffset), JSTaggedValue(length)); \ - array_size_t argc = 3; \ + uint32_t argc = 3; \ JSTaggedValue result = JSFunction::Construct(thread, func, argc, argv->GetArgv(), func); \ RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); \ JSHandle resultHandle(thread, result); \ @@ -1434,8 +1434,8 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *info) // arguments std::vector> arguments; - array_size_t length = info->GetArgsNumber(); - for (array_size_t i = 0; i < length; ++i) { + uint32_t length = info->GetArgsNumber(); + for (uint32_t i = 0; i < length; ++i) { arguments.emplace_back(JSNApiHelper::ToLocal(BuiltinsBase::GetCallArg(info, i))); } @@ -1486,8 +1486,8 @@ JSTaggedValue Callback::RegisterCallbackWithProperty(ecmascript::EcmaRuntimeCall // arguments std::vector> arguments; - array_size_t length = info->GetArgsNumber(); - for (array_size_t i = 0; i < length; ++i) { + uint32_t length = info->GetArgsNumber(); + for (uint32_t i = 0; i < length; ++i) { arguments.emplace_back(JSNApiHelper::ToLocal(BuiltinsBase::GetCallArg(info, i))); } @@ -1542,8 +1542,8 @@ JSTaggedValue Callback::RegisterCallbackWithNewTarget(ecmascript::EcmaRuntimeCal // arguments std::vector> arguments; - array_size_t length = info->GetArgsNumber(); - for (array_size_t i = 0; i < length; ++i) { + uint32_t length = info->GetArgsNumber(); + for (uint32_t i = 0; i < length; ++i) { arguments.emplace_back(JSNApiHelper::ToLocal(BuiltinsBase::GetCallArg(info, i))); } diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index e03b4fd34f..744f41dc2d 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -309,7 +309,7 @@ JSHandle ObjectFactory::NewJSObject(const JSHandle &jshclass JSHandle ObjectFactory::CloneProperties(const JSHandle &old) { - array_size_t newLength = old->GetLength(); + uint32_t newLength = old->GetLength(); if (newLength == 0) { return EmptyArray(); } @@ -320,7 +320,7 @@ JSHandle ObjectFactory::CloneProperties(const JSHandle JSHandle newArray(thread_, header); newArray->SetLength(newLength); - for (array_size_t i = 0; i < newLength; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); newArray->Set(thread_, i, value); } @@ -374,14 +374,14 @@ JSHandle ObjectFactory::CloneProperties(const JSHandle const JSHandle &env, const JSHandle &obj, const JSHandle &constpool) { - array_size_t newLength = old->GetLength(); + uint32_t newLength = old->GetLength(); if (newLength == 0) { return EmptyArray(); } NewObjectHook(); JSHandle newArray = NewTaggedArray(newLength); - for (array_size_t i = 0; i < newLength; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); if (!value.IsJSFunction()) { newArray->Set(thread_, i, value); @@ -1479,13 +1479,13 @@ JSHandle ObjectFactory::NewJSRealm() JSHandle ObjectFactory::NewEmptyArray() { NewObjectHook(); - auto header = heapHelper_.AllocateNonMovableOrHugeObject(arrayClass_, sizeof(TaggedArray)); + auto header = heapHelper_.AllocateNonMovableOrHugeObject(arrayClass_, TaggedArray::SIZE); JSHandle array(thread_, header); array->SetLength(0); return array; } -JSHandle ObjectFactory::NewTaggedArray(array_size_t length, JSTaggedValue initVal, bool nonMovable) +JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue initVal, bool nonMovable) { if (nonMovable) { return NewTaggedArray(length, initVal, MemSpaceType::NON_MOVABLE); @@ -1493,7 +1493,7 @@ JSHandle ObjectFactory::NewTaggedArray(array_size_t length, JSTagge return NewTaggedArray(length, initVal, MemSpaceType::SEMI_SPACE); } -JSHandle ObjectFactory::NewTaggedArray(array_size_t length, JSTaggedValue initVal, MemSpaceType spaceType) +JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType) { NewObjectHook(); if (length == 0) { @@ -1521,7 +1521,7 @@ JSHandle ObjectFactory::NewTaggedArray(array_size_t length, JSTagge return array; } -JSHandle ObjectFactory::NewTaggedArray(array_size_t length, JSTaggedValue initVal) +JSHandle ObjectFactory::NewTaggedArray(uint32_t length, JSTaggedValue initVal) { NewObjectHook(); if (length == 0) { @@ -1535,7 +1535,7 @@ JSHandle ObjectFactory::NewTaggedArray(array_size_t length, JSTagge return array; } -JSHandle ObjectFactory::NewDictionaryArray(array_size_t length) +JSHandle ObjectFactory::NewDictionaryArray(uint32_t length) { NewObjectHook(); ASSERT(length > 0); @@ -1548,7 +1548,7 @@ JSHandle ObjectFactory::NewDictionaryArray(array_size_t length) return array; } -JSHandle ObjectFactory::ExtendArray(const JSHandle &old, array_size_t length, +JSHandle ObjectFactory::ExtendArray(const JSHandle &old, uint32_t length, JSTaggedValue initVal) { ASSERT(length > old->GetLength()); @@ -1558,26 +1558,26 @@ JSHandle ObjectFactory::ExtendArray(const JSHandle &ol JSHandle newArray(thread_, header); newArray->SetLength(length); - array_size_t oldLength = old->GetLength(); - for (array_size_t i = 0; i < oldLength; i++) { + uint32_t oldLength = old->GetLength(); + for (uint32_t i = 0; i < oldLength; i++) { JSTaggedValue value = old->Get(i); newArray->Set(thread_, i, value); } - for (array_size_t i = oldLength; i < length; i++) { + for (uint32_t i = oldLength; i < length; i++) { newArray->Set(thread_, i, initVal); } return newArray; } -JSHandle ObjectFactory::CopyPartArray(const JSHandle &old, array_size_t start, - array_size_t end) +JSHandle ObjectFactory::CopyPartArray(const JSHandle &old, uint32_t start, + uint32_t end) { ASSERT(start <= end); ASSERT(end <= old->GetLength()); - array_size_t newLength = end - start; + uint32_t newLength = end - start; if (newLength == 0) { return EmptyArray(); } @@ -1588,7 +1588,7 @@ JSHandle ObjectFactory::CopyPartArray(const JSHandle & JSHandle newArray(thread_, header); newArray->SetLength(newLength); - for (array_size_t i = 0; i < newLength; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i + start); if (value.IsHole()) { break; @@ -1599,7 +1599,7 @@ JSHandle ObjectFactory::CopyPartArray(const JSHandle & } JSHandle ObjectFactory::CopyArray(const JSHandle &old, - [[maybe_unused]] array_size_t oldLength, array_size_t newLength, + [[maybe_unused]] uint32_t oldLength, uint32_t newLength, JSTaggedValue initVal) { if (newLength == 0) { @@ -1615,7 +1615,7 @@ JSHandle ObjectFactory::CopyArray(const JSHandle &old, JSHandle newArray(thread_, header); newArray->SetLength(newLength); - for (array_size_t i = 0; i < newLength; i++) { + for (uint32_t i = 0; i < newLength; i++) { JSTaggedValue value = old->Get(i); newArray->Set(thread_, i, value); } @@ -1811,9 +1811,9 @@ void ObjectFactory::NewObjectHook() const #endif } -JSHandle ObjectFactory::NewTaggedQueue(array_size_t length) +JSHandle ObjectFactory::NewTaggedQueue(uint32_t length) { - array_size_t queueLength = TaggedQueue::QueueToArrayIndex(length); + uint32_t queueLength = TaggedQueue::QueueToArrayIndex(length); auto queue = JSHandle::Cast(NewTaggedArray(queueLength, JSTaggedValue::Hole())); queue->SetStart(thread_, JSTaggedValue(0)); // equal to 0 when add 1. queue->SetEnd(thread_, JSTaggedValue(0)); diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index e9263cdc72..fd4f1c91d1 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -219,10 +219,10 @@ public: JSHandle NewJSString(const JSHandle &str); - JSHandle NewTaggedArray(array_size_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); - JSHandle NewTaggedArray(array_size_t length, JSTaggedValue initVal, bool nonMovable); - JSHandle NewTaggedArray(array_size_t length, JSTaggedValue initVal, MemSpaceType spaceType); - JSHandle NewDictionaryArray(array_size_t length); + JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); + JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal, bool nonMovable); + JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType); + JSHandle NewDictionaryArray(uint32_t length); JSHandle NewJSForinIterator(const JSHandle &obj); JSHandle NewPropertyBox(const JSHandle &name); @@ -232,10 +232,10 @@ public: JSHandle NewProtoChangeDetails(); // use for copy properties keys's array to another array - JSHandle ExtendArray(const JSHandle &old, array_size_t length, + JSHandle ExtendArray(const JSHandle &old, uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); - JSHandle CopyPartArray(const JSHandle &old, array_size_t start, array_size_t end); - JSHandle CopyArray(const JSHandle &old, array_size_t oldLength, array_size_t newLength, + JSHandle CopyPartArray(const JSHandle &old, uint32_t start, uint32_t end); + JSHandle CopyArray(const JSHandle &old, uint32_t oldLength, uint32_t newLength, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle CloneProperties(const JSHandle &old); JSHandle CloneProperties(const JSHandle &old, const JSHandle &env, @@ -262,7 +262,7 @@ public: void InitializeExtraProperties(const JSHandle &dynclass, TaggedObject *obj, int inobjPropCount); - JSHandle NewTaggedQueue(array_size_t length); + JSHandle NewTaggedQueue(uint32_t length); JSHandle GetEmptyTaggedQueue() const; diff --git a/ecmascript/snapshot/mem/snapshot_serialize.cpp b/ecmascript/snapshot/mem/snapshot_serialize.cpp index c6e479aa3b..4e5971310b 100644 --- a/ecmascript/snapshot/mem/snapshot_serialize.cpp +++ b/ecmascript/snapshot/mem/snapshot_serialize.cpp @@ -914,10 +914,10 @@ void SnapShotSerialize::DynArraySerialize(TaggedObject *objectHeader, uintptr_t CQueue *queue, std::unordered_map *data) { auto arrayObject = reinterpret_cast(objectHeader); - size_t beginOffset = TaggedArray::GetDataOffset(); + size_t beginOffset = TaggedArray::DATA_OFFSET; auto arrayLength = arrayObject->GetLength(); uintptr_t startAddr = ToUintPtr(objectHeader) + beginOffset; - for (array_size_t i = 0; i < arrayLength; i++) { + for (uint32_t i = 0; i < arrayLength; i++) { auto fieldAddr = reinterpret_cast(startAddr + i * TAGGED_SIZE); SetObjectSlotField(snapshotObj, beginOffset + i * TAGGED_SIZE, HandleTaggedField(fieldAddr, queue, data)); } @@ -930,9 +930,9 @@ void SnapShotSerialize::DynArrayDeserialize(uint64_t *objectHeader) DeserializeHandleClassWord(object); auto arrayLength = object->GetLength(); - size_t dataOffset = TaggedArray::GetDataOffset(); + size_t dataOffset = TaggedArray::DATA_OFFSET; uintptr_t startAddr = ToUintPtr(objectHeader) + dataOffset; - for (array_size_t i = 0; i < arrayLength; i++) { + for (uint32_t i = 0; i < arrayLength; i++) { auto fieldAddr = reinterpret_cast(startAddr + i * TAGGED_SIZE); DeserializeHandleTaggedField(fieldAddr); } diff --git a/ecmascript/tagged_array-inl.h b/ecmascript/tagged_array-inl.h index a340d85726..a9a6727b5e 100644 --- a/ecmascript/tagged_array-inl.h +++ b/ecmascript/tagged_array-inl.h @@ -21,12 +21,7 @@ #include "ecmascript/tagged_array.h" namespace panda::ecmascript { -inline array_size_t TaggedArray::GetLength() const -{ - return Barriers::GetDynValue(this, TaggedArray::GetLengthOffset()); -} - -inline JSTaggedValue TaggedArray::Get(array_size_t idx) const +inline JSTaggedValue TaggedArray::Get(uint32_t idx) const { ASSERT(idx < GetLength()); // Note: Here we can't statically decide the element type is a primitive or heap object, especially for @@ -36,16 +31,16 @@ inline JSTaggedValue TaggedArray::Get(array_size_t idx) const return JSTaggedValue(Barriers::GetDynValue(GetData(), offset)); } -inline JSTaggedValue TaggedArray::Get([[maybe_unused]] const JSThread *thread, array_size_t idx) const +inline JSTaggedValue TaggedArray::Get([[maybe_unused]] const JSThread *thread, uint32_t idx) const { return Get(idx); } -inline array_size_t TaggedArray::GetIdx(const JSTaggedValue &value) const +inline uint32_t TaggedArray::GetIdx(const JSTaggedValue &value) const { - array_size_t length = GetLength(); + uint32_t length = GetLength(); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { if (JSTaggedValue::SameValue(Get(i), value)) { return i; } @@ -54,7 +49,7 @@ inline array_size_t TaggedArray::GetIdx(const JSTaggedValue &value) const } template -inline void TaggedArray::Set(const JSThread *thread, array_size_t idx, const JSHandle &value) +inline void TaggedArray::Set(const JSThread *thread, uint32_t idx, const JSHandle &value) { ASSERT(idx < GetLength()); size_t offset = JSTaggedValue::TaggedTypeSize() * idx; @@ -67,7 +62,7 @@ inline void TaggedArray::Set(const JSThread *thread, array_size_t idx, const JSH } } -inline void TaggedArray::Set(const JSThread *thread, array_size_t idx, const JSTaggedValue &value) +inline void TaggedArray::Set(const JSThread *thread, uint32_t idx, const JSTaggedValue &value) { ASSERT(idx < GetLength()); size_t offset = JSTaggedValue::TaggedTypeSize() * idx; @@ -83,12 +78,12 @@ inline void TaggedArray::Set(const JSThread *thread, array_size_t idx, const JST JSHandle TaggedArray::Append(const JSThread *thread, const JSHandle &first, const JSHandle &second) { - array_size_t firstLength = first->GetLength(); - array_size_t secondLength = second->GetLength(); - array_size_t length = firstLength + secondLength; + uint32_t firstLength = first->GetLength(); + uint32_t secondLength = second->GetLength(); + uint32_t length = firstLength + secondLength; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle argument = factory->NewTaggedArray(length); - array_size_t index = 0; + uint32_t index = 0; for (; index < firstLength; ++index) { argument->Set(thread, index, first->Get(index)); } @@ -99,15 +94,15 @@ JSHandle TaggedArray::Append(const JSThread *thread, const JSHandle } JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const JSHandle &first, - const JSHandle &second, array_size_t copyLength) + const JSHandle &second, uint32_t copyLength) { - array_size_t firstLength = first->GetLength(); - array_size_t secondLength = second->GetLength(); + uint32_t firstLength = first->GetLength(); + uint32_t secondLength = second->GetLength(); ASSERT(firstLength + secondLength >= copyLength); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle argument = factory->NewTaggedArray(copyLength); - array_size_t index = 0; + uint32_t index = 0; for (; index < firstLength; ++index) { JSTaggedValue val = first->Get(index); if (val.IsHole()) { @@ -116,7 +111,7 @@ JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const argument->Set(thread, index, val); ASSERT(copyLength >= index); } - for (array_size_t i = 0; i < secondLength; ++i) { + for (uint32_t i = 0; i < secondLength; ++i) { JSTaggedValue val = second->Get(i); if (val.IsHole()) { break; @@ -129,9 +124,9 @@ JSHandle TaggedArray::AppendSkipHole(const JSThread *thread, const inline bool TaggedArray::HasDuplicateEntry() const { - array_size_t length = GetLength(); - for (array_size_t i = 0; i < length; i++) { - for (array_size_t j = i + 1; j < length; j++) { + uint32_t length = GetLength(); + for (uint32_t i = 0; i < length; i++) { + for (uint32_t j = i + 1; j < length; j++) { if (JSTaggedValue::SameValue(Get(i), Get(j))) { return true; } @@ -140,21 +135,21 @@ inline bool TaggedArray::HasDuplicateEntry() const return false; } -void TaggedArray::InitializeWithSpecialValue(JSTaggedValue initValue, array_size_t length) +void TaggedArray::InitializeWithSpecialValue(JSTaggedValue initValue, uint32_t length) { ASSERT(initValue.IsSpecial()); SetLength(length); - for (array_size_t i = 0; i < length; i++) { + for (uint32_t i = 0; i < length; i++) { size_t offset = JSTaggedValue::TaggedTypeSize() * i; Barriers::SetDynPrimitive(GetData(), offset, initValue.GetRawData()); } } inline JSHandle TaggedArray::SetCapacity(const JSThread *thread, const JSHandle &array, - array_size_t capa) + uint32_t capa) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t oldLength = array->GetLength(); + uint32_t oldLength = array->GetLength(); JSHandle newArray = factory->CopyArray(array, oldLength, capa); return newArray; } @@ -164,10 +159,10 @@ inline bool TaggedArray::IsDictionaryMode() const return GetClass()->IsDictionary(); } -void TaggedArray::Trim(JSThread *thread, array_size_t newLength) +void TaggedArray::Trim(JSThread *thread, uint32_t newLength) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t oldLength = GetLength(); + uint32_t oldLength = GetLength(); ASSERT(oldLength > newLength); size_t trimBytes = (oldLength - newLength) * JSTaggedValue::TaggedTypeSize(); size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), newLength); diff --git a/ecmascript/tagged_array.h b/ecmascript/tagged_array.h index e3ac7c9813..5b247c07e0 100644 --- a/ecmascript/tagged_array.h +++ b/ecmascript/tagged_array.h @@ -25,8 +25,8 @@ class ObjectFactory; class TaggedArray : public TaggedObject { public: - static constexpr array_size_t MAX_ARRAY_INDEX = std::numeric_limits::max(); - static constexpr array_size_t MAX_END_UNUSED = 4; + static constexpr uint32_t MAX_ARRAY_INDEX = std::numeric_limits::max(); + static constexpr uint32_t MAX_END_UNUSED = 4; inline static TaggedArray *Cast(ObjectHeader *obj) { @@ -34,30 +34,28 @@ public: return static_cast(obj); } - array_size_t GetLength() const; + JSTaggedValue Get(uint32_t idx) const; - JSTaggedValue Get(array_size_t idx) const; - - array_size_t GetIdx(const JSTaggedValue &value) const; + uint32_t GetIdx(const JSTaggedValue &value) const; template - void Set(const JSThread *thread, array_size_t idx, const JSHandle &value); + void Set(const JSThread *thread, uint32_t idx, const JSHandle &value); - JSTaggedValue Get(const JSThread *thread, array_size_t idx) const; + JSTaggedValue Get(const JSThread *thread, uint32_t idx) const; - void Set(const JSThread *thread, array_size_t idx, const JSTaggedValue &value); + void Set(const JSThread *thread, uint32_t idx, const JSTaggedValue &value); static inline JSHandle Append(const JSThread *thread, const JSHandle &first, const JSHandle &second); static inline JSHandle AppendSkipHole(const JSThread *thread, const JSHandle &first, - const JSHandle &second, array_size_t copyLength); + const JSHandle &second, uint32_t copyLength); - static inline size_t ComputeSize(size_t elemSize, array_size_t length) + static inline size_t ComputeSize(size_t elemSize, uint32_t length) { ASSERT(elemSize != 0); - size_t size = sizeof(TaggedArray) + elemSize * length; + size_t size = DATA_OFFSET + elemSize * length; #ifdef PANDA_TARGET_32 - size_t sizeLimit = (std::numeric_limits::max() - sizeof(TaggedArray)) / elemSize; + size_t sizeLimit = (std::numeric_limits::max() - DATA_OFFSET) / elemSize; if (UNLIKELY(sizeLimit < static_cast(length))) { return 0; } @@ -65,14 +63,9 @@ public: return size; } - JSTaggedType *GetData() - { - return data_; - } - - const JSTaggedType *GetData() const + inline JSTaggedType *GetData() const { - return data_; + return reinterpret_cast(ToUintPtr(this) + DATA_OFFSET); } inline bool IsDictionaryMode() const; @@ -80,45 +73,27 @@ public: bool HasDuplicateEntry() const; static JSHandle SetCapacity(const JSThread *thread, const JSHandle &array, - array_size_t capa); + uint32_t capa); - static constexpr uint32_t GetLengthOffset() - { - return MEMBER_OFFSET(TaggedArray, length_); - } + inline void InitializeWithSpecialValue(JSTaggedValue initValue, uint32_t length); - static constexpr uint32_t GetDataOffset() + static inline bool ShouldTrim(JSThread *thread, uint32_t oldLength, uint32_t newLength) { - return MEMBER_OFFSET(TaggedArray, data_); + return (oldLength - newLength > MAX_END_UNUSED); } + inline void Trim(JSThread *thread, uint32_t newLength); - inline void InitializeWithSpecialValue(JSTaggedValue initValue, array_size_t length); + static constexpr size_t LENGTH_OFFSET = TaggedObjectSize(); + SET_GET_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, DATA_OFFSET); + static constexpr size_t SIZE = DATA_OFFSET; // Empty Array size - static inline bool ShouldTrim(JSThread *thread, array_size_t oldLength, array_size_t newLength) - { - return (oldLength - newLength > MAX_END_UNUSED); - } - inline void Trim(JSThread *thread, array_size_t newLength); - void VisitRangeSlot(const EcmaObjectRangeVisitor &v) - { - uintptr_t dataAddr = ToUintPtr(this) + TaggedArray::GetDataOffset(); - v(this, ObjectSlot(dataAddr), ObjectSlot(dataAddr + GetLength() * JSTaggedValue::TaggedTypeSize())); - } + DECL_VISIT_ARRAY(DATA_OFFSET, GetLength()); private: friend class ObjectFactory; - - void SetLength(array_size_t length) - { - length_ = length; - } - - array_size_t length_; - uint32_t placeholder_; // Add for 8bits align of data_ - // should align by 8, 32bit using TaggedType also - __extension__ alignas(sizeof(JSTaggedType)) JSTaggedType data_[0]; // NOLINT(modernize-avoid-c-arrays) }; -static_assert(TaggedArray::GetLengthOffset() == sizeof(TaggedObject)); +static_assert(TaggedArray::LENGTH_OFFSET == sizeof(TaggedObject)); +static_assert((TaggedArray::DATA_OFFSET % static_cast(MemAlignment::MEM_ALIGN_OBJECT)) == 0); } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_ARRAY_H diff --git a/ecmascript/tagged_dictionary.cpp b/ecmascript/tagged_dictionary.cpp index 5affe3f06a..3eff690db8 100644 --- a/ecmascript/tagged_dictionary.cpp +++ b/ecmascript/tagged_dictionary.cpp @@ -59,9 +59,9 @@ void NameDictionary::GetAllKeys(const JSThread *thread, int offset, TaggedArray } } -void NameDictionary::GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, array_size_t *keys) const +void NameDictionary::GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const { - array_size_t arrayIndex = 0; + uint32_t arrayIndex = 0; int size = Size(); CVector> sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { @@ -177,11 +177,11 @@ void NumberDictionary::GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &keyArray, array_size_t *keys) + const JSHandle &keyArray, uint32_t *keys) { ASSERT_PRINT(offset + obj->EntriesCount() <= static_cast(keyArray->GetLength()), "keyArray capacity is not enough for dictionary"); - array_size_t arrayIndex = 0; + uint32_t arrayIndex = 0; int size = obj->Size(); CVector sortArr; for (int hashIndex = 0; hashIndex < size; hashIndex++) { diff --git a/ecmascript/tagged_dictionary.h b/ecmascript/tagged_dictionary.h index ddfb9de24c..16616d79b5 100644 --- a/ecmascript/tagged_dictionary.h +++ b/ecmascript/tagged_dictionary.h @@ -53,7 +53,7 @@ public: void UpdateAttributes(int entry, const PropertyAttributes &metaData); void ClearEntry(const JSThread *thread, int entry); void GetAllKeys(const JSThread *thread, int offset, TaggedArray *keyArray) const; - void GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, array_size_t *keys) const; + void GetAllEnumKeys(const JSThread *thread, int offset, TaggedArray *keyArray, uint32_t *keys) const; static inline bool CompKey(const std::pair &a, const std::pair &b) { @@ -104,7 +104,7 @@ public: static void GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, const JSHandle &keyArray); static void GetAllEnumKeys(const JSThread *thread, const JSHandle &obj, int offset, - const JSHandle &keyArray, array_size_t *keys); + const JSHandle &keyArray, uint32_t *keys); static inline bool CompKey(const JSTaggedValue &a, const JSTaggedValue &b) { ASSERT(a.IsNumber() && b.IsNumber()); diff --git a/ecmascript/tagged_queue-inl.h b/ecmascript/tagged_queue-inl.h index 50cedce12a..30f5b582ca 100644 --- a/ecmascript/tagged_queue-inl.h +++ b/ecmascript/tagged_queue-inl.h @@ -19,9 +19,9 @@ #include "ecmascript/tagged_queue.h" namespace panda::ecmascript { -inline TaggedQueue *TaggedQueue::Create(JSThread *thread, array_size_t capacity, JSTaggedValue initVal) +inline TaggedQueue *TaggedQueue::Create(JSThread *thread, uint32_t capacity, JSTaggedValue initVal) { - array_size_t length = QueueToArrayIndex(capacity); + uint32_t length = QueueToArrayIndex(capacity); auto queue = TaggedQueue::Cast(*thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length, initVal)); queue->SetStart(thread, JSTaggedValue(0)); // equal to 0 when add 1. @@ -36,10 +36,10 @@ inline JSTaggedValue TaggedQueue::Pop(JSThread *thread) return JSTaggedValue::Hole(); } - array_size_t start = GetStart().GetArrayLength(); + uint32_t start = GetStart().GetArrayLength(); JSTaggedValue value = Get(start); - array_size_t capacity = GetCapacity().GetArrayLength(); + uint32_t capacity = GetCapacity().GetArrayLength(); ASSERT(capacity != 0); SetStart(thread, JSTaggedValue((start + 1) % capacity)); return value; diff --git a/ecmascript/tagged_queue.h b/ecmascript/tagged_queue.h index c5ca3717b8..442544e45e 100644 --- a/ecmascript/tagged_queue.h +++ b/ecmascript/tagged_queue.h @@ -33,7 +33,7 @@ public: static TaggedQueue *Push(const JSThread *thread, const JSHandle &queue, const JSHandle &value) { - array_size_t capacity = queue->GetCapacity().GetArrayLength(); + uint32_t capacity = queue->GetCapacity().GetArrayLength(); if (capacity == 0) { // If there is no capacity, directly create a queue whose capacity is MIN_CAPACITY. Add elements. ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -45,9 +45,9 @@ public: return *newQueue; } - array_size_t start = queue->GetStart().GetArrayLength(); - array_size_t end = queue->GetEnd().GetArrayLength(); - array_size_t size = queue->Size(); + uint32_t start = queue->GetStart().GetArrayLength(); + uint32_t end = queue->GetEnd().GetArrayLength(); + uint32_t size = queue->Size(); if ((end + 1) % capacity == start) { // The original queue is full and needs to be expanded. if (capacity == MAX_QUEUE_INDEX) { @@ -56,11 +56,11 @@ public: } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // Grow Array for 1.5 times - array_size_t newCapacity = capacity + (capacity >> 1U); + uint32_t newCapacity = capacity + (capacity >> 1U); newCapacity = newCapacity < capacity ? MAX_QUEUE_INDEX : newCapacity; JSHandle newQueue = factory->NewTaggedQueue(newCapacity); - array_size_t newEnd = 0; - for (array_size_t i = start; newEnd < size; i = (i + 1) % capacity) { + uint32_t newEnd = 0; + for (uint32_t i = start; newEnd < size; i = (i + 1) % capacity) { newQueue->Set(thread, newEnd, queue->Get(i)); newEnd++; } @@ -80,8 +80,8 @@ public: static inline void PushFixedQueue(const JSThread *thread, const JSHandle &queue, const JSHandle &value) { - array_size_t end = queue->GetEnd().GetArrayLength(); - array_size_t capacity = queue->GetCapacity().GetArrayLength(); + uint32_t end = queue->GetEnd().GetArrayLength(); + uint32_t capacity = queue->GetCapacity().GetArrayLength(); ASSERT(capacity != 0); queue->Set(thread, end, value.GetTaggedValue()); queue->SetEnd(thread, JSTaggedValue((end + 1) % capacity)); @@ -97,7 +97,7 @@ public: if (Empty()) { return JSTaggedValue::Hole(); } - array_size_t start = GetStart().GetArrayLength(); + uint32_t start = GetStart().GetArrayLength(); return JSTaggedValue(Get(start)); } @@ -109,38 +109,38 @@ public: return JSTaggedValue(Get(GetEnd().GetArrayLength() - 1)); } - inline array_size_t Size() + inline uint32_t Size() { - array_size_t capacity = GetCapacity().GetArrayLength(); + uint32_t capacity = GetCapacity().GetArrayLength(); if (capacity == 0) { return 0; } - array_size_t end = GetEnd().GetArrayLength(); - array_size_t start = GetStart().GetArrayLength(); + uint32_t end = GetEnd().GetArrayLength(); + uint32_t start = GetStart().GetArrayLength(); return (end - start + capacity) % capacity; } - inline JSTaggedValue Get(array_size_t index) const + inline JSTaggedValue Get(uint32_t index) const { return TaggedArray::Get(QueueToArrayIndex(index)); } - inline void Set(const JSThread *thread, array_size_t index, JSTaggedValue value) + inline void Set(const JSThread *thread, uint32_t index, JSTaggedValue value) { return TaggedArray::Set(thread, QueueToArrayIndex(index), value); } - static const array_size_t MIN_CAPACITY = 2; - static const array_size_t CAPACITY_INDEX = 0; - static const array_size_t START_INDEX = 1; - static const array_size_t END_INDEX = 2; - static const array_size_t ELEMENTS_START_INDEX = 3; - static const array_size_t MAX_QUEUE_INDEX = TaggedArray::MAX_ARRAY_INDEX - ELEMENTS_START_INDEX; + static const uint32_t MIN_CAPACITY = 2; + static const uint32_t CAPACITY_INDEX = 0; + static const uint32_t START_INDEX = 1; + static const uint32_t END_INDEX = 2; + static const uint32_t ELEMENTS_START_INDEX = 3; + static const uint32_t MAX_QUEUE_INDEX = TaggedArray::MAX_ARRAY_INDEX - ELEMENTS_START_INDEX; private: friend class ObjectFactory; - inline static constexpr array_size_t QueueToArrayIndex(array_size_t index) + inline static constexpr uint32_t QueueToArrayIndex(uint32_t index) { return index + ELEMENTS_START_INDEX; } @@ -175,7 +175,7 @@ private: return TaggedArray::Get(END_INDEX); } - static TaggedQueue *Create(JSThread *thread, array_size_t capacity, JSTaggedValue initVal = JSTaggedValue::Hole()); + static TaggedQueue *Create(JSThread *thread, uint32_t capacity, JSTaggedValue initVal = JSTaggedValue::Hole()); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_QUEUE_H \ No newline at end of file diff --git a/ecmascript/tests/concurrent_marking_test.cpp b/ecmascript/tests/concurrent_marking_test.cpp index c3b82e627f..7c58b64b7a 100644 --- a/ecmascript/tests/concurrent_marking_test.cpp +++ b/ecmascript/tests/concurrent_marking_test.cpp @@ -62,7 +62,7 @@ public: TestHelper::DestroyEcmaVMWithScope(instance, scope); } - JSHandle CreateTaggedArray(array_size_t length, JSTaggedValue initVal, MemSpaceType spaceType) + JSHandle CreateTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); return factory->NewTaggedArray(length, initVal, spaceType); @@ -75,18 +75,18 @@ public: HWTEST_F_L0(ConcurrentMarkingTest, PerformanceWithConcurrentMarking) { - array_size_t rootLength = 1024; + uint32_t rootLength = 1024; JSHandle rootArray = CreateTaggedArray(rootLength, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE); - for (array_size_t i = 0; i < rootLength; i++) { - array_size_t subArrayLength = 1024; + for (uint32_t i = 0; i < rootLength; i++) { + uint32_t subArrayLength = 1024; auto array = CreateTaggedArray(subArrayLength, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE); rootArray->Set(thread, i, array); } auto heap = const_cast(thread->GetEcmaVM()->GetHeap()); heap->TriggerConcurrentMarking(); // concurrent mark - for (array_size_t i = 0; i < rootLength; i++) { - array_size_t subArrayLength = 1024; + for (uint32_t i = 0; i < rootLength; i++) { + uint32_t subArrayLength = 1024; auto array = CreateTaggedArray(subArrayLength, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE); rootArray->Set(thread, i, array); } @@ -95,17 +95,17 @@ HWTEST_F_L0(ConcurrentMarkingTest, PerformanceWithConcurrentMarking) HWTEST_F_L0(ConcurrentMarkingTest, PerformanceWithoutConcurrentMarking) { - array_size_t rootLength = 1024; + uint32_t rootLength = 1024; JSHandle rootArray = CreateTaggedArray(rootLength, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE); - for (array_size_t i = 0; i < rootLength; i++) { - array_size_t subArrayLength = 1024; + for (uint32_t i = 0; i < rootLength; i++) { + uint32_t subArrayLength = 1024; auto array = CreateTaggedArray(subArrayLength, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE); rootArray->Set(thread, i, array); } auto heap = const_cast(thread->GetEcmaVM()->GetHeap()); - for (array_size_t i = 0; i < rootLength; i++) { - array_size_t subArrayLength = 1024; + for (uint32_t i = 0; i < rootLength; i++) { + uint32_t subArrayLength = 1024; auto array = CreateTaggedArray(subArrayLength, JSTaggedValue::Undefined(), MemSpaceType::OLD_SPACE); rootArray->Set(thread, i, array); } diff --git a/ecmascript/tests/ecma_string_test.cpp b/ecmascript/tests/ecma_string_test.cpp index f3e39b5b2e..1d10a4cbb1 100644 --- a/ecmascript/tests/ecma_string_test.cpp +++ b/ecmascript/tests/ecma_string_test.cpp @@ -213,7 +213,7 @@ HWTEST_F_L0(EcmaStringTest, ComputeSizeUtf8) uint32_t scale = 3333; for (uint32_t i = 0x40000000U - 1; i > scale; i = i - scale) { uint32_t length = i; - EXPECT_EQ(EcmaString::ComputeSizeUtf8(length), length + sizeof(EcmaString)); + EXPECT_EQ(EcmaString::ComputeSizeUtf8(length), length + EcmaString::SIZE); } } @@ -243,7 +243,7 @@ HWTEST_F_L0(EcmaStringTest, ComputeSizeUtf16) uint32_t scale = 3333; for (uint32_t i = 0x40000000U - 1; i > scale; i = i - scale) { uint32_t length = i; - EXPECT_EQ(EcmaString::ComputeSizeUtf16(length), 2 * length + sizeof(EcmaString)); + EXPECT_EQ(EcmaString::ComputeSizeUtf16(length), 2 * length + EcmaString::SIZE); } } @@ -258,38 +258,38 @@ HWTEST_F_L0(EcmaStringTest, ObjectSize) EcmaVM* ecmaVMPtr = EcmaVM::Cast(instance); JSHandle handleEcmaStrEmpty(thread, EcmaString::CreateEmptyString(ecmaVMPtr)); - EXPECT_EQ(handleEcmaStrEmpty->ObjectSize(), sizeof(EcmaString) + 0); + EXPECT_EQ(handleEcmaStrEmpty->ObjectSize(), EcmaString::SIZE + 0); size_t lengthEcmaStrAllocComp = 5; JSHandle handleEcmaStrAllocComp(thread, EcmaString::AllocStringObject(lengthEcmaStrAllocComp, true, ecmaVMPtr)); - EXPECT_EQ(handleEcmaStrAllocComp->ObjectSize(), sizeof(EcmaString) + sizeof(uint8_t) * lengthEcmaStrAllocComp); + EXPECT_EQ(handleEcmaStrAllocComp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrAllocComp); size_t lengthEcmaStrAllocNotComp = 5; JSHandle handleEcmaStrAllocNotComp(thread, EcmaString::AllocStringObject(lengthEcmaStrAllocNotComp, false, ecmaVMPtr)); EXPECT_EQ(handleEcmaStrAllocNotComp->ObjectSize(), - sizeof(EcmaString) + sizeof(uint16_t) * lengthEcmaStrAllocNotComp); + EcmaString::SIZE + sizeof(uint16_t) * lengthEcmaStrAllocNotComp); uint8_t arrayU8[] = {"abcde"}; size_t lengthEcmaStrU8 = sizeof(arrayU8) - 1; JSHandle handleEcmaStrU8(thread, EcmaString::CreateFromUtf8(&arrayU8[0], lengthEcmaStrU8, ecmaVMPtr, true)); - EXPECT_EQ(handleEcmaStrU8->ObjectSize(), sizeof(EcmaString) + sizeof(uint8_t) * lengthEcmaStrU8); + EXPECT_EQ(handleEcmaStrU8->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrU8); // ObjectSize(). EcmaString made by CreateFromUtf16( , , , true). uint16_t arrayU16Comp[] = {1, 23, 45, 67, 127}; size_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]); JSHandle handleEcmaStrU16Comp(thread, EcmaString::CreateFromUtf16(&arrayU16Comp[0], lengthEcmaStrU16Comp, ecmaVMPtr, true)); - EXPECT_EQ(handleEcmaStrU16Comp->ObjectSize(), sizeof(EcmaString) + sizeof(uint8_t) * lengthEcmaStrU16Comp); + EXPECT_EQ(handleEcmaStrU16Comp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrU16Comp); // ObjectSize(). EcmaString made by CreateFromUtf16( , , , false). uint16_t arrayU16NotComp[] = {127, 128, 256, 11100, 65535}; size_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]); JSHandle handleEcmaStrU16NotComp(thread, EcmaString::CreateFromUtf16(&arrayU16NotComp[0], lengthEcmaStrU16NotComp, ecmaVMPtr, false)); - EXPECT_EQ(handleEcmaStrU16NotComp->ObjectSize(), sizeof(EcmaString) + sizeof(uint16_t) * lengthEcmaStrU16NotComp); + EXPECT_EQ(handleEcmaStrU16NotComp->ObjectSize(), EcmaString::SIZE + sizeof(uint16_t) * lengthEcmaStrU16NotComp); } /* diff --git a/ecmascript/tests/js_object_test.cpp b/ecmascript/tests/js_object_test.cpp index 21d849f4c2..1300618805 100644 --- a/ecmascript/tests/js_object_test.cpp +++ b/ecmascript/tests/js_object_test.cpp @@ -1180,7 +1180,7 @@ HWTEST_F_L0(JSObjectTest, NoticeThroughChain) JSTaggedValue listeners1Value = ProtoChangeDetails::Cast(protoDetails1.GetTaggedObject())->GetChangeListener(); EXPECT_TRUE(listeners1Value != JSTaggedValue(0)); JSHandle listeners1(thread, listeners1Value.GetTaggedObject()); - array_size_t holeIndex = ChangeListener::CheckHole(listeners1); + uint32_t holeIndex = ChangeListener::CheckHole(listeners1); EXPECT_TRUE(holeIndex == 0); JSTaggedValue protoDetails2 = obj2Dynclass->GetProtoChangeDetails(); diff --git a/ecmascript/tests/test_helper.h b/ecmascript/tests/test_helper.h index 9eea157c35..f00a6529b4 100755 --- a/ecmascript/tests/test_helper.h +++ b/ecmascript/tests/test_helper.h @@ -45,7 +45,7 @@ using ecmascript::JSRuntimeOptions; class TestHelper { public: static std::unique_ptr CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue newTgt, - array_size_t argvLength) + uint32_t argvLength) { const uint8_t testDecodedSize = 2; // argvLength includes number of int64_t to store value and tag of function, 'this' and call args diff --git a/ecmascript/tooling/agent/js_backend.cpp b/ecmascript/tooling/agent/js_backend.cpp index f0f0fce4f8..cb8a9ab8bf 100644 --- a/ecmascript/tooling/agent/js_backend.cpp +++ b/ecmascript/tooling/agent/js_backend.cpp @@ -702,9 +702,9 @@ void JSBackend::GetProperties(uint32_t objectId, bool isOwn, bool isAccessorOnly return; } Local keys = Local(value)->GetOwnPropertyNames(ecmaVm_); - array_size_t length = keys->Length(ecmaVm_); + uint32_t length = keys->Length(ecmaVm_); Local name = JSValueRef::Undefined(ecmaVm_); - for (array_size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { name = keys->Get(ecmaVm_, i); PropertyAttribute jsProperty = PropertyAttribute::Default(); if (!Local(value)->GetOwnProperty(ecmaVm_, name, jsProperty)) { diff --git a/ecmascript/tooling/base/pt_params.cpp b/ecmascript/tooling/base/pt_params.cpp index 2893c27617..b93b78b394 100644 --- a/ecmascript/tooling/base/pt_params.cpp +++ b/ecmascript/tooling/base/pt_params.cpp @@ -309,7 +309,7 @@ std::unique_ptr SetBlackboxPatternsParams::Create(con Local array = Local(result); uint32_t len = array->Length(ecmaVm); Local key = JSValueRef::Undefined(ecmaVm); - for (array_size_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { key = IntegerRef::New(ecmaVm, i); Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); if (value->IsString()) { @@ -460,7 +460,7 @@ std::unique_ptr StepIntoParams::Create(const EcmaVM *ecmaVm, con Local array = Local(result); uint32_t len = array->Length(ecmaVm); Local key = JSValueRef::Undefined(ecmaVm); - for (array_size_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { key = IntegerRef::New(ecmaVm, i); Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); if (value->IsObject()) { @@ -503,7 +503,7 @@ std::unique_ptr StepOverParams::Create(const EcmaVM *ecmaVm, con Local array = Local(result); uint32_t len = array->Length(ecmaVm); Local key = JSValueRef::Undefined(ecmaVm); - for (array_size_t i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { key = IntegerRef::New(ecmaVm, i); Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); if (value->IsObject()) { diff --git a/ecmascript/weak_vector-inl.h b/ecmascript/weak_vector-inl.h index d17c66aa7e..7e515d0f3b 100644 --- a/ecmascript/weak_vector-inl.h +++ b/ecmascript/weak_vector-inl.h @@ -20,7 +20,7 @@ #include "tagged_array-inl.h" namespace panda::ecmascript { -array_size_t WeakVector::GetEnd() const +uint32_t WeakVector::GetEnd() const { return TaggedArray::Get(END_INDEX).GetArrayLength(); } @@ -35,24 +35,24 @@ bool WeakVector::Empty() const return GetEnd() == 0; } -array_size_t WeakVector::GetCapacity() const +uint32_t WeakVector::GetCapacity() const { return TaggedArray::GetLength() - ELEMENTS_START_INDEX; } -JSTaggedValue WeakVector::Get(array_size_t index) const +JSTaggedValue WeakVector::Get(uint32_t index) const { ASSERT(index < GetCapacity()); return TaggedArray::Get(VectorToArrayIndex(index)); } -void WeakVector::Set(const JSThread *thread, array_size_t index, JSTaggedValue value) +void WeakVector::Set(const JSThread *thread, uint32_t index, JSTaggedValue value) { ASSERT(index < GetCapacity()); TaggedArray::Set(thread, VectorToArrayIndex(index), value); } -void WeakVector::SetEnd(const JSThread *thread, array_size_t end) +void WeakVector::SetEnd(const JSThread *thread, uint32_t end) { ASSERT(end <= GetCapacity()); TaggedArray::Set(thread, END_INDEX, JSTaggedValue(end)); diff --git a/ecmascript/weak_vector.cpp b/ecmascript/weak_vector.cpp index 2809a115f6..2cade2e4a6 100644 --- a/ecmascript/weak_vector.cpp +++ b/ecmascript/weak_vector.cpp @@ -18,20 +18,20 @@ #include "ecmascript/weak_vector-inl.h" namespace panda::ecmascript { -JSHandle WeakVector::Create(const JSThread *thread, array_size_t capacity) +JSHandle WeakVector::Create(const JSThread *thread, uint32_t capacity) { ASSERT(capacity < MAX_VECTOR_INDEX); - array_size_t length = VectorToArrayIndex(capacity); + uint32_t length = VectorToArrayIndex(capacity); JSHandle vector = JSHandle(thread->GetEcmaVM()->GetFactory()->NewTaggedArray(length)); vector->SetEnd(thread, 0); return vector; } -bool WeakVector::Delete(const JSThread *thread, array_size_t index) +bool WeakVector::Delete(const JSThread *thread, uint32_t index) { - array_size_t end = GetEnd(); + uint32_t end = GetEnd(); if (index < end) { Set(thread, index, JSTaggedValue::Hole()); return true; @@ -39,9 +39,9 @@ bool WeakVector::Delete(const JSThread *thread, array_size_t index) return false; } -JSHandle WeakVector::Grow(const JSThread *thread, const JSHandle &old, array_size_t newCapacity) +JSHandle WeakVector::Grow(const JSThread *thread, const JSHandle &old, uint32_t newCapacity) { - array_size_t oldCapacity = old->GetCapacity(); + uint32_t oldCapacity = old->GetCapacity(); ASSERT(newCapacity > oldCapacity); if (oldCapacity == MAX_VECTOR_INDEX) { return old; @@ -58,9 +58,9 @@ JSHandle WeakVector::Grow(const JSThread *thread, const JSHandle(newVec); } -array_size_t WeakVector::PushBack(const JSThread *thread, JSTaggedValue value) +uint32_t WeakVector::PushBack(const JSThread *thread, JSTaggedValue value) { - array_size_t end = GetEnd(); + uint32_t end = GetEnd(); if (end == GetCapacity()) { return TaggedArray::MAX_ARRAY_INDEX; } diff --git a/ecmascript/weak_vector.h b/ecmascript/weak_vector.h index 0e8eb02c96..6d14d7856e 100644 --- a/ecmascript/weak_vector.h +++ b/ecmascript/weak_vector.h @@ -28,37 +28,37 @@ public: return static_cast(object); } - static constexpr array_size_t DEFALUT_CAPACITY = 4; - static JSHandle Create(const JSThread *thread, array_size_t capacity = DEFALUT_CAPACITY); - static JSHandle Grow(const JSThread *thread, const JSHandle &old, array_size_t newCapacity); - array_size_t PushBack(const JSThread *thread, JSTaggedValue value); + static constexpr uint32_t DEFALUT_CAPACITY = 4; + static JSHandle Create(const JSThread *thread, uint32_t capacity = DEFALUT_CAPACITY); + static JSHandle Grow(const JSThread *thread, const JSHandle &old, uint32_t newCapacity); + uint32_t PushBack(const JSThread *thread, JSTaggedValue value); // just set index value to Hole - bool Delete(const JSThread *thread, array_size_t index); + bool Delete(const JSThread *thread, uint32_t index); - inline array_size_t GetEnd() const; + inline uint32_t GetEnd() const; inline bool Full() const; inline bool Empty() const; - inline array_size_t GetCapacity() const; + inline uint32_t GetCapacity() const; - inline JSTaggedValue Get(array_size_t index) const; + inline JSTaggedValue Get(uint32_t index) const; - inline void Set(const JSThread *thread, array_size_t index, JSTaggedValue value); + inline void Set(const JSThread *thread, uint32_t index, JSTaggedValue value); private: - static const array_size_t MIN_CAPACITY = 2; - static const array_size_t END_INDEX = 0; - static const array_size_t ELEMENTS_START_INDEX = 1; - static const array_size_t MAX_VECTOR_INDEX = TaggedArray::MAX_ARRAY_INDEX - ELEMENTS_START_INDEX; + static const uint32_t MIN_CAPACITY = 2; + static const uint32_t END_INDEX = 0; + static const uint32_t ELEMENTS_START_INDEX = 1; + static const uint32_t MAX_VECTOR_INDEX = TaggedArray::MAX_ARRAY_INDEX - ELEMENTS_START_INDEX; - inline static constexpr array_size_t VectorToArrayIndex(array_size_t index) + inline static constexpr uint32_t VectorToArrayIndex(uint32_t index) { return index + ELEMENTS_START_INDEX; } - inline void SetEnd(const JSThread *thread, array_size_t end); + inline void SetEnd(const JSThread *thread, uint32_t end); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_WEAK_VECTOR_H -- Gitee