mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 10:09:54 +00:00
!10154 SharedBitVector
Merge pull request !10154 from YuliCheng/SharedBitVector
This commit is contained in:
commit
0f15d3f637
@ -48,6 +48,9 @@ public:
|
||||
void Initialize(const JSHandle<GlobalEnv> &env, JSThread *thread, bool lazyInit = false, bool isRealm = false);
|
||||
void InitializeForSnapshot(JSThread *thread);
|
||||
|
||||
void InitializeSharedBitVector(const JSHandle<GlobalEnv> &env,
|
||||
const JSHandle<JSObject> &sObjPrototype,
|
||||
const JSHandle<JSFunction> &sFuncPrototype) const;
|
||||
private:
|
||||
JSThread *thread_{nullptr};
|
||||
ObjectFactory *factory_{nullptr};
|
||||
@ -443,7 +446,9 @@ private:
|
||||
JSHandle<JSHClass> CreateSSetPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const;
|
||||
JSHandle<JSHClass> CreateSSetFunctionHClass(const JSHandle<JSFunction> &sFuncPrototype) const;
|
||||
JSHandle<JSHClass> CreateSMapPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const;
|
||||
JSHandle<JSHClass> CreateBitVectorPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const;
|
||||
JSHandle<JSHClass> CreateSMapFunctionHClass(const JSHandle<JSFunction> &sFuncPrototype) const;
|
||||
JSHandle<JSHClass> CreateBitVectorFunctionHClass(const JSHandle<JSFunction> &sFuncPrototype) const;
|
||||
JSHandle<JSHClass> CreateSArrayPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const;
|
||||
JSHandle<JSHClass> CreateSArrayFunctionHClass(const JSHandle<JSFunction> &sFuncPrototype) const;
|
||||
JSHandle<JSHClass> CreateSTypedArrayPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const;
|
||||
|
@ -25,6 +25,9 @@
|
||||
#include "ecmascript/builtins/builtins_shared_map.h"
|
||||
#include "ecmascript/builtins/builtins_shared_set.h"
|
||||
#include "ecmascript/builtins/builtins_shared_typedarray.h"
|
||||
#include "ecmascript/containers/containers_bitvector.h"
|
||||
#include "ecmascript/containers/containers_private.h"
|
||||
#include "ecmascript/js_api/js_api_bitvector.h"
|
||||
#include "ecmascript/shared_objects/js_shared_array.h"
|
||||
#include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
|
||||
#include "ecmascript/shared_objects/js_shared_map.h"
|
||||
@ -46,6 +49,7 @@ using BuiltinsSharedMap = builtins::BuiltinsSharedMap;
|
||||
using BuiltinsSharedArray = builtins::BuiltinsSharedArray;
|
||||
using BuiltinsSharedTypedArray = builtins::BuiltinsSharedTypedArray;
|
||||
using BuiltinsSendableArrayBuffer = builtins::BuiltinsSendableArrayBuffer;
|
||||
using ContainersBitVector = containers::ContainersBitVector;
|
||||
|
||||
void Builtins::InitializeSObjectAndSFunction(const JSHandle<GlobalEnv> &env) const
|
||||
{
|
||||
@ -572,6 +576,35 @@ JSHandle<JSHClass> Builtins::CreateSMapFunctionHClass(const JSHandle<JSFunction>
|
||||
return sobjPrototypeHClass;
|
||||
}
|
||||
|
||||
JSHandle<JSHClass> Builtins::CreateBitVectorFunctionHClass(const JSHandle<JSFunction> &sFuncPrototype) const
|
||||
{
|
||||
uint32_t index = 0;
|
||||
auto env = vm_->GetGlobalEnv();
|
||||
PropertyAttributes attributes = PropertyAttributes::Default(false, false, false);
|
||||
attributes.SetIsInlinedProps(true);
|
||||
attributes.SetRepresentation(Representation::TAGGED);
|
||||
auto properties = ContainersBitVector::GetFunctionProperties();
|
||||
uint32_t length = properties.size();
|
||||
JSHandle<JSTaggedValue> keyString;
|
||||
JSHandle<LayoutInfo> layout = factory_->CreateSLayoutInfo(length);
|
||||
for (const auto &[key, isAccessor] : properties) {
|
||||
attributes.SetOffset(index);
|
||||
attributes.SetIsAccessor(isAccessor);
|
||||
if (key == "[Symbol.species]") {
|
||||
keyString = env->GetSpeciesSymbol();
|
||||
} else {
|
||||
keyString = JSHandle<JSTaggedValue>(factory_->NewFromUtf8ReadOnly(key));
|
||||
}
|
||||
layout->AddKey(thread_, index++, keyString.GetTaggedValue(), attributes);
|
||||
}
|
||||
JSHandle<JSHClass> sobjPrototypeHClass =
|
||||
factory_->NewSEcmaHClass(JSSharedFunction::SIZE, length, JSType::JS_SHARED_FUNCTION,
|
||||
JSHandle<JSTaggedValue>(sFuncPrototype), JSHandle<JSTaggedValue>(layout));
|
||||
sobjPrototypeHClass->SetConstructor(true);
|
||||
sobjPrototypeHClass->SetCallable(true);
|
||||
return sobjPrototypeHClass;
|
||||
}
|
||||
|
||||
JSHandle<JSHClass> Builtins::CreateSFunctionPrototypeHClass(const JSHandle<JSTaggedValue> &sObjPrototypeVal) const
|
||||
{
|
||||
uint32_t index = 0;
|
||||
@ -691,6 +724,37 @@ JSHandle<JSHClass> Builtins::CreateSMapPrototypeHClass(const JSHandle<JSObject>
|
||||
return sMapPrototypeHClass;
|
||||
}
|
||||
|
||||
JSHandle<JSHClass> Builtins::CreateBitVectorPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const
|
||||
{
|
||||
uint32_t index = 0;
|
||||
auto env = vm_->GetGlobalEnv();
|
||||
PropertyAttributes attributes = PropertyAttributes::Default(false, false, false);
|
||||
attributes.SetIsInlinedProps(true);
|
||||
attributes.SetRepresentation(Representation::TAGGED);
|
||||
auto properties = ContainersBitVector::GetPrototypeProperties();
|
||||
uint32_t length = properties.size();
|
||||
ASSERT(length == ContainersBitVector::GetNumPrototypeInlinedProperties());
|
||||
JSHandle<LayoutInfo> layout = factory_->CreateSLayoutInfo(length);
|
||||
JSHandle<JSTaggedValue> keyString;
|
||||
for (const auto &[key, isAccessor] : properties) {
|
||||
attributes.SetOffset(index);
|
||||
attributes.SetIsAccessor(isAccessor);
|
||||
if (key == "[Symbol.iterator]") {
|
||||
keyString = env->GetIteratorSymbol();
|
||||
} else if (key == "[Symbol.toStringTag]") {
|
||||
keyString = env->GetToStringTagSymbol();
|
||||
} else {
|
||||
keyString = JSHandle<JSTaggedValue>(factory_->NewFromUtf8ReadOnly(key));
|
||||
}
|
||||
layout->AddKey(thread_, index++, keyString.GetTaggedValue(), attributes);
|
||||
}
|
||||
JSHandle<JSHClass> sBitVectorPrototypeHClass =
|
||||
factory_->NewSEcmaHClass(JSSharedObject::SIZE, length, JSType::JS_SHARED_OBJECT,
|
||||
JSHandle<JSTaggedValue>(sObjPrototype),
|
||||
JSHandle<JSTaggedValue>(layout));
|
||||
return sBitVectorPrototypeHClass;
|
||||
}
|
||||
|
||||
JSHandle<JSHClass> Builtins::CreateSArrayPrototypeHClass(const JSHandle<JSObject> &sObjPrototype) const
|
||||
{
|
||||
uint32_t index = 0;
|
||||
@ -983,6 +1047,56 @@ void Builtins::InitializeSharedArray(const JSHandle<GlobalEnv> &env, const JSHan
|
||||
env->SetSharedArrayPrototype(thread_, arrFuncPrototype);
|
||||
}
|
||||
|
||||
void Builtins::InitializeSharedBitVector(const JSHandle<GlobalEnv> &env, const JSHandle<JSObject> &sObjPrototype,
|
||||
const JSHandle<JSFunction> &sFuncPrototype) const
|
||||
{
|
||||
[[maybe_unused]] EcmaHandleScope scope(thread_);
|
||||
auto globalConst = const_cast<GlobalEnvConstants*>(thread_->GlobalConstants());
|
||||
// BitVector.prototype
|
||||
JSHandle<JSHClass> prototypeHClass = CreateBitVectorPrototypeHClass(sObjPrototype);
|
||||
JSHandle<JSObject> bitVectorFuncPrototype = factory_->NewSharedOldSpaceJSObjectWithInit(prototypeHClass);
|
||||
JSHandle<JSTaggedValue> bitVectorFuncPrototypeValue(bitVectorFuncPrototype);
|
||||
|
||||
// BitVector.prototype_or_hclass
|
||||
auto emptySLayout = globalConst->GetHandledEmptySLayoutInfo();
|
||||
JSHandle<JSHClass> bitVectorInstanceClass =
|
||||
factory_->NewSEcmaHClass(JSAPIBitVector::SIZE, 0,
|
||||
JSType::JS_API_BITVECTOR, bitVectorFuncPrototypeValue, emptySLayout);
|
||||
|
||||
// BitVector.hclass
|
||||
JSHandle<JSHClass> bitVectorFuncHClass = CreateBitVectorFunctionHClass(sFuncPrototype);
|
||||
bitVectorFuncHClass->SetExtensible(false);
|
||||
|
||||
// BitVector() = new Function()
|
||||
JSHandle<JSFunction> bitVectorFunction =
|
||||
factory_->NewSFunctionByHClass(reinterpret_cast<void *>(ContainersBitVector::BitVectorConstructor),
|
||||
bitVectorFuncHClass, FunctionKind::BUILTIN_CONSTRUCTOR);
|
||||
InitializeSCtor(bitVectorInstanceClass, bitVectorFunction, "BitVector", FunctionLength::ONE);
|
||||
// BitVector.prototype
|
||||
int32_t protoFieldIndex = 0;
|
||||
bitVectorFuncPrototype->SetPropertyInlinedProps(thread_, protoFieldIndex++, bitVectorFunction.GetTaggedValue());
|
||||
for (const base::BuiltinFunctionEntry &entry: ContainersBitVector::GetBitVectorPrototypeFunctions()) {
|
||||
SetSFunction(env, bitVectorFuncPrototype, entry.GetName(), entry.GetEntrypoint(), protoFieldIndex++,
|
||||
entry.GetLength(), entry.GetBuiltinStubId());
|
||||
}
|
||||
// @@StringTag
|
||||
JSHandle<JSTaggedValue> strTag(factory_->NewFromUtf8ReadOnly("BitVector"));
|
||||
bitVectorFuncPrototype->SetPropertyInlinedProps(thread_, protoFieldIndex++, strTag.GetTaggedValue());
|
||||
|
||||
JSHandle<JSTaggedValue> sizeGetter = CreateSGetterSetter(env, ContainersBitVector::GetSize, "size",
|
||||
FunctionLength::ZERO);
|
||||
JSHandle<JSTaggedValue> lengthGetter = CreateSGetterSetter(env, ContainersBitVector::GetSize, "length",
|
||||
FunctionLength::ZERO);
|
||||
SetSAccessor(bitVectorFuncPrototype, protoFieldIndex++, sizeGetter, globalConst->GetHandledUndefined());
|
||||
SetSAccessor(bitVectorFuncPrototype, protoFieldIndex++, lengthGetter, globalConst->GetHandledUndefined());
|
||||
|
||||
SetSFunction(env, bitVectorFuncPrototype, "[Symbol.iterator]",
|
||||
ContainersBitVector::GetIteratorObj, protoFieldIndex++, FunctionLength::ONE);
|
||||
env->SetBitVectorPrototype(thread_, bitVectorFuncPrototype);
|
||||
env->SetBitVectorFunction(thread_, bitVectorFunction);
|
||||
}
|
||||
|
||||
|
||||
// todo: remove sendableName when refactor
|
||||
#define BUILTIN_SHARED_TYPED_ARRAY_DEFINE_INITIALIZE(Type, ctorName, TYPE, bytesPerElement, sendableName) \
|
||||
void Builtins::InitializeS##Type(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &arrFuncClass) const \
|
||||
|
@ -34,8 +34,10 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg
|
||||
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception());
|
||||
}
|
||||
JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
|
||||
ASSERT(constructor->IsJSSharedFunction() && constructor.GetTaggedValue().IsInSharedHeap());
|
||||
JSHandle<JSAPIBitVector> obj =
|
||||
JSHandle<JSAPIBitVector>(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget));
|
||||
ASSERT(obj.GetTaggedValue().IsInSharedHeap());
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
|
||||
|
||||
JSHandle<JSTaggedValue> length = GetCallArg(argv, 0);
|
||||
@ -54,8 +56,9 @@ JSTaggedValue ContainersBitVector::BitVectorConstructor(EcmaRuntimeCallInfo* arg
|
||||
std::bitset<JSAPIBitVector::BIT_SET_LENGTH> initBitSet;
|
||||
newBitSetVector->resize(capacity, initBitSet);
|
||||
}
|
||||
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(newBitSetVector,
|
||||
ContainersBitVector::FreeBitsetVectorPointer);
|
||||
JSHandle<JSNativePointer> pointer = factory->NewSJSNativePointer(newBitSetVector,
|
||||
ContainersBitVector::FreeBitsetVectorPointer,
|
||||
newBitSetVector);
|
||||
obj->SetNativePointer(thread, pointer);
|
||||
obj->SetLength(length->GetInt());
|
||||
return obj.GetTaggedValue();
|
||||
|
@ -19,6 +19,21 @@
|
||||
#include "ecmascript/base/builtins_base.h"
|
||||
#include "ecmascript/ecma_runtime_call_info.h"
|
||||
|
||||
#define BUILTIN_BITVECTOR_PROTOTYPE_FUNCTIONS(V) \
|
||||
V("push", Push, 1, INVALID) \
|
||||
V("pop", Pop, 0, INVALID) \
|
||||
V("has", Has, 3, INVALID) \
|
||||
V("setBitsByRange", SetBitsByRange, 3, INVALID) \
|
||||
V("getBitsByRange", GetBitsByRange, 2, INVALID) \
|
||||
V("setAllBits", SetAllBits, 1, INVALID) \
|
||||
V("resize", Resize, 1, INVALID) \
|
||||
V("getBitCountByRange", GetBitCountByRange, 3, INVALID) \
|
||||
V("getIndexOf", GetIndexOf, 3, INVALID) \
|
||||
V("getLastIndexOf", GetLastIndexOf, 3, INVALID) \
|
||||
V("flipBitByIndex", FlipBitByIndex, 1, INVALID) \
|
||||
V("flipBitsByRange", FlipBitsByRange, 2, INVALID) \
|
||||
V("values", GetIteratorObj, 0, INVALID)
|
||||
|
||||
namespace panda::ecmascript::containers {
|
||||
class ContainersBitVector : public base::BuiltinsBase {
|
||||
public:
|
||||
@ -37,8 +52,63 @@ public:
|
||||
static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo* argv);
|
||||
static JSTaggedValue GetSize(EcmaRuntimeCallInfo* argv);
|
||||
static JSTaggedValue SetAllBits(EcmaRuntimeCallInfo* argv);
|
||||
|
||||
// Excluding the constructor and '@@' internal properties.
|
||||
static Span<const base::BuiltinFunctionEntry> GetBitVectorPrototypeFunctions()
|
||||
{
|
||||
return Span<const base::BuiltinFunctionEntry>(BITVECTOR_PROTOTYPE_FUNCTIONS);
|
||||
}
|
||||
|
||||
static size_t GetNumPrototypeInlinedProperties()
|
||||
{
|
||||
// 4 : 4 more inline properties in BitVector.prototype
|
||||
// (1) BitVector.prototype.constructor
|
||||
// (2) BitVector.prototype [ @@toStringTag ]
|
||||
// (3) BitVector.prototype [ @@iterator ]
|
||||
// (4) get BitVector.prototype.size
|
||||
// (5) get BitVector.prototype.length
|
||||
return GetBitVectorPrototypeFunctions().Size() + 5;
|
||||
}
|
||||
|
||||
static Span<const std::pair<std::string_view, bool>> GetPrototypeProperties()
|
||||
{
|
||||
return Span<const std::pair<std::string_view, bool>>(BITVECTOR_PROTOTYPE_PROPERTIES);
|
||||
}
|
||||
|
||||
static Span<const std::pair<std::string_view, bool>> GetFunctionProperties()
|
||||
{
|
||||
return Span<const std::pair<std::string_view, bool>>(BITVECTOR_FUNCTION_PROPERTIES);
|
||||
}
|
||||
private:
|
||||
static void FreeBitsetVectorPointer([[maybe_unused]] void *env, void *pointer, void *data);
|
||||
|
||||
#define BUILTIN_BITVECTOR_FUNCTION_ENTRY(name, func, length, id) \
|
||||
base::BuiltinFunctionEntry::Create(name, ContainersBitVector::func, length, kungfu::BuiltinsStubCSigns::id),
|
||||
|
||||
static constexpr std::array BITVECTOR_PROTOTYPE_FUNCTIONS = {
|
||||
BUILTIN_BITVECTOR_PROTOTYPE_FUNCTIONS(BUILTIN_BITVECTOR_FUNCTION_ENTRY)
|
||||
};
|
||||
#undef BUILTIN_BITVECTOR_FUNCTION_ENTRY
|
||||
|
||||
#define BITVECTOR_PROPERTIES_PAIR(name, func, length, id) \
|
||||
std::pair<std::string_view, bool>(name, false),
|
||||
|
||||
static constexpr std::array BITVECTOR_PROTOTYPE_PROPERTIES = {
|
||||
std::pair<std::string_view, bool>("constructor", false),
|
||||
BUILTIN_BITVECTOR_PROTOTYPE_FUNCTIONS(BITVECTOR_PROPERTIES_PAIR)
|
||||
std::pair<std::string_view, bool>("[Symbol.toStringTag]", false),
|
||||
std::pair<std::string_view, bool>("length", true),
|
||||
std::pair<std::string_view, bool>("size", true),
|
||||
std::pair<std::string_view, bool>("[Symbol.iterator]", false)
|
||||
};
|
||||
|
||||
static constexpr std::array BITVECTOR_FUNCTION_PROPERTIES = {
|
||||
std::pair<std::string_view, bool>("length", false),
|
||||
std::pair<std::string_view, bool>("name", false),
|
||||
std::pair<std::string_view, bool>("prototype", false),
|
||||
std::pair<std::string_view, bool>("[Symbol.species]", true),
|
||||
};
|
||||
#undef BITVECTOR_PROPERTIES_PAIR
|
||||
};
|
||||
} // namespace panda::ecmascript::containers
|
||||
#endif // ECMASCRIPT_CONTAINERS_CONTAINERS_BIT_VECTOR_H
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "containers_treemap.h"
|
||||
#include "containers_treeset.h"
|
||||
#include "containers_vector.h"
|
||||
#include "ecmascript/global_env_fields.h"
|
||||
#include "ecmascript/js_api/js_api_arraylist_iterator.h"
|
||||
#include "ecmascript/js_api/js_api_bitvector_iterator.h"
|
||||
#include "ecmascript/js_api/js_api_deque_iterator.h"
|
||||
@ -50,6 +51,7 @@
|
||||
#include "ecmascript/js_api/js_api_tree_set_iterator.h"
|
||||
#include "ecmascript/js_api/js_api_tree_set.h"
|
||||
#include "ecmascript/js_api/js_api_vector_iterator.h"
|
||||
#include "ecmascript/builtins/builtins.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
|
||||
namespace panda::ecmascript::containers {
|
||||
@ -195,7 +197,9 @@ void ContainersPrivate::SetFrozenFunction(JSThread *thread, const JSHandle<JSObj
|
||||
void ContainersPrivate::SetFrozenConstructor(JSThread *thread, const JSHandle<JSObject> &obj, const char *keyChar,
|
||||
JSHandle<JSTaggedValue> &value)
|
||||
{
|
||||
JSObject::PreventExtensions(thread, JSHandle<JSObject>::Cast(value));
|
||||
if (value->IsECMAObject()) {
|
||||
JSObject::PreventExtensions(thread, JSHandle<JSObject>::Cast(value));
|
||||
}
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSTaggedValue> key(factory->NewFromASCII(keyChar));
|
||||
PropertyDescriptor descriptor(thread, value, false, false, false);
|
||||
@ -849,53 +853,15 @@ void ContainersPrivate::InitializeVectorIterator(JSThread *thread, const JSHandl
|
||||
JSHandle<JSTaggedValue> ContainersPrivate::InitializeBitVector(JSThread* thread)
|
||||
{
|
||||
auto globalConst = const_cast<GlobalEnvConstants*>(thread->GlobalConstants());
|
||||
ObjectFactory* factory = thread->GetEcmaVM()->GetFactory();
|
||||
// BitVector.prototype
|
||||
JSHandle<JSObject> prototype = factory->NewEmptyJSObject();
|
||||
JSHandle<JSTaggedValue> bitVectorFuncPrototypeValue(prototype);
|
||||
// BitVector.prototype_or_hclass
|
||||
JSHandle<JSHClass> bitVectorInstanceClass =
|
||||
factory->NewEcmaHClass(JSAPIBitVector::SIZE, JSType::JS_API_BITVECTOR, bitVectorFuncPrototypeValue);
|
||||
// BitVector() = new Function()
|
||||
JSHandle<JSTaggedValue> bitVectorFunction(NewContainerConstructor(
|
||||
thread, prototype, ContainersBitVector::BitVectorConstructor, "BitVector", FuncLength::ONE));
|
||||
JSFunction::SetFunctionPrototypeOrInstanceHClass(
|
||||
thread, JSHandle<JSFunction>::Cast(bitVectorFunction), bitVectorInstanceClass.GetTaggedValue());
|
||||
|
||||
// "constructor" property on the prototype
|
||||
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
|
||||
JSObject::SetProperty(thread, JSHandle<JSTaggedValue>(prototype), constructorKey, bitVectorFunction);
|
||||
RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
|
||||
|
||||
// BitVector.prototype
|
||||
SetFrozenFunction(thread, prototype, "push", ContainersBitVector::Push, FuncLength::ONE);
|
||||
SetFrozenFunction(thread, prototype, "pop", ContainersBitVector::Pop, FuncLength::ZERO);
|
||||
SetFrozenFunction(thread, prototype, "has", ContainersBitVector::Has, FuncLength::THREE);
|
||||
SetFrozenFunction(thread, prototype, "setBitsByRange", ContainersBitVector::SetBitsByRange, FuncLength::THREE);
|
||||
SetFrozenFunction(thread, prototype, "getBitsByRange", ContainersBitVector::GetBitsByRange, FuncLength::TWO);
|
||||
SetFrozenFunction(thread, prototype, "setAllBits", ContainersBitVector::SetAllBits, FuncLength::ONE);
|
||||
SetFrozenFunction(thread, prototype, "resize", ContainersBitVector::Resize, FuncLength::ONE);
|
||||
SetFrozenFunction(
|
||||
thread, prototype, "getBitCountByRange", ContainersBitVector::GetBitCountByRange, FuncLength::THREE);
|
||||
SetFrozenFunction(thread, prototype, "getIndexOf", ContainersBitVector::GetIndexOf, FuncLength::THREE);
|
||||
SetFrozenFunction(thread, prototype, "getLastIndexOf", ContainersBitVector::GetLastIndexOf, FuncLength::THREE);
|
||||
SetFrozenFunction(thread, prototype, "flipBitByIndex", ContainersBitVector::FlipBitByIndex, FuncLength::ONE);
|
||||
SetFrozenFunction(thread, prototype, "flipBitsByRange", ContainersBitVector::FlipBitsByRange, FuncLength::TWO);
|
||||
SetFrozenFunction(thread, prototype, "values", ContainersBitVector::GetIteratorObj, FuncLength::ZERO);
|
||||
|
||||
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
SetStringTagSymbol(thread, env, prototype, "BitVector");
|
||||
|
||||
JSHandle<JSTaggedValue> lengthGetter =
|
||||
CreateGetter(thread, ContainersBitVector::GetSize, "length", FuncLength::ZERO);
|
||||
JSHandle<JSTaggedValue> lengthKey(thread, globalConst->GetLengthString());
|
||||
SetGetter(thread, prototype, lengthKey, lengthGetter);
|
||||
|
||||
SetFunctionAtSymbol(thread, env, prototype, env->GetIteratorSymbol(), "[Symbol.iterator]",
|
||||
ContainersBitVector::GetIteratorObj, FuncLength::ONE);
|
||||
ContainersPrivate::InitializeBitVectorIterator(thread, env, globalConst);
|
||||
|
||||
globalConst->SetConstant(ConstantIndex::BITVECTOR_FUNCTION_INDEX, bitVectorFunction.GetTaggedValue());
|
||||
auto vm = thread->GetEcmaVM();
|
||||
ObjectFactory* factory = vm->GetFactory();
|
||||
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
|
||||
Builtins builtin(thread, factory, vm);
|
||||
JSHandle<JSObject> sObjPrototype = JSHandle<JSObject>::Cast(env->GetSObjectFunctionPrototype());
|
||||
JSHandle<JSFunction> sFuncPrototype = JSHandle<JSFunction>::Cast(env->GetSFunctionPrototype());
|
||||
builtin.InitializeSharedBitVector(env, sObjPrototype, sFuncPrototype);
|
||||
InitializeBitVectorIterator(thread, env, globalConst);
|
||||
JSHandle<JSTaggedValue> bitVectorFunction = env->GetBitVectorFunction();
|
||||
return bitVectorFunction;
|
||||
}
|
||||
|
||||
@ -903,15 +869,13 @@ void ContainersPrivate::InitializeBitVectorIterator(
|
||||
JSThread* thread, const JSHandle<GlobalEnv>& env, GlobalEnvConstants* globalConst)
|
||||
{
|
||||
ObjectFactory* factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<JSHClass> iteratorFuncHClass =
|
||||
JSHandle<JSHClass>(thread, globalConst->GetHandledJSAPIIteratorFuncHClass().GetObject<JSHClass>());
|
||||
// BitVectorIterator.prototype
|
||||
JSHandle<JSObject> bitVectorIteratorPrototype(factory->NewJSObject(iteratorFuncHClass));
|
||||
JSHandle<JSHClass> iteratorFuncClass = JSHandle<JSHClass>(thread,
|
||||
globalConst->GetHandledJSAPIIteratorFuncHClass().GetObject<JSHClass>());
|
||||
JSHandle<JSObject> bitVectorIteratorPrototype(factory->NewJSObjectWithInit(iteratorFuncClass));
|
||||
// Iterator.prototype.next()
|
||||
SetFrozenFunction(thread, bitVectorIteratorPrototype, "next", JSAPIBitVectorIterator::Next, FuncLength::ONE);
|
||||
SetStringTagSymbol(thread, env, bitVectorIteratorPrototype, "BitVector Iterator");
|
||||
globalConst->SetConstant(
|
||||
ConstantIndex::BITVECTOR_ITERATOR_PROTOTYPE_INDEX, bitVectorIteratorPrototype.GetTaggedValue());
|
||||
env->SetBitVectorIteratorPrototype(thread, bitVectorIteratorPrototype);
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> ContainersPrivate::InitializeQueue(JSThread *thread)
|
||||
|
@ -649,8 +649,6 @@ class ObjectFactory;
|
||||
V(JSTaggedValue, TreeSetIteratorPrototype, TREESET_ITERATOR_PROTOTYPE_INDEX, TreeSetIterator) \
|
||||
V(JSTaggedValue, VectorFunction, VECTOR_FUNCTION_INDEX, VectorFunction) \
|
||||
V(JSTaggedValue, VectorIteratorPrototype, VECTOR_ITERATOR_PROTOTYPE_INDEX, VectorIterator) \
|
||||
V(JSTaggedValue, BitVectorFunction, BITVECTOR_FUNCTION_INDEX, BitVectorFunction) \
|
||||
V(JSTaggedValue, BitVectorIteratorPrototype, BITVECTOR_ITERATOR_PROTOTYPE_INDEX, BitVectorIterator) \
|
||||
V(JSTaggedValue, QueueIteratorPrototype, QUEUE_ITERATOR_PROTOTYPE_INDEX, QueueIterator) \
|
||||
V(JSTaggedValue, PlainArrayIteratorPrototype, PLAIN_ARRAY_ITERATOR_PROTOTYPE_INDEX, PlainArrayIterator) \
|
||||
V(JSTaggedValue, PlainArrayFunction, PLAIN_ARRAY_FUNCTION_INDEX, PlainArrayFunction) \
|
||||
|
@ -135,6 +135,8 @@
|
||||
V(JSTaggedValue, BuiltinsWeakRefFunction, BUILTINS_WEAK_REF_FUNCTION_INDEX) \
|
||||
V(JSTaggedValue, BuiltinsFinalizationRegistryFunction, \
|
||||
BUILTINS_FINALIZATION_REGISTRY_FUNCTION_INDEX) \
|
||||
V(JSTaggedValue, BitVectorPrototype, BITVECTOR_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, BitVectorFunction, BITVECTOR_FUNCTION_INDEX) \
|
||||
V(JSTaggedValue, MapPrototype, MAP_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, MathFunction, MATH_FUNCTION_INDEX) \
|
||||
V(JSTaggedValue, MathFunctionClass, MATH_FUNCTION_CLASS_INDEX) \
|
||||
@ -167,6 +169,7 @@
|
||||
V(JSTaggedValue, StringIteratorClass, STRING_ITERATOR_CLASS_INDEX) \
|
||||
V(JSTaggedValue, AsyncFromSyncIterator, ASYNC_FROM_SYNC_ITERATOR_INDEX) \
|
||||
V(JSTaggedValue, MapIteratorPrototype, MAP_ITERATOR_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, BitVectorIteratorPrototype, BITVECTOR_ITERATOR_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, SharedMapIteratorPrototype, SHARED_MAP_ITERATOR_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, SetIteratorPrototype, SET_ITERATOR_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, SharedSetIteratorPrototype, SHARED_SET_ITERATOR_PROTOTYPE_INDEX) \
|
||||
|
@ -157,6 +157,7 @@ bool JSHClass::IsJSTypeShared(JSType type)
|
||||
case JSType::JS_SHARED_OBJECT:
|
||||
case JSType::JS_SHARED_FUNCTION:
|
||||
case JSType::JS_SHARED_ASYNC_FUNCTION:
|
||||
case JSType::JS_API_BITVECTOR:
|
||||
case JSType::JS_SHARED_SET:
|
||||
case JSType::JS_SHARED_MAP:
|
||||
case JSType::JS_SHARED_ARRAY:
|
||||
|
@ -1 +1 @@
|
||||
{"name": "GLOBAL_ENV", "offsets": [], "end_offset": 2360, "parents": ["TAGGED_OBJECT"]}
|
||||
{"name": "GLOBAL_ENV", "offsets": [], "end_offset": 2384, "parents": ["TAGGED_OBJECT"]}
|
@ -1534,6 +1534,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle<JSObject> &obj, const JSHa
|
||||
break;
|
||||
}
|
||||
case JSType::JS_API_BITVECTOR: {
|
||||
JSAPIBitVector::Cast(*obj)->SetNativePointer(thread_, JSTaggedValue::Undefined());
|
||||
JSAPIBitVector::Cast(*obj)->SetLength(0);
|
||||
JSAPIBitVector::Cast(*obj)->SetModRecord(0);
|
||||
break;
|
||||
@ -4539,7 +4540,7 @@ JSHandle<JSAPIVectorIterator> ObjectFactory::NewJSAPIVectorIterator(const JSHand
|
||||
JSHandle<JSAPIBitVector> ObjectFactory::NewJSAPIBitVector(uint32_t capacity)
|
||||
{
|
||||
NewObjectHook();
|
||||
JSHandle<JSFunction> builtinObj(thread_, thread_->GlobalConstants()->GetBitVectorFunction());
|
||||
JSHandle<JSFunction> builtinObj(thread_->GetEcmaVM()->GetGlobalEnv()->GetBitVectorFunction());
|
||||
JSHandle<JSAPIBitVector> obj = JSHandle<JSAPIBitVector>(NewJSObjectByConstructor(builtinObj));
|
||||
uint32_t taggedArrayCapacity = (capacity >> JSAPIBitVector::TAGGED_VALUE_BIT_SIZE) + 1;
|
||||
auto *newBitSetVector = new std::vector<std::bitset<JSAPIBitVector::BIT_SET_LENGTH>>();
|
||||
@ -4554,7 +4555,8 @@ JSHandle<JSAPIBitVectorIterator> ObjectFactory::NewJSAPIBitVectorIterator(const
|
||||
{
|
||||
NewObjectHook();
|
||||
const GlobalEnvConstants *globalConst = thread_->GlobalConstants();
|
||||
JSHandle<JSTaggedValue> proto(thread_, globalConst->GetBitVectorIteratorPrototype());
|
||||
JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSTaggedValue> proto(env->GetBitVectorIteratorPrototype());
|
||||
JSHandle<JSHClass> hclassHandle(globalConst->GetHandledJSAPIBitVectorIteratorClass());
|
||||
hclassHandle->SetPrototype(thread_, proto);
|
||||
JSHandle<JSAPIBitVectorIterator> iter(NewJSObject(hclassHandle));
|
||||
|
@ -480,6 +480,8 @@ JSTaggedType BaseDeserializer::RelocateObjectProtoAddr(uint8_t objectType)
|
||||
return env->GetArrayPrototype().GetTaggedType();
|
||||
case (uint8_t)JSType::JS_SHARED_ARRAY:
|
||||
return env->GetSharedArrayPrototype().GetTaggedType();
|
||||
case (uint8_t)JSType::JS_API_BITVECTOR:
|
||||
return env->GetBitVectorPrototype().GetTaggedType();
|
||||
case (uint8_t)JSType::JS_MAP:
|
||||
return env->GetMapPrototype().GetTaggedType();
|
||||
case (uint8_t)JSType::JS_SHARED_MAP:
|
||||
|
@ -62,6 +62,7 @@ bool ValueSerializer::CheckObjectCanSerialize(TaggedObject *object, bool &findSh
|
||||
case JSType::JS_OBJECT:
|
||||
case JSType::JS_ASYNC_FUNCTION: // means CONCURRENT_FUNCTION
|
||||
return true;
|
||||
case JSType::JS_API_BITVECTOR:
|
||||
case JSType::JS_SHARED_SET:
|
||||
case JSType::JS_SHARED_MAP:
|
||||
case JSType::JS_SENDABLE_ARRAY_BUFFER:
|
||||
|
@ -333,6 +333,7 @@ group("ark_aot_ts_test") {
|
||||
"unaryop_special_value",
|
||||
"useless_gate_elimination",
|
||||
"xor",
|
||||
"sharedbitvector",
|
||||
"sharedcheck",
|
||||
"sharedarray",
|
||||
"sharedcollectionsexception",
|
||||
|
21
test/aottest/sharedbitvector/BUILD.gn
Normal file
21
test/aottest/sharedbitvector/BUILD.gn
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//arkcompiler/ets_runtime/test/test_helper.gni")
|
||||
|
||||
host_aot_test_action("sharedbitvector") {
|
||||
deps = []
|
||||
src_dir = "$js_root/test/sharedtest/sharedbitvector"
|
||||
is_enable_pgo = true
|
||||
use_one_expect_path = true
|
||||
}
|
15
test/sharedtest/sharedbitvector/expect_output.txt
Normal file
15
test/sharedtest/sharedbitvector/expect_output.txt
Normal file
@ -0,0 +1,15 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
Start Test newsharedclassfrom
|
||||
bitvector pass
|
50
test/sharedtest/sharedbitvector/sharedbitvector.ts
Normal file
50
test/sharedtest/sharedbitvector/sharedbitvector.ts
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @tc.name:sharedbitvector
|
||||
* @tc.desc:test sharedbitvector
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI8QUU0
|
||||
*/
|
||||
|
||||
// @ts-nocheck
|
||||
declare function print(str: any): string;
|
||||
|
||||
class SuperClass {
|
||||
public obj : BitVector;
|
||||
constructor(obj : BitVector) {
|
||||
"use sendable"
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
|
||||
function newsharedclassfrom() {
|
||||
let arkPrivate = globalThis.ArkPrivate;
|
||||
var BitVector = arkPrivate.Load(arkPrivate.BitVector);
|
||||
let bitvector = new BitVector(10);
|
||||
bitvector.push(0)
|
||||
bitvector.push(1)
|
||||
|
||||
print("Start Test newsharedclassfrom")
|
||||
try {
|
||||
let bit = new SuperClass(bitvector);
|
||||
print("bitvector pass")
|
||||
} catch (err) {
|
||||
print("bitvector fail")
|
||||
}
|
||||
}
|
||||
|
||||
newsharedclassfrom()
|
Loading…
Reference in New Issue
Block a user