tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ArrayBufferObject-inl.h (2342B)


      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 bool ArrayBufferObjectMaybeShared::isImmutable() const {
     42  if (this->is<ArrayBufferObject>()) {
     43    return this->as<ArrayBufferObject>().isImmutable();
     44  }
     45  return false;
     46 }
     47 
     48 inline size_t ArrayBufferObjectMaybeShared::byteLength() const {
     49  if (this->is<ArrayBufferObject>()) {
     50    return this->as<ArrayBufferObject>().byteLength();
     51  }
     52  return this->as<SharedArrayBufferObject>().byteLength();
     53 }
     54 
     55 inline bool ArrayBufferObjectMaybeShared::isPreparedForAsmJS() const {
     56  if (this->is<ArrayBufferObject>()) {
     57    return this->as<ArrayBufferObject>().isPreparedForAsmJS();
     58  }
     59  return false;
     60 }
     61 
     62 inline bool ArrayBufferObjectMaybeShared::isWasm() const {
     63  if (this->is<ArrayBufferObject>()) {
     64    return this->as<ArrayBufferObject>().isWasm();
     65  }
     66  return this->as<SharedArrayBufferObject>().isWasm();
     67 }
     68 
     69 inline bool ArrayBufferObjectMaybeShared::pinLength(bool pin) {
     70  if (is<ArrayBufferObject>()) {
     71    return as<ArrayBufferObject>().pinLength(pin);
     72  }
     73  return false;  // Cannot pin or unpin shared array buffers.
     74 }
     75 
     76 }  // namespace js
     77 
     78 #endif  // vm_ArrayBufferObject_inl_h