Bug 1155985 - Set FieldInto::mType just before storing to reserved slot. r=jonco, a=abillings

This commit is contained in:
Tooru Fujisawa 2015-04-22 18:26:13 +09:00
parent e423aa7681
commit 288adf212a
2 changed files with 21 additions and 1 deletions

View File

@ -4963,7 +4963,7 @@ StructType::DefineInternal(JSContext* cx, JSObject* typeObj_, JSObject* fieldsOb
// Add field name to the hash
FieldInfo info;
info.mType = fieldType;
info.mType = nullptr; // Value of fields are not yet traceable here.
info.mIndex = i;
info.mOffset = fieldOffset;
ASSERT_OK(fields->add(entryPtr, name, info));
@ -4996,6 +4996,12 @@ StructType::DefineInternal(JSContext* cx, JSObject* typeObj_, JSObject* fieldsOb
if (!SizeTojsval(cx, structSize, &sizeVal))
return false;
for (FieldInfoHash::Range r = fields->all(); !r.empty(); r.popFront()) {
FieldInfo& field = r.front().value();
MOZ_ASSERT(field.mIndex < fieldRoots.length());
field.mType = &fieldRoots[field.mIndex].toObject();
}
JS_SetReservedSlot(typeObj, SLOT_FIELDINFO, PRIVATE_TO_JSVAL(fields.release()));
JS_SetReservedSlot(typeObj, SLOT_SIZE, sizeVal);

View File

@ -0,0 +1,14 @@
function test() {
for (let i = 0; i < 100; i++) {
let test_struct = ctypes.StructType("test_struct", [{ "x": ctypes.int32_t },
{ "bar": ctypes.uint32_t }]);
try {
new test_struct("foo", "x");
} catch (e) {
}
}
}
if (typeof ctypes === "object")
test();