!10240 SharedBitvector part2

Merge pull request !10240 from chengyuli/SharedBitVector
This commit is contained in:
openharmony_ci 2024-11-15 09:46:45 +00:00 committed by Gitee
commit 264dc89213
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 16 additions and 4 deletions

View File

@ -51,7 +51,7 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg
auto* newBitSetVector = new std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>>();
if (!length->IsZero()) {
int32_t capacity = (length->GetInt() / JSAPIBitVector::BIT_SET_LENGTH) + 1;
int32_t capacity = std::max(0, (length->GetInt() / JSAPIBitVector::BIT_SET_LENGTH) + 1);
std::bitset<JSAPIBitVector::BIT_SET_LENGTH> initBitSet;
newBitSetVector->resize(capacity, initBitSet);
@ -60,7 +60,7 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg
ContainersBitVector::FreeBitsetVectorPointer,
newBitSetVector);
obj->SetNativePointer(thread, pointer);
obj->SetLength(length->GetInt());
obj->SetLength(std::max(0, length->GetInt()));
return obj.GetTaggedValue();
}

View File

@ -359,7 +359,7 @@ JSTaggedValue JSAPIBitVector::FlipBitByIndex(JSThread* thread, const JSHandle<JS
{
[[maybe_unused]] ConcurrentApiScope<JSAPIBitVector, ModType::WRITE> scope(thread,
JSHandle<JSTaggedValue>::Cast(bitVector));
if (index >= bitVector->GetLength()) {
if (index >= bitVector->GetLength() || index < 0) {
std::ostringstream oss;
oss << "The value of \"index\" is out of range. It must be >= 0 && <= " << (bitVector->GetLength() - 1)
<< ". Received value is: " << index;

View File

@ -80,7 +80,9 @@ public:
ACCESSORS_PRIMITIVE_FIELD(Length, int32_t, LENGTH_OFFSET, MOD_RECORD_OFFSET);
ACCESSORS_SYNCHRONIZED_PRIMITIVE_FIELD(ModRecord, uint32_t, MOD_RECORD_OFFSET, LAST_OFFSET);
DEFINE_ALIGN_SIZE(LAST_OFFSET);
static constexpr uint32_t MAX_INLINE = PropertyAttributes::MAX_FAST_PROPS_CAPACITY -
SIZE / JSTaggedValue::TaggedTypeSize() + 1;
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, NATIVE_POINTER_OFFSET, LENGTH_OFFSET);
DECL_DUMP()

View File

@ -15,6 +15,7 @@
#include "ecmascript/jspandafile/class_info_extractor.h"
#include "ecmascript/js_api/js_api_bitvector.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/jspandafile/program_object.h"
#include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
@ -1179,6 +1180,8 @@ std::pair<uint32_t, uint32_t> SendableClassDefiner::GetSizeAndMaxInlineByType(JS
return { JSSharedSet::SIZE, JSSharedSet::MAX_INLINE };
case JSType::JS_SENDABLE_ARRAY_BUFFER:
return { JSSendableArrayBuffer::SIZE, JSSendableArrayBuffer::MAX_INLINE };
case JSType::JS_API_BITVECTOR:
return { JSAPIBitVector::SIZE, JSAPIBitVector::MAX_INLINE };
default:
if (JSType::JS_SHARED_TYPED_ARRAY_FIRST < type && type <= JSType::JS_SHARED_TYPED_ARRAY_LAST) {
return { JSSharedTypedArray::SIZE, JSSharedTypedArray::MAX_INLINE };

View File

@ -602,6 +602,7 @@ public:
bool IsTreeMap(const EcmaVM *vm);
bool IsTreeSet(const EcmaVM *vm);
bool IsVector(const EcmaVM *vm);
bool IsBitVector(const EcmaVM *vm);
bool IsSendableObject(const EcmaVM *vm);
bool IsJSShared(const EcmaVM *vm);
bool IsSharedArray(const EcmaVM *vm);

View File

@ -1004,6 +1004,12 @@ bool JSValueRef::IsVector(const EcmaVM *vm)
return JSNApiHelper::ToJSTaggedValue(this).IsJSAPIVector();
}
bool JSValueRef::IsBitVector(const EcmaVM *vm)
{
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
return JSNApiHelper::ToJSTaggedValue(this).IsJSAPIBitVector();
}
bool JSValueRef::IsSendableObject(const EcmaVM *vm)
{
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());