| 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 "vm/SharedArrayObject.h" |
| 16 |
#include "vm/SharedMem.h" |
| 17 |
|
| 18 |
namespace js { |
| 19 |
|
| 20 |
inline SharedMem<uint8_t*> ArrayBufferObjectMaybeShared::dataPointerEither() { |
| 21 |
if (this->is<ArrayBufferObject>()) { |
| 22 |
return this->as<ArrayBufferObject>().dataPointerShared(); |
| 23 |
} |
| 24 |
return this->as<SharedArrayBufferObject>().dataPointerShared(); |
| 25 |
} |
| 26 |
|
| 27 |
inline bool ArrayBufferObjectMaybeShared::isDetached() const { |
| 28 |
if (this->is<ArrayBufferObject>()) { |
| 29 |
return this->as<ArrayBufferObject>().isDetached(); |
| 30 |
} |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
inline bool ArrayBufferObjectMaybeShared::isResizable() const { |
| 35 |
if (this->is<ArrayBufferObject>()) { |
| 36 |
return this->as<ArrayBufferObject>().isResizable(); |
| 37 |
} |
| 38 |
return this->as<SharedArrayBufferObject>().isGrowable(); |
| 39 |
} |
| 40 |
|
| 41 |
inline size_t ArrayBufferObjectMaybeShared::byteLength() const { |
| 42 |
if (this->is<ArrayBufferObject>()) { |
| 43 |
return this->as<ArrayBufferObject>().byteLength(); |
| 44 |
} |
| 45 |
return this->as<SharedArrayBufferObject>().byteLength(); |
| 46 |
} |
| 47 |
|
| 48 |
inline bool ArrayBufferObjectMaybeShared::isPreparedForAsmJS() const { |
| 49 |
if (this->is<ArrayBufferObject>()) { |
| 50 |
return this->as<ArrayBufferObject>().isPreparedForAsmJS(); |
| 51 |
} |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
inline bool ArrayBufferObjectMaybeShared::isWasm() const { |
| 56 |
if (this->is<ArrayBufferObject>()) { |
| 57 |
return this->as<ArrayBufferObject>().isWasm(); |
| 58 |
} |
| 59 |
return this->as<SharedArrayBufferObject>().isWasm(); |
| 60 |
} |
| 61 |
|
| 62 |
inline bool ArrayBufferObjectMaybeShared::pinLength(bool pin) { |
| 63 |
if (is<ArrayBufferObject>()) { |
| 64 |
return as<ArrayBufferObject>().pinLength(pin); |
| 65 |
} |
| 66 |
return false; // Cannot pin or unpin shared array buffers. |
| 67 |
} |
| 68 |
|
| 69 |
} // namespace js |
| 70 |
|
| 71 |
#endif // vm_ArrayBufferObject_inl_h |