LCOV - code coverage report
Current view: top level - js/src/builtin - DataViewObject.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 27 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  * vim: set ts=8 sts=4 et sw=4 tw=99:
       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_DataViewObject_h
       8             : #define vm_DataViewObject_h
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : 
      12             : #include "jsobj.h"
      13             : 
      14             : #include "gc/Barrier.h"
      15             : #include "js/Class.h"
      16             : #include "vm/ArrayBufferObject.h"
      17             : #include "vm/SharedArrayObject.h"
      18             : #include "vm/TypedArrayObject.h"
      19             : 
      20             : namespace js {
      21             : 
      22             : // In the DataViewObject, the private slot contains a raw pointer into
      23             : // the buffer.  The buffer may be shared memory and the raw pointer
      24             : // should not be exposed without sharedness information accompanying
      25             : // it.
      26             : 
      27             : class DataViewObject : public NativeObject
      28             : {
      29             :   private:
      30             :     static const Class protoClass_;
      31             :     static const ClassSpec classSpec_;
      32             : 
      33             :     static JSObject* CreatePrototype(JSContext* cx, JSProtoKey key);
      34             : 
      35           0 :     static bool is(HandleValue v) {
      36           0 :         return v.isObject() && v.toObject().hasClass(&class_);
      37             :     }
      38             : 
      39             :     template <typename NativeType>
      40             :     static SharedMem<uint8_t*>
      41             :     getDataPointer(JSContext* cx, Handle<DataViewObject*> obj, uint64_t offset, bool* isSharedMemory);
      42             : 
      43             :     static bool bufferGetterImpl(JSContext* cx, const CallArgs& args);
      44             :     static bool bufferGetter(JSContext* cx, unsigned argc, Value* vp);
      45             : 
      46             :     static bool byteLengthGetterImpl(JSContext* cx, const CallArgs& args);
      47             :     static bool byteLengthGetter(JSContext* cx, unsigned argc, Value* vp);
      48             : 
      49             :     static bool byteOffsetGetterImpl(JSContext* cx, const CallArgs& args);
      50             :     static bool byteOffsetGetter(JSContext* cx, unsigned argc, Value* vp);
      51             : 
      52             :     static bool
      53             :     getAndCheckConstructorArgs(JSContext* cx, HandleObject bufobj, const CallArgs& args,
      54             :                                uint32_t* byteOffset, uint32_t* byteLength);
      55             :     static bool constructSameCompartment(JSContext* cx, HandleObject bufobj, const CallArgs& args);
      56             :     static bool constructWrapped(JSContext* cx, HandleObject bufobj, const CallArgs& args);
      57             : 
      58             :     static DataViewObject*
      59             :     create(JSContext* cx, uint32_t byteOffset, uint32_t byteLength,
      60             :            Handle<ArrayBufferObjectMaybeShared*> arrayBuffer, JSObject* proto);
      61             : 
      62             :   public:
      63             :     static const Class class_;
      64             : 
      65           0 :     static Value byteOffsetValue(DataViewObject* view) {
      66           0 :         Value v = view->getFixedSlot(TypedArrayObject::BYTEOFFSET_SLOT);
      67           0 :         MOZ_ASSERT(v.toInt32() >= 0);
      68           0 :         return v;
      69             :     }
      70             : 
      71           0 :     static Value byteLengthValue(DataViewObject* view) {
      72           0 :         Value v = view->getFixedSlot(TypedArrayObject::LENGTH_SLOT);
      73           0 :         MOZ_ASSERT(v.toInt32() >= 0);
      74           0 :         return v;
      75             :     }
      76             : 
      77           0 :     static Value bufferValue(DataViewObject* view) {
      78           0 :         return view->getFixedSlot(TypedArrayObject::BUFFER_SLOT);
      79             :     }
      80             : 
      81           0 :     uint32_t byteOffset() const {
      82           0 :         return byteOffsetValue(const_cast<DataViewObject*>(this)).toInt32();
      83             :     }
      84             : 
      85           0 :     uint32_t byteLength() const {
      86           0 :         return byteLengthValue(const_cast<DataViewObject*>(this)).toInt32();
      87             :     }
      88             : 
      89           0 :     ArrayBufferObjectMaybeShared& arrayBufferEither() const {
      90           0 :         return bufferValue(
      91           0 :             const_cast<DataViewObject*>(this)).toObject().as<ArrayBufferObjectMaybeShared>();
      92             :     }
      93             : 
      94           0 :     SharedMem<void*> dataPointerEither() const {
      95           0 :         void *p = getPrivate();
      96           0 :         if (isSharedMemory())
      97           0 :             return SharedMem<void*>::shared(p);
      98           0 :         return SharedMem<void*>::unshared(p);
      99             :     }
     100             : 
     101           0 :     void* dataPointerUnshared() const {
     102           0 :         MOZ_ASSERT(!isSharedMemory());
     103           0 :         return getPrivate();
     104             :     }
     105             : 
     106             :     void* dataPointerShared() const {
     107             :         MOZ_ASSERT(isSharedMemory());
     108             :         return getPrivate();
     109             :     }
     110             : 
     111             :     static bool construct(JSContext* cx, unsigned argc, Value* vp);
     112             : 
     113             :     static bool getInt8Impl(JSContext* cx, const CallArgs& args);
     114             :     static bool fun_getInt8(JSContext* cx, unsigned argc, Value* vp);
     115             : 
     116             :     static bool getUint8Impl(JSContext* cx, const CallArgs& args);
     117             :     static bool fun_getUint8(JSContext* cx, unsigned argc, Value* vp);
     118             : 
     119             :     static bool getInt16Impl(JSContext* cx, const CallArgs& args);
     120             :     static bool fun_getInt16(JSContext* cx, unsigned argc, Value* vp);
     121             : 
     122             :     static bool getUint16Impl(JSContext* cx, const CallArgs& args);
     123             :     static bool fun_getUint16(JSContext* cx, unsigned argc, Value* vp);
     124             : 
     125             :     static bool getInt32Impl(JSContext* cx, const CallArgs& args);
     126             :     static bool fun_getInt32(JSContext* cx, unsigned argc, Value* vp);
     127             : 
     128             :     static bool getUint32Impl(JSContext* cx, const CallArgs& args);
     129             :     static bool fun_getUint32(JSContext* cx, unsigned argc, Value* vp);
     130             : 
     131             :     static bool getFloat32Impl(JSContext* cx, const CallArgs& args);
     132             :     static bool fun_getFloat32(JSContext* cx, unsigned argc, Value* vp);
     133             : 
     134             :     static bool getFloat64Impl(JSContext* cx, const CallArgs& args);
     135             :     static bool fun_getFloat64(JSContext* cx, unsigned argc, Value* vp);
     136             : 
     137             :     static bool setInt8Impl(JSContext* cx, const CallArgs& args);
     138             :     static bool fun_setInt8(JSContext* cx, unsigned argc, Value* vp);
     139             : 
     140             :     static bool setUint8Impl(JSContext* cx, const CallArgs& args);
     141             :     static bool fun_setUint8(JSContext* cx, unsigned argc, Value* vp);
     142             : 
     143             :     static bool setInt16Impl(JSContext* cx, const CallArgs& args);
     144             :     static bool fun_setInt16(JSContext* cx, unsigned argc, Value* vp);
     145             : 
     146             :     static bool setUint16Impl(JSContext* cx, const CallArgs& args);
     147             :     static bool fun_setUint16(JSContext* cx, unsigned argc, Value* vp);
     148             : 
     149             :     static bool setInt32Impl(JSContext* cx, const CallArgs& args);
     150             :     static bool fun_setInt32(JSContext* cx, unsigned argc, Value* vp);
     151             : 
     152             :     static bool setUint32Impl(JSContext* cx, const CallArgs& args);
     153             :     static bool fun_setUint32(JSContext* cx, unsigned argc, Value* vp);
     154             : 
     155             :     static bool setFloat32Impl(JSContext* cx, const CallArgs& args);
     156             :     static bool fun_setFloat32(JSContext* cx, unsigned argc, Value* vp);
     157             : 
     158             :     static bool setFloat64Impl(JSContext* cx, const CallArgs& args);
     159             :     static bool fun_setFloat64(JSContext* cx, unsigned argc, Value* vp);
     160             : 
     161             :     static bool initClass(JSContext* cx);
     162             :     template<typename NativeType>
     163             :     static bool read(JSContext* cx, Handle<DataViewObject*> obj, const CallArgs& args,
     164             :                      NativeType* val);
     165             :     template<typename NativeType>
     166             :     static bool write(JSContext* cx, Handle<DataViewObject*> obj, const CallArgs& args);
     167             : 
     168             :     void notifyBufferDetached(void* newData);
     169             : 
     170             :   private:
     171             :     static const JSFunctionSpec methods[];
     172             :     static const JSPropertySpec properties[];
     173             : };
     174             : 
     175             : } // namespace js
     176             : 
     177             : #endif /* vm_DataViewObject_h */

Generated by: LCOV version 1.13