!5217 add function getdata and setdata

Merge pull request !5217 from wangzhaoyong/scope11
This commit is contained in:
openharmony_ci 2023-11-12 11:03:17 +00:00 committed by Gitee
commit e1b9aa3ed4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 29 additions and 0 deletions

View File

@ -771,6 +771,8 @@ public:
Local<StringRef> GetName(const EcmaVM *vm); Local<StringRef> GetName(const EcmaVM *vm);
Local<StringRef> GetSourceCode(const EcmaVM *vm, int lineNumber); Local<StringRef> GetSourceCode(const EcmaVM *vm, int lineNumber);
bool IsNative(const EcmaVM *vm); bool IsNative(const EcmaVM *vm);
void SetData(const EcmaVM *vm, void *data, Deleter deleter = nullptr, bool callNapi = false);
void* GetData(const EcmaVM *vm);
}; };
class PUBLIC_API ArrayRef : public ObjectRef { class PUBLIC_API ArrayRef : public ObjectRef {

View File

@ -1920,6 +1920,33 @@ bool FunctionRef::IsNative(const EcmaVM *vm)
return method->IsNativeWithCallField(); return method->IsNativeWithCallField();
} }
void FunctionRef::SetData(const EcmaVM *vm, void *data, Deleter deleter, bool callNapi)
{
CHECK_HAS_PENDING_EXCEPTION_WITHOUT_RETURN(vm);
JSThread *thread = vm->GetJSThread();
JSHandle<JSTaggedValue> funcValue = JSNApiHelper::ToJSHandle(this);
JSHandle<JSFunction> function(funcValue);
function->SetFunctionExtraInfo(thread, nullptr, deleter, data, 0);
function->SetCallNapi(callNapi);
}
void* FunctionRef::GetData(const EcmaVM *vm)
{
CHECK_HAS_PENDING_EXCEPTION(vm, nullptr);
JSThread *thread = vm->GetJSThread();
JSHandle<JSTaggedValue> funcValue = JSNApiHelper::ToJSHandle(this);
JSHandle<JSFunction> function(funcValue);
if (!function->IsCallNapi()) {
return nullptr;
}
JSTaggedValue extraInfoValue = function->GetFunctionExtraInfo();
if (!extraInfoValue.IsNativePointer()) {
return nullptr;
}
JSHandle<JSNativePointer> extraInfo(thread, extraInfoValue);
return extraInfo->GetData();
}
// ----------------------------------- ArrayRef ---------------------------------------- // ----------------------------------- ArrayRef ----------------------------------------
Local<ArrayRef> ArrayRef::New(const EcmaVM *vm, uint32_t length) Local<ArrayRef> ArrayRef::New(const EcmaVM *vm, uint32_t length)
{ {