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
|
|
|
|
|
2013-08-05 21:40:01 +04:00
|
|
|
#include "jsapi.h"
|
2013-09-06 10:43:04 +04:00
|
|
|
#include "jsfriendapi.h"
|
|
|
|
#include "js/RootingAPI.h"
|
2014-04-12 02:19:05 +04:00
|
|
|
#include "js/TracingAPI.h"
|
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"
|
2013-08-24 06:42:40 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2012-05-04 20:36:56 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-08-29 08:30:04 +04:00
|
|
|
/*
|
|
|
|
* Class that just handles the JSObject storage and tracing for typed arrays
|
|
|
|
*/
|
|
|
|
struct TypedArrayObjectStorage : AllTypedArraysBase {
|
|
|
|
protected:
|
2014-06-04 05:47:59 +04:00
|
|
|
JSObject* mTypedObj;
|
|
|
|
JSObject* mWrappedObj;
|
2013-08-29 08:30:04 +04:00
|
|
|
|
2014-06-04 05:47:59 +04:00
|
|
|
TypedArrayObjectStorage()
|
|
|
|
: mTypedObj(nullptr),
|
|
|
|
mWrappedObj(nullptr)
|
2013-08-29 08:30:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
TypedArrayObjectStorage(TypedArrayObjectStorage&& aOther)
|
2014-06-04 05:47:59 +04:00
|
|
|
: mTypedObj(aOther.mTypedObj),
|
|
|
|
mWrappedObj(aOther.mWrappedObj)
|
2014-05-24 01:32:38 +04:00
|
|
|
{
|
2014-06-04 05:47:59 +04:00
|
|
|
aOther.mTypedObj = nullptr;
|
|
|
|
aOther.mWrappedObj = nullptr;
|
2014-05-24 01:32:38 +04:00
|
|
|
}
|
|
|
|
|
2013-08-29 08:30:04 +04:00
|
|
|
public:
|
|
|
|
inline void TraceSelf(JSTracer* trc)
|
|
|
|
{
|
2014-06-04 05:47:59 +04:00
|
|
|
if (mTypedObj) {
|
2014-08-13 13:05:22 +04:00
|
|
|
JS_CallUnbarrieredObjectTracer(trc, &mTypedObj, "TypedArray.mTypedObj");
|
2014-06-04 05:47:59 +04:00
|
|
|
}
|
|
|
|
if (mWrappedObj) {
|
2014-08-13 13:05:22 +04:00
|
|
|
JS_CallUnbarrieredObjectTracer(trc, &mTypedObj, "TypedArray.mWrappedObj");
|
2013-10-28 20:37:58 +04:00
|
|
|
}
|
2013-08-29 08:30:04 +04:00
|
|
|
}
|
2013-08-29 08:30:05 +04:00
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
TypedArrayObjectStorage(const TypedArrayObjectStorage&) = delete;
|
2013-08-29 08:30:04 +04:00
|
|
|
};
|
|
|
|
|
2012-05-04 20:36:56 +04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-01 07:45:20 +04:00
|
|
|
template<typename T,
|
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
|
|
|
JSObject* UnwrapArray(JSObject*),
|
|
|
|
void GetLengthAndData(JSObject*, uint32_t*, T**)>
|
2013-08-29 08:30:04 +04:00
|
|
|
struct TypedArray_base : public TypedArrayObjectStorage {
|
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),
|
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(0),
|
|
|
|
mComputed(false)
|
2013-08-05 21:40:01 +04:00
|
|
|
{
|
2012-08-01 07:45:20 +04:00
|
|
|
}
|
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
TypedArray_base(TypedArray_base&& aOther)
|
2014-05-24 01:32:38 +04:00
|
|
|
: TypedArrayObjectStorage(Move(aOther)),
|
|
|
|
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),
|
|
|
|
mComputed(aOther.mComputed)
|
2014-05-24 01:32:38 +04:00
|
|
|
{
|
|
|
|
aOther.mData = nullptr;
|
|
|
|
aOther.mLength = 0;
|
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;
|
|
|
|
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());
|
2014-06-04 05:47:59 +04:00
|
|
|
mTypedObj = mWrappedObj = UnwrapArray(obj);
|
2013-08-05 21:40:01 +04:00
|
|
|
return inited();
|
2013-08-05 21:40:01 +04:00
|
|
|
}
|
|
|
|
|
2012-08-01 07:45:20 +04:00
|
|
|
inline bool inited() const {
|
2014-06-04 05:47:59 +04:00
|
|
|
return !!mTypedObj;
|
2012-08-01 07:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline T *Data() 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 {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JSObject *Obj() const {
|
|
|
|
MOZ_ASSERT(inited());
|
2014-06-04 05:47:59 +04:00
|
|
|
return mWrappedObj;
|
2012-08-01 07:45:20 +04:00
|
|
|
}
|
2013-08-05 21:40:01 +04:00
|
|
|
|
2013-08-05 21:40:01 +04:00
|
|
|
inline bool WrapIntoNewCompartment(JSContext* cx)
|
|
|
|
{
|
2013-11-11 12:04:41 +04:00
|
|
|
return JS_WrapObject(cx,
|
2014-06-04 05:47:59 +04:00
|
|
|
JS::MutableHandle<JSObject*>::fromMarkedLocation(&mWrappedObj));
|
2013-08-05 21:40:01 +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
|
|
|
inline void ComputeLengthAndData() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(inited());
|
|
|
|
MOZ_ASSERT(!mComputed);
|
2014-06-04 05:47:59 +04:00
|
|
|
GetLengthAndData(mTypedObj, &mLength, &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
|
|
|
};
|
|
|
|
|
2012-08-01 07:45:20 +04:00
|
|
|
template<typename T,
|
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
|
|
|
JSObject* UnwrapArray(JSObject*),
|
2014-10-07 21:44:07 +04:00
|
|
|
T* GetData(JSObject*, const JS::AutoCheckCannotGC&),
|
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
|
|
|
void GetLengthAndData(JSObject*, uint32_t*, T**),
|
2012-05-04 20:36:56 +04:00
|
|
|
JSObject* CreateNew(JSContext*, uint32_t)>
|
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
|
|
|
struct TypedArray : public TypedArray_base<T, UnwrapArray, GetLengthAndData> {
|
|
|
|
private:
|
|
|
|
typedef TypedArray_base<T, UnwrapArray, GetLengthAndData> Base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TypedArray()
|
|
|
|
: Base()
|
2013-08-05 21:40:01 +04:00
|
|
|
{}
|
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
TypedArray(TypedArray&& aOther)
|
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
|
|
|
: Base(Move(aOther))
|
2014-05-24 01:32:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:36:56 +04:00
|
|
|
static inline JSObject*
|
2012-06-25 20:37:46 +04:00
|
|
|
Create(JSContext* cx, nsWrapperCache* creator, uint32_t length,
|
2013-08-23 09:17:07 +04:00
|
|
|
const T* data = nullptr) {
|
2013-05-31 01:46:48 +04:00
|
|
|
JS::Rooted<JSObject*> creatorWrapper(cx);
|
2012-08-22 05:42:53 +04:00
|
|
|
Maybe<JSAutoCompartment> ac;
|
2012-06-25 20:37:46 +04:00
|
|
|
if (creator && (creatorWrapper = creator->GetWrapperPreserveColor())) {
|
2014-08-14 02:39:41 +04:00
|
|
|
ac.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
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSObject*
|
2014-04-10 08:58:42 +04:00
|
|
|
Create(JSContext* cx, uint32_t length, const T* data = nullptr) {
|
|
|
|
return CreateCommon(cx, length, data);
|
2013-08-23 09:17:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static inline JSObject*
|
2014-04-10 08:58:42 +04:00
|
|
|
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;
|
|
|
|
T* buf = static_cast<T*>(GetData(obj, nogc));
|
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*),
|
|
|
|
void GetLengthAndData(JSObject*, uint32_t*, uint8_t**),
|
|
|
|
js::Scalar::Type GetViewType(JSObject*)>
|
|
|
|
struct ArrayBufferView_base : public TypedArray_base<uint8_t, UnwrapArray,
|
|
|
|
GetLengthAndData> {
|
|
|
|
private:
|
|
|
|
typedef TypedArray_base<uint8_t, UnwrapArray, GetLengthAndData> Base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ArrayBufferView_base()
|
|
|
|
: Base()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-03 17:51:42 +03:00
|
|
|
ArrayBufferView_base(ArrayBufferView_base&& aOther)
|
2015-06-24 18:10:15 +03:00
|
|
|
: Base(Move(aOther)),
|
|
|
|
mType(aOther.mType)
|
|
|
|
{
|
|
|
|
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;
|
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::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<int8_t, js::UnwrapSharedInt8Array, JS_GetSharedInt8ArrayData,
|
|
|
|
js::GetSharedInt8ArrayLengthAndData, JS_NewSharedInt8Array>
|
|
|
|
SharedInt8Array;
|
|
|
|
typedef TypedArray<uint8_t, js::UnwrapSharedUint8Array, JS_GetSharedUint8ArrayData,
|
|
|
|
js::GetSharedUint8ArrayLengthAndData, JS_NewSharedUint8Array>
|
|
|
|
SharedUint8Array;
|
|
|
|
typedef TypedArray<uint8_t, js::UnwrapSharedUint8ClampedArray, JS_GetSharedUint8ClampedArrayData,
|
|
|
|
js::GetSharedUint8ClampedArrayLengthAndData, JS_NewSharedUint8ClampedArray>
|
|
|
|
SharedUint8ClampedArray;
|
|
|
|
typedef TypedArray<int16_t, js::UnwrapSharedInt16Array, JS_GetSharedInt16ArrayData,
|
|
|
|
js::GetSharedInt16ArrayLengthAndData, JS_NewSharedInt16Array>
|
|
|
|
SharedInt16Array;
|
|
|
|
typedef TypedArray<uint16_t, js::UnwrapSharedUint16Array, JS_GetSharedUint16ArrayData,
|
|
|
|
js::GetSharedUint16ArrayLengthAndData, JS_NewSharedUint16Array>
|
|
|
|
SharedUint16Array;
|
|
|
|
typedef TypedArray<int32_t, js::UnwrapSharedInt32Array, JS_GetSharedInt32ArrayData,
|
|
|
|
js::GetSharedInt32ArrayLengthAndData, JS_NewSharedInt32Array>
|
|
|
|
SharedInt32Array;
|
|
|
|
typedef TypedArray<uint32_t, js::UnwrapSharedUint32Array, JS_GetSharedUint32ArrayData,
|
|
|
|
js::GetSharedUint32ArrayLengthAndData, JS_NewSharedUint32Array>
|
|
|
|
SharedUint32Array;
|
|
|
|
typedef TypedArray<float, js::UnwrapSharedFloat32Array, JS_GetSharedFloat32ArrayData,
|
|
|
|
js::GetSharedFloat32ArrayLengthAndData, JS_NewSharedFloat32Array>
|
|
|
|
SharedFloat32Array;
|
|
|
|
typedef TypedArray<double, js::UnwrapSharedFloat64Array, JS_GetSharedFloat64ArrayData,
|
|
|
|
js::GetSharedFloat64ArrayLengthAndData, JS_NewSharedFloat64Array>
|
|
|
|
SharedFloat64Array;
|
2015-06-24 18:10:15 +03:00
|
|
|
typedef ArrayBufferView_base<js::UnwrapSharedArrayBufferView,
|
|
|
|
js::GetSharedArrayBufferViewLengthAndData,
|
|
|
|
JS_GetSharedArrayBufferViewType>
|
2015-06-13 14:02:46 +03:00
|
|
|
SharedArrayBufferView;
|
|
|
|
typedef TypedArray<uint8_t, js::UnwrapSharedArrayBuffer, JS_GetSharedArrayBufferData,
|
|
|
|
js::GetSharedArrayBufferLengthAndData, JS_NewSharedArrayBuffer>
|
|
|
|
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
|
|
|
|
// things that understand TypedArray, as with Promise::ArgumentToJSValue.
|
|
|
|
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)
|
2014-03-10 16:55:46 +04:00
|
|
|
: mArray(aArray)
|
|
|
|
{}
|
|
|
|
|
2014-04-09 02:27:19 +04:00
|
|
|
JSObject* Create(JSContext* aCx) const
|
2014-03-10 16:55:46 +04:00
|
|
|
{
|
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;
|
|
|
|
};
|
|
|
|
|
2013-08-29 08:30:04 +04:00
|
|
|
// A class for rooting an existing TypedArray struct
|
|
|
|
template<typename ArrayType>
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII TypedArrayRooter : private JS::CustomAutoRooter
|
2013-08-29 08:30:04 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TypedArrayRooter(JSContext* cx,
|
|
|
|
ArrayType* aArray MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
|
|
JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT),
|
|
|
|
mArray(aArray)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void trace(JSTracer* trc) override
|
2013-08-29 08:30:04 +04:00
|
|
|
{
|
|
|
|
mArray->TraceSelf(trc);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TypedArrayObjectStorage* const mArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
// And a specialization for dealing with nullable typed arrays
|
|
|
|
template<typename Inner> struct Nullable;
|
|
|
|
template<typename ArrayType>
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII TypedArrayRooter<Nullable<ArrayType> > :
|
2013-08-29 08:30:04 +04:00
|
|
|
private JS::CustomAutoRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TypedArrayRooter(JSContext* cx,
|
|
|
|
Nullable<ArrayType>* aArray MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
|
|
JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT),
|
|
|
|
mArray(aArray)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void trace(JSTracer* trc) override
|
2013-08-29 08:30:04 +04:00
|
|
|
{
|
|
|
|
if (!mArray->IsNull()) {
|
|
|
|
mArray->Value().TraceSelf(trc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Nullable<ArrayType>* const mArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Class for easily setting up a rooted typed array object on the stack
|
|
|
|
template<typename ArrayType>
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII RootedTypedArray : public ArrayType,
|
|
|
|
private TypedArrayRooter<ArrayType>
|
2013-08-29 08:30:04 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-08-05 17:19:51 +04:00
|
|
|
explicit RootedTypedArray(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
2013-08-29 08:30:04 +04:00
|
|
|
ArrayType(),
|
2015-01-07 08:39:46 +03:00
|
|
|
TypedArrayRooter<ArrayType>(cx, this
|
2013-08-29 08:30:04 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RootedTypedArray(JSContext* cx, JSObject* obj MOZ_GUARD_OBJECT_NOTIFIER_PARAM) :
|
|
|
|
ArrayType(obj),
|
2015-01-07 08:39:46 +03:00
|
|
|
TypedArrayRooter<ArrayType>(cx, this
|
2013-08-29 08:30:04 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-04 20:36:56 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_TypedArray_h */
|