Bug 1176214 - Part 2: Preliminary adjustments. r=waldo

--HG--
extra : rebase_source : b306ed5c0ded6830a9333e975d521bc6729c8312
This commit is contained in:
Lars T Hansen 2015-11-23 19:51:50 +01:00
Родитель 8da342c976
Коммит 5aae98ed9a
9 изменённых файлов: 185 добавлений и 320 удалений

Просмотреть файл

@ -1590,25 +1590,6 @@ JS_NewFloat32Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewFloat64Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedInt8Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint8Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint8ClampedArray(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedInt16Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint16Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedInt32Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint32Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedFloat32Array(JSContext* cx, uint32_t nelements);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedFloat64Array(JSContext* cx, uint32_t nelements);
/*
* Create a new typed array and copy in values from the given object. The
* object is used as if it were an array; that is, the new array (if
@ -1637,9 +1618,10 @@ extern JS_FRIEND_API(JSObject*)
JS_NewFloat64ArrayFromArray(JSContext* cx, JS::HandleObject array);
/*
* Create a new typed array using the given ArrayBuffer for storage. The
* length value is optional; if -1 is passed, enough elements to use up the
* remainder of the byte array is used as the default value.
* Create a new typed array using the given ArrayBuffer or
* SharedArrayBuffer for storage. The length value is optional; if -1
* is passed, enough elements to use up the remainder of the byte
* array is used as the default value.
*/
extern JS_FRIEND_API(JSObject*)
@ -1670,37 +1652,6 @@ extern JS_FRIEND_API(JSObject*)
JS_NewFloat64ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, int32_t length);
// As for the above, passing length==(uint32_t)-1 signifies "up to the
// end of the buffer".
extern JS_FRIEND_API(JSObject*)
JS_NewSharedInt8ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint8ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint8ClampedArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedInt16ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint16ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedInt32ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedUint32ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedFloat32ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
extern JS_FRIEND_API(JSObject*)
JS_NewSharedFloat64ArrayWithBuffer(JSContext* cx, JS::HandleObject arrayBuffer,
uint32_t byteOffset, uint32_t length);
/**
* Create a new SharedArrayBuffer with the given byte length.
*/
@ -1722,12 +1673,6 @@ JS_NewArrayBuffer(JSContext* cx, uint32_t nbytes);
extern JS_FRIEND_API(bool)
JS_IsTypedArrayObject(JSObject* obj);
/**
* Ditto for JS_GetSharedTypedArray* APIs.
*/
extern JS_FRIEND_API(bool)
JS_IsSharedTypedArrayObject(JSObject* obj);
/**
* Check whether obj supports JS_GetArrayBufferView* APIs. Note that this may
* return false if a security wrapper is encountered that denies the
@ -1761,25 +1706,6 @@ JS_IsFloat32Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsFloat64Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedInt8Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedUint8Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedUint8ClampedArray(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedInt16Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedUint16Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedInt32Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedUint32Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedFloat32Array(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_IsSharedFloat64Array(JSObject* obj);
/*
* Test for specific typed array types (ArrayBufferView subtypes) and return
* the unwrapped object if so, else nullptr. Never throws.
@ -1812,31 +1738,9 @@ UnwrapArrayBuffer(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapArrayBufferView(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedInt8Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedUint8Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedUint8ClampedArray(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedInt16Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedUint16Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedInt32Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedUint32Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedFloat32Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedFloat64Array(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedArrayBuffer(JSObject* obj);
extern JS_FRIEND_API(JSObject*)
UnwrapSharedArrayBufferView(JSObject* obj);
namespace detail {
@ -1850,17 +1754,8 @@ extern JS_FRIEND_DATA(const Class* const) Uint32ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) Float32ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) Float64ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedInt8ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedUint8ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedUint8ClampedArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedInt16ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedUint16ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedInt32ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedUint32ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedFloat32ArrayClassPtr;
extern JS_FRIEND_DATA(const Class* const) SharedFloat64ArrayClassPtr;
const size_t TypedArrayLengthSlot = 1;
const size_t TypedArrayIsSharedmemSlot = 3;
} // namespace detail
@ -1871,11 +1766,13 @@ const size_t TypedArrayLengthSlot = 1;
#define JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Type, type) \
inline void \
Get ## Type ## ArrayLengthAndData(JSObject* obj, uint32_t* length, type** data) \
Get ## Type ## ArrayLengthAndData(JSObject* obj, uint32_t* length, bool* isSharedMemory, type** data) \
{ \
MOZ_ASSERT(GetObjectClass(obj) == detail::Type ## ArrayClassPtr); \
const JS::Value& slot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \
*length = mozilla::AssertedCast<uint32_t>(slot.toInt32()); \
const JS::Value& lenSlot = GetReservedSlot(obj, detail::TypedArrayLengthSlot); \
*length = mozilla::AssertedCast<uint32_t>(lenSlot.toInt32()); \
const JS::Value& isSharedmemSlot = GetReservedSlot(obj, detail::TypedArrayIsSharedmemSlot); \
*isSharedMemory = mozilla::AssertedCast<bool>(isSharedmemSlot.toBoolean()); \
*data = static_cast<type*>(GetObjectPrivate(obj)); \
}
@ -1889,61 +1786,62 @@ JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Uint32, uint32_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float32, float)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(Float64, double)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedInt8, int8_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedUint8, uint8_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedUint8Clamped, uint8_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedInt16, int16_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedUint16, uint16_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedInt32, int32_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedUint32, uint32_t)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedFloat32, float)
JS_DEFINE_DATA_AND_LENGTH_ACCESSOR(SharedFloat64, double)
#undef JS_DEFINE_DATA_AND_LENGTH_ACCESSOR
// This one isn't inlined because it's rather tricky (by dint of having to deal
// with a dozen-plus classes and varying slot layouts.
extern JS_FRIEND_API(void)
GetArrayBufferViewLengthAndData(JSObject* obj, uint32_t* length, uint8_t** data);
extern JS_FRIEND_API(void)
GetSharedArrayBufferViewLengthAndData(JSObject* obj, uint32_t* length, uint8_t** data);
GetArrayBufferViewLengthAndData(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data);
// This one isn't inlined because there are a bunch of different ArrayBuffer
// classes that would have to be individually handled here.
//
// There is an isShared out argument for API consistency (eases use from DOM).
// It will always be set to false.
extern JS_FRIEND_API(void)
GetArrayBufferLengthAndData(JSObject* obj, uint32_t* length, uint8_t** data);
GetArrayBufferLengthAndData(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data);
// Ditto for SharedArrayBuffer.
//
// There is an isShared out argument for API consistency (eases use from DOM).
// It will always be set to true.
extern JS_FRIEND_API(void)
GetSharedArrayBufferLengthAndData(JSObject* obj, uint32_t* length, uint8_t** data);
GetSharedArrayBufferLengthAndData(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data);
} // namespace js
JS_FRIEND_API(uint8_t*)
JS_GetSharedArrayBufferData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
/*
* Unwrap Typed arrays all at once. Return nullptr without throwing if the
* object cannot be viewed as the correct typed array, or the typed array
* object on success, filling both outparameters.
*/
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsInt8Array(JSObject* obj, uint32_t* length, int8_t** data);
JS_GetObjectAsInt8Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, int8_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsUint8Array(JSObject* obj, uint32_t* length, uint8_t** data);
JS_GetObjectAsUint8Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsUint8ClampedArray(JSObject* obj, uint32_t* length, uint8_t** data);
JS_GetObjectAsUint8ClampedArray(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsInt16Array(JSObject* obj, uint32_t* length, int16_t** data);
JS_GetObjectAsInt16Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, int16_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsUint16Array(JSObject* obj, uint32_t* length, uint16_t** data);
JS_GetObjectAsUint16Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint16_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsInt32Array(JSObject* obj, uint32_t* length, int32_t** data);
JS_GetObjectAsInt32Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, int32_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsUint32Array(JSObject* obj, uint32_t* length, uint32_t** data);
JS_GetObjectAsUint32Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint32_t** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsFloat32Array(JSObject* obj, uint32_t* length, float** data);
JS_GetObjectAsFloat32Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, float** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsFloat64Array(JSObject* obj, uint32_t* length, double** data);
JS_GetObjectAsFloat64Array(JSObject* obj, uint32_t* length, bool* isSharedMemory, double** data);
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsArrayBufferView(JSObject* obj, uint32_t* length, uint8_t** data);
JS_GetObjectAsArrayBufferView(JSObject* obj, uint32_t* length, bool* isSharedMemory, uint8_t** data);
/*
* Unwrap an ArrayBuffer, return nullptr if it's a different type.
*/
extern JS_FRIEND_API(JSObject*)
JS_GetObjectAsArrayBuffer(JSObject* obj, uint32_t* length, uint8_t** data);
@ -1982,6 +1880,9 @@ JS_IsSharedArrayBufferObject(JSObject* obj);
extern JS_FRIEND_API(uint32_t)
JS_GetArrayBufferByteLength(JSObject* obj);
extern JS_FRIEND_API(uint32_t)
JS_GetSharedArrayBufferByteLength(JSObject* obj);
/**
* Return true if the arrayBuffer contains any data. This will return false for
* ArrayBuffer.prototype and neutered ArrayBuffers.
@ -1993,6 +1894,23 @@ JS_GetArrayBufferByteLength(JSObject* obj);
extern JS_FRIEND_API(bool)
JS_ArrayBufferHasData(JSObject* obj);
/**
* Return a pointer to the start of the data referenced by a typed array. The
* data is still owned by the typed array, and should not be modified on
* another thread. Furthermore, the pointer can become invalid on GC (if the
* data is small and fits inside the array's GC header), so callers must take
* care not to hold on across anything that could GC.
*
* |obj| must have passed a JS_IsArrayBufferObject test, or somehow be known
* that it would pass such a test: it is an ArrayBuffer or a wrapper of an
* ArrayBuffer, and the unwrapping will succeed.
*
* *isSharedMemory will be set to false, the argument is present to simplify
* its use from code that also interacts with SharedArrayBuffer.
*/
extern JS_FRIEND_API(uint8_t*)
JS_GetArrayBufferData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
/**
* Check whether the obj is ArrayBufferObject and memory mapped. Note that this
* may return false if a security wrapper is encountered that denies the
@ -2032,6 +1950,17 @@ JS_GetTypedArrayByteOffset(JSObject* obj);
extern JS_FRIEND_API(uint32_t)
JS_GetTypedArrayByteLength(JSObject* obj);
/**
* Return the isShared flag of a typed array, which denotes whether
* the underlying buffer is a SharedArrayBuffer.
*
* |obj| must have passed a JS_IsTypedArrayObject/JS_Is*Array test, or somehow
* be known that it would pass such a test: it is a typed array or a wrapper of
* a typed array, and the unwrapping will succeed.
*/
extern JS_FRIEND_API(bool)
JS_GetTypedArraySharedness(JSObject* obj);
/**
* Check whether obj supports JS_ArrayBufferView* APIs. Note that this may
* return false if a security wrapper is encountered that denies the
@ -2056,64 +1985,45 @@ JS_GetArrayBufferViewByteLength(JSObject* obj);
* |obj| must have passed a JS_Is*Array test, or somehow be known that it would
* pass such a test: it is a typed array or a wrapper of a typed array, and the
* unwrapping will succeed.
*
* *isSharedMemory will be set to true if the typed array maps a
* SharedArrayBuffer, otherwise to false.
*/
extern JS_FRIEND_API(uint8_t*)
JS_GetArrayBufferData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(int8_t*)
JS_GetInt8ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetInt8ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint8_t*)
JS_GetUint8ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetUint8ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint8_t*)
JS_GetUint8ClampedArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetUint8ClampedArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(int16_t*)
JS_GetInt16ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetInt16ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint16_t*)
JS_GetUint16ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetUint16ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(int32_t*)
JS_GetInt32ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetInt32ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint32_t*)
JS_GetUint32ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetUint32ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(float*)
JS_GetFloat32ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetFloat32ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(double*)
JS_GetFloat64ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint8_t*)
JS_GetSharedArrayBufferData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(int8_t*)
JS_GetSharedInt8ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint8_t*)
JS_GetSharedUint8ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint8_t*)
JS_GetSharedUint8ClampedArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(int16_t*)
JS_GetSharedInt16ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint16_t*)
JS_GetSharedUint16ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(int32_t*)
JS_GetSharedInt32ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(uint32_t*)
JS_GetSharedUint32ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(float*)
JS_GetSharedFloat32ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
extern JS_FRIEND_API(double*)
JS_GetSharedFloat64ArrayData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetFloat64ArrayData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
/**
* Same as above, but for any kind of ArrayBufferView. Prefer the type-specific
* versions when possible.
*/
extern JS_FRIEND_API(void*)
JS_GetArrayBufferViewData(JSObject* obj, const JS::AutoCheckCannotGC&);
JS_GetArrayBufferViewData(JSObject* obj, bool* isSharedMemory, const JS::AutoCheckCannotGC&);
/**
* Return the ArrayBuffer underlying an ArrayBufferView. If the buffer has been
* neutered, this will still return the neutered buffer. |obj| must be an
* object that would return true for JS_IsArrayBufferViewObject().
* Return the ArrayBuffer or SharedArrayBuffer underlying an
* ArrayBufferView. If the buffer has been neutered, this will still
* return the neutered buffer. |obj| must be an object that would
* return true for JS_IsArrayBufferViewObject().
*/
extern JS_FRIEND_API(JSObject*)
JS_GetArrayBufferViewBuffer(JSContext* cx, JS::HandleObject obj);
JS_GetArrayBufferViewBuffer(JSContext* cx, JS::HandleObject obj, bool* isSharedMemory);
typedef enum {
ChangeData,

Просмотреть файл

@ -76,7 +76,6 @@ enum State {
D(ScopeObject*) \
D(ScriptSourceObject*) \
D(SharedArrayBufferObject*) \
D(SharedTypedArrayObject*) \
D(ImportEntryObject*) \
D(ExportEntryObject*) \
D(JSScript*) \

Просмотреть файл

@ -3560,7 +3560,7 @@ JSObject::allocKindForTenure(const js::Nursery& nursery) const
* Typed arrays in the nursery may have a lazily allocated buffer, make
* sure there is room for the array's fixed data when moving the array.
*/
if (is<TypedArrayObject>() && !as<TypedArrayObject>().buffer()) {
if (is<TypedArrayObject>() && !as<TypedArrayObject>().hasBuffer()) {
size_t nbytes = as<TypedArrayObject>().byteLength();
return GetBackgroundAllocKind(TypedArrayObject::AllocKindForLazyBuffer(nbytes));
}

Просмотреть файл

@ -36,7 +36,6 @@
#define OCLASP(name) (&name##Object::class_)
#define TYPED_ARRAY_CLASP(type) (&TypedArrayObject::classes[Scalar::type])
#define ERROR_CLASP(type) (&ErrorObject::classes[type])
#define SHARED_TYPED_ARRAY_CLASP(type) (&SharedTypedArrayObject::classes[Scalar::type])
#ifdef EXPOSE_INTL_API
#define IF_INTL(real,imaginary) real
@ -100,21 +99,12 @@ IF_BDATA(real,imaginary)(TypedObject, 39, InitTypedObjectModuleObj
real(Reflect, 40, InitReflect, nullptr) \
IF_BDATA(real,imaginary)(SIMD, 41, InitSIMDClass, OCLASP(SIMD)) \
real(WeakSet, 42, InitWeakSetClass, OCLASP(WeakSet)) \
IF_SAB(real,imaginary)(SharedInt8Array, 43, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Int8)) \
IF_SAB(real,imaginary)(SharedUint8Array, 44, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Uint8)) \
IF_SAB(real,imaginary)(SharedInt16Array, 45, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Int16)) \
IF_SAB(real,imaginary)(SharedUint16Array, 46, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Uint16)) \
IF_SAB(real,imaginary)(SharedInt32Array, 47, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Int32)) \
IF_SAB(real,imaginary)(SharedUint32Array, 48, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Uint32)) \
IF_SAB(real,imaginary)(SharedFloat32Array, 49, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Float32)) \
IF_SAB(real,imaginary)(SharedFloat64Array, 50, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Float64)) \
IF_SAB(real,imaginary)(SharedUint8ClampedArray, 51, InitViaClassSpec, SHARED_TYPED_ARRAY_CLASP(Uint8Clamped)) \
real(TypedArray, 52, InitViaClassSpec, &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \
IF_SAB(real,imaginary)(Atomics, 53, InitAtomicsClass, OCLASP(Atomics)) \
real(SavedFrame, 54, InitViaClassSpec, &js::SavedFrame::class_) \
real(Module, 55, InitModuleClass, OCLASP(Module)) \
real(ImportEntry, 56, InitImportEntryClass, OCLASP(ImportEntry)) \
real(ExportEntry, 57, InitExportEntryClass, OCLASP(ExportEntry)) \
real(TypedArray, 43, InitViaClassSpec, &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \
IF_SAB(real,imaginary)(Atomics, 44, InitAtomicsClass, OCLASP(Atomics)) \
real(SavedFrame, 45, InitViaClassSpec, &js::SavedFrame::class_) \
real(Module, 46, InitModuleClass, OCLASP(Module)) \
real(ImportEntry, 47, InitImportEntryClass, OCLASP(ImportEntry)) \
real(ExportEntry, 48, InitExportEntryClass, OCLASP(ExportEntry)) \
#define JS_FOR_EACH_PROTOTYPE(macro) JS_FOR_PROTOTYPES(macro,macro)

Просмотреть файл

@ -19,7 +19,7 @@
namespace js {
inline SharedMem<uint8_t*>
ArrayBufferObjectMaybeShared::dataPointerMaybeShared()
ArrayBufferObjectMaybeShared::dataPointerEither()
{
ArrayBufferObjectMaybeShared* buf = this;
if (buf->is<ArrayBufferObject>())

Просмотреть файл

@ -33,32 +33,26 @@ class ArrayBufferViewObject;
// - Int8ArrayObject
// - Uint8ArrayObject
// - ...
// - SharedTypedArrayObject (declared in vm/SharedTypedArrayObject.h)
// - SharedTypedArrayObjectTemplate
// - SharedInt8ArrayObject
// - SharedUint8ArrayObject
// - ...
// - JSObject
// - ArrayBufferViewObject
// - TypedObject (declared in builtin/TypedObject.h)
//
// Note that |TypedArrayObjectTemplate| and |SharedTypedArrayObjectTemplate| are
// just implementation details that make implementing their various subclasses easier.
// Note that |TypedArrayObjectTemplate| is just an implementation
// detail that makes implementing its various subclasses easier.
//
// ArrayBufferObject and SharedArrayBufferObject are unrelated data types:
// the racy memory of the latter cannot substitute for the non-racy memory of
// the former; the non-racy memory of the former cannot be used with the atomics;
// the former can be neutered and the latter not; and they have different
// method suites. Hence they have been separated completely.
// the former can be neutered and the latter not. Hence they have been separated
// completely.
//
// Most APIs will only accept ArrayBufferObject. ArrayBufferObjectMaybeShared exists
// as a join point to allow APIs that can take or use either, notably AsmJS.
// Most APIs will only accept ArrayBufferObject. ArrayBufferObjectMaybeShared
// exists as a join point to allow APIs that can take or use either, notably AsmJS.
//
// As ArrayBufferObject and SharedArrayBufferObject are separated, so are the
// TypedArray hierarchies below the two. However, the TypedArrays have the
// same layout (see TypedArrayObject.h), so there is little code duplication.
// In contrast with the separation of ArrayBufferObject and
// SharedArrayBufferObject, the TypedArray types can map either.
//
// The possible data ownership and reference relationships with array buffers
// The possible data ownership and reference relationships with ArrayBuffers
// and related classes are enumerated below. These are the possible locations
// for typed data:
//
@ -86,7 +80,7 @@ class ArrayBufferObjectMaybeShared : public NativeObject
return AnyArrayBufferByteLength(this);
}
inline SharedMem<uint8_t*> dataPointerMaybeShared();
inline SharedMem<uint8_t*> dataPointerEither();
};
/*
@ -384,12 +378,14 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared
class ArrayBufferViewObject : public JSObject
{
public:
static ArrayBufferObject* bufferObject(JSContext* cx, Handle<ArrayBufferViewObject*> obj);
static ArrayBufferObjectMaybeShared* bufferObject(JSContext* cx, Handle<ArrayBufferViewObject*> obj);
void neuter(void* newData);
uint8_t* dataPointer();
void setDataPointer(uint8_t* data);
// By construction we only need unshared variants here. See
// comments in ArrayBufferObject.cpp.
uint8_t* dataPointerUnshared();
void setDataPointerUnshared(uint8_t* data);
static void trace(JSTracer* trc, JSObject* obj);
};

Просмотреть файл

@ -103,9 +103,9 @@ class SharedArrayRawBuffer
* SharedArrayBufferObject (or really the underlying memory) /is
* racy/: more than one worker can access the memory at the same time.
*
* A SharedTypedArrayObject (a view) references a SharedArrayBuffer
* A TypedArrayObject (a view) references a SharedArrayBuffer
* and keeps it alive. The SharedArrayBuffer does /not/ reference its
* views, nor do the views reference each other in any way.
* views.
*/
class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared
{
@ -166,6 +166,7 @@ private:
bool IsSharedArrayBuffer(HandleValue v);
bool IsSharedArrayBuffer(HandleObject o);
bool IsSharedArrayBuffer(JSObject* o);
SharedArrayBufferObject& AsSharedArrayBuffer(HandleObject o);

Просмотреть файл

@ -133,6 +133,10 @@ class SharedMem
MOZ_ASSERT(sharedness_ == IsUnshared);
return ptr_;
}
uintptr_t unwrapValue() const {
return reinterpret_cast<uintptr_t>(ptr_);
}
};
template<typename T>

Просмотреть файл

@ -75,69 +75,49 @@ template<> struct TypeIDOfType<uint8_clamped> { static const Scalar::Type id = S
inline bool
IsAnyTypedArray(JSObject* obj)
{
return obj->is<TypedArrayObject>() || obj->is<SharedTypedArrayObject>();
return obj->is<TypedArrayObject>();
}
inline uint32_t
AnyTypedArrayLength(JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().length();
return obj->as<SharedTypedArrayObject>().length();
return obj->as<TypedArrayObject>().length();
}
inline Scalar::Type
AnyTypedArrayType(JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().type();
return obj->as<SharedTypedArrayObject>().type();
return obj->as<TypedArrayObject>().type();
}
inline Shape*
AnyTypedArrayShape(JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().lastProperty();
return obj->as<SharedTypedArrayObject>().lastProperty();
}
inline const TypedArrayLayout&
AnyTypedArrayLayout(const JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().layout();
return obj->as<SharedTypedArrayObject>().layout();
return obj->as<TypedArrayObject>().lastProperty();
}
inline SharedMem<void*>
AnyTypedArrayViewData(const JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().viewDataShared();
return obj->as<SharedTypedArrayObject>().viewDataShared();
return obj->as<TypedArrayObject>().viewDataEither();
}
inline uint32_t
AnyTypedArrayBytesPerElement(const JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().bytesPerElement();
return obj->as<SharedTypedArrayObject>().bytesPerElement();
return obj->as<TypedArrayObject>().bytesPerElement();
}
inline uint32_t
AnyTypedArrayByteLength(const JSObject* obj)
{
if (obj->is<TypedArrayObject>())
return obj->as<TypedArrayObject>().byteLength();
return obj->as<SharedTypedArrayObject>().byteLength();
return obj->as<TypedArrayObject>().byteLength();
}
inline bool
IsAnyTypedArrayClass(const Class* clasp)
{
return IsTypedArrayClass(clasp) || IsSharedTypedArrayClass(clasp);
return IsTypedArrayClass(clasp);
}
class SharedOps
@ -162,6 +142,10 @@ class SharedOps
static void memmove(SharedMem<T*> dest, SharedMem<T*> src, size_t size) {
js::jit::AtomicOperations::memmoveSafeWhenRacy(dest, src, size);
}
static SharedMem<void*> extract(TypedArrayObject* obj) {
return obj->viewDataEither();
}
};
class UnsharedOps
@ -186,6 +170,10 @@ class UnsharedOps
static void memmove(SharedMem<T*> dest, SharedMem<T*> src, size_t size) {
::memmove(dest.unwrapUnshared(), src.unwrapUnshared(), size);
}
static SharedMem<void*> extract(TypedArrayObject* obj) {
return SharedMem<void*>::unshared(obj->viewDataUnshared());
}
};
template<class SpecificArray, typename Ops>
@ -232,7 +220,7 @@ class ElementSpecific
# define JS_VOLATILE_ARM
#endif
SharedMem<void*> data = AnyTypedArrayViewData(source);
SharedMem<void*> data = Ops::extract(source.as<TypedArrayObject>());
switch (AnyTypedArrayType(source)) {
case Scalar::Int8: {
SharedMem<JS_VOLATILE_ARM int8_t*> src = data.cast<JS_VOLATILE_ARM int8_t*>();
@ -504,32 +492,10 @@ class ElementSpecific
}
};
template<class SomeTypedArray>
inline bool
EitherShared(Handle<SomeTypedArray*> target, HandleObject source)
{
return target->template is<SharedTypedArrayObject>() || source->is<SharedTypedArrayObject>();
}
template<>
inline bool
EitherShared(Handle<SharedTypedArrayObject*> target, HandleObject source)
{
return true;
}
template<>
inline bool
EitherShared(Handle<TypedArrayObject*> target, HandleObject source)
{
return source->is<SharedTypedArrayObject>();
}
template<typename SomeTypedArray>
class TypedArrayMethods
{
static_assert(mozilla::IsSame<SomeTypedArray, TypedArrayObject>::value ||
mozilla::IsSame<SomeTypedArray, SharedTypedArrayObject>::value,
static_assert(mozilla::IsSame<SomeTypedArray, TypedArrayObject>::value,
"methods must be shared/unshared-specific, not "
"element-type-specific");
@ -797,59 +763,59 @@ class TypedArrayMethods
}
private:
static bool
setFromAnyTypedArray(JSContext* cx, Handle<SomeTypedArray*> target, HandleObject source,
uint32_t offset)
{
MOZ_ASSERT(IsAnyTypedArray(source), "use setFromNonTypedArray");
static bool
setFromAnyTypedArray(JSContext* cx, Handle<SomeTypedArray*> target, HandleObject source,
uint32_t offset)
{
MOZ_ASSERT(IsAnyTypedArray(source), "use setFromNonTypedArray");
bool isShared = EitherShared(target, source);
bool isShared = target->isSharedMemory() || source->as<TypedArrayObject>().isSharedMemory();
switch (target->type()) {
case Scalar::Int8:
if (isShared)
return ElementSpecific<Int8ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Int8ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint8:
if (isShared)
return ElementSpecific<Uint8ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint8ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Int16:
if (isShared)
return ElementSpecific<Int16ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Int16ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint16:
if (isShared)
return ElementSpecific<Uint16ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint16ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Int32:
if (isShared)
return ElementSpecific<Int32ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Int32ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint32:
if (isShared)
return ElementSpecific<Uint32ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint32ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Float32:
if (isShared)
return ElementSpecific<Float32ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Float32ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Float64:
if (isShared)
return ElementSpecific<Float64ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Float64ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint8Clamped:
if (isShared)
return ElementSpecific<Uint8ClampedArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint8ClampedArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Float32x4:
case Scalar::Int32x4:
case Scalar::MaxTypedArrayViewType:
break;
}
switch (target->type()) {
case Scalar::Int8:
if (isShared)
return ElementSpecific<Int8ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Int8ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint8:
if (isShared)
return ElementSpecific<Uint8ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint8ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Int16:
if (isShared)
return ElementSpecific<Int16ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Int16ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint16:
if (isShared)
return ElementSpecific<Uint16ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint16ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Int32:
if (isShared)
return ElementSpecific<Int32ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Int32ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint32:
if (isShared)
return ElementSpecific<Uint32ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint32ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Float32:
if (isShared)
return ElementSpecific<Float32ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Float32ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Float64:
if (isShared)
return ElementSpecific<Float64ArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Float64ArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Uint8Clamped:
if (isShared)
return ElementSpecific<Uint8ClampedArrayType, SharedOps>::setFromAnyTypedArray(cx, target, source, offset);
return ElementSpecific<Uint8ClampedArrayType, UnsharedOps>::setFromAnyTypedArray(cx, target, source, offset);
case Scalar::Float32x4:
case Scalar::Int32x4:
case Scalar::MaxTypedArrayViewType:
break;
}
MOZ_CRASH("nonsense target element type");
}
MOZ_CRASH("nonsense target element type");
}
static bool
setFromNonTypedArray(JSContext* cx, Handle<SomeTypedArray*> target, HandleObject source,
@ -857,7 +823,7 @@ class TypedArrayMethods
{
MOZ_ASSERT(!IsAnyTypedArray(source), "use setFromAnyTypedArray");
bool isShared = EitherShared(target, source);
bool isShared = target->isSharedMemory();
switch (target->type()) {
case Scalar::Int8:
@ -901,7 +867,6 @@ class TypedArrayMethods
case Scalar::MaxTypedArrayViewType:
break;
}
MOZ_CRASH("bad target array type");
}
};