Bug 880041 (part 3) - Use JSObject::{is,as} for ArrayBufferObject. r=luke.

--HG--
extra : rebase_source : 0c37996aa68c943451a52e819d6c6fb71eb0a7b4
This commit is contained in:
Nicholas Nethercote 2013-06-16 17:07:35 -07:00
parent f27d4f199a
commit 03ea5702f9
13 changed files with 65 additions and 73 deletions

View File

@ -360,7 +360,7 @@ js::Nursery::moveElementsToTenured(JSObject *dst, JSObject *src, AllocKind dstKi
} }
/* ArrayBuffer stores byte-length, not Value count. */ /* ArrayBuffer stores byte-length, not Value count. */
if (src->isArrayBuffer()) { if (src->is<ArrayBufferObject>()) {
size_t nbytes = sizeof(ObjectElements) + srcHeader->initializedLength; size_t nbytes = sizeof(ObjectElements) + srcHeader->initializedLength;
if (src->hasDynamicElements()) { if (src->hasDynamicElements()) {
dstHeader = static_cast<ObjectElements *>(alloc->malloc_(nbytes)); dstHeader = static_cast<ObjectElements *>(alloc->malloc_(nbytes));

View File

@ -186,7 +186,7 @@ DynamicallyLinkModule(JSContext *cx, CallArgs args, AsmJSModule &module)
if (!IsTypedArrayBuffer(bufferVal)) if (!IsTypedArrayBuffer(bufferVal))
return LinkFail(cx, "bad ArrayBuffer argument"); return LinkFail(cx, "bad ArrayBuffer argument");
heap = &bufferVal.toObject().asArrayBuffer(); heap = &bufferVal.toObject().as<ArrayBufferObject>();
if (!IsPowerOfTwo(heap->byteLength()) || heap->byteLength() < AsmJSAllocationGranularity) if (!IsPowerOfTwo(heap->byteLength()) || heap->byteLength() < AsmJSAllocationGranularity)
return LinkFail(cx, "ArrayBuffer byteLength must be a power of two greater than or equal to 4096"); return LinkFail(cx, "ArrayBuffer byteLength must be a power of two greater than or equal to 4096");

View File

@ -1882,7 +1882,7 @@ static JSStdName standard_class_names[] = {
{js_InitIteratorClasses, EAGER_CLASS_ATOM(Iterator), &PropertyIteratorObject::class_}, {js_InitIteratorClasses, EAGER_CLASS_ATOM(Iterator), &PropertyIteratorObject::class_},
/* Typed Arrays */ /* Typed Arrays */
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(ArrayBuffer), &ArrayBufferClass}, {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(ArrayBuffer), &ArrayBufferObject::class_},
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Int8Array), TYPED_ARRAY_CLASP(TYPE_INT8)}, {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Int8Array), TYPED_ARRAY_CLASP(TYPE_INT8)},
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Uint8Array), TYPED_ARRAY_CLASP(TYPE_UINT8)}, {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Uint8Array), TYPED_ARRAY_CLASP(TYPE_UINT8)},
{js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Int16Array), TYPED_ARRAY_CLASP(TYPE_INT16)}, {js_InitTypedArrayClasses, EAGER_CLASS_ATOM(Int16Array), TYPED_ARRAY_CLASP(TYPE_INT16)},

View File

@ -485,7 +485,7 @@ JSStructuredCloneWriter::parseTransferable()
JS_ReportError(context(), "Permission denied to access object"); JS_ReportError(context(), "Permission denied to access object");
return false; return false;
} }
if (!tObj->isArrayBuffer()) { if (!tObj->is<ArrayBufferObject>()) {
reportErrorTransferable(); reportErrorTransferable();
return false; return false;
} }
@ -600,7 +600,7 @@ JSStructuredCloneWriter::writeTypedArray(HandleObject arr)
bool bool
JSStructuredCloneWriter::writeArrayBuffer(JSHandleObject obj) JSStructuredCloneWriter::writeArrayBuffer(JSHandleObject obj)
{ {
ArrayBufferObject &buffer = obj->asArrayBuffer(); ArrayBufferObject &buffer = obj->as<ArrayBufferObject>();
return out.writePair(SCTAG_ARRAY_BUFFER_OBJECT, buffer.byteLength()) && return out.writePair(SCTAG_ARRAY_BUFFER_OBJECT, buffer.byteLength()) &&
out.writeBytes(buffer.dataPointer(), buffer.byteLength()); out.writeBytes(buffer.dataPointer(), buffer.byteLength());
} }
@ -690,7 +690,7 @@ JSStructuredCloneWriter::startWrite(const Value &v)
return out.writePair(SCTAG_DATE_OBJECT, 0) && out.writeDouble(d); return out.writePair(SCTAG_DATE_OBJECT, 0) && out.writeDouble(d);
} else if (obj->isTypedArray()) { } else if (obj->isTypedArray()) {
return writeTypedArray(obj); return writeTypedArray(obj);
} else if (obj->isArrayBuffer() && obj->asArrayBuffer().hasData()) { } else if (obj->is<ArrayBufferObject>() && obj->as<ArrayBufferObject>().hasData()) {
return writeArrayBuffer(obj); return writeArrayBuffer(obj);
} else if (obj->isObject() || obj->isArray()) { } else if (obj->isObject() || obj->isArray()) {
return traverseObject(obj); return traverseObject(obj);
@ -947,7 +947,7 @@ JSStructuredCloneReader::readArrayBuffer(uint32_t nbytes, Value *vp)
if (!obj) if (!obj)
return false; return false;
vp->setObject(*obj); vp->setObject(*obj);
ArrayBufferObject &buffer = obj->asArrayBuffer(); ArrayBufferObject &buffer = obj->as<ArrayBufferObject>();
JS_ASSERT(buffer.byteLength() == nbytes); JS_ASSERT(buffer.byteLength() == nbytes);
return in.readArray(buffer.dataPointer(), nbytes); return in.readArray(buffer.dataPointer(), nbytes);
} }
@ -989,7 +989,7 @@ JSStructuredCloneReader::readV1ArrayBuffer(uint32_t arrayType, uint32_t nelems,
if (!obj) if (!obj)
return false; return false;
vp->setObject(*obj); vp->setObject(*obj);
ArrayBufferObject &buffer = obj->asArrayBuffer(); ArrayBufferObject &buffer = obj->as<ArrayBufferObject>();
JS_ASSERT(buffer.byteLength() == nbytes); JS_ASSERT(buffer.byteLength() == nbytes);
switch (arrayType) { switch (arrayType) {

View File

@ -485,7 +485,7 @@ GetClassForProtoKey(JSProtoKey key)
return &TypedArray::classes[key - JSProto_Int8Array]; return &TypedArray::classes[key - JSProto_Int8Array];
case JSProto_ArrayBuffer: case JSProto_ArrayBuffer:
return &ArrayBufferClass; return &ArrayBufferObject::class_;
case JSProto_DataView: case JSProto_DataView:
return &DataViewClass; return &DataViewClass;

View File

@ -1989,7 +1989,7 @@ JSObject::TradeGuts(JSContext *cx, JSObject *a, JSObject *b, TradeGutsReserved &
* Callers should not try to swap ArrayBuffer objects, * Callers should not try to swap ArrayBuffer objects,
* these use a different slot representation from other objects. * these use a different slot representation from other objects.
*/ */
JS_ASSERT(!a->isArrayBuffer() && !b->isArrayBuffer()); JS_ASSERT(!a->is<ArrayBufferObject>() && !b->is<ArrayBufferObject>());
/* Trade the guts of the objects. */ /* Trade the guts of the objects. */
const size_t size = a->tenuredSizeOfThis(); const size_t size = a->tenuredSizeOfThis();
@ -5330,7 +5330,7 @@ JSObject::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, JS::ObjectsExtraSi
#if defined (JS_CPU_X64) #if defined (JS_CPU_X64)
// On x64, ArrayBufferObject::prepareForAsmJS switches the // On x64, ArrayBufferObject::prepareForAsmJS switches the
// ArrayBufferObject to use mmap'd storage. // ArrayBufferObject to use mmap'd storage.
sizes->elementsAsmJSNonHeap = asArrayBuffer().byteLength(); sizes->elementsAsmJSNonHeap = as<ArrayBufferObject>().byteLength();
#else #else
sizes->elementsAsmJSHeap = mallocSizeOf(elements); sizes->elementsAsmJSHeap = mallocSizeOf(elements);
#endif #endif

View File

@ -204,7 +204,6 @@ DeleteGeneric(JSContext *cx, HandleObject obj, HandleId id, JSBool *succeeded);
} /* namespace js::baseops */ } /* namespace js::baseops */
extern Class ArrayClass; extern Class ArrayClass;
extern Class ArrayBufferClass;
extern Class BlockClass; extern Class BlockClass;
extern Class BooleanClass; extern Class BooleanClass;
extern Class CallableObjectClass; extern Class CallableObjectClass;
@ -979,7 +978,6 @@ class JSObject : public js::ObjectImpl
/* Direct subtypes of JSObject: */ /* Direct subtypes of JSObject: */
inline bool isArray() const { return hasClass(&js::ArrayClass); } inline bool isArray() const { return hasClass(&js::ArrayClass); }
inline bool isArrayBuffer() const { return hasClass(&js::ArrayBufferClass); }
inline bool isDataView() const { return hasClass(&js::DataViewClass); } inline bool isDataView() const { return hasClass(&js::DataViewClass); }
inline bool isDate() const { return hasClass(&js::DateClass); } inline bool isDate() const { return hasClass(&js::DateClass); }
inline bool isElementIterator() const { return hasClass(&js::ElementIteratorClass); } inline bool isElementIterator() const { return hasClass(&js::ElementIteratorClass); }
@ -1021,7 +1019,6 @@ class JSObject : public js::ObjectImpl
inline bool isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); } inline bool isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); }
inline bool isCrossCompartmentWrapper() const; inline bool isCrossCompartmentWrapper() const;
inline js::ArrayBufferObject &asArrayBuffer();
inline js::BlockObject &asBlock(); inline js::BlockObject &asBlock();
inline js::BooleanObject &asBoolean(); inline js::BooleanObject &asBoolean();
inline js::CallObject &asCall(); inline js::CallObject &asCall();

View File

@ -926,7 +926,7 @@ JSObject::create(JSContext *cx, js::gc::AllocKind kind, js::gc::InitialHeap heap
obj->privateRef(shape->numFixedSlots()) = NULL; obj->privateRef(shape->numFixedSlots()) = NULL;
size_t span = shape->slotSpan(); size_t span = shape->slotSpan();
if (span && clasp != &js::ArrayBufferClass) if (span && clasp != &js::ArrayBufferObject::class_)
obj->initializeSlotRange(0, span); obj->initializeSlotRange(0, span);
return obj; return obj;
@ -1686,7 +1686,7 @@ ObjectClassIs(HandleObject obj, ESClassValue classValue, JSContext *cx)
case ESClass_String: return obj->isString(); case ESClass_String: return obj->isString();
case ESClass_Boolean: return obj->isBoolean(); case ESClass_Boolean: return obj->isBoolean();
case ESClass_RegExp: return obj->isRegExp(); case ESClass_RegExp: return obj->isRegExp();
case ESClass_ArrayBuffer: return obj->isArrayBuffer(); case ESClass_ArrayBuffer: return obj->is<ArrayBufferObject>();
case ESClass_Date: return obj->isDate(); case ESClass_Date: return obj->isDate();
} }
JS_NOT_REACHED("bad classValue"); JS_NOT_REACHED("bad classValue");

View File

@ -114,14 +114,14 @@ ToClampedIndex(JSContext *cx, const Value &v, uint32_t length, uint32_t *out)
JS_ALWAYS_INLINE bool JS_ALWAYS_INLINE bool
IsArrayBuffer(const Value &v) IsArrayBuffer(const Value &v)
{ {
return v.isObject() && v.toObject().hasClass(&ArrayBufferClass); return v.isObject() && v.toObject().hasClass(&ArrayBufferObject::class_);
} }
JS_ALWAYS_INLINE bool JS_ALWAYS_INLINE bool
ArrayBufferObject::byteLengthGetterImpl(JSContext *cx, CallArgs args) ArrayBufferObject::byteLengthGetterImpl(JSContext *cx, CallArgs args)
{ {
JS_ASSERT(IsArrayBuffer(args.thisv())); JS_ASSERT(IsArrayBuffer(args.thisv()));
args.rval().setInt32(args.thisv().toObject().asArrayBuffer().byteLength()); args.rval().setInt32(args.thisv().toObject().as<ArrayBufferObject>().byteLength());
return true; return true;
} }
@ -140,7 +140,7 @@ ArrayBufferObject::fun_slice_impl(JSContext *cx, CallArgs args)
Rooted<JSObject*> thisObj(cx, &args.thisv().toObject()); Rooted<JSObject*> thisObj(cx, &args.thisv().toObject());
// these are the default values // these are the default values
uint32_t length = thisObj->asArrayBuffer().byteLength(); uint32_t length = thisObj->as<ArrayBufferObject>().byteLength();
uint32_t begin = 0, end = length; uint32_t begin = 0, end = length;
if (args.length() > 0) { if (args.length() > 0) {
@ -156,7 +156,7 @@ ArrayBufferObject::fun_slice_impl(JSContext *cx, CallArgs args)
if (begin > end) if (begin > end)
begin = end; begin = end;
JSObject *nobj = createSlice(cx, thisObj->asArrayBuffer(), begin, end); JSObject *nobj = createSlice(cx, thisObj->as<ArrayBufferObject>(), begin, end);
if (!nobj) if (!nobj)
return false; return false;
args.rval().setObject(*nobj); args.rval().setObject(*nobj);
@ -244,7 +244,7 @@ ArrayBufferObject::allocateSlots(JSContext *maybecx, uint32_t bytes, uint8_t *co
* their internal layout can use the object's fixed slots for storage. * their internal layout can use the object's fixed slots for storage.
* Set up the object to look like an array with an elements header. * Set up the object to look like an array with an elements header.
*/ */
JS_ASSERT(isArrayBuffer() && !hasDynamicSlots() && !hasDynamicElements()); JS_ASSERT(is<ArrayBufferObject>() && !hasDynamicSlots() && !hasDynamicElements());
size_t usableSlots = ARRAYBUFFER_RESERVED_SLOTS - ObjectElements::VALUES_PER_HEADER; size_t usableSlots = ARRAYBUFFER_RESERVED_SLOTS - ObjectElements::VALUES_PER_HEADER;
@ -412,7 +412,7 @@ ArrayBufferObject::prepareForAsmJS(JSContext *cx, Handle<ArrayBufferObject*> buf
void void
ArrayBufferObject::releaseAsmJSArrayBuffer(FreeOp *fop, JSObject *obj) ArrayBufferObject::releaseAsmJSArrayBuffer(FreeOp *fop, JSObject *obj)
{ {
ArrayBufferObject &buffer = obj->asArrayBuffer(); ArrayBufferObject &buffer = obj->as<ArrayBufferObject>();
JS_ASSERT(buffer.isAsmJSArrayBuffer()); JS_ASSERT(buffer.isAsmJSArrayBuffer());
uint8_t *p = buffer.dataPointer() - PageSize ; uint8_t *p = buffer.dataPointer() - PageSize ;
@ -453,7 +453,7 @@ ArrayBufferObject::prepareForAsmJS(JSContext *cx, Handle<ArrayBufferObject*> buf
void void
ArrayBufferObject::releaseAsmJSArrayBuffer(FreeOp *fop, JSObject *obj) ArrayBufferObject::releaseAsmJSArrayBuffer(FreeOp *fop, JSObject *obj)
{ {
fop->free_(obj->asArrayBuffer().getElementsHeader()); fop->free_(obj->as<ArrayBufferObject>().getElementsHeader());
} }
void void
@ -551,13 +551,13 @@ ArrayBufferObject::create(JSContext *cx, uint32_t nbytes, uint8_t *contents)
{ {
SkipRoot skip(cx, &contents); SkipRoot skip(cx, &contents);
RootedObject obj(cx, NewBuiltinClassInstance(cx, &ArrayBufferClass)); RootedObject obj(cx, NewBuiltinClassInstance(cx, &class_));
if (!obj) if (!obj)
return NULL; return NULL;
JS_ASSERT_IF(obj->isTenured(), obj->tenuredGetAllocKind() == gc::FINALIZE_OBJECT16_BACKGROUND); JS_ASSERT_IF(obj->isTenured(), obj->tenuredGetAllocKind() == gc::FINALIZE_OBJECT16_BACKGROUND);
JS_ASSERT(obj->getClass() == &ArrayBufferClass); JS_ASSERT(obj->getClass() == &class_);
js::Shape *empty = EmptyShape::getInitialShape(cx, &ArrayBufferClass, js::Shape *empty = EmptyShape::getInitialShape(cx, &class_,
obj->getProto(), obj->getParent(), obj->getMetadata(), obj->getProto(), obj->getParent(), obj->getMetadata(),
gc::FINALIZE_OBJECT16_BACKGROUND); gc::FINALIZE_OBJECT16_BACKGROUND);
if (!empty) if (!empty)
@ -568,7 +568,7 @@ ArrayBufferObject::create(JSContext *cx, uint32_t nbytes, uint8_t *contents)
* The beginning stores an ObjectElements header structure holding the * The beginning stores an ObjectElements header structure holding the
* length. The rest of it is a flat data store for the array buffer. * length. The rest of it is a flat data store for the array buffer.
*/ */
if (!obj->asArrayBuffer().allocateSlots(cx, nbytes, contents)) if (!obj->as<ArrayBufferObject>().allocateSlots(cx, nbytes, contents))
return NULL; return NULL;
return obj; return obj;
@ -624,7 +624,7 @@ bool
ArrayBufferObject::stealContents(JSContext *cx, JSObject *obj, void **contents, ArrayBufferObject::stealContents(JSContext *cx, JSObject *obj, void **contents,
uint8_t **data) uint8_t **data)
{ {
ArrayBufferObject &buffer = obj->asArrayBuffer(); ArrayBufferObject &buffer = obj->as<ArrayBufferObject>();
JSObject *views = *GetViewList(&buffer); JSObject *views = *GetViewList(&buffer);
js::ObjectElements *header = js::ObjectElements::fromElements((js::HeapSlot*)buffer.dataPointer()); js::ObjectElements *header = js::ObjectElements::fromElements((js::HeapSlot*)buffer.dataPointer());
if (buffer.hasDynamicElements() && !buffer.isAsmJSArrayBuffer()) { if (buffer.hasDynamicElements() && !buffer.isAsmJSArrayBuffer()) {
@ -686,7 +686,7 @@ ArrayBufferObject::obj_trace(JSTracer *trc, JSObject *obj)
// linked list during collection, and then swept to prune out their dead // linked list during collection, and then swept to prune out their dead
// views. // views.
HeapPtrObject *views = GetViewList(&obj->asArrayBuffer()); HeapPtrObject *views = GetViewList(&obj->as<ArrayBufferObject>());
if (!*views) if (!*views)
return; return;
@ -742,7 +742,7 @@ ArrayBufferObject::sweep(JSCompartment *compartment)
compartment->gcLiveArrayBuffers = NULL; compartment->gcLiveArrayBuffers = NULL;
while (buffer) { while (buffer) {
HeapPtrObject *views = GetViewList(&buffer->asArrayBuffer()); HeapPtrObject *views = GetViewList(&buffer->as<ArrayBufferObject>());
JS_ASSERT(*views); JS_ASSERT(*views);
JSObject *nextBuffer = BufferLink(*views); JSObject *nextBuffer = BufferLink(*views);
@ -776,7 +776,7 @@ ArrayBufferObject::resetArrayBufferList(JSCompartment *comp)
comp->gcLiveArrayBuffers = NULL; comp->gcLiveArrayBuffers = NULL;
while (buffer) { while (buffer) {
JSObject *view = *GetViewList(&buffer->asArrayBuffer()); JSObject *view = *GetViewList(&buffer->as<ArrayBufferObject>());
JS_ASSERT(view); JS_ASSERT(view);
JSObject *nextBuffer = BufferLink(view); JSObject *nextBuffer = BufferLink(view);
@ -793,7 +793,7 @@ ArrayBufferObject::saveArrayBufferList(JSCompartment *comp, ArrayBufferVector &v
JSObject *obj = comp->gcLiveArrayBuffers; JSObject *obj = comp->gcLiveArrayBuffers;
while (obj) { while (obj) {
JS_ASSERT(obj != UNSET_BUFFER_LINK); JS_ASSERT(obj != UNSET_BUFFER_LINK);
ArrayBufferObject *buffer = &obj->asArrayBuffer(); ArrayBufferObject *buffer = &obj->as<ArrayBufferObject>();
if (!vector.append(buffer)) if (!vector.append(buffer))
return false; return false;
@ -810,7 +810,7 @@ ArrayBufferObject::restoreArrayBufferLists(ArrayBufferVector &vector)
for (ArrayBufferObject **p = vector.begin(); p != vector.end(); p++) { for (ArrayBufferObject **p = vector.begin(); p != vector.end(); p++) {
ArrayBufferObject *buffer = *p; ArrayBufferObject *buffer = *p;
JSCompartment *comp = buffer->compartment(); JSCompartment *comp = buffer->compartment();
JSObject *firstView = *GetViewList(&buffer->asArrayBuffer()); JSObject *firstView = *GetViewList(&buffer->as<ArrayBufferObject>());
JS_ASSERT(firstView); JS_ASSERT(firstView);
JS_ASSERT(firstView->compartment() == comp); JS_ASSERT(firstView->compartment() == comp);
JS_ASSERT(BufferLink(firstView) == UNSET_BUFFER_LINK); JS_ASSERT(BufferLink(firstView) == UNSET_BUFFER_LINK);
@ -946,7 +946,7 @@ JSBool
ArrayBufferObject::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, ArrayBufferObject::obj_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver,
HandleId id, MutableHandleValue vp) HandleId id, MutableHandleValue vp)
{ {
JS_ASSERT(obj->isArrayBuffer()); JS_ASSERT(obj->is<ArrayBufferObject>());
RootedObject delegate(cx, ArrayBufferDelegate(cx, obj)); RootedObject delegate(cx, ArrayBufferDelegate(cx, obj));
if (!delegate) if (!delegate)
return false; return false;
@ -957,7 +957,7 @@ JSBool
ArrayBufferObject::obj_getProperty(JSContext *cx, HandleObject obj, ArrayBufferObject::obj_getProperty(JSContext *cx, HandleObject obj,
HandleObject receiver, HandlePropertyName name, MutableHandleValue vp) HandleObject receiver, HandlePropertyName name, MutableHandleValue vp)
{ {
JS_ASSERT(obj->isArrayBuffer()); JS_ASSERT(obj->is<ArrayBufferObject>());
RootedObject delegate(cx, ArrayBufferDelegate(cx, obj)); RootedObject delegate(cx, ArrayBufferDelegate(cx, obj));
if (!delegate) if (!delegate)
return false; return false;
@ -969,7 +969,7 @@ JSBool
ArrayBufferObject::obj_getElement(JSContext *cx, HandleObject obj, ArrayBufferObject::obj_getElement(JSContext *cx, HandleObject obj,
HandleObject receiver, uint32_t index, MutableHandleValue vp) HandleObject receiver, uint32_t index, MutableHandleValue vp)
{ {
JS_ASSERT(obj->isArrayBuffer()); JS_ASSERT(obj->is<ArrayBufferObject>());
RootedObject delegate(cx, ArrayBufferDelegate(cx, obj)); RootedObject delegate(cx, ArrayBufferDelegate(cx, obj));
if (!delegate) if (!delegate)
return false; return false;
@ -980,7 +980,7 @@ JSBool
ArrayBufferObject::obj_getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver, ArrayBufferObject::obj_getElementIfPresent(JSContext *cx, HandleObject obj, HandleObject receiver,
uint32_t index, MutableHandleValue vp, bool *present) uint32_t index, MutableHandleValue vp, bool *present)
{ {
JS_ASSERT(obj->isArrayBuffer()); JS_ASSERT(obj->is<ArrayBufferObject>());
RootedObject delegate(cx, ArrayBufferDelegate(cx, obj)); RootedObject delegate(cx, ArrayBufferDelegate(cx, obj));
if (!delegate) if (!delegate)
return false; return false;
@ -1767,8 +1767,8 @@ class TypedArrayTemplate
obj->setSlot(TYPE_SLOT, Int32Value(ArrayTypeID())); obj->setSlot(TYPE_SLOT, Int32Value(ArrayTypeID()));
obj->setSlot(BUFFER_SLOT, ObjectValue(*bufobj)); obj->setSlot(BUFFER_SLOT, ObjectValue(*bufobj));
JS_ASSERT(bufobj->isArrayBuffer()); JS_ASSERT(bufobj->is<ArrayBufferObject>());
Rooted<ArrayBufferObject *> buffer(cx, &bufobj->asArrayBuffer()); Rooted<ArrayBufferObject *> buffer(cx, &bufobj->as<ArrayBufferObject>());
InitArrayBufferViewDataPointer(obj, buffer, byteOffset); InitArrayBufferViewDataPointer(obj, buffer, byteOffset);
obj->setSlot(LENGTH_SLOT, Int32Value(len)); obj->setSlot(LENGTH_SLOT, Int32Value(len));
@ -1858,7 +1858,7 @@ class TypedArrayTemplate
* properties from the object, treating it as some sort of array. * properties from the object, treating it as some sort of array.
* Note that offset and length will be ignored * Note that offset and length will be ignored
*/ */
if (!UncheckedUnwrap(dataObj)->isArrayBuffer()) if (!UncheckedUnwrap(dataObj)->is<ArrayBufferObject>())
return fromArray(cx, dataObj); return fromArray(cx, dataObj);
/* (ArrayBuffer, [byteOffset, [length]]) */ /* (ArrayBuffer, [byteOffset, [length]]) */
@ -2128,7 +2128,7 @@ class TypedArrayTemplate
return NULL; // must be arrayBuffer return NULL; // must be arrayBuffer
} }
JS_ASSERT(bufobj->isArrayBuffer() || bufobj->isProxy()); JS_ASSERT(bufobj->is<ArrayBufferObject>() || bufobj->isProxy());
if (bufobj->isProxy()) { if (bufobj->isProxy()) {
/* /*
* Normally, NonGenericMethodGuard handles the case of transparent * Normally, NonGenericMethodGuard handles the case of transparent
@ -2146,7 +2146,7 @@ class TypedArrayTemplate
JS_ReportError(cx, "Permission denied to access object"); JS_ReportError(cx, "Permission denied to access object");
return NULL; return NULL;
} }
if (wrapped->isArrayBuffer()) { if (wrapped->is<ArrayBufferObject>()) {
/* /*
* And for even more fun, the new view's prototype should be * And for even more fun, the new view's prototype should be
* set to the origin compartment's prototype object, not the * set to the origin compartment's prototype object, not the
@ -2181,12 +2181,12 @@ class TypedArrayTemplate
} }
} }
if (!bufobj->isArrayBuffer()) { if (!bufobj->is<ArrayBufferObject>()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_TYPED_ARRAY_BAD_ARGS); JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_TYPED_ARRAY_BAD_ARGS);
return NULL; // must be arrayBuffer return NULL; // must be arrayBuffer
} }
ArrayBufferObject &buffer = bufobj->asArrayBuffer(); ArrayBufferObject &buffer = bufobj->as<ArrayBufferObject>();
if (byteOffset > buffer.byteLength() || byteOffset % sizeof(NativeType) != 0) { if (byteOffset > buffer.byteLength() || byteOffset % sizeof(NativeType) != 0) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_TYPED_ARRAY_BAD_ARGS); JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_TYPED_ARRAY_BAD_ARGS);
@ -2703,13 +2703,13 @@ TypedArrayTemplate<double>::copyIndexToValue(JSObject *tarray, uint32_t index,
JSBool JSBool
DataViewObject::construct(JSContext *cx, JSObject *bufobj, const CallArgs &args, HandleObject proto) DataViewObject::construct(JSContext *cx, JSObject *bufobj, const CallArgs &args, HandleObject proto)
{ {
if (!bufobj->isArrayBuffer()) { if (!bufobj->is<ArrayBufferObject>()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_EXPECTED_TYPE, JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_EXPECTED_TYPE,
"DataView", "ArrayBuffer", bufobj->getClass()->name); "DataView", "ArrayBuffer", bufobj->getClass()->name);
return false; return false;
} }
Rooted<ArrayBufferObject*> buffer(cx, &bufobj->asArrayBuffer()); Rooted<ArrayBufferObject*> buffer(cx, &bufobj->as<ArrayBufferObject>());
uint32_t bufferLength = buffer->byteLength(); uint32_t bufferLength = buffer->byteLength();
uint32_t byteOffset = 0; uint32_t byteOffset = 0;
uint32_t byteLength = bufferLength; uint32_t byteLength = bufferLength;
@ -2766,7 +2766,7 @@ DataViewObject::class_constructor(JSContext *cx, unsigned argc, Value *vp)
if (!GetFirstArgumentAsObject(cx, args, "DataView constructor", &bufobj)) if (!GetFirstArgumentAsObject(cx, args, "DataView constructor", &bufobj))
return false; return false;
if (bufobj->isWrapper() && UncheckedUnwrap(bufobj)->isArrayBuffer()) { if (bufobj->isWrapper() && UncheckedUnwrap(bufobj)->is<ArrayBufferObject>()) {
Rooted<GlobalObject*> global(cx, cx->compartment()->maybeGlobal()); Rooted<GlobalObject*> global(cx, cx->compartment()->maybeGlobal());
Rooted<JSObject*> proto(cx, global->getOrCreateDataViewPrototype(cx)); Rooted<JSObject*> proto(cx, global->getOrCreateDataViewPrototype(cx));
if (!proto) if (!proto)
@ -3308,7 +3308,7 @@ Class ArrayBufferObject::protoClass = {
JS_ConvertStub JS_ConvertStub
}; };
Class js::ArrayBufferClass = { Class ArrayBufferObject::class_ = {
"ArrayBuffer", "ArrayBuffer",
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_PRIVATE |
JSCLASS_IMPLEMENTS_BARRIERS | JSCLASS_IMPLEMENTS_BARRIERS |
@ -3872,7 +3872,7 @@ js::IsTypedArrayConstructor(const Value &v, uint32_t type)
bool bool
js::IsTypedArrayBuffer(const Value &v) js::IsTypedArrayBuffer(const Value &v)
{ {
return v.isObject() && v.toObject().isArrayBuffer(); return v.isObject() && v.toObject().is<ArrayBufferObject>();
} }
/* JS Friend API */ /* JS Friend API */
@ -3881,7 +3881,7 @@ JS_FRIEND_API(JSBool)
JS_IsArrayBufferObject(JSObject *obj) JS_IsArrayBufferObject(JSObject *obj)
{ {
obj = CheckedUnwrap(obj); obj = CheckedUnwrap(obj);
return obj ? obj->isArrayBuffer() : false; return obj ? obj->is<ArrayBufferObject>() : false;
} }
JS_FRIEND_API(JSBool) JS_FRIEND_API(JSBool)
@ -3902,7 +3902,7 @@ JS_FRIEND_API(uint32_t)
JS_GetArrayBufferByteLength(JSObject *obj) JS_GetArrayBufferByteLength(JSObject *obj)
{ {
obj = CheckedUnwrap(obj); obj = CheckedUnwrap(obj);
return obj ? obj->asArrayBuffer().byteLength() : 0; return obj ? obj->as<ArrayBufferObject>().byteLength() : 0;
} }
JS_FRIEND_API(uint8_t *) JS_FRIEND_API(uint8_t *)
@ -3911,7 +3911,7 @@ JS_GetArrayBufferData(JSObject *obj)
obj = CheckedUnwrap(obj); obj = CheckedUnwrap(obj);
if (!obj) if (!obj)
return NULL; return NULL;
ArrayBufferObject &buffer = obj->asArrayBuffer(); ArrayBufferObject &buffer = obj->as<ArrayBufferObject>();
if (!buffer.uninlineData(NULL)) if (!buffer.uninlineData(NULL))
return NULL; return NULL;
return buffer.dataPointer(); return buffer.dataPointer();
@ -3932,7 +3932,7 @@ JS_NewArrayBufferWithContents(JSContext *cx, void *contents)
if (!obj) if (!obj)
return NULL; return NULL;
obj->setDynamicElements(reinterpret_cast<js::ObjectElements *>(contents)); obj->setDynamicElements(reinterpret_cast<js::ObjectElements *>(contents));
JS_ASSERT(*GetViewList(&obj->asArrayBuffer()) == NULL); JS_ASSERT(*GetViewList(&obj->as<ArrayBufferObject>()) == NULL);
return obj; return obj;
} }
@ -3971,7 +3971,7 @@ JS_StealArrayBufferContents(JSContext *cx, JSObject *obj, void **contents,
if (!(obj = CheckedUnwrap(obj))) if (!(obj = CheckedUnwrap(obj)))
return false; return false;
if (!obj->isArrayBuffer()) { if (!obj->is<ArrayBufferObject>()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_TYPED_ARRAY_BAD_ARGS); JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_TYPED_ARRAY_BAD_ARGS);
return false; return false;
} }
@ -4215,11 +4215,11 @@ JS_GetObjectAsArrayBuffer(JSObject *obj, uint32_t *length, uint8_t **data)
{ {
if (!(obj = CheckedUnwrap(obj))) if (!(obj = CheckedUnwrap(obj)))
return NULL; return NULL;
if (!obj->isArrayBuffer()) if (!obj->is<ArrayBufferObject>())
return NULL; return NULL;
*length = obj->asArrayBuffer().byteLength(); *length = obj->as<ArrayBufferObject>().byteLength();
*data = obj->asArrayBuffer().dataPointer(); *data = obj->as<ArrayBufferObject>().dataPointer();
return obj; return obj;
} }

View File

@ -33,6 +33,8 @@ class ArrayBufferObject : public JSObject
static bool fun_slice_impl(JSContext *cx, CallArgs args); static bool fun_slice_impl(JSContext *cx, CallArgs args);
public: public:
static Class class_;
static Class protoClass; static Class protoClass;
static const JSFunctionSpec jsfuncs[]; static const JSFunctionSpec jsfuncs[];

View File

@ -38,7 +38,7 @@ js::ArrayBufferObject::getElementsHeaderInitializedLength(const js::ObjectElemen
inline uint32_t inline uint32_t
js::ArrayBufferObject::byteLength() const js::ArrayBufferObject::byteLength() const
{ {
JS_ASSERT(isArrayBuffer()); JS_ASSERT(is<ArrayBufferObject>());
return getElementsHeader()->initializedLength; return getElementsHeader()->initializedLength;
} }
@ -48,13 +48,6 @@ js::ArrayBufferObject::dataPointer() const
return (uint8_t *) elements; return (uint8_t *) elements;
} }
inline js::ArrayBufferObject &
JSObject::asArrayBuffer()
{
JS_ASSERT(isArrayBuffer());
return *static_cast<js::ArrayBufferObject *>(this);
}
inline js::DataViewObject & inline js::DataViewObject &
JSObject::asDataView() JSObject::asDataView()
{ {
@ -67,7 +60,7 @@ namespace js {
inline bool inline bool
ArrayBufferObject::hasData() const ArrayBufferObject::hasData() const
{ {
return getClass() == &ArrayBufferClass; return getClass() == &class_;
} }
inline bool inline bool
@ -142,7 +135,7 @@ TypedArray::bufferValue(JSObject *obj)
inline ArrayBufferObject * inline ArrayBufferObject *
TypedArray::buffer(JSObject *obj) TypedArray::buffer(JSObject *obj)
{ {
return &bufferValue(obj).toObject().asArrayBuffer(); return &bufferValue(obj).toObject().as<ArrayBufferObject>();
} }
inline void * inline void *
@ -203,7 +196,7 @@ class ArrayBufferViewByteOffsetRef : public gc::BufferableRef
MarkObjectUnbarriered(trc, &obj, "TypedArray"); MarkObjectUnbarriered(trc, &obj, "TypedArray");
HeapSlot &bufSlot = obj->getReservedSlotRef(BufferView::BUFFER_SLOT); HeapSlot &bufSlot = obj->getReservedSlotRef(BufferView::BUFFER_SLOT);
gc::MarkSlot(trc, &bufSlot, "TypedArray::BUFFER_SLOT"); gc::MarkSlot(trc, &bufSlot, "TypedArray::BUFFER_SLOT");
ArrayBufferObject &buf = bufSlot.toObject().asArrayBuffer(); ArrayBufferObject &buf = bufSlot.toObject().as<ArrayBufferObject>();
int32_t offset = obj->getReservedSlot(BufferView::BYTEOFFSET_SLOT).toInt32(); int32_t offset = obj->getReservedSlot(BufferView::BYTEOFFSET_SLOT).toInt32();
obj->initPrivate(buf.dataPointer() + offset); obj->initPrivate(buf.dataPointer() + offset);
} }
@ -270,7 +263,7 @@ DataViewObject::create(JSContext *cx, uint32_t byteOffset, uint32_t byteLength,
} }
} }
JS_ASSERT(arrayBuffer->isArrayBuffer()); JS_ASSERT(arrayBuffer->is<ArrayBufferObject>());
DataViewObject &dvobj = obj->asDataView(); DataViewObject &dvobj = obj->asDataView();
dvobj.setFixedSlot(BYTEOFFSET_SLOT, Int32Value(byteOffset)); dvobj.setFixedSlot(BYTEOFFSET_SLOT, Int32Value(byteOffset));
@ -284,7 +277,7 @@ DataViewObject::create(JSContext *cx, uint32_t byteOffset, uint32_t byteLength,
// Verify that the private slot is at the expected place // Verify that the private slot is at the expected place
JS_ASSERT(dvobj.numFixedSlots() == DATA_SLOT); JS_ASSERT(dvobj.numFixedSlots() == DATA_SLOT);
arrayBuffer->asArrayBuffer().addView(&dvobj); arrayBuffer->as<ArrayBufferObject>().addView(&dvobj);
return &dvobj; return &dvobj;
} }
@ -318,7 +311,7 @@ inline ArrayBufferObject &
DataViewObject::arrayBuffer() DataViewObject::arrayBuffer()
{ {
JS_ASSERT(isDataView()); JS_ASSERT(isDataView());
return getReservedSlot(BUFFER_SLOT).toObject().asArrayBuffer(); return getReservedSlot(BUFFER_SLOT).toObject().as<ArrayBufferObject>();
} }
inline bool inline bool

View File

@ -135,7 +135,7 @@ ProtoSetterImpl(JSContext *cx, CallArgs args)
* which due to their complicated delegate-object shenanigans can't easily * which due to their complicated delegate-object shenanigans can't easily
* have a mutable [[Prototype]]. * have a mutable [[Prototype]].
*/ */
if (obj->isProxy() || obj->isArrayBuffer()) { if (obj->isProxy() || obj->is<ArrayBufferObject>()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO, JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INCOMPATIBLE_PROTO,
"Object", "__proto__ setter", "Object", "__proto__ setter",
obj->isProxy() ? "Proxy" : "ArrayBuffer"); obj->isProxy() ? "Proxy" : "ArrayBuffer");

View File

@ -514,7 +514,7 @@ DenseElementsHeader::defineElement(JSContext *cx, Handle<ObjectImpl*> obj, uint3
JSObject * JSObject *
js::ArrayBufferDelegate(JSContext *cx, Handle<ObjectImpl*> obj) js::ArrayBufferDelegate(JSContext *cx, Handle<ObjectImpl*> obj)
{ {
MOZ_ASSERT(obj->hasClass(&ArrayBufferClass)); MOZ_ASSERT(obj->hasClass(&ArrayBufferObject::class_));
if (obj->getPrivate()) if (obj->getPrivate())
return static_cast<JSObject *>(obj->getPrivate()); return static_cast<JSObject *>(obj->getPrivate());
JSObject *delegate = NewObjectWithGivenProto(cx, &ObjectClass, obj->getProto(), NULL); JSObject *delegate = NewObjectWithGivenProto(cx, &ObjectClass, obj->getProto(), NULL);