modify napi performance

1. add env in JSNativePointer deleter
2. delete new NativeObjectInfo
3. delete NapiNativeCallbackInfo, use ark stackinfo instead

https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9IDMS

Signed-off-by: wengchangcheng <wengchangcheng@huawei.com>
Change-Id: I1acf0e9f26096319ef74ef20e108ac63c9c2c21c
This commit is contained in:
wengchangcheng 2024-04-21 00:08:22 +08:00
parent c90a67a7dc
commit 38db6db8ad
68 changed files with 232 additions and 220 deletions

View File

@ -208,7 +208,7 @@ EcmaContext::~EcmaContext()
}
}
// clear icu cache
ClearIcuCache();
ClearIcuCache(thread_);
if (runtimeStat_ != nullptr) {
vm_->GetChunk()->Delete(runtimeStat_);

View File

@ -91,7 +91,6 @@ using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm,
PromiseRejectionEvent operation,
void* data);
using PromiseRejectCallback = void (*)(void* info);
using IcuDeleteEntry = void(*)(void *pointer, void *data);
class EcmaContext {
public:
static EcmaContext *CreateAndInitialize(JSThread *thread);
@ -304,7 +303,7 @@ public:
// For icu objects cache
void SetIcuFormatterToCache(IcuFormatterType type, const std::string &locale, void *icuObj,
IcuDeleteEntry deleteEntry = nullptr)
NativePointerCallback deleteEntry = nullptr)
{
EcmaContext::IcuFormatter icuFormatter = IcuFormatter(locale, icuObj, deleteEntry);
icuObjCache_[static_cast<int>(type)] = icuFormatter;
@ -319,13 +318,13 @@ public:
return nullptr;
}
void ClearIcuCache()
void ClearIcuCache(JSThread *thread)
{
for (uint32_t i = 0; i < static_cast<uint32_t>(IcuFormatterType::ICU_FORMATTER_TYPE_COUNT); i++) {
auto &icuFormatter = icuObjCache_[i];
IcuDeleteEntry deleteEntry = icuFormatter.deleteEntry;
NativePointerCallback deleteEntry = icuFormatter.deleteEntry;
if (deleteEntry != nullptr) {
deleteEntry(icuFormatter.icuObj, vm_);
deleteEntry(thread->GetEnv(), icuFormatter.icuObj, vm_);
}
icuFormatter = EcmaContext::IcuFormatter{};
}
@ -584,10 +583,10 @@ private:
struct IcuFormatter {
std::string locale;
void *icuObj {nullptr};
IcuDeleteEntry deleteEntry {nullptr};
NativePointerCallback deleteEntry {nullptr};
IcuFormatter() = default;
IcuFormatter(const std::string &locale, void *icuObj, IcuDeleteEntry deleteEntry = nullptr)
IcuFormatter(const std::string &locale, void *icuObj, NativePointerCallback deleteEntry = nullptr)
: locale(locale), icuObj(icuObj), deleteEntry(deleteEntry) {}
};
IcuFormatter icuObjCache_[static_cast<uint32_t>(IcuFormatterType::ICU_FORMATTER_TYPE_COUNT)];

View File

@ -526,7 +526,7 @@ void EcmaVM::ProcessNativeDelete(const WeakRootVisitor &visitor)
auto fwd = visitor(reinterpret_cast<TaggedObject *>(object));
if (fwd == nullptr) {
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
object->Destroy();
object->Destroy(thread_);
iter = nativePointerList_.erase(iter);
} else {
++iter;
@ -581,7 +581,7 @@ void EcmaVM::ProcessReferences(const WeakRootVisitor &visitor)
auto fwd = visitor(reinterpret_cast<TaggedObject *>(object));
if (fwd == nullptr) {
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
object->Destroy();
object->Destroy(thread_);
iter = nativePointerList_.erase(iter);
continue;
}
@ -636,14 +636,14 @@ void EcmaVM::RemoveFromNativePointerList(JSNativePointer *pointer)
if (iter != nativePointerList_.end()) {
JSNativePointer *object = *iter;
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
object->Destroy();
object->Destroy(thread_);
nativePointerList_.erase(iter);
}
auto newIter = std::find(concurrentNativePointerList_.begin(), concurrentNativePointerList_.end(), pointer);
if (newIter != concurrentNativePointerList_.end()) {
JSNativePointer *object = *newIter;
nativeAreaAllocator_->DecreaseNativeSizeStats(object->GetBindingSize(), object->GetNativeFlag());
object->Destroy();
object->Destroy(thread_);
concurrentNativePointerList_.erase(newIter);
}
}
@ -670,10 +670,10 @@ bool EcmaVM::ContainInDeregisterModuleList(CString module)
void EcmaVM::ClearBufferData()
{
for (auto iter : nativePointerList_) {
iter->Destroy();
iter->Destroy(thread_);
}
for (auto iter : concurrentNativePointerList_) {
iter->Destroy();
iter->Destroy(thread_);
}
nativePointerList_.clear();
thread_->GetCurrentEcmaContext()->ClearBufferData();

View File

@ -102,7 +102,7 @@ using RequestAotCallback =
using SearchHapPathCallBack = std::function<bool(const std::string moduleName, std::string &hapPath)>;
using DeviceDisconnectCallback = std::function<bool()>;
using UncatchableErrorHandler = std::function<void(panda::TryCatch&)>;
using DeleteEntryPoint = void (*)(void *, void *);
using NativePointerCallback = void (*)(void *, void *, void *);
class EcmaVM {
public:
static EcmaVM *Create(const JSRuntimeOptions &options);
@ -666,7 +666,7 @@ public:
return thread_->GetThreadId();
}
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> &GetNativePointerCallbacks()
std::vector<std::pair<NativePointerCallback, std::pair<void *, void *>>> &GetNativePointerCallbacks()
{
return nativePointerCallbacks_;
}
@ -683,21 +683,10 @@ public:
static void InitializeIcuData(const JSRuntimeOptions &options);
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> &GetSharedNativePointerCallbacks()
std::vector<std::pair<NativePointerCallback, std::pair<void *, void *>>> &GetSharedNativePointerCallbacks()
{
return sharedNativePointerCallbacks_;
}
void *GetEnv() const
{
return env_;
}
void SetEnv(void *env)
{
env_ = env;
}
protected:
void PrintJSErrorInfo(const JSHandle<JSTaggedValue> &exceptionInfo) const;
@ -728,9 +717,9 @@ private:
ObjectFactory *factory_ {nullptr};
CList<JSNativePointer *> nativePointerList_;
CList<JSNativePointer *> concurrentNativePointerList_;
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> nativePointerCallbacks_ {};
std::vector<std::pair<NativePointerCallback, std::pair<void *, void *>>> nativePointerCallbacks_ {};
CList<JSNativePointer *> sharedNativePointerList_;
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> sharedNativePointerCallbacks_ {};
std::vector<std::pair<NativePointerCallback, std::pair<void *, void *>>> sharedNativePointerCallbacks_ {};
// VM execution states.
JSThread *thread_ {nullptr};
@ -817,7 +806,6 @@ private:
bool isEnableOsr_ {false};
bool isJitCompileVM_ {false};
bool overLimit_ {false};
void *env_ = nullptr;
};
} // namespace ecmascript
} // namespace panda

View File

@ -135,7 +135,7 @@ public:
globalObject = tObject.release();
return reinterpret_cast<T *>(globalObject);
}
static void FreeCollatorFormat(void *pointer, void *data)
static void FreeCollatorFormat([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;
@ -146,7 +146,7 @@ public:
reinterpret_cast<EcmaVM *>(data)->GetNativeAreaAllocator()->FreeBuffer(pointer);
}
}
static void FreeNumberFormat(void *pointer, void *data)
static void FreeNumberFormat([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;
@ -157,7 +157,7 @@ public:
reinterpret_cast<EcmaVM *>(data)->GetNativeAreaAllocator()->FreeBuffer(pointer);
}
}
static void FreeDateTimeFormat(void *pointer, void *data)
static void FreeDateTimeFormat([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;

View File

@ -61,7 +61,7 @@ JSHandle<TaggedArray> JSCollator::GetAvailableLocales(JSThread *thread, bool ena
/* static */
void JSCollator::SetIcuCollator(JSThread *thread, const JSHandle<JSCollator> &collator,
icu::Collator *icuCollator, const DeleteEntryPoint &callback)
icu::Collator *icuCollator, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -70,7 +70,7 @@ void JSCollator::SetIcuCollator(JSThread *thread, const JSHandle<JSCollator> &co
JSTaggedValue data = collator->GetIcuField();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuCollator);
native->ResetExternalPointer(thread, icuCollator);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuCollator, callback);

View File

@ -68,7 +68,7 @@ public:
return reinterpret_cast<icu::Collator *>(result);
}
static void FreeIcuCollator(void *pointer, [[maybe_unused]] void *hint = nullptr)
static void FreeIcuCollator([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void *hint = nullptr)
{
if (pointer == nullptr) {
return;
@ -78,7 +78,7 @@ public:
}
static void SetIcuCollator(JSThread *thread, const JSHandle<JSCollator> &collator,
icu::Collator *icuCollator, const DeleteEntryPoint &callback);
icu::Collator *icuCollator, const NativePointerCallback &callback);
// 11.1.1 InitializeCollator ( collator, locales, options )
static JSHandle<JSCollator> InitializeCollator(JSThread *thread, const JSHandle<JSCollator> &collator,

View File

@ -108,7 +108,7 @@ icu::Locale *JSDateTimeFormat::GetIcuLocale() const
/* static */
void JSDateTimeFormat::SetIcuLocale(JSThread *thread, JSHandle<JSDateTimeFormat> obj,
const icu::Locale &icuLocale, const DeleteEntryPoint &callback)
const icu::Locale &icuLocale, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -117,14 +117,14 @@ void JSDateTimeFormat::SetIcuLocale(JSThread *thread, JSHandle<JSDateTimeFormat>
JSTaggedValue data = obj->GetLocaleIcu();
if (data.IsHeapObject() && data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuPointer);
native->ResetExternalPointer(thread, icuPointer);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuPointer, callback, ecmaVm);
obj->SetLocaleIcu(thread, pointer.GetTaggedValue());
}
void JSDateTimeFormat::FreeIcuLocale(void *pointer, void *data)
void JSDateTimeFormat::FreeIcuLocale([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;
@ -145,7 +145,7 @@ icu::SimpleDateFormat *JSDateTimeFormat::GetIcuSimpleDateFormat() const
/* static */
void JSDateTimeFormat::SetIcuSimpleDateFormat(JSThread *thread, JSHandle<JSDateTimeFormat> obj,
const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const DeleteEntryPoint &callback)
const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -155,7 +155,7 @@ void JSDateTimeFormat::SetIcuSimpleDateFormat(JSThread *thread, JSHandle<JSDateT
JSTaggedValue data = obj->GetSimpleDateTimeFormatIcu();
if (data.IsHeapObject() && data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuPointer);
native->ResetExternalPointer(thread, icuPointer);
return;
}
// According to the observed native memory, we give an approximate native binding value.
@ -165,7 +165,7 @@ void JSDateTimeFormat::SetIcuSimpleDateFormat(JSThread *thread, JSHandle<JSDateT
obj->SetSimpleDateTimeFormatIcu(thread, pointer.GetTaggedValue());
}
void JSDateTimeFormat::FreeSimpleDateFormat(void *pointer, void *data)
void JSDateTimeFormat::FreeSimpleDateFormat([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;

View File

@ -122,13 +122,13 @@ public:
icu::Locale *GetIcuLocale() const;
static void SetIcuLocale(JSThread *thread, JSHandle<JSDateTimeFormat> obj,
const icu::Locale &icuLocale, const DeleteEntryPoint &callback);
static void FreeIcuLocale(void *pointer, void *data);
const icu::Locale &icuLocale, const NativePointerCallback &callback);
static void FreeIcuLocale(void *env, void *pointer, void *data);
icu::SimpleDateFormat *GetIcuSimpleDateFormat() const;
static void SetIcuSimpleDateFormat(JSThread *thread, JSHandle<JSDateTimeFormat> obj,
const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const DeleteEntryPoint &callback);
static void FreeSimpleDateFormat(void *pointer, void *data);
const icu::SimpleDateFormat &icuSimpleDateTimeFormat, const NativePointerCallback &callback);
static void FreeSimpleDateFormat(void *env, void *pointer, void *data);
static icu::SimpleDateFormat *GetCachedIcuSimpleDateFormat(JSThread *thread,
const JSHandle<JSTaggedValue> &locales,
IcuFormatterType type);

View File

@ -53,7 +53,7 @@ icu::LocaleDisplayNames *JSDisplayNames::GetIcuLocaleDisplayNames() const
return reinterpret_cast<icu::LocaleDisplayNames *>(result);
}
void JSDisplayNames::FreeIcuLocaleDisplayNames(void *pointer, [[maybe_unused]] void* hint)
void JSDisplayNames::FreeIcuLocaleDisplayNames([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -64,7 +64,7 @@ void JSDisplayNames::FreeIcuLocaleDisplayNames(void *pointer, [[maybe_unused]] v
void JSDisplayNames::SetIcuLocaleDisplayNames(JSThread *thread, const JSHandle<JSDisplayNames> &displayNames,
icu::LocaleDisplayNames* iculocaledisplaynames,
const DeleteEntryPoint &callback)
const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -73,7 +73,7 @@ void JSDisplayNames::SetIcuLocaleDisplayNames(JSThread *thread, const JSHandle<J
JSTaggedValue data = displayNames->GetIcuLDN();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(iculocaledisplaynames);
native->ResetExternalPointer(thread, iculocaledisplaynames);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(iculocaledisplaynames, callback);

View File

@ -78,12 +78,12 @@ public:
icu::LocaleDisplayNames *GetIcuLocaleDisplayNames() const;
static void FreeIcuLocaleDisplayNames(void *pointer, [[maybe_unused]] void* hint);
static void FreeIcuLocaleDisplayNames(void *env, void *pointer, void* hint);
static JSHandle<TaggedArray> GetAvailableLocales(JSThread *thread);
static void SetIcuLocaleDisplayNames(JSThread *thread, const JSHandle<JSDisplayNames> &displayNames,
icu::LocaleDisplayNames* icuPointer, const DeleteEntryPoint &callback);
icu::LocaleDisplayNames* icuPointer, const NativePointerCallback &callback);
// 12.1.1 CanonicalCodeForDisplayNames ( type, code )
static JSHandle<EcmaString> CanonicalCodeForDisplayNames(JSThread *thread,

View File

@ -894,7 +894,7 @@ bool JSFunction::NameSetter(JSThread *thread, const JSHandle<JSObject> &self, co
return true;
}
void JSFunction::SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter,
void JSFunction::SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const NativePointerCallback &deleter,
void *data, size_t nativeBindingsize, Concurrent isConcurrent)
{
JSTaggedType hashField = Barriers::GetValue<JSTaggedType>(this, HASH_OFFSET);
@ -937,7 +937,7 @@ void JSFunction::SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const
}
void JSFunction::SetSFunctionExtraInfo(
JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter, void *data, size_t nativeBindingsize)
JSThread *thread, void *nativeFunc, const NativePointerCallback &deleter, void *data, size_t nativeBindingsize)
{
JSTaggedType hashField = Barriers::GetValue<JSTaggedType>(this, HASH_OFFSET);
EcmaVM *vm = thread->GetEcmaVM();

View File

@ -220,10 +220,10 @@ public:
GetClass()->SetClassConstructor(flag);
}
void SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter,
void *data, size_t nativeBindingsize = 0, Concurrent isConcurrent = Concurrent::NO);
void SetSFunctionExtraInfo(
JSThread *thread, void *nativeFunc, const DeleteEntryPoint &deleter, void *data, size_t nativeBindingsize = 0);
void SetFunctionExtraInfo(JSThread *thread, void *nativeFunc, const NativePointerCallback &deleter,
void *data, size_t nativeBindingsize = 0, Concurrent isConcurrent = Concurrent::NO);
void SetSFunctionExtraInfo(JSThread *thread, void *nativeFunc, const NativePointerCallback &deleter,
void *data, size_t nativeBindingsize = 0);
JSTaggedValue GetFunctionExtraInfo() const;
JSTaggedValue GetNativeFunctionExtraInfo() const;

View File

@ -44,7 +44,7 @@ icu::ListFormatter *JSListFormat::GetIcuListFormatter() const
return reinterpret_cast<icu::ListFormatter *>(result);
}
void JSListFormat::FreeIcuListFormatter(void *pointer, [[maybe_unused]] void* hint)
void JSListFormat::FreeIcuListFormatter([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -55,7 +55,7 @@ void JSListFormat::FreeIcuListFormatter(void *pointer, [[maybe_unused]] void* hi
}
void JSListFormat::SetIcuListFormatter(JSThread *thread, const JSHandle<JSListFormat> listFormat,
icu::ListFormatter *icuListFormatter, const DeleteEntryPoint &callback)
icu::ListFormatter *icuListFormatter, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -63,7 +63,7 @@ void JSListFormat::SetIcuListFormatter(JSThread *thread, const JSHandle<JSListFo
JSTaggedValue data = listFormat->GetIcuLF();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuListFormatter);
native->ResetExternalPointer(thread, icuListFormatter);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuListFormatter, callback);

View File

@ -61,10 +61,10 @@ public:
icu::ListFormatter *GetIcuListFormatter() const;
static void FreeIcuListFormatter(void *pointer, [[maybe_unused]] void* hint);
static void FreeIcuListFormatter(void *env, void *pointer, [[maybe_unused]] void* hint);
static void SetIcuListFormatter(JSThread *thread, const JSHandle<JSListFormat> obj,
icu::ListFormatter *icuListFormatter, const DeleteEntryPoint &callback);
icu::ListFormatter *icuListFormatter, const NativePointerCallback &callback);
static JSHandle<TaggedArray> GetAvailableLocales(JSThread *thread);

View File

@ -167,7 +167,7 @@ public:
return reinterpret_cast<icu::Locale *>(result);
}
static void FreeIcuLocale(void *pointer, void *data)
static void FreeIcuLocale([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;

View File

@ -17,12 +17,11 @@
#define ECMASCRIPT_JSNATIVEPOINTER_H
#include "ecmascript/ecma_macros.h"
#include "ecmascript/js_thread.h"
#include "ecmascript/mem/tagged_object.h"
#include "ecmascript/mem/native_area_allocator.h"
namespace panda::ecmascript {
using DeleteEntryPoint = void (*)(void *, void *);
// Used for the requirement of ACE that wants to associated a registered C++ resource with a JSObject.
class JSNativePointer : public TaggedObject {
public:
@ -32,15 +31,15 @@ public:
return reinterpret_cast<JSNativePointer *>(object);
}
inline void ResetExternalPointer(void *externalPointer)
inline void ResetExternalPointer(JSThread *thread, void *externalPointer)
{
DeleteExternalPointer();
DeleteExternalPointer(thread);
SetExternalPointer(externalPointer);
}
inline void Destroy()
inline void Destroy(JSThread *thread)
{
DeleteExternalPointer();
DeleteExternalPointer(thread);
SetExternalPointer(nullptr);
SetDeleter(nullptr);
SetData(nullptr);
@ -55,7 +54,7 @@ public:
static constexpr size_t POINTER_OFFSET = TaggedObjectSize();
ACCESSORS_NATIVE_FIELD(ExternalPointer, void, POINTER_OFFSET, DELETER_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(Deleter, DeleteEntryPoint, DELETER_OFFSET, DATA_OFFSET)
ACCESSORS_PRIMITIVE_FIELD(Deleter, NativePointerCallback, DELETER_OFFSET, DATA_OFFSET)
ACCESSORS_NATIVE_FIELD(Data, void, DATA_OFFSET, DATA_SIZE_OFFSET);
ACCESSORS_PRIMITIVE_FIELD(BindingSize, uint64_t, DATA_SIZE_OFFSET, FLAG_OFFSET);
// native memory statistic flag
@ -65,12 +64,13 @@ public:
DECL_VISIT_NATIVE_FIELD(POINTER_OFFSET, DATA_SIZE_OFFSET)
private:
inline void DeleteExternalPointer()
inline void DeleteExternalPointer(JSThread *thread)
{
void *externalPointer = GetExternalPointer();
DeleteEntryPoint deleter = GetDeleter();
NativePointerCallback deleter = GetDeleter();
auto env = thread->GetEnv();
if (deleter != nullptr) {
deleter(externalPointer, GetData());
deleter(env, externalPointer, GetData());
}
}
};

View File

@ -98,7 +98,7 @@ public:
return reinterpret_cast<icu::number::LocalizedNumberFormatter *>(result);
}
static void FreeIcuNumberformat(void *pointer, void *data)
static void FreeIcuNumberformat([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;

View File

@ -2882,7 +2882,7 @@ void *ECMAObject::GetNativePointerField(int32_t index) const
}
void ECMAObject::SetNativePointerField(const JSThread *thread, int32_t index, void *nativePointer,
const DeleteEntryPoint &callBack, void *data, size_t nativeBindingsize, Concurrent isConcurrent)
const NativePointerCallback &callBack, void *data, size_t nativeBindingsize, Concurrent isConcurrent)
{
JSTaggedType hashField = Barriers::GetValue<JSTaggedType>(this, HASH_OFFSET);
JSTaggedValue value(hashField);

View File

@ -384,7 +384,7 @@ public:
void* GetNativePointerField(int32_t index) const;
void SetNativePointerField(const JSThread *thread, int32_t index, void *nativePointer,
const DeleteEntryPoint &callBack, void *data, size_t nativeBindingsize = 0,
const NativePointerCallback &callBack, void *data, size_t nativeBindingsize = 0,
Concurrent isConcurrent = Concurrent::NO);
int32_t GetNativePointerFieldCount() const;
void SetNativePointerFieldCount(const JSThread *thread, int32_t count);

View File

@ -33,7 +33,7 @@ icu::number::LocalizedNumberFormatter *JSPluralRules::GetIcuNumberFormatter() co
return reinterpret_cast<icu::number::LocalizedNumberFormatter *>(result);
}
void JSPluralRules::FreeIcuNumberFormatter(void *pointer, void* hint)
void JSPluralRules::FreeIcuNumberFormatter([[maybe_unused]] void *env, void *pointer, void* hint)
{
if (pointer == nullptr) {
return;
@ -46,7 +46,7 @@ void JSPluralRules::FreeIcuNumberFormatter(void *pointer, void* hint)
}
void JSPluralRules::SetIcuNumberFormatter(JSThread *thread, const JSHandle<JSPluralRules> &pluralRules,
const icu::number::LocalizedNumberFormatter &icuNF, const DeleteEntryPoint &callback)
const icu::number::LocalizedNumberFormatter &icuNF, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -57,7 +57,7 @@ void JSPluralRules::SetIcuNumberFormatter(JSThread *thread, const JSHandle<JSPlu
JSTaggedValue data = pluralRules->GetIcuNF();
if (data.IsHeapObject() && data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuPointer);
native->ResetExternalPointer(thread, icuPointer);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuPointer, callback, ecmaVm);
@ -71,7 +71,7 @@ icu::PluralRules *JSPluralRules::GetIcuPluralRules() const
return reinterpret_cast<icu::PluralRules *>(result);
}
void JSPluralRules::FreeIcuPluralRules(void *pointer, void* hint)
void JSPluralRules::FreeIcuPluralRules([[maybe_unused]] void *env, void *pointer, void* hint)
{
if (pointer == nullptr) {
return;
@ -84,7 +84,7 @@ void JSPluralRules::FreeIcuPluralRules(void *pointer, void* hint)
}
void JSPluralRules::SetIcuPluralRules(JSThread *thread, const JSHandle<JSPluralRules> &pluralRules,
const icu::PluralRules &icuPR, const DeleteEntryPoint &callback)
const icu::PluralRules &icuPR, const NativePointerCallback &callback)
{
[[maybe_unused]] EcmaHandleScope scope(thread);
EcmaVM *ecmaVm = thread->GetEcmaVM();
@ -95,7 +95,7 @@ void JSPluralRules::SetIcuPluralRules(JSThread *thread, const JSHandle<JSPluralR
JSTaggedValue data = pluralRules->GetIcuPR();
if (data.IsHeapObject() && data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuPointer);
native->ResetExternalPointer(thread, icuPointer);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuPointer, callback, ecmaVm);

View File

@ -55,16 +55,16 @@ public:
icu::number::LocalizedNumberFormatter *GetIcuNumberFormatter() const;
static void SetIcuNumberFormatter(JSThread *thread, const JSHandle<JSPluralRules> &pluralRules,
const icu::number::LocalizedNumberFormatter &icuNF, const DeleteEntryPoint &callback);
const icu::number::LocalizedNumberFormatter &icuNF, const NativePointerCallback &callback);
static void FreeIcuNumberFormatter(void *pointer, [[maybe_unused]] void* hint = nullptr);
static void FreeIcuNumberFormatter(void *env, void *pointer, void* hint = nullptr);
icu::PluralRules *GetIcuPluralRules() const;
static void SetIcuPluralRules(JSThread *thread, const JSHandle<JSPluralRules> &pluralRules,
const icu::PluralRules &icuPR, const DeleteEntryPoint &callback);
const icu::PluralRules &icuPR, const NativePointerCallback &callback);
static void FreeIcuPluralRules(void *pointer, [[maybe_unused]] void* hint = nullptr);
static void FreeIcuPluralRules(void *env, void *pointer, void* hint = nullptr);
static JSHandle<TaggedArray> BuildLocaleSet(JSThread *thread, const std::set<std::string> &icuAvailableLocales);

View File

@ -74,7 +74,7 @@ public:
return reinterpret_cast<icu::RelativeDateTimeFormatter *>(result);
}
static void FreeIcuRTFFormatter(void *pointer, void *data)
static void FreeIcuRTFFormatter([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr) {
return;

View File

@ -37,7 +37,7 @@
namespace panda::ecmascript {
void JSSegmentIterator::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
icu::BreakIterator* icuBreakIterator, const DeleteEntryPoint &callback)
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -46,7 +46,7 @@ void JSSegmentIterator::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSS
JSTaggedValue data = iterator->GetIcuField();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuBreakIterator);
native->ResetExternalPointer(thread, icuBreakIterator);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
@ -54,7 +54,7 @@ void JSSegmentIterator::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSS
}
void JSSegmentIterator::SetUString(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
icu::UnicodeString* icuUnicodeString, const DeleteEntryPoint &callback)
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -63,7 +63,7 @@ void JSSegmentIterator::SetUString(JSThread *thread, const JSHandle<JSSegmentIte
JSTaggedValue data = iterator->GetUnicodeString();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuUnicodeString);
native->ResetExternalPointer(thread, icuUnicodeString);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuUnicodeString, callback);

View File

@ -65,7 +65,7 @@ public:
return reinterpret_cast<icu::BreakIterator *>(result);
}
static void FreeIcuBreakIterator(void *pointer, [[maybe_unused]] void* hint)
static void FreeIcuBreakIterator([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -75,9 +75,9 @@ public:
}
static void SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
icu::BreakIterator* icuBreakIterator, const DeleteEntryPoint &callback);
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback);
static void FreeUString(void *pointer, [[maybe_unused]] void* hint)
static void FreeUString([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -87,7 +87,7 @@ public:
}
static void SetUString(JSThread *thread, const JSHandle<JSSegmentIterator> &iterator,
icu::UnicodeString* icuUnicodeString, const DeleteEntryPoint &callback);
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback);
icu::UnicodeString *GetUString() const
{

View File

@ -34,7 +34,7 @@
namespace panda::ecmascript {
void JSSegmenter::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
icu::BreakIterator* icuBreakIterator, const DeleteEntryPoint &callback)
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -43,7 +43,7 @@ void JSSegmenter::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegment
JSTaggedValue data = segmenter->GetIcuField();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuBreakIterator);
native->ResetExternalPointer(thread, icuBreakIterator);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);

View File

@ -66,7 +66,7 @@ public:
return reinterpret_cast<icu::BreakIterator *>(result);
}
static void FreeIcuBreakIterator(void *pointer, [[maybe_unused]] void* hint)
static void FreeIcuBreakIterator([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -76,7 +76,7 @@ public:
}
static void SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegmenter> &segmenter,
icu::BreakIterator* icuBreakIterator, const DeleteEntryPoint &callback);
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback);
static JSHandle<TaggedArray> GetAvailableLocales(JSThread *thread);

View File

@ -35,7 +35,7 @@
namespace panda::ecmascript {
void JSSegments::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegments> &segments,
icu::BreakIterator* icuBreakIterator, const DeleteEntryPoint &callback)
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -44,7 +44,7 @@ void JSSegments::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegments
JSTaggedValue data = segments->GetIcuField();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuBreakIterator);
native->ResetExternalPointer(thread, icuBreakIterator);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuBreakIterator, callback);
@ -52,7 +52,7 @@ void JSSegments::SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegments
}
void JSSegments::SetUString(JSThread *thread, const JSHandle<JSSegments> &segments,
icu::UnicodeString* icuUnicodeString, const DeleteEntryPoint &callback)
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback)
{
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
@ -61,7 +61,7 @@ void JSSegments::SetUString(JSThread *thread, const JSHandle<JSSegments> &segmen
JSTaggedValue data = segments->GetUnicodeString();
if (data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuUnicodeString);
native->ResetExternalPointer(thread, icuUnicodeString);
return;
}
JSHandle<JSNativePointer> pointer = factory->NewJSNativePointer(icuUnicodeString, callback);

View File

@ -61,7 +61,7 @@ public:
return reinterpret_cast<icu::BreakIterator *>(result);
}
static void FreeIcuBreakIterator(void *pointer, [[maybe_unused]] void* hint)
static void FreeIcuBreakIterator([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -71,9 +71,9 @@ public:
}
static void SetIcuBreakIterator(JSThread *thread, const JSHandle<JSSegments> &segments,
icu::BreakIterator* icuBreakIterator, const DeleteEntryPoint &callback);
icu::BreakIterator* icuBreakIterator, const NativePointerCallback &callback);
static void FreeUString(void *pointer, [[maybe_unused]] void* hint)
static void FreeUString([[maybe_unused]] void *env, void *pointer, [[maybe_unused]] void* hint)
{
if (pointer == nullptr) {
return;
@ -83,7 +83,7 @@ public:
}
static void SetUString(JSThread *thread, const JSHandle<JSSegments> &segments,
icu::UnicodeString* icuUnicodeString, const DeleteEntryPoint &callback);
icu::UnicodeString* icuUnicodeString, const NativePointerCallback &callback);
icu::UnicodeString *GetUString() const
{

View File

@ -1784,7 +1784,7 @@ JSHandle<JSTaggedValue> JSDeserializer::ReadJSNativePointer()
return JSHandle<JSTaggedValue>();
}
JSHandle<JSNativePointer> np = factory_->NewJSNativePointer(ToVoidPtr(externalPtr),
reinterpret_cast<DeleteEntryPoint>(deleter),
reinterpret_cast<NativePointerCallback>(deleter),
ToVoidPtr(allocatorPtr),
false,
bindingSize);

View File

@ -242,7 +242,7 @@ void JSThread::InvokeSharedNativePointerCallbacks()
ASSERT(callbackPair.first != nullptr && callbackPair.second.first != nullptr &&
callbackPair.second.second != nullptr);
auto callback = callbackPair.first;
(*callback)(callbackPair.second.first, callbackPair.second.second);
(*callback)(env_, callbackPair.second.first, callbackPair.second.second);
}
}

View File

@ -1267,6 +1267,16 @@ public:
{
return machineCodeLowMemory_;
}
void *GetEnv() const
{
return env_;
}
void SetEnv(void *env)
{
env_ = env;
}
private:
NO_COPY_SEMANTIC(JSThread);
NO_MOVE_SEMANTIC(JSThread);
@ -1315,6 +1325,7 @@ private:
GlueData glueData_;
std::atomic<ThreadId> id_;
EcmaVM *vm_ {nullptr};
void *env_ {nullptr};
Area *regExpCache_ {nullptr};
// MM: handles, global-handles, and aot-stubs.

View File

@ -1761,7 +1761,7 @@ void Heap::CleanCallBack()
auto &callbacks = this->GetEcmaVM()->GetNativePointerCallbacks();
if (!callbacks.empty()) {
Taskpool::GetCurrentTaskpool()->PostTask(
std::make_unique<DeleteCallbackTask>(this->GetJSThread()->GetThreadId(), callbacks)
std::make_unique<DeleteCallbackTask>(thread_, thread_->GetThreadId(), callbacks)
);
}
ASSERT(callbacks.empty());
@ -1771,7 +1771,7 @@ bool Heap::DeleteCallbackTask::Run([[maybe_unused]] uint32_t threadIndex)
{
for (auto iter : nativePointerCallbacks_) {
if (iter.first != nullptr) {
iter.first(iter.second.first, iter.second.second);
iter.first(thread_, iter.second.first, iter.second.second);
}
}
return true;

View File

@ -1095,8 +1095,9 @@ private:
class DeleteCallbackTask : public Task {
public:
DeleteCallbackTask(int32_t id, std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> &callbacks)
: Task(id)
DeleteCallbackTask(JSThread *thread, int32_t id,
std::vector<std::pair<NativePointerCallback, std::pair<void *, void *>>> &callbacks)
: Task(id), thread_(thread)
{
std::swap(callbacks, nativePointerCallbacks_);
};
@ -1107,7 +1108,8 @@ private:
NO_MOVE_SEMANTIC(DeleteCallbackTask);
private:
std::vector<std::pair<DeleteEntryPoint, std::pair<void *, void *>>> nativePointerCallbacks_ {};
std::vector<std::pair<NativePointerCallback, std::pair<void *, void *>>> nativePointerCallbacks_ {};
JSThread *thread_ {nullptr};
};
class RecursionScope {

View File

@ -128,7 +128,7 @@ void NativeAreaAllocator::FreeBuffer(void *mem)
free(mem);
}
void NativeAreaAllocator::FreeBufferFunc(void *buffer, void *data)
void NativeAreaAllocator::FreeBufferFunc([[maybe_unused]] void *env, void *buffer, void *data)
{
if (buffer == nullptr || data == nullptr) {
return;

View File

@ -49,10 +49,10 @@ public:
void *AllocateBuffer(size_t size);
void FreeBuffer(void *mem);
static void FreeBufferFunc(void* buffer, void* data);
static void FreeBufferFunc(void *env, void* buffer, void* data);
template<class T>
static void FreeObjectFunc(void* buffer, void* data)
static void FreeObjectFunc([[maybe_unused]] void *env, void* buffer, void* data)
{
if (buffer == nullptr || data == nullptr) {
return;

View File

@ -30,7 +30,7 @@
namespace panda::ecmascript {
using PathHelper = base::PathHelper;
void ModuleDeregister::FreeModuleRecord(void *pointer, void *hint)
void ModuleDeregister::FreeModuleRecord([[maybe_unused]] void *env, void *pointer, void *hint)
{
if (pointer == nullptr) {
LOG_FULL(FATAL) << "Lacking deregister module's name.";

View File

@ -42,7 +42,7 @@ public:
moduleRecord->SetNamespace(thread, weakNameSp);
}
static void FreeModuleRecord(void *pointer, void *hint);
static void FreeModuleRecord(void *env, void *pointer, void *hint);
static void RemoveModule(JSThread *thread, JSHandle<SourceTextModule> module);

View File

@ -329,7 +329,7 @@ bool ModuleNamespace::ValidateKeysAvailable(JSThread *thread, const JSHandle<Tag
}
void ModuleNamespace::SetModuleDeregisterProcession(JSThread *thread, const JSHandle<ModuleNamespace> &nameSpace,
const DeleteEntryPoint &callback)
const NativePointerCallback &callback)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();

View File

@ -25,7 +25,7 @@ public:
CAST_CHECK(ModuleNamespace, IsModuleNamespace);
static void SetModuleDeregisterProcession(JSThread *thread, const JSHandle<ModuleNamespace> &nameSpace,
const DeleteEntryPoint &callback);
const NativePointerCallback &callback);
// 9.4.6.11ModuleNamespaceCreate ( module, exports )
static JSHandle<ModuleNamespace> ModuleNamespaceCreate(JSThread *thread, const JSHandle<JSTaggedValue> &module,

View File

@ -6,7 +6,7 @@ ArrayBufferRef
Local<ArrayBufferRef> ArrayBufferRef::New(const EcmaVM *vm, int32_t length)
Local<ArrayBufferRef> ArrayBufferRef::New(const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter, void *data)
Local<ArrayBufferRef> ArrayBufferRef::New(const EcmaVM *vm, void *buffer, int32_t length, const NativePointerCallback &deleter, void *data)
创建一个ArrayBuffer对象。
@ -17,7 +17,7 @@ Local<ArrayBufferRef> ArrayBufferRef::New(const EcmaVM *vm, void *buffer, int32_
| vm | const EcmaVM * | 是 | 虚拟机对象。 |
| length | int32_t | 是 | 指定的长度。 |
| buffer | void * | 是 | 指定缓冲区。 |
| deleter | const Deleter & | 是 | 删除ArrayBuffer时所作的操作 |
| deleter | const NativePointerCallback & | 是 | 删除ArrayBuffer时所作的操作 |
| data | void * | 是 | 指定数据。 |
**返回值:**
@ -33,7 +33,7 @@ Local<ArrayBufferRef> arrayBuffer1 = ArrayBufferRef::New(vm, 10);
uint8_t *buffer = new uint8_t[10]();
int *data = new int;
*data = 10;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
int *currentData = reinterpret_cast<int *>(data);
delete currentData;
@ -65,7 +65,7 @@ void *ArrayBufferRef::GetBuffer()
uint8_t *buffer = new uint8_t[10]();
int *data = new int;
*data = 10;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
int *currentData = reinterpret_cast<int *>(data);
delete currentData;
@ -188,7 +188,7 @@ Local<BooleanRef> boolRef = BooleanRef::New(vm, true);
Local<BufferRef> BufferRef::New(const EcmaVM *vm, int32_t length);
Local<BufferRef> BufferRef::New(const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter, void *data)
Local<BufferRef> BufferRef::New(const EcmaVM *vm, void *buffer, int32_t length, const NativePointerCallback &deleter, void *data)
创建一个BufferRef对象。
@ -199,7 +199,7 @@ Local<BufferRef> BufferRef::New(const EcmaVM *vm, void *buffer, int32_t length,
| vm | const EcmaVM * | 是 | 虚拟机对象。 |
| length | int32_t | 是 | 指定的长度。 |
| buffer | void * | 是 | 指定缓冲区 |
| deleter | const Deleter & | 是 | 一个删除器对象,用于在不再需要缓冲区时释放其内存。 |
| deleter | const NativePointerCallback & | 是 | 一个删除器对象,用于在不再需要缓冲区时释放其内存。 |
| data | void * | 是 | 传递给删除器的额外数据。 |
**返回值:**
@ -215,7 +215,7 @@ Local<BufferRef> bufferRef1 = BufferRef::New(vm, 10);
uint8_t *buffer = new uint8_t[10]();
int *data = new int;
*data = 10;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
int *currentData = reinterpret_cast<int *>(data);
delete currentData;
@ -272,7 +272,7 @@ void *BufferRef::GetBuffer()
uint8_t *buffer = new uint8_t[10]();
int *data = new int;
*data = 10;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
int *currentData = reinterpret_cast<int *>(data);
delete currentData;
@ -4115,7 +4115,7 @@ object->SetPrototype(vm_, prototype);
### New
Local<FunctionRef> FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
Local<FunctionRef> FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
创建一个新的函数对象。
@ -4125,7 +4125,7 @@ Local<FunctionRef> FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc, Del
| :---------------: | ---------------- | ---- | ------------------------------------------------------------ |
| vm | const EcmaVM * | 是 | 指定虚拟机对象。 |
| nativeFunc | FunctionCallback | 是 | 一个回调函数当JS调用这个本地函数时将调用这个回调函。 |
| deleter | Deleter | 否 | 一个删除器函数,用于在不再需要`FunctionRef`对象时释放其资源。 |
| deleter | NativePointerCallback | 否 | 一个删除器函数,用于在不再需要`FunctionRef`对象时释放其资源。 |
| data | void * | 否 | 一个可选的指针,可以传递给回调函数或删除器函数。 |
| callNapi | bool | 否 | 一个布尔值,表示是否在创建`FunctionRef`对象时立即调用回调函数。如果为`true`,则在创建对象时立即调用回调函数;如果为`false`,则需要手动调用回调函数。 |
| nativeBindingsize | size_t | 否 | 表示nativeFunc函数的大小0表示未知大小。 |
@ -4149,7 +4149,7 @@ Local<FunctionRef> callback = FunctionRef::New(vm, FunCallback);
### NewClassFunction
Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallback nativeFunc, NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
创建一个新的类函数对象。
@ -4159,7 +4159,7 @@ Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallback na
| :---------------: | ---------------- | ---- | ------------------------------------------------------------ |
| vm | const EcmaVM * | 是 | 指定虚拟机对象。 |
| nativeFunc | FunctionCallback | 是 | 一个回调函数当JS调用这个本地函数时将调用这个回调函。 |
| deleter | Deleter | 否 | 一个删除器函数,用于在不再需要`FunctionRef`对象时释放其资源。 |
| deleter | NativePointerCallback | 否 | 一个删除器函数,用于在不再需要`FunctionRef`对象时释放其资源。 |
| data | void * | 否 | 一个可选的指针,可以传递给回调函数或删除器函数。 |
| callNapi | bool | 否 | 一个布尔值,表示是否在创建`FunctionRef`对象时立即调用回调函数。如果为`true`,则在创建对象时立即调用回调函数;如果为`false`,则需要手动调用回调函数。 |
| nativeBindingsize | size_t | 否 | 表示nativeFunc函数的大小0表示未知大小。 |
@ -4178,7 +4178,7 @@ Local<JSValueRef> FunCallback(JsiRuntimeCallInfo *info)
EscapeLocalScope scope(info->GetVM());
return scope.Escape(ArrayRef::New(info->GetVM(), info->GetArgsNumber()));
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
void *cb = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
bool callNative = true;
size_t nativeBindingSize = 15;

View File

@ -78,7 +78,6 @@ struct AlignedPointer;
}
} // namespace ecmascript
using Deleter = void (*)(void *nativePointer, void *data);
using WeakRefClearCallBack = void (*)(void *);
using EcmaVM = ecmascript::EcmaVM;
using EcmaContext = ecmascript::EcmaContext;

View File

@ -87,7 +87,6 @@ struct HmsMap {
uint32_t sinceVersion;
};
using Deleter = void (*)(void *nativePointer, void *data);
using WeakRefClearCallBack = void (*)(void *);
using WeakFinalizeTaskCallback = std::function<void()>;
using EcmaVM = ecmascript::EcmaVM;
@ -620,7 +619,7 @@ private:
bool hasConfigurable_ = false;
};
using NativePointerCallback = void (*)(void* value, void* hint);
using NativePointerCallback = void (*)(void *env, void* data, void* hint);
class ECMA_PUBLIC_API NativePointerRef : public JSValueRef {
public:
static Local<NativePointerRef> New(const EcmaVM *vm, void *nativePointer, size_t nativeBindingsize = 0);
@ -714,27 +713,39 @@ public:
SendablePropertiesInfo staticPropertiesInfo;
SendablePropertiesInfo nonStaticPropertiesInfo;
};
static Local<FunctionRef> New(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter = nullptr,
static Local<FunctionRef> New(EcmaVM *vm, FunctionCallback nativeFunc, NativePointerCallback deleter = nullptr,
void *data = nullptr, bool callNapi = false, size_t nativeBindingsize = 0);
static Local<FunctionRef> NewConcurrent(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter = nullptr,
void *data = nullptr, bool callNapi = false, size_t nativeBindingsize = 0);
static Local<FunctionRef> New(EcmaVM *vm, InternalFunctionCallback nativeFunc, Deleter deleter,
void *data = nullptr, bool callNapi = false, size_t nativeBindingsize = 0);
static Local<FunctionRef> NewConcurrent(EcmaVM *vm, InternalFunctionCallback nativeFunc, Deleter deleter,
static Local<FunctionRef> NewConcurrent(EcmaVM *vm,
FunctionCallback nativeFunc,
NativePointerCallback deleter = nullptr,
void *data = nullptr,
bool callNapi = false,
size_t nativeBindingsize = 0);
static Local<FunctionRef> New(EcmaVM *vm, InternalFunctionCallback nativeFunc, NativePointerCallback deleter,
void *data = nullptr, bool callNapi = false, size_t nativeBindingsize = 0);
static Local<FunctionRef> NewConcurrent(EcmaVM *vm,
InternalFunctionCallback nativeFunc,
NativePointerCallback deleter,
void *data = nullptr,
bool callNapi = false,
size_t nativeBindingsize = 0);
static Local<FunctionRef> NewSendable(EcmaVM *vm,
InternalFunctionCallback nativeFunc,
Deleter deleter,
NativePointerCallback deleter,
void *data = nullptr,
bool callNapi = false,
size_t nativeBindingsize = 0);
static Local<FunctionRef> NewClassFunction(EcmaVM *vm, FunctionCallback nativeFunc, Deleter deleter,
void *data, bool callNapi = false, size_t nativeBindingsize = 0);
static Local<FunctionRef> NewClassFunction(EcmaVM *vm, InternalFunctionCallback nativeFunc, Deleter deleter,
static Local<FunctionRef> NewClassFunction(EcmaVM *vm, FunctionCallback nativeFunc, NativePointerCallback deleter,
void *data, bool callNapi = false, size_t nativeBindingsize = 0);
static Local<FunctionRef> NewClassFunction(EcmaVM *vm,
InternalFunctionCallback nativeFunc,
NativePointerCallback deleter,
void *data,
bool callNapi = false,
size_t nativeBindingsize = 0);
static Local<FunctionRef> NewSendableClassFunction(const EcmaVM *vm,
InternalFunctionCallback nativeFunc,
Deleter deleter,
NativePointerCallback deleter,
void *data,
Local<StringRef> name,
SendablePropertiesInfos &infos,
@ -754,7 +765,7 @@ public:
Local<StringRef> GetName(const EcmaVM *vm);
Local<StringRef> GetSourceCode(const EcmaVM *vm, int lineNumber);
bool IsNative(const EcmaVM *vm);
void SetData(const EcmaVM *vm, void *data, Deleter deleter = nullptr, bool callNapi = false);
void SetData(const EcmaVM *vm, void *data, NativePointerCallback deleter = nullptr, bool callNapi = false);
void* GetData(const EcmaVM *vm);
};
@ -908,8 +919,8 @@ public:
class ECMA_PUBLIC_API ArrayBufferRef : public ObjectRef {
public:
static Local<ArrayBufferRef> New(const EcmaVM *vm, int32_t length);
static Local<ArrayBufferRef> New(const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter,
void *data);
static Local<ArrayBufferRef> New(const EcmaVM *vm, void *buffer, int32_t length,
const NativePointerCallback &deleter, void *data);
int32_t ByteLength(const EcmaVM *vm);
void *GetBuffer();
@ -1150,7 +1161,7 @@ public:
class ECMA_PUBLIC_API BufferRef : public ObjectRef {
public:
static Local<BufferRef> New(const EcmaVM *vm, int32_t length);
static Local<BufferRef> New(const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter,
static Local<BufferRef> New(const EcmaVM *vm, void *buffer, int32_t length, const NativePointerCallback &deleter,
void *data);
int32_t ByteLength(const EcmaVM *vm);

View File

@ -1153,13 +1153,13 @@ Local<BufferRef> BufferRef::New(const EcmaVM *vm, int32_t length)
}
Local<BufferRef> BufferRef::New(
const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter, void *data)
const EcmaVM *vm, void *buffer, int32_t length, const NativePointerCallback &deleter, void *data)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
ObjectFactory *factory = vm->GetFactory();
JSHandle<JSArrayBuffer> arrayBuffer =
factory->NewJSArrayBuffer(buffer, length, reinterpret_cast<ecmascript::DeleteEntryPoint>(deleter), data);
factory->NewJSArrayBuffer(buffer, length, reinterpret_cast<ecmascript::NativePointerCallback>(deleter), data);
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
JSHandle<JSFunction> current =
@ -2138,13 +2138,13 @@ Local<ArrayBufferRef> ArrayBufferRef::New(const EcmaVM *vm, int32_t length)
}
Local<ArrayBufferRef> ArrayBufferRef::New(
const EcmaVM *vm, void *buffer, int32_t length, const Deleter &deleter, void *data)
const EcmaVM *vm, void *buffer, int32_t length, const NativePointerCallback &deleter, void *data)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
ObjectFactory *factory = vm->GetFactory();
JSHandle<JSArrayBuffer> arrayBuffer =
factory->NewJSArrayBuffer(buffer, length, reinterpret_cast<ecmascript::DeleteEntryPoint>(deleter), data);
factory->NewJSArrayBuffer(buffer, length, reinterpret_cast<ecmascript::NativePointerCallback>(deleter), data);
return JSNApiHelper::ToLocal<ArrayBufferRef>(JSHandle<JSTaggedValue>(arrayBuffer));
}
@ -2258,7 +2258,7 @@ Local<ArrayBufferRef> TypedArrayRef::GetArrayBuffer(const EcmaVM *vm)
// ----------------------------------- FunctionRef --------------------------------------
Local<FunctionRef> FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc,
Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
@ -2271,7 +2271,7 @@ Local<FunctionRef> FunctionRef::New(EcmaVM *vm, FunctionCallback nativeFunc,
}
Local<FunctionRef> FunctionRef::NewConcurrent(EcmaVM *vm, FunctionCallback nativeFunc,
Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ObjectFactory *factory = vm->GetFactory();
@ -2284,7 +2284,7 @@ Local<FunctionRef> FunctionRef::NewConcurrent(EcmaVM *vm, FunctionCallback nativ
}
Local<FunctionRef> FunctionRef::New(EcmaVM *vm, InternalFunctionCallback nativeFunc,
Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
@ -2298,7 +2298,7 @@ Local<FunctionRef> FunctionRef::New(EcmaVM *vm, InternalFunctionCallback nativeF
Local<FunctionRef> FunctionRef::NewSendable(EcmaVM *vm,
InternalFunctionCallback nativeFunc,
Deleter deleter,
NativePointerCallback deleter,
void *data,
bool callNapi,
size_t nativeBindingsize)
@ -2314,7 +2314,7 @@ Local<FunctionRef> FunctionRef::NewSendable(EcmaVM *vm,
}
Local<FunctionRef> FunctionRef::NewConcurrent(EcmaVM *vm, InternalFunctionCallback nativeFunc,
Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ObjectFactory *factory = vm->GetFactory();
@ -2346,7 +2346,7 @@ static void InitClassFunction(EcmaVM *vm, JSHandle<JSFunction> &func, bool callN
}
Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallback nativeFunc,
Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
@ -2364,7 +2364,7 @@ Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, FunctionCallback na
}
Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, InternalFunctionCallback nativeFunc,
Deleter deleter, void *data, bool callNapi, size_t nativeBindingsize)
NativePointerCallback deleter, void *data, bool callNapi, size_t nativeBindingsize)
{
CROSS_THREAD_AND_EXCEPTION_CHECK_WITH_RETURN(vm, JSValueRef::Undefined(vm));
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
@ -2383,7 +2383,7 @@ Local<FunctionRef> FunctionRef::NewClassFunction(EcmaVM *vm, InternalFunctionCal
Local<FunctionRef> FunctionRef::NewSendableClassFunction(const EcmaVM *vm,
InternalFunctionCallback nativeFunc,
Deleter deleter,
NativePointerCallback deleter,
void *data,
Local<StringRef> name,
SendablePropertiesInfos &infos,
@ -2670,7 +2670,7 @@ bool FunctionRef::IsNative(const EcmaVM *vm)
return method->IsNativeWithCallField();
}
void FunctionRef::SetData(const EcmaVM *vm, void *data, Deleter deleter, [[maybe_unused]] bool callNapi)
void FunctionRef::SetData(const EcmaVM *vm, void *data, NativePointerCallback deleter, [[maybe_unused]] bool callNapi)
{
CROSS_THREAD_AND_EXCEPTION_CHECK(vm);
ecmascript::ThreadManagedScope managedScope(vm->GetJSThread());
@ -3026,12 +3026,14 @@ void JSNApi::AllowCrossThreadExecution(EcmaVM *vm)
void* JSNApi::GetEnv(EcmaVM *vm)
{
return vm->GetEnv();
JSThread *thread = vm->GetJSThread();
return thread->GetEnv();
}
void JSNApi::SetEnv(EcmaVM *vm, void *env)
{
vm->SetEnv(env);
JSThread *thread = vm->GetJSThread();
thread->SetEnv(env);
}
void JSNApi::SynchronizVMInfo(EcmaVM *vm, const EcmaVM *hostVM)

View File

@ -380,7 +380,7 @@ HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFunction_True)
{
LocalScope scope(vm_);
CalculateForTime();
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
void *cb = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
bool callNative = true;
size_t nativeBindingSize = 15;
@ -529,7 +529,7 @@ HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayBuffer)
const int32_t length = 15;
Data *data = new Data();
data->length = length;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
delete currentData;
@ -554,7 +554,7 @@ HWTEST_F_L0(JSNApiSplTest, BufferRef_New1)
int32_t length;
};
const int32_t length = 15;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
delete currentData;
@ -850,7 +850,7 @@ HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_New1)
int32_t length;
};
const int32_t length = 15;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
delete currentData;
@ -6335,7 +6335,7 @@ HWTEST_F_L0(JSNApiSplTest, JSValueRef_InitForConcurrentFunction)
{
LocalScope scope(vm_);
CalculateForTime();
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
void *cb = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
bool callNative = true;
size_t nativeBindingsize = 15;

View File

@ -484,7 +484,7 @@ HWTEST_F_L0(JSNApiTests, CreateNativeObject)
size_t nativeBindingSize = 7 * sizeof(void *); // 7 : params num
Local<NativePointerRef> nativeInfo = NativePointerRef::New(
vm_, reinterpret_cast<void *>(info),
[](void *data, [[maybe_unused]] void *info) {
[]([[maybe_unused]] void *env, void *data, [[maybe_unused]] void *info) {
auto externalInfo = reinterpret_cast<panda::JSNApi::NativeBindingInfo *>(data);
delete externalInfo;
},
@ -572,7 +572,7 @@ HWTEST_F_L0(JSNApiTests, GetProtoType)
size_t nativeBindingSize = 7 * sizeof(void *); // 7 : params num
Local<NativePointerRef> nativeInfo = NativePointerRef::New(
vm_, reinterpret_cast<void *>(info),
[](void *data, [[maybe_unused]] void *info) {
[]([[maybe_unused]] void *env, void *data, [[maybe_unused]] void *info) {
auto externalInfo = reinterpret_cast<panda::JSNApi::NativeBindingInfo *>(data);
delete externalInfo;
},
@ -718,7 +718,7 @@ HWTEST_F_L0(JSNApiTests, ArrayBufferWithBuffer)
const int32_t length = 15;
Data *data = new Data();
data->length = length;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
ASSERT_EQ(currentData->length, 15); // 5 : size of arguments
@ -1655,7 +1655,7 @@ HWTEST_F_L0(JSNApiTests, ObjectRef_SetNativePointerFieldCount_GetNativePointerFi
HWTEST_F_L0(JSNApiTests, FunctionRef_GetFunctionPrototype_SetName_GetName)
{
LocalScope scope(vm_);
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
void *cb = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
bool callNative = true;
size_t nativeBindingsize = 15;

View File

@ -309,7 +309,7 @@ HWTEST_F_L0(JSNApiSampleTest, sample_NativePointerRef)
GTEST_LOG_(INFO) << "sample_NativePointer adress: " << nativePointerTestClass;
Local<NativePointerRef> nativePoint = NativePointerRef::New(
vm_, nativePointerTestClass,
[](void *value, void *hint) {
[](void *env, void *value, void *hint) {
GTEST_LOG_(INFO) << "NativePointerCb value : " << value;
GTEST_LOG_(INFO) << "NativePointerCb hint : " << hint;
NativePointerTestClass *ptr = static_cast<NativePointerTestClass *>(value);
@ -1085,7 +1085,7 @@ Local<FunctionRef> Greeter::NewClassFunction(EcmaVM *vm)
thisRef->Set(vm, StringRef::NewFromUtf8(vm, "greeting"), greet);
return thisRef;
},
[](void *nativePointer, void *data) {
[](void *env, void *nativePointer, void *data) {
GTEST_LOG_(INFO) << "NewClassFunction, nativePointer is " << nativePointer;
Tag *t = static_cast<Tag *>(data);
delete t;
@ -2148,7 +2148,7 @@ HWTEST_F_L0(JSNApiSampleTest, sample_ArrayBufferWithBuffer_New_Detach)
const int32_t length = 5; // arraybuffer length = 5
Data *data = new Data();
data->length = length;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
delete currentData;
@ -2183,7 +2183,7 @@ HWTEST_F_L0(JSNApiSampleTest, sample_BufferWithBuffer_New_GetBuffer)
const int32_t length = 5; // buffer length = 5
Data *data = new Data();
data->length = length;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
delete currentData;

View File

@ -291,7 +291,7 @@ HWTEST_F_L0(JSNApiTests, BufferRef_New01_ByteLength_GetBuffer_BufferToStringCall
int32_t length;
};
const int32_t length = 15;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
delete currentData;
@ -524,7 +524,7 @@ HWTEST_F_L0(JSNApiTests, New2)
const int32_t length = 15;
Data *data = new Data();
data->length = length;
Deleter deleter = [](void *buffer, void *data) -> void {
NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
delete[] reinterpret_cast<uint8_t *>(buffer);
Data *currentData = reinterpret_cast<Data *>(data);
ASSERT_EQ(currentData->length, 15); // 5 : size of arguments

View File

@ -93,7 +93,7 @@ EcmaString *ObjectFactory::AllocTreeStringObject()
}
JSHandle<JSNativePointer> ObjectFactory::NewJSNativePointer(void *externalPointer,
const DeleteEntryPoint &callBack,
const NativePointerCallback &callBack,
void *data,
bool nonMovable,
size_t nativeBindingsize,
@ -140,14 +140,14 @@ LexicalEnv *ObjectFactory::InlineNewLexicalEnv(int numSlots)
}
template<typename T, typename S>
void ObjectFactory::NewJSIntlIcuData(const JSHandle<T> &obj, const S &icu, const DeleteEntryPoint &callback)
void ObjectFactory::NewJSIntlIcuData(const JSHandle<T> &obj, const S &icu, const NativePointerCallback &callback)
{
S *icuPoint = vm_->GetNativeAreaAllocator()->New<S>(icu);
ASSERT(icuPoint != nullptr);
JSTaggedValue data = obj->GetIcuField();
if (data.IsHeapObject() && data.IsJSNativePointer()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(icuPoint);
native->ResetExternalPointer(thread_, icuPoint);
return;
}
JSHandle<JSNativePointer> pointer = NewJSNativePointer(icuPoint, callback, vm_);

View File

@ -259,7 +259,7 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle<JSArrayBuffer> &array, i
LOG_FULL(FATAL) << "memset_s failed";
UNREACHABLE();
}
pointer->ResetExternalPointer(newData);
pointer->ResetExternalPointer(thread_, newData);
vm_->GetNativeAreaAllocator()->ModifyNativeSizeStats(pointer->GetBindingSize(), size,
NativeFlag::ARRAY_BUFFER);
return;
@ -294,7 +294,7 @@ void ObjectFactory::NewJSSendableArrayBufferData(const JSHandle<JSSendableArrayB
LOG_FULL(FATAL) << "memset_s failed";
UNREACHABLE();
}
pointer->ResetExternalPointer(newData);
pointer->ResetExternalPointer(thread_, newData);
nativeAreaAllocator->ModifyNativeSizeStats(pointer->GetBindingSize(), size,
NativeFlag::ARRAY_BUFFER);
return;
@ -368,8 +368,8 @@ JSHandle<JSArrayBuffer> ObjectFactory::NewJSArrayBuffer(int32_t length)
return arrayBuffer;
}
JSHandle<JSArrayBuffer> ObjectFactory::NewJSArrayBuffer(void *buffer, int32_t length, const DeleteEntryPoint &deleter,
void *data, bool share)
JSHandle<JSArrayBuffer> ObjectFactory::NewJSArrayBuffer(void *buffer, int32_t length,
const NativePointerCallback &deleter, void *data, bool share)
{
JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
@ -451,7 +451,7 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle<JSRegExp> &regexp, vo
JSTaggedValue data = regexp->GetByteCodeBuffer();
if (!data.IsUndefined()) {
JSNativePointer *native = JSNativePointer::Cast(data.GetTaggedObject());
native->ResetExternalPointer(newBuffer);
native->ResetExternalPointer(thread_, newBuffer);
return;
}
JSHandle<JSNativePointer> pointer = NewJSNativePointer(newBuffer, NativeAreaAllocator::FreeBufferFunc,

View File

@ -502,8 +502,8 @@ public:
JSHandle<JSArrayBuffer> NewJSArrayBuffer(int32_t length);
JSHandle<JSArrayBuffer> NewJSArrayBuffer(void *buffer, int32_t length, const DeleteEntryPoint &deleter, void *data,
bool share = false);
JSHandle<JSArrayBuffer> NewJSArrayBuffer(void *buffer, int32_t length, const NativePointerCallback &deleter,
void *data, bool share = false);
JSHandle<JSDataView> NewJSDataView(JSHandle<JSArrayBuffer> buffer, uint32_t offset, uint32_t length);
@ -516,12 +516,12 @@ public:
void NewJSRegExpByteCodeData(const JSHandle<JSRegExp> &regexp, void *buffer, size_t size);
template<typename T, typename S>
inline void NewJSIntlIcuData(const JSHandle<T> &obj, const S &icu, const DeleteEntryPoint &callback);
inline void NewJSIntlIcuData(const JSHandle<T> &obj, const S &icu, const NativePointerCallback &callback);
EcmaString *PUBLIC_API InternString(const JSHandle<JSTaggedValue> &key);
inline JSHandle<JSNativePointer> NewJSNativePointer(void *externalPointer,
const DeleteEntryPoint &callBack = nullptr,
const NativePointerCallback &callBack = nullptr,
void *data = nullptr,
bool nonMovable = false,
size_t nativeBindingsize = 0,
@ -830,7 +830,7 @@ public:
const JSHandle<JSTaggedValue> &prototype, bool isAccessor = true);
JSHandle<JSNativePointer> NewSJSNativePointer(void *externalPointer,
const DeleteEntryPoint &callBack,
const NativePointerCallback &callBack,
void *data = nullptr,
bool nonMovable = false,
size_t nativeBindingsize = 0,

View File

@ -344,7 +344,7 @@ public:
{
auto manager = JSSharedMemoryManager::GetInstance();
for (auto iter = sharedArrayBufferSet_.begin(); iter != sharedArrayBufferSet_.end(); iter++) {
JSSharedMemoryManager::RemoveSharedMemory(reinterpret_cast<void *>(*iter), manager);
JSSharedMemoryManager::RemoveSharedMemory(thread_->GetEnv(), reinterpret_cast<void *>(*iter), manager);
}
sharedArrayBufferSet_.clear();
}

View File

@ -106,7 +106,7 @@ void JSSharedMemoryManager::FreeBuffer(void *mem)
free(mem);
}
void JSSharedMemoryManager::RemoveSharedMemory(void *pointer, void *data)
void JSSharedMemoryManager::RemoveSharedMemory([[maybe_unused]] void *env, void *pointer, void *data)
{
if (pointer == nullptr || data == nullptr) {
return;

View File

@ -32,7 +32,7 @@ public:
return &jsSharedMemoryManager;
}
bool CreateOrLoad(void **pointer, size_t size);
static void RemoveSharedMemory(void *pointer, void *data);
static void RemoveSharedMemory(void *env, void *pointer, void *data);
private:
JSSharedMemoryManager() = default;

View File

@ -503,7 +503,7 @@ JSHandle<MutantTaggedArray> ObjectFactory::NewSEmptyMutantArray()
}
JSHandle<JSNativePointer> ObjectFactory::NewSJSNativePointer(void *externalPointer,
const DeleteEntryPoint &callBack,
const NativePointerCallback &callBack,
void *data,
bool nonMovable,
size_t nativeBindingsize,

View File

@ -203,7 +203,7 @@ HWTEST_F_L0(GCTest, CallbackTask)
void *externalPointer = malloc(10);
[[maybe_unused]] JSHandle<JSNativePointer> nativePointer
= factory->NewJSNativePointer(externalPointer,
[](void* pointer, [[maybe_unused]] void* data) {
[](void *env, void* pointer, [[maybe_unused]] void* data) {
if (pointer != nullptr) {
free(pointer);
}

View File

@ -30,7 +30,7 @@ void ArrayBufferRefNewFuzzTest(const uint8_t* data, size_t size)
if (size <= 0) {
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
JSNApi::DestroyJSVM(vm);
}
@ -43,7 +43,7 @@ void ArrayBufferRef_New_IsDetach_Detach_ByteLength_GetBuffer_FuzzTest(const uint
if (size <= 0) {
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
arrayBuffer->IsDetach();
arrayBuffer->Detach(vm);

View File

@ -43,7 +43,7 @@ void BufferRefMultiParamNewFuzzTest(const uint8_t *data, size_t size)
RuntimeOption option;
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
EcmaVM *vm = JSNApi::CreateJSVM(option);
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
BufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
JSNApi::DestroyJSVM(vm);
}

View File

@ -36,7 +36,7 @@ void EscapeLocalScopeFuzzTest(const uint8_t *data, size_t size)
return;
}
FunctionCallback nativeFunc = FuncRefNewCFCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
FunctionRef::NewClassFunction(vm, nativeFunc, deleter, (void *)(data + size));
JSNApi::DestroyJSVM(vm);
}

View File

@ -36,7 +36,7 @@ namespace OHOS {
return;
}
FunctionCallback nativeFunc = FuncRefCallCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<FunctionRef> func = FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
const int32_t argvLen = 3;
Local<JSValueRef> thisObj(JSValueRef::Undefined(vm));

View File

@ -37,7 +37,7 @@ namespace OHOS {
return;
}
FunctionCallback nativeFunc = FuncRefConCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<FunctionRef> func = FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
Local<JSValueRef> argv[1];
argv[0] = NumberRef::New(vm, 1.3); // 1.3 : test case of input

View File

@ -37,7 +37,7 @@ void FunctionRefGetFunctionPrototypeFuzzTest(const uint8_t *data, size_t size)
return;
}
FunctionCallback nativeFunc = FuncRefConCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<FunctionRef> func = FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
func->GetFunctionPrototype(vm);
JSNApi::DestroyJSVM(vm);

View File

@ -37,7 +37,7 @@ void FunctionRefSetNameFuzzTest(const uint8_t *data, size_t size)
return;
}
FunctionCallback nativeFunc = FuncRefConCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<FunctionRef> func = FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
Local<StringRef> name = StringRef::NewFromUtf8(vm, (char *)data, (int)size);
func->SetName(vm, name);
@ -54,7 +54,7 @@ void FunctionRefGetNameFuzzTest(const uint8_t *data, size_t size)
return;
}
FunctionCallback nativeFunc = FuncRefConCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<FunctionRef> func = FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
Local<StringRef> name = StringRef::NewFromUtf8(vm, (char *)data, (int)size);
func->SetName(vm, name);

View File

@ -36,7 +36,7 @@ namespace OHOS {
return;
}
FunctionCallback nativeFunc = FuncRefNewCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
JSNApi::DestroyJSVM(vm);
}

View File

@ -36,7 +36,7 @@ namespace OHOS {
return;
}
FunctionCallback nativeFunc = FuncRefNewCFCallbackForTest;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
FunctionRef::NewClassFunction(vm, nativeFunc, deleter, (void *)(data + size));
JSNApi::DestroyJSVM(vm);
}

View File

@ -112,7 +112,7 @@ void JSValueRefIsFunctionValueFuzzTest(const uint8_t *data, size_t size)
std::cout << "illegal input!";
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
FunctionCallback nativeFunc = FunCallback;
Local<FunctionRef> obj(FunctionRef::NewClassFunction(vm, nativeFunc, deleter, (void *)(data + size)));
(void)obj->IsFunction();

View File

@ -30,7 +30,7 @@ void IsInt8ArrayFuzztest(const uint8_t *data, size_t size)
LOG_ECMA(ERROR) << "illegal input!";
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
Local<JSValueRef> typedArray = Int8ArrayRef::New(vm, arrayBuffer, 0, (int32_t)size);
typedArray->IsInt8Array();
@ -46,7 +46,7 @@ void IsUint8ArrayFuzztest(const uint8_t *data, size_t size)
LOG_ECMA(ERROR) << "illegal input!";
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
Local<JSValueRef> typedArray = Uint8ArrayRef::New(vm, arrayBuffer, 0, (int32_t)size);
typedArray->IsUint8Array();
@ -62,7 +62,7 @@ void IsUint8ClampedArrayFuzztest(const uint8_t *data, size_t size)
LOG_ECMA(ERROR) << "illegal input!";
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
Local<JSValueRef> typedArray = Uint8ClampedArrayRef::New(vm, arrayBuffer, 0, (int32_t)size);
typedArray->IsUint8ClampedArray();
@ -78,7 +78,7 @@ void IsInt16ArrayFuzztest(const uint8_t *data, size_t size)
LOG_ECMA(ERROR) << "illegal input!";
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
int32_t length = size / sizeof(int16_t);
Local<JSValueRef> typedArray = Int16ArrayRef::New(vm, arrayBuffer, 0, length);
@ -95,7 +95,7 @@ void IsUint16ArrayFuzztest(const uint8_t *data, size_t size)
LOG_ECMA(ERROR) << "illegal input!";
return;
}
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm, (void *)data, (int32_t)size, deleter, (void *)data);
int32_t length = size / sizeof(uint16_t);
Local<JSValueRef> typedArray = Uint16ArrayRef::New(vm, arrayBuffer, 0, length);

View File

@ -40,7 +40,7 @@ void JSValueRefIsPromiseValueFuzzTest(const uint8_t *data, size_t size)
Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm);
Local<PromiseRef> promise = capability->GetPromise(vm);
FunctionCallback nativeFunc = RejectCallback;
Deleter deleter = nullptr;
NativePointerCallback deleter = nullptr;
Local<FunctionRef> reject = FunctionRef::New(vm, nativeFunc, deleter, (void *)(data + size));
Local<PromiseRef> catchPromise = promise->Catch(vm, reject);
promise->IsPromise();