2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-04 20:36:56 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_TypedArray_h
|
|
|
|
#define mozilla_dom_TypedArray_h
|
|
|
|
|
2019-03-05 02:19:16 +03:00
|
|
|
#include "jsfriendapi.h" // js::Scalar
|
|
|
|
#include "js/ArrayBuffer.h"
|
|
|
|
#include "js/SharedArrayBuffer.h"
|
|
|
|
#include "js/GCAPI.h" // JS::AutoCheckCannotGC
|
|
|
|
#include "js/RootingAPI.h" // JS::Rooted
|
2013-08-29 08:30:04 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-05-24 01:32:38 +04:00
|
|
|
#include "mozilla/Move.h"
|
2013-08-05 21:40:02 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2017-08-11 04:04:54 +03:00
|
|
|
#include "mozilla/dom/SpiderMonkeyInterface.h"
|
2013-08-24 06:42:40 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2012-05-04 20:36:56 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Various typed array classes for argument conversion. We have a base class
|
|
|
|
* that has a way of initializing a TypedArray from an existing typed array, and
|
|
|
|
* a subclass of the base class that supports creation of a relevant typed array
|
|
|
|
* or array buffer object.
|
|
|
|
*/
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
template <typename T, JSObject* UnwrapArray(JSObject*),
|
2015-11-25 21:04:50 +03:00
|
|
|
void GetLengthAndDataAndSharedness(JSObject*, uint32_t*, bool*, T**)>
|
2017-08-11 04:04:54 +03:00
|
|
|
struct TypedArray_base : public SpiderMonkeyInterfaceObjectStorage,
|
|
|
|
AllTypedArraysBase {
|
2014-03-10 16:55:46 +04:00
|
|
|
typedef T element_type;
|
|
|
|
|
2013-08-29 08:30:04 +04:00
|
|
|
TypedArray_base()
|
2014-06-04 05:31:43 +04:00
|
|
|
: mData(nullptr), mLength(0), mShared(false), mComputed(false) {}
|
2012-08-01 07:45:20 +04:00
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
TypedArray_base(TypedArray_base&& aOther)
|
2018-05-30 22:15:35 +03:00
|
|
|
: SpiderMonkeyInterfaceObjectStorage(std::move(aOther)),
|
2014-05-24 01:32:38 +04:00
|
|
|
mData(aOther.mData),
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
mLength(aOther.mLength),
|
2015-11-25 21:04:50 +03:00
|
|
|
mShared(aOther.mShared),
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
mComputed(aOther.mComputed) {
|
2014-05-24 01:32:38 +04:00
|
|
|
aOther.mData = nullptr;
|
|
|
|
aOther.mLength = 0;
|
2015-11-25 21:04:50 +03:00
|
|
|
aOther.mShared = false;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
aOther.mComputed = false;
|
2014-05-24 01:32:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-01 07:45:20 +04:00
|
|
|
private:
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
mutable T* mData;
|
|
|
|
mutable uint32_t mLength;
|
2015-11-25 21:04:50 +03:00
|
|
|
mutable bool mShared;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
mutable bool mComputed;
|
2012-08-01 07:06:35 +04:00
|
|
|
|
2012-08-01 07:45:20 +04:00
|
|
|
public:
|
2013-08-05 21:40:01 +04:00
|
|
|
inline bool Init(JSObject* obj) {
|
2013-08-05 21:40:01 +04:00
|
|
|
MOZ_ASSERT(!inited());
|
2017-08-11 04:04:54 +03:00
|
|
|
mImplObj = mWrappedObj = UnwrapArray(obj);
|
2013-08-05 21:40:01 +04:00
|
|
|
return inited();
|
2013-08-05 21:40:01 +04:00
|
|
|
}
|
|
|
|
|
2015-11-25 21:04:50 +03:00
|
|
|
// About shared memory:
|
|
|
|
//
|
2016-11-24 16:16:17 +03:00
|
|
|
// Any DOM TypedArray as well as any DOM ArrayBufferView can map the
|
|
|
|
// memory of either a JS ArrayBuffer or a JS SharedArrayBuffer. If
|
|
|
|
// the TypedArray maps a SharedArrayBuffer the Length() and Data()
|
|
|
|
// accessors on the DOM view will return zero and nullptr; to get
|
|
|
|
// the actual length and data, call the LengthAllowShared() and
|
|
|
|
// DataAllowShared() accessors instead.
|
2015-11-25 21:04:50 +03:00
|
|
|
//
|
|
|
|
// Two methods are available for determining if a DOM view maps
|
|
|
|
// shared memory. The IsShared() method is cheap and can be called
|
|
|
|
// if the view has been computed; the JS_GetTypedArraySharedness()
|
|
|
|
// method is slightly more expensive and can be called on the Obj()
|
|
|
|
// value if the view may not have been computed and if the value is
|
|
|
|
// known to represent a JS TypedArray.
|
|
|
|
//
|
2019-03-05 02:19:16 +03:00
|
|
|
// (Just use JS::IsSharedArrayBuffer() to test if any object is of
|
2015-11-25 21:04:50 +03:00
|
|
|
// that type.)
|
|
|
|
//
|
|
|
|
// Code that elects to allow views that map shared memory to be used
|
|
|
|
// -- ie, code that "opts in to shared memory" -- should generally
|
|
|
|
// not access the raw data buffer with standard C++ mechanisms as
|
|
|
|
// that creates the possibility of C++ data races, which is
|
|
|
|
// undefined behavior. The JS engine will eventually export (bug
|
|
|
|
// 1225033) a suite of methods that avoid undefined behavior.
|
|
|
|
//
|
|
|
|
// Callers of Obj() that do not opt in to shared memory can produce
|
|
|
|
// better diagnostics by checking whether the JSObject in fact maps
|
|
|
|
// shared memory and throwing an error if it does. However, it is
|
|
|
|
// safe to use the value of Obj() without such checks.
|
|
|
|
//
|
|
|
|
// The DOM TypedArray abstraction prevents the underlying buffer object
|
|
|
|
// from being accessed directly, but JS_GetArrayBufferViewBuffer(Obj())
|
|
|
|
// will obtain the buffer object. Code that calls that function must
|
|
|
|
// not assume the returned buffer is an ArrayBuffer. That is guarded
|
|
|
|
// against by an out parameter on that call that communicates the
|
|
|
|
// sharedness of the buffer.
|
|
|
|
//
|
|
|
|
// Finally, note that the buffer memory of a SharedArrayBuffer is
|
|
|
|
// not detachable.
|
|
|
|
|
|
|
|
inline bool IsShared() const {
|
|
|
|
MOZ_ASSERT(mComputed);
|
|
|
|
return mShared;
|
|
|
|
}
|
|
|
|
|
2012-08-01 07:45:20 +04:00
|
|
|
inline T* Data() const {
|
2015-11-25 21:04:50 +03:00
|
|
|
MOZ_ASSERT(mComputed);
|
|
|
|
if (mShared) return nullptr;
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T* DataAllowShared() const {
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
MOZ_ASSERT(mComputed);
|
2012-08-01 07:45:20 +04:00
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t Length() const {
|
2015-11-25 21:04:50 +03:00
|
|
|
MOZ_ASSERT(mComputed);
|
|
|
|
if (mShared) return 0;
|
|
|
|
return mLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t LengthAllowShared() const {
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
MOZ_ASSERT(mComputed);
|
2012-08-01 07:45:20 +04:00
|
|
|
return mLength;
|
|
|
|
}
|
|
|
|
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
inline void ComputeLengthAndData() const {
|
|
|
|
MOZ_ASSERT(inited());
|
|
|
|
MOZ_ASSERT(!mComputed);
|
2017-08-11 04:04:54 +03:00
|
|
|
GetLengthAndDataAndSharedness(mImplObj, &mLength, &mShared, &mData);
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
mComputed = true;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:30:05 +04:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
TypedArray_base(const TypedArray_base&) = delete;
|
2012-05-04 20:36:56 +04:00
|
|
|
};
|
|
|
|
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
template <typename T, JSObject* UnwrapArray(JSObject*),
|
2017-07-26 13:20:59 +03:00
|
|
|
T* GetData(JSObject*, bool* isShared, const JS::AutoRequireNoGC&),
|
2015-11-25 21:04:50 +03:00
|
|
|
void GetLengthAndDataAndSharedness(JSObject*, uint32_t*, bool*, T**),
|
2012-05-04 20:36:56 +04:00
|
|
|
JSObject* CreateNew(JSContext*, uint32_t)>
|
2015-11-25 21:04:50 +03:00
|
|
|
struct TypedArray
|
|
|
|
: public TypedArray_base<T, UnwrapArray, GetLengthAndDataAndSharedness> {
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
private:
|
2015-11-25 21:04:50 +03:00
|
|
|
typedef TypedArray_base<T, UnwrapArray, GetLengthAndDataAndSharedness> Base;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
TypedArray() : Base() {}
|
2013-08-05 21:40:01 +04:00
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
TypedArray(TypedArray&& aOther) : Base(std::move(aOther)) {}
|
2014-05-24 01:32:38 +04:00
|
|
|
|
2012-06-25 20:37:46 +04:00
|
|
|
static inline JSObject* Create(JSContext* cx, nsWrapperCache* creator,
|
2013-08-23 09:17:07 +04:00
|
|
|
uint32_t length, const T* data = nullptr) {
|
2013-05-31 01:46:48 +04:00
|
|
|
JS::Rooted<JSObject*> creatorWrapper(cx);
|
2018-08-02 09:48:50 +03:00
|
|
|
Maybe<JSAutoRealm> ar;
|
2012-06-25 20:37:46 +04:00
|
|
|
if (creator && (creatorWrapper = creator->GetWrapperPreserveColor())) {
|
2018-05-16 11:53:16 +03:00
|
|
|
ar.emplace(cx, creatorWrapper);
|
2012-06-25 20:37:46 +04:00
|
|
|
}
|
2013-08-23 09:17:07 +04:00
|
|
|
|
2014-04-10 08:58:42 +04:00
|
|
|
return CreateCommon(cx, length, data);
|
2013-08-23 09:17:07 +04:00
|
|
|
}
|
|
|
|
|
2014-04-10 08:58:42 +04:00
|
|
|
static inline JSObject* Create(JSContext* cx, uint32_t length,
|
|
|
|
const T* data = nullptr) {
|
|
|
|
return CreateCommon(cx, length, data);
|
2013-08-23 09:17:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-04-10 08:58:42 +04:00
|
|
|
static inline JSObject* CreateCommon(JSContext* cx, uint32_t length,
|
|
|
|
const T* data) {
|
2012-05-04 20:36:56 +04:00
|
|
|
JSObject* obj = CreateNew(cx, length);
|
|
|
|
if (!obj) {
|
2013-08-23 09:17:07 +04:00
|
|
|
return nullptr;
|
2012-05-04 20:36:56 +04:00
|
|
|
}
|
|
|
|
if (data) {
|
2014-10-07 21:44:07 +04:00
|
|
|
JS::AutoCheckCannotGC nogc;
|
2015-11-25 21:04:50 +03:00
|
|
|
bool isShared;
|
|
|
|
T* buf = static_cast<T*>(GetData(obj, &isShared, nogc));
|
|
|
|
// Data will not be shared, until a construction protocol exists
|
|
|
|
// for constructing shared data.
|
|
|
|
MOZ_ASSERT(!isShared);
|
2012-05-04 20:36:56 +04:00
|
|
|
memcpy(buf, data, length * sizeof(T));
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
2013-08-29 08:30:05 +04:00
|
|
|
|
2015-01-07 02:35:02 +03:00
|
|
|
TypedArray(const TypedArray&) = delete;
|
2012-05-04 20:36:56 +04:00
|
|
|
};
|
|
|
|
|
2015-06-24 18:10:15 +03:00
|
|
|
template <JSObject* UnwrapArray(JSObject*),
|
2015-11-25 21:04:50 +03:00
|
|
|
void GetLengthAndDataAndSharedness(JSObject*, uint32_t*, bool*,
|
|
|
|
uint8_t**),
|
2015-06-24 18:10:15 +03:00
|
|
|
js::Scalar::Type GetViewType(JSObject*)>
|
2015-11-25 21:04:50 +03:00
|
|
|
struct ArrayBufferView_base
|
|
|
|
: public TypedArray_base<uint8_t, UnwrapArray,
|
|
|
|
GetLengthAndDataAndSharedness> {
|
2015-06-24 18:10:15 +03:00
|
|
|
private:
|
2015-11-25 21:04:50 +03:00
|
|
|
typedef TypedArray_base<uint8_t, UnwrapArray, GetLengthAndDataAndSharedness>
|
|
|
|
Base;
|
2015-06-24 18:10:15 +03:00
|
|
|
|
|
|
|
public:
|
2018-06-16 17:21:46 +03:00
|
|
|
ArrayBufferView_base() : Base(), mType(js::Scalar::MaxTypedArrayViewType) {}
|
2015-06-24 18:10:15 +03:00
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
ArrayBufferView_base(ArrayBufferView_base&& aOther)
|
2018-05-30 22:15:35 +03:00
|
|
|
: Base(std::move(aOther)), mType(aOther.mType) {
|
2015-06-24 18:10:15 +03:00
|
|
|
aOther.mType = js::Scalar::MaxTypedArrayViewType;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
js::Scalar::Type mType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline bool Init(JSObject* obj) {
|
|
|
|
if (!Base::Init(obj)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mType = GetViewType(this->Obj());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Scalar::Type Type() const {
|
|
|
|
MOZ_ASSERT(this->inited());
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<int8_t, js::UnwrapInt8Array, JS_GetInt8ArrayData,
|
|
|
|
js::GetInt8ArrayLengthAndData, JS_NewInt8Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Int8Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<uint8_t, js::UnwrapUint8Array, JS_GetUint8ArrayData,
|
|
|
|
js::GetUint8ArrayLengthAndData, JS_NewUint8Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Uint8Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<
|
|
|
|
uint8_t, js::UnwrapUint8ClampedArray, JS_GetUint8ClampedArrayData,
|
|
|
|
js::GetUint8ClampedArrayLengthAndData, JS_NewUint8ClampedArray>
|
2012-05-04 20:36:56 +04:00
|
|
|
Uint8ClampedArray;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<int16_t, js::UnwrapInt16Array, JS_GetInt16ArrayData,
|
|
|
|
js::GetInt16ArrayLengthAndData, JS_NewInt16Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Int16Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<uint16_t, js::UnwrapUint16Array, JS_GetUint16ArrayData,
|
|
|
|
js::GetUint16ArrayLengthAndData, JS_NewUint16Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Uint16Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<int32_t, js::UnwrapInt32Array, JS_GetInt32ArrayData,
|
|
|
|
js::GetInt32ArrayLengthAndData, JS_NewInt32Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Int32Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<uint32_t, js::UnwrapUint32Array, JS_GetUint32ArrayData,
|
|
|
|
js::GetUint32ArrayLengthAndData, JS_NewUint32Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Uint32Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<float, js::UnwrapFloat32Array, JS_GetFloat32ArrayData,
|
|
|
|
js::GetFloat32ArrayLengthAndData, JS_NewFloat32Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Float32Array;
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
typedef TypedArray<double, js::UnwrapFloat64Array, JS_GetFloat64ArrayData,
|
|
|
|
js::GetFloat64ArrayLengthAndData, JS_NewFloat64Array>
|
2012-05-04 20:36:56 +04:00
|
|
|
Float64Array;
|
2015-06-24 18:10:15 +03:00
|
|
|
typedef ArrayBufferView_base<js::UnwrapArrayBufferView,
|
|
|
|
js::GetArrayBufferViewLengthAndData,
|
|
|
|
JS_GetArrayBufferViewType>
|
2012-05-04 20:36:56 +04:00
|
|
|
ArrayBufferView;
|
2019-03-05 02:19:16 +03:00
|
|
|
typedef TypedArray<uint8_t, JS::UnwrapArrayBuffer, JS::GetArrayBufferData,
|
|
|
|
JS::GetArrayBufferLengthAndData, JS::NewArrayBuffer>
|
2012-05-04 20:36:56 +04:00
|
|
|
ArrayBuffer;
|
|
|
|
|
2015-06-13 14:02:46 +03:00
|
|
|
typedef TypedArray<
|
2019-03-05 02:19:16 +03:00
|
|
|
uint8_t, JS::UnwrapSharedArrayBuffer, JS::GetSharedArrayBufferData,
|
|
|
|
JS::GetSharedArrayBufferLengthAndData, JS::NewSharedArrayBuffer>
|
2015-06-13 14:02:46 +03:00
|
|
|
SharedArrayBuffer;
|
|
|
|
|
2014-03-10 16:55:46 +04:00
|
|
|
// A class for converting an nsTArray to a TypedArray
|
|
|
|
// Note: A TypedArrayCreator must not outlive the nsTArray it was created from.
|
|
|
|
// So this is best used to pass from things that understand nsTArray to
|
2016-12-20 02:38:42 +03:00
|
|
|
// things that understand TypedArray, as with ToJSValue.
|
2014-03-10 16:55:46 +04:00
|
|
|
template <typename TypedArrayType>
|
|
|
|
class TypedArrayCreator {
|
|
|
|
typedef nsTArray<typename TypedArrayType::element_type> ArrayType;
|
|
|
|
|
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit TypedArrayCreator(const ArrayType& aArray) : mArray(aArray) {}
|
2014-03-10 16:55:46 +04:00
|
|
|
|
2014-04-09 02:27:19 +04:00
|
|
|
JSObject* Create(JSContext* aCx) const {
|
2014-04-16 21:56:52 +04:00
|
|
|
return TypedArrayType::Create(aCx, mArray.Length(), mArray.Elements());
|
2014-03-10 16:55:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ArrayType& mArray;
|
|
|
|
};
|
|
|
|
|
2012-05-04 20:36:56 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_TypedArray_h */
|