• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 ECMASCRIPT_JSARRAYBUFFER_H
17 #define ECMASCRIPT_JSARRAYBUFFER_H
18 
19 #include "ecmascript/js_object.h"
20 
21 namespace panda::ecmascript {
22 class JSArrayBuffer final : public JSObject {
23 public:
24     CAST_NO_CHECK(JSArrayBuffer);
25 
26     // 6.2.6.2
27     static void CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue fromBlock, int32_t fromIndex, int32_t count);
28 
29     void Attach(JSThread *thread, uint32_t arrayBufferByteLength, JSTaggedValue arrayBufferData);
30     void Detach(JSThread *thread);
31 
IsDetach()32     bool IsDetach()
33     {
34         JSTaggedValue arrayBufferData = GetArrayBufferData();
35         return arrayBufferData == JSTaggedValue::Null();
36     }
37 
38     static constexpr size_t DATA_OFFSET = JSObject::SIZE;
39     ACCESSORS(ArrayBufferData, DATA_OFFSET, BYTE_LENGTH_OFFSET)
40     ACCESSORS_PRIMITIVE_FIELD(ArrayBufferByteLength, uint32_t, BYTE_LENGTH_OFFSET, BIT_FIELD_OFFSET)
41     ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
42     DEFINE_ALIGN_SIZE(LAST_OFFSET);
43 
44     // define BitField
45     static constexpr size_t SHARED_BITS = 2;
46     FIRST_BIT_FIELD(BitField, Shared, bool, SHARED_BITS)
47 
48     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, DATA_OFFSET, BYTE_LENGTH_OFFSET)
49     DECL_DUMP()
50 };
51 }  // namespace panda::ecmascript
52 
53 #endif  // ECMASCRIPT_JSARRAYBUFFER_H