• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_RUNTIME_ETS_FFI_CLASSES_ETS_ARRAYBUFFER_H_
17 #define PANDA_RUNTIME_ETS_FFI_CLASSES_ETS_ARRAYBUFFER_H_
18 
19 #include "plugins/ets/runtime/types/ets_object.h"
20 #include "plugins/ets/runtime/types/ets_array.h"
21 #include "plugins/ets/runtime/types/ets_primitives.h"
22 
23 namespace ark::ets {
24 
25 namespace test {
26 class EtsArrayBufferTest;
27 }  // namespace test
28 
29 class EtsArrayBuffer : public ObjectHeader {
30 public:
31     EtsArrayBuffer() = delete;
32     ~EtsArrayBuffer() = delete;
33 
34     NO_COPY_SEMANTIC(EtsArrayBuffer);
35     NO_MOVE_SEMANTIC(EtsArrayBuffer);
36 
FromCoreType(ObjectHeader * obj)37     static EtsArrayBuffer *FromCoreType(ObjectHeader *obj)
38     {
39         return reinterpret_cast<EtsArrayBuffer *>(obj);
40     }
41 
GetCoreType()42     ObjectHeader *GetCoreType()
43     {
44         return reinterpret_cast<ObjectHeader *>(this);
45     }
46 
AsObject()47     EtsObject *AsObject()
48     {
49         return EtsObject::FromCoreType(this);
50     }
51 
AsObject()52     const EtsObject *AsObject() const
53     {
54         return EtsObject::FromCoreType(this);
55     }
56 
FromEtsObject(EtsObject * etsObj)57     static EtsArrayBuffer *FromEtsObject(EtsObject *etsObj)
58     {
59         return reinterpret_cast<EtsArrayBuffer *>(etsObj);
60     }
61 
GetByteLength()62     EtsInt GetByteLength() const
63     {
64         return byteLength_;
65     }
66 
SetByteLength(EtsInt length)67     void SetByteLength(EtsInt length)
68     {
69         byteLength_ = length;
70     }
71 
GetData()72     EtsByteArray *GetData()
73     {
74         return data_;
75     }
76 
SetData(EtsCoroutine * coro,EtsByteArray * data)77     void SetData(EtsCoroutine *coro, EtsByteArray *data)
78     {
79         ObjectAccessor::SetObject(coro, this, MEMBER_OFFSET(EtsArrayBuffer, data_), data->GetCoreType());
80     }
81 
82 private:
83     ObjectPointer<EtsByteArray> data_;
84     EtsInt byteLength_;
85 
86     friend class test::EtsArrayBufferTest;
87 };
88 
89 }  // namespace ark::ets
90 
91 #endif  // PANDA_RUNTIME_ETS_FFI_CLASSES_ETS_ARRAYBUFFER_H_
92