зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1496378 part 1 - Make ArrayBufferViewObject a base class of TypedArrayObject and DataViewObject. r=jwalden
Differential Revision: https://phabricator.services.mozilla.com/D7721 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6c423021f3
Коммит
e3bba47ba5
|
@ -71,9 +71,9 @@ DataViewObject::create(JSContext* cx, uint32_t byteOffset, uint32_t byteLength,
|
|||
obj->setIsSharedMemory();
|
||||
}
|
||||
|
||||
obj->setFixedSlot(TypedArrayObject::BYTEOFFSET_SLOT, Int32Value(byteOffset));
|
||||
obj->setFixedSlot(TypedArrayObject::LENGTH_SLOT, Int32Value(byteLength));
|
||||
obj->setFixedSlot(TypedArrayObject::BUFFER_SLOT, ObjectValue(*arrayBuffer));
|
||||
obj->setFixedSlot(BYTEOFFSET_SLOT, Int32Value(byteOffset));
|
||||
obj->setFixedSlot(LENGTH_SLOT, Int32Value(byteLength));
|
||||
obj->setFixedSlot(BUFFER_SLOT, ObjectValue(*arrayBuffer));
|
||||
|
||||
SharedMem<uint8_t*> ptr = arrayBuffer->dataPointerEither();
|
||||
// A pointer to raw shared memory is exposed through the private slot. This
|
||||
|
@ -98,7 +98,7 @@ DataViewObject::create(JSContext* cx, uint32_t byteOffset, uint32_t byteLength,
|
|||
}
|
||||
|
||||
// Verify that the private slot is at the expected place
|
||||
MOZ_ASSERT(obj->numFixedSlots() == TypedArrayObject::DATA_SLOT);
|
||||
MOZ_ASSERT(obj->numFixedSlots() == DATA_SLOT);
|
||||
|
||||
if (arrayBuffer->is<ArrayBufferObject>()) {
|
||||
if (!arrayBuffer->as<ArrayBufferObject>().addView(cx, obj)) {
|
||||
|
@ -967,7 +967,7 @@ const ClassSpec DataViewObject::classSpec_ = {
|
|||
const Class DataViewObject::class_ = {
|
||||
"DataView",
|
||||
JSCLASS_HAS_PRIVATE |
|
||||
JSCLASS_HAS_RESERVED_SLOTS(TypedArrayObject::RESERVED_SLOTS) |
|
||||
JSCLASS_HAS_RESERVED_SLOTS(DataViewObject::RESERVED_SLOTS) |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_DataView),
|
||||
&DataViewObjectClassOps,
|
||||
&DataViewObject::classSpec_
|
||||
|
@ -1013,8 +1013,8 @@ const JSPropertySpec DataViewObject::properties[] = {
|
|||
void
|
||||
DataViewObject::notifyBufferDetached(void* newData)
|
||||
{
|
||||
setFixedSlot(TypedArrayObject::LENGTH_SLOT, Int32Value(0));
|
||||
setFixedSlot(TypedArrayObject::BYTEOFFSET_SLOT, Int32Value(0));
|
||||
setFixedSlot(LENGTH_SLOT, Int32Value(0));
|
||||
setFixedSlot(BYTEOFFSET_SLOT, Int32Value(0));
|
||||
setPrivate(newData);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "vm/ArrayBufferObject.h"
|
||||
#include "vm/JSObject.h"
|
||||
#include "vm/SharedArrayObject.h"
|
||||
#include "vm/TypedArrayObject.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
|
@ -23,7 +22,7 @@ namespace js {
|
|||
// should not be exposed without sharedness information accompanying
|
||||
// it.
|
||||
|
||||
class DataViewObject : public NativeObject
|
||||
class DataViewObject : public ArrayBufferViewObject
|
||||
{
|
||||
private:
|
||||
static const ClassSpec classSpec_;
|
||||
|
@ -62,19 +61,19 @@ class DataViewObject : public NativeObject
|
|||
static const Class protoClass_;
|
||||
|
||||
static Value byteOffsetValue(const DataViewObject* view) {
|
||||
Value v = view->getFixedSlot(TypedArrayObject::BYTEOFFSET_SLOT);
|
||||
Value v = view->getFixedSlot(BYTEOFFSET_SLOT);
|
||||
MOZ_ASSERT(v.toInt32() >= 0);
|
||||
return v;
|
||||
}
|
||||
|
||||
static Value byteLengthValue(const DataViewObject* view) {
|
||||
Value v = view->getFixedSlot(TypedArrayObject::LENGTH_SLOT);
|
||||
Value v = view->getFixedSlot(LENGTH_SLOT);
|
||||
MOZ_ASSERT(v.toInt32() >= 0);
|
||||
return v;
|
||||
}
|
||||
|
||||
static Value bufferValue(const DataViewObject* view) {
|
||||
return view->getFixedSlot(TypedArrayObject::BUFFER_SLOT);
|
||||
return view->getFixedSlot(BUFFER_SLOT);
|
||||
}
|
||||
|
||||
uint32_t byteOffset() const {
|
||||
|
|
|
@ -1761,34 +1761,14 @@ ArrayBufferViewObject::dataPointerUnshared(const JS::AutoRequireNoGC& nogc)
|
|||
MOZ_ASSERT(!as<TypedArrayObject>().isSharedMemory());
|
||||
return static_cast<uint8_t*>(as<TypedArrayObject>().viewDataUnshared());
|
||||
}
|
||||
return as<TypedObject>().typedMem(nogc);
|
||||
MOZ_CRASH("Unknown ArrayBufferViewObject");
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
bool
|
||||
ArrayBufferViewObject::isSharedMemory()
|
||||
{
|
||||
if (is<TypedArrayObject>()) {
|
||||
return as<TypedArrayObject>().isSharedMemory();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ArrayBufferViewObject::setDataPointerUnshared(uint8_t* data)
|
||||
{
|
||||
if (is<DataViewObject>()) {
|
||||
MOZ_ASSERT(!as<DataViewObject>().isSharedMemory());
|
||||
as<DataViewObject>().setPrivate(data);
|
||||
} else if (is<TypedArrayObject>()) {
|
||||
MOZ_ASSERT(!as<TypedArrayObject>().isSharedMemory());
|
||||
as<TypedArrayObject>().setPrivate(data);
|
||||
} else if (is<OutlineTypedObject>()) {
|
||||
as<OutlineTypedObject>().setData(data);
|
||||
} else {
|
||||
MOZ_CRASH();
|
||||
}
|
||||
MOZ_ASSERT(!isSharedMemory());
|
||||
setPrivate(data);
|
||||
}
|
||||
|
||||
/* static */ ArrayBufferObjectMaybeShared*
|
||||
|
|
|
@ -52,19 +52,20 @@ int32_t LiveMappedBufferCount();
|
|||
// The inheritance hierarchy for the various classes relating to typed arrays
|
||||
// is as follows.
|
||||
//
|
||||
// - NativeObject
|
||||
// - ArrayBufferObjectMaybeShared
|
||||
// - ArrayBufferObject
|
||||
// - SharedArrayBufferObject
|
||||
// - DataViewObject
|
||||
// - TypedArrayObject (declared in vm/TypedArrayObject.h)
|
||||
// - TypedArrayObjectTemplate
|
||||
// - Int8ArrayObject
|
||||
// - Uint8ArrayObject
|
||||
// - ...
|
||||
//
|
||||
// - JSObject
|
||||
// - ArrayBufferViewObject
|
||||
// - TypedObject (declared in builtin/TypedObject.h)
|
||||
// - NativeObject
|
||||
// - ArrayBufferObjectMaybeShared
|
||||
// - ArrayBufferObject
|
||||
// - SharedArrayBufferObject
|
||||
// - ArrayBufferViewObject
|
||||
// - DataViewObject
|
||||
// - TypedArrayObject (declared in vm/TypedArrayObject.h)
|
||||
// - TypedArrayObjectTemplate
|
||||
// - Int8ArrayObject
|
||||
// - Uint8ArrayObject
|
||||
// - ...
|
||||
//
|
||||
// Note that |TypedArrayObjectTemplate| is just an implementation
|
||||
// detail that makes implementing its various subclasses easier.
|
||||
|
@ -461,14 +462,40 @@ bool CreateWasmBuffer(JSContext* cx, const wasm::Limits& memory,
|
|||
class ArrayBufferViewObject : public NativeObject
|
||||
{
|
||||
public:
|
||||
// Underlying (Shared)ArrayBufferObject.
|
||||
static constexpr size_t BUFFER_SLOT = 0;
|
||||
static_assert(BUFFER_SLOT == JS_TYPEDARRAYLAYOUT_BUFFER_SLOT,
|
||||
"self-hosted code with burned-in constants must get the "
|
||||
"right buffer slot");
|
||||
|
||||
// Slot containing length of the view in number of typed elements.
|
||||
static constexpr size_t LENGTH_SLOT = 1;
|
||||
static_assert(LENGTH_SLOT == JS_TYPEDARRAYLAYOUT_LENGTH_SLOT,
|
||||
"self-hosted code with burned-in constants must get the "
|
||||
"right length slot");
|
||||
|
||||
// Offset of view within underlying (Shared)ArrayBufferObject.
|
||||
static constexpr size_t BYTEOFFSET_SLOT = 2;
|
||||
static_assert(BYTEOFFSET_SLOT == JS_TYPEDARRAYLAYOUT_BYTEOFFSET_SLOT,
|
||||
"self-hosted code with burned-in constants must get the "
|
||||
"right byteOffset slot");
|
||||
|
||||
static constexpr size_t RESERVED_SLOTS = 3;
|
||||
|
||||
#ifdef DEBUG
|
||||
static const uint8_t ZeroLengthArrayData = 0x4A;
|
||||
#endif
|
||||
|
||||
// The raw pointer to the buffer memory, the "private" value.
|
||||
//
|
||||
// This offset is exposed for performance reasons - so that it
|
||||
// need not be looked up on accesses.
|
||||
static constexpr size_t DATA_SLOT = 3;
|
||||
|
||||
static ArrayBufferObjectMaybeShared* bufferObject(JSContext* cx, Handle<ArrayBufferViewObject*> obj);
|
||||
|
||||
void notifyBufferDetached(JSContext* cx, void* newData);
|
||||
|
||||
#ifdef DEBUG
|
||||
bool isSharedMemory();
|
||||
#endif
|
||||
|
||||
// By construction we only need unshared variants here. See
|
||||
// comments in ArrayBufferObject.cpp.
|
||||
uint8_t* dataPointerUnshared(const JS::AutoRequireNoGC&);
|
||||
|
|
|
@ -37,42 +37,12 @@ namespace js {
|
|||
* the subclasses.
|
||||
*/
|
||||
|
||||
class TypedArrayObject : public NativeObject
|
||||
class TypedArrayObject : public ArrayBufferViewObject
|
||||
{
|
||||
public:
|
||||
// Underlying (Shared)ArrayBufferObject.
|
||||
static const size_t BUFFER_SLOT = 0;
|
||||
static_assert(BUFFER_SLOT == JS_TYPEDARRAYLAYOUT_BUFFER_SLOT,
|
||||
"self-hosted code with burned-in constants must get the "
|
||||
"right buffer slot");
|
||||
|
||||
// Slot containing length of the view in number of typed elements.
|
||||
static const size_t LENGTH_SLOT = 1;
|
||||
static_assert(LENGTH_SLOT == JS_TYPEDARRAYLAYOUT_LENGTH_SLOT,
|
||||
"self-hosted code with burned-in constants must get the "
|
||||
"right length slot");
|
||||
|
||||
// Offset of view within underlying (Shared)ArrayBufferObject.
|
||||
static const size_t BYTEOFFSET_SLOT = 2;
|
||||
static_assert(BYTEOFFSET_SLOT == JS_TYPEDARRAYLAYOUT_BYTEOFFSET_SLOT,
|
||||
"self-hosted code with burned-in constants must get the "
|
||||
"right byteOffset slot");
|
||||
|
||||
static const size_t RESERVED_SLOTS = 3;
|
||||
|
||||
#ifdef DEBUG
|
||||
static const uint8_t ZeroLengthArrayData = 0x4A;
|
||||
#endif
|
||||
|
||||
static int lengthOffset();
|
||||
static int dataOffset();
|
||||
|
||||
// The raw pointer to the buffer memory, the "private" value.
|
||||
//
|
||||
// This offset is exposed for performance reasons - so that it
|
||||
// need not be looked up on accesses.
|
||||
static const size_t DATA_SLOT = 3;
|
||||
|
||||
static_assert(js::detail::TypedArrayLengthSlot == LENGTH_SLOT,
|
||||
"bad inlined constant in jsfriendapi.h");
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче