mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
Fix Jsnapi_Sendable_Test
Signed-off-by: liu-zelin <liuzelin8@huawei.com> Change-Id: I69626e3dc83ee6085289c9cc8e174d41f3d5d95f
This commit is contained in:
parent
8c1d4935a5
commit
e8e8a21598
@ -936,6 +936,49 @@ void JSFunction::SetFunctionExtraInfo(JSThread *thread, void *nativeFunc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSFunction::SetSFunctionExtraInfo(
|
||||||
|
JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter, void *data, size_t nativeBindingsize)
|
||||||
|
{
|
||||||
|
JSTaggedType hashField = Barriers::GetValue<JSTaggedType>(this, HASH_OFFSET);
|
||||||
|
EcmaVM *vm = thread->GetEcmaVM();
|
||||||
|
JSHandle<JSTaggedValue> value(thread, JSTaggedValue(hashField));
|
||||||
|
JSHandle<ECMAObject> obj(thread, this);
|
||||||
|
JSHandle<JSNativePointer> pointer =
|
||||||
|
vm->GetFactory()->NewSJSNativePointer(nativeFunc, deleter, data, false, nativeBindingsize);
|
||||||
|
if (!obj->HasHash()) {
|
||||||
|
Barriers::SetObject<true>(thread, *obj, HASH_OFFSET, pointer.GetTaggedValue().GetRawData());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (value->IsHeapObject()) {
|
||||||
|
if (value->IsJSNativePointer()) {
|
||||||
|
Barriers::SetObject<true>(thread, *obj, HASH_OFFSET, pointer.GetTaggedValue().GetRawData());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JSHandle<TaggedArray> array(value);
|
||||||
|
|
||||||
|
uint32_t nativeFieldCount = array->GetExtraLength();
|
||||||
|
if (array->GetLength() >= nativeFieldCount + RESOLVED_MAX_SIZE) {
|
||||||
|
array->Set(thread, nativeFieldCount + FUNCTION_EXTRA_INDEX, pointer);
|
||||||
|
} else {
|
||||||
|
JSHandle<TaggedArray> newArray =
|
||||||
|
vm->GetFactory()->NewSTaggedArrayWithoutInit(nativeFieldCount + RESOLVED_MAX_SIZE);
|
||||||
|
newArray->SetExtraLength(nativeFieldCount);
|
||||||
|
for (uint32_t i = 0; i < nativeFieldCount; i++) {
|
||||||
|
newArray->Set(thread, i, array->Get(i));
|
||||||
|
}
|
||||||
|
newArray->Set(thread, nativeFieldCount + HASH_INDEX, array->Get(nativeFieldCount + HASH_INDEX));
|
||||||
|
newArray->Set(thread, nativeFieldCount + FUNCTION_EXTRA_INDEX, pointer);
|
||||||
|
Barriers::SetObject<true>(thread, *obj, HASH_OFFSET, newArray.GetTaggedValue().GetRawData());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
JSHandle<TaggedArray> newArray = vm->GetFactory()->NewSTaggedArrayWithoutInit(RESOLVED_MAX_SIZE);
|
||||||
|
newArray->SetExtraLength(0);
|
||||||
|
newArray->Set(thread, HASH_INDEX, value);
|
||||||
|
newArray->Set(thread, FUNCTION_EXTRA_INDEX, pointer);
|
||||||
|
Barriers::SetObject<true>(thread, *obj, HASH_OFFSET, newArray.GetTaggedValue().GetRawData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JSTaggedValue JSFunction::GetFunctionExtraInfo() const
|
JSTaggedValue JSFunction::GetFunctionExtraInfo() const
|
||||||
{
|
{
|
||||||
JSTaggedType hashField = Barriers::GetValue<JSTaggedType>(this, HASH_OFFSET);
|
JSTaggedType hashField = Barriers::GetValue<JSTaggedType>(this, HASH_OFFSET);
|
||||||
|
@ -222,6 +222,8 @@ public:
|
|||||||
|
|
||||||
void SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter,
|
void SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter,
|
||||||
void *data, size_t nativeBindingsize = 0);
|
void *data, size_t nativeBindingsize = 0);
|
||||||
|
void SetSFunctionExtraInfo(
|
||||||
|
JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter, void *data, size_t nativeBindingsize = 0);
|
||||||
|
|
||||||
JSTaggedValue GetFunctionExtraInfo() const;
|
JSTaggedValue GetFunctionExtraInfo() const;
|
||||||
JSTaggedValue GetNativeFunctionExtraInfo() const;
|
JSTaggedValue GetNativeFunctionExtraInfo() const;
|
||||||
|
@ -2201,7 +2201,7 @@ Local<FunctionRef> FunctionRef::NewSendable(EcmaVM *vm,
|
|||||||
ObjectFactory *factory = vm->GetFactory();
|
ObjectFactory *factory = vm->GetFactory();
|
||||||
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
|
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
|
||||||
JSHandle<JSFunction> current(factory->NewSFunction(env, reinterpret_cast<void *>(nativeFunc)));
|
JSHandle<JSFunction> current(factory->NewSFunction(env, reinterpret_cast<void *>(nativeFunc)));
|
||||||
current->SetFunctionExtraInfo(thread, nullptr, deleter, data, nativeBindingsize);
|
current->SetSFunctionExtraInfo(thread, nullptr, deleter, data, nativeBindingsize);
|
||||||
current->SetCallNapi(callNapi);
|
current->SetCallNapi(callNapi);
|
||||||
return JSNApiHelper::ToLocal<FunctionRef>(JSHandle<JSTaggedValue>(current));
|
return JSNApiHelper::ToLocal<FunctionRef>(JSHandle<JSTaggedValue>(current));
|
||||||
}
|
}
|
||||||
@ -2296,8 +2296,7 @@ JSHandle<JSHClass> CreateInlinedSendableHClass(JSThread *thread,
|
|||||||
JSHandle<JSHClass> hclass;
|
JSHandle<JSHClass> hclass;
|
||||||
uint32_t length = info.keys->Length(vm);
|
uint32_t length = info.keys->Length(vm);
|
||||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||||
JSHandle<ecmascript::LayoutInfo> layout =
|
JSHandle<ecmascript::LayoutInfo> layout = factory->CreateSLayoutInfo(length);
|
||||||
factory->CreateLayoutInfo(length, ecmascript::MemSpaceType::OLD_SPACE, ecmascript::GrowMode::KEEP);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < length; ++i) {
|
for (uint32_t i = 0; i < length; ++i) {
|
||||||
key.Update(JSNApiHelper::ToJSHandle(info.keys->Get(vm, i)));
|
key.Update(JSNApiHelper::ToJSHandle(info.keys->Get(vm, i)));
|
||||||
@ -2334,7 +2333,8 @@ JSHandle<JSHClass> CreateDictSendableHClass(JSThread *thread,
|
|||||||
uint32_t length = info.keys->Length(vm);
|
uint32_t length = info.keys->Length(vm);
|
||||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||||
JSMutableHandle<ecmascript::NameDictionary> dict(
|
JSMutableHandle<ecmascript::NameDictionary> dict(
|
||||||
thread, ecmascript::NameDictionary::Create(thread, ecmascript::NameDictionary::ComputeHashTableSize(length)));
|
thread, ecmascript::NameDictionary::CreateInSharedHeap(
|
||||||
|
thread, ecmascript::NameDictionary::ComputeHashTableSize(length)));
|
||||||
auto globalConst = const_cast<GlobalEnvConstants *>(thread->GlobalConstants());
|
auto globalConst = const_cast<GlobalEnvConstants *>(thread->GlobalConstants());
|
||||||
JSHandle<JSTaggedValue> value = globalConst->GetHandledUndefined();
|
JSHandle<JSTaggedValue> value = globalConst->GetHandledUndefined();
|
||||||
|
|
||||||
@ -2401,8 +2401,8 @@ void SetInlinedAndDictProps(JSThread *thread,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSMutableHandle<ecmascript::NameDictionary> dict(
|
JSMutableHandle<ecmascript::NameDictionary> dict(
|
||||||
thread,
|
thread, ecmascript::NameDictionary::CreateInSharedHeap(
|
||||||
ecmascript::NameDictionary::Create(thread, ecmascript::NameDictionary::ComputeHashTableSize(length)));
|
thread, ecmascript::NameDictionary::ComputeHashTableSize(length)));
|
||||||
for (uint32_t i = 0; i < length; i++) {
|
for (uint32_t i = 0; i < length; i++) {
|
||||||
ecmascript::PropertyAttributes attr = ecmascript::PropertyAttributes::Default(
|
ecmascript::PropertyAttributes attr = ecmascript::PropertyAttributes::Default(
|
||||||
info.attributes[i].IsWritable(), info.attributes[i].IsEnumerable(),
|
info.attributes[i].IsWritable(), info.attributes[i].IsEnumerable(),
|
||||||
@ -2462,9 +2462,9 @@ Local<FunctionRef> FunctionRef::NewSendableClassFunction(const EcmaVM *vm,
|
|||||||
constructor->SetProtoOrHClass(thread, prototype);
|
constructor->SetProtoOrHClass(thread, prototype);
|
||||||
constructor->SetLexicalEnv(thread, constructor);
|
constructor->SetLexicalEnv(thread, constructor);
|
||||||
constructor->SetCallNapi(callNapi);
|
constructor->SetCallNapi(callNapi);
|
||||||
constructor->SetFunctionExtraInfo(thread, nullptr, deleter, data, nativeBindingSize);
|
constructor->SetSFunctionExtraInfo(thread, nullptr, deleter, data, nativeBindingSize);
|
||||||
|
|
||||||
JSHandle<JSHClass> iHClass = CreateSendableHClass(thread, instancePropertiesInfo, false);
|
JSHandle<JSHClass> iHClass = CreateSendableHClass(thread, instancePropertiesInfo, true);
|
||||||
iHClass->SetPrototype(thread, JSHandle<JSTaggedValue>(prototype));
|
iHClass->SetPrototype(thread, JSHandle<JSTaggedValue>(prototype));
|
||||||
iHClass->SetExtensible(false);
|
iHClass->SetExtensible(false);
|
||||||
constructor->SetProtoOrHClass(thread, iHClass);
|
constructor->SetProtoOrHClass(thread, iHClass);
|
||||||
|
@ -43,6 +43,7 @@ class JSNApiTests : public testing::Test {
|
|||||||
ASSERT_TRUE(vm_ != nullptr) << "Cannot create Runtime";
|
ASSERT_TRUE(vm_ != nullptr) << "Cannot create Runtime";
|
||||||
thread_ = vm_->GetJSThread();
|
thread_ = vm_->GetJSThread();
|
||||||
vm_->SetEnableForceGC(true);
|
vm_->SetEnableForceGC(true);
|
||||||
|
thread_->ManagedCodeBegin();
|
||||||
staticKey = StringRef::NewFromUtf8(vm_, "static");
|
staticKey = StringRef::NewFromUtf8(vm_, "static");
|
||||||
nonStaticKey = StringRef::NewFromUtf8(vm_, "nonStatic");
|
nonStaticKey = StringRef::NewFromUtf8(vm_, "nonStatic");
|
||||||
instanceKey = StringRef::NewFromUtf8(vm_, "instance");
|
instanceKey = StringRef::NewFromUtf8(vm_, "instance");
|
||||||
@ -52,6 +53,7 @@ class JSNApiTests : public testing::Test {
|
|||||||
|
|
||||||
void TearDown() override
|
void TearDown() override
|
||||||
{
|
{
|
||||||
|
thread_->ManagedCodeEnd();
|
||||||
vm_->SetEnableForceGC(false);
|
vm_->SetEnableForceGC(false);
|
||||||
JSNApi::DestroyJSVM(vm_);
|
JSNApi::DestroyJSVM(vm_);
|
||||||
}
|
}
|
||||||
|
@ -792,6 +792,7 @@ public:
|
|||||||
const JSHandle<JSTaggedValue> &prototype, bool isAccessor = true);
|
const JSHandle<JSTaggedValue> &prototype, bool isAccessor = true);
|
||||||
|
|
||||||
JSHandle<JSNativePointer> NewSJSNativePointer(void *externalPointer,
|
JSHandle<JSNativePointer> NewSJSNativePointer(void *externalPointer,
|
||||||
|
const DeleteEntryPoint &callBack,
|
||||||
void *data = nullptr,
|
void *data = nullptr,
|
||||||
bool nonMovable = false,
|
bool nonMovable = false,
|
||||||
size_t nativeBindingsize = 0,
|
size_t nativeBindingsize = 0,
|
||||||
|
@ -328,6 +328,7 @@ JSHandle<MutantTaggedArray> ObjectFactory::NewSEmptyMutantArray()
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSHandle<JSNativePointer> ObjectFactory::NewSJSNativePointer(void *externalPointer,
|
JSHandle<JSNativePointer> ObjectFactory::NewSJSNativePointer(void *externalPointer,
|
||||||
|
const DeleteEntryPoint &callBack,
|
||||||
void *data,
|
void *data,
|
||||||
bool nonMovable,
|
bool nonMovable,
|
||||||
size_t nativeBindingsize,
|
size_t nativeBindingsize,
|
||||||
@ -343,10 +344,18 @@ JSHandle<JSNativePointer> ObjectFactory::NewSJSNativePointer(void *externalPoint
|
|||||||
}
|
}
|
||||||
JSHandle<JSNativePointer> obj(thread_, header);
|
JSHandle<JSNativePointer> obj(thread_, header);
|
||||||
obj->SetExternalPointer(externalPointer);
|
obj->SetExternalPointer(externalPointer);
|
||||||
obj->SetDeleter(nullptr);
|
obj->SetDeleter(callBack);
|
||||||
obj->SetData(data);
|
obj->SetData(data);
|
||||||
obj->SetBindingSize(nativeBindingsize);
|
obj->SetBindingSize(nativeBindingsize);
|
||||||
obj->SetNativeFlag(flag);
|
obj->SetNativeFlag(flag);
|
||||||
|
|
||||||
|
if (callBack != nullptr) {
|
||||||
|
// heap_->IncreaseNativeBindingSize(nativeBindingsize);
|
||||||
|
vm_->PushToNativePointerList(static_cast<JSNativePointer *>(header));
|
||||||
|
// In some cases, the size of JS/TS object is too small and the native binding size is too large.
|
||||||
|
// Check and try trigger concurrent mark here.
|
||||||
|
// heap_->TryTriggerFullMarkByNativeSize();
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,11 +368,11 @@ JSHandle<AccessorData> ObjectFactory::NewSInternalAccessor(void *setter, void *g
|
|||||||
obj->SetGetter(thread_, JSTaggedValue::Undefined());
|
obj->SetGetter(thread_, JSTaggedValue::Undefined());
|
||||||
obj->SetSetter(thread_, JSTaggedValue::Undefined());
|
obj->SetSetter(thread_, JSTaggedValue::Undefined());
|
||||||
if (setter != nullptr) {
|
if (setter != nullptr) {
|
||||||
JSHandle<JSNativePointer> setFunc = NewSJSNativePointer(setter, nullptr, true);
|
JSHandle<JSNativePointer> setFunc = NewSJSNativePointer(setter, nullptr, nullptr, true);
|
||||||
obj->SetSetter(thread_, setFunc.GetTaggedValue());
|
obj->SetSetter(thread_, setFunc.GetTaggedValue());
|
||||||
}
|
}
|
||||||
if (getter != nullptr) {
|
if (getter != nullptr) {
|
||||||
JSHandle<JSNativePointer> getFunc = NewSJSNativePointer(getter, nullptr, true);
|
JSHandle<JSNativePointer> getFunc = NewSJSNativePointer(getter, nullptr, nullptr, true);
|
||||||
obj->SetGetter(thread_, getFunc);
|
obj->SetGetter(thread_, getFunc);
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
@ -583,4 +592,4 @@ JSHandle<AOTLiteralInfo> ObjectFactory::NewSAOTLiteralInfo(uint32_t length, JSTa
|
|||||||
aotLiteralInfo->InitializeWithSpecialValue(initVal, length);
|
aotLiteralInfo->InitializeWithSpecialValue(initVal, length);
|
||||||
return aotLiteralInfo;
|
return aotLiteralInfo;
|
||||||
}
|
}
|
||||||
} // namespace panda::ecmascript
|
} // namespace panda::ecmascript
|
||||||
|
Loading…
Reference in New Issue
Block a user