Bug 969159 -- Adjust assertion to account for zero-sized objects r=shu

This commit is contained in:
Nicholas D. Matsakis 2014-02-07 13:48:35 -05:00
parent e8a25536e3
commit c6df708ead
3 changed files with 16 additions and 1 deletions

View File

@ -1341,6 +1341,7 @@ void
TypedDatum::attach(TypedDatum &datum, uint32_t offset)
{
JS_ASSERT(datum.getReservedSlot(JS_DATUM_SLOT_OWNER).isObject());
JS_ASSERT(offset + size() <= datum.size());
// find the location in memory
uint8_t *mem = datum.typedMem(offset);

View File

@ -516,7 +516,12 @@ class TypedDatum : public JSObject
}
uint8_t *typedMem(size_t offset) const {
JS_ASSERT(offset < size());
// It seems a bit surprising that one might request an offset
// == size(), but it can happen when taking the "address of" a
// 0-sized value. (In other words, we maintain the invariant
// that `offset + size <= size()` -- this is always checked in
// the caller's side.)
JS_ASSERT(offset <= size());
return typedMem() + offset;
}
};

View File

@ -0,0 +1,9 @@
// Test access to a 0-sized element (in this case,
// a zero-length array).
if (!this.hasOwnProperty("TypedObject"))
quit();
var AA = TypedObject.uint8.array(0.).array(5);
var aa = new AA();
var aa0 = aa[0];