1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  * vim: set ts=8 sts=2 et sw=2 tw=80:
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef vm_ArrayBufferObject_inl_h
8 #define vm_ArrayBufferObject_inl_h
9 
10 // Utilities and common inline code for ArrayBufferObject and
11 // SharedArrayBufferObject.
12 
13 #include "vm/ArrayBufferObject.h"
14 
15 #include "js/Value.h"
16 
17 #include "vm/SharedArrayObject.h"
18 #include "vm/SharedMem.h"
19 
20 namespace js {
21 
dataPointerEither()22 inline SharedMem<uint8_t*> ArrayBufferObjectMaybeShared::dataPointerEither() {
23   if (this->is<ArrayBufferObject>()) {
24     return this->as<ArrayBufferObject>().dataPointerShared();
25   }
26   return this->as<SharedArrayBufferObject>().dataPointerShared();
27 }
28 
isDetached()29 inline bool ArrayBufferObjectMaybeShared::isDetached() const {
30   if (this->is<ArrayBufferObject>()) {
31     return this->as<ArrayBufferObject>().isDetached();
32   }
33   return false;
34 }
35 
byteLength()36 inline size_t ArrayBufferObjectMaybeShared::byteLength() const {
37   if (this->is<ArrayBufferObject>()) {
38     return this->as<ArrayBufferObject>().byteLength();
39   }
40   return this->as<SharedArrayBufferObject>().byteLength();
41 }
42 
isPreparedForAsmJS()43 inline bool ArrayBufferObjectMaybeShared::isPreparedForAsmJS() const {
44   if (this->is<ArrayBufferObject>()) {
45     return this->as<ArrayBufferObject>().isPreparedForAsmJS();
46   }
47   return false;
48 }
49 
isWasm()50 inline bool ArrayBufferObjectMaybeShared::isWasm() const {
51   if (this->is<ArrayBufferObject>()) {
52     return this->as<ArrayBufferObject>().isWasm();
53   }
54   return this->as<SharedArrayBufferObject>().isWasm();
55 }
56 
57 }  // namespace js
58 
59 #endif  // vm_ArrayBufferObject_inl_h
60