зеркало из https://github.com/mozilla/gecko-dev.git
Bug 898371 - Enumerate binary structs. r=nsm
This commit is contained in:
Родитель
97389b3a03
Коммит
490a8fe79f
|
@ -1346,7 +1346,7 @@ BinaryArray::obj_getGenericAttributes(JSContext *cx, HandleObject obj,
|
|||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
JSBool
|
||||
|
@ -1455,36 +1455,36 @@ Class BinaryStruct::class_ = {
|
|||
BinaryStruct::obj_trace,
|
||||
JS_NULL_CLASS_EXT,
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* lookupGeneric */
|
||||
NULL, /* lookupProperty */
|
||||
NULL, /* lookupElement */
|
||||
NULL, /* lookupSpecial */
|
||||
NULL, /* defineGeneric */
|
||||
NULL, /* defineProperty */
|
||||
NULL, /* defineElement */
|
||||
NULL, /* defineSpecial */
|
||||
BinaryStruct::obj_getGeneric,
|
||||
BinaryStruct::obj_getProperty,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* getElement */
|
||||
NULL, /* getElementIfPresent */
|
||||
BinaryStruct::obj_getSpecial,
|
||||
BinaryStruct::obj_setGeneric,
|
||||
BinaryStruct::obj_setProperty,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* setElement */
|
||||
NULL, /* setSpecial */
|
||||
NULL, /* getGenericAttributes */
|
||||
NULL, /* getPropertyAttributes */
|
||||
NULL, /* getElementAttributes */
|
||||
NULL, /* getSpecialAttributes */
|
||||
NULL, /* setGenericAttributes */
|
||||
NULL, /* setPropertyAttributes */
|
||||
NULL, /* setElementAttributes */
|
||||
NULL, /* setSpecialAttributes */
|
||||
NULL, /* deleteProperty */
|
||||
NULL, /* deleteElement */
|
||||
NULL, /* deleteSpecial */
|
||||
BinaryStruct::obj_enumerate,
|
||||
NULL, /* thisObject */
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1817,6 +1817,45 @@ BinaryStruct::obj_trace(JSTracer *tracer, JSObject *obj)
|
|||
MarkObject(tracer, &type, "binarystruct.type");
|
||||
}
|
||||
|
||||
JSBool
|
||||
BinaryStruct::obj_enumerate(JSContext *cx, HandleObject obj, JSIterateOp enum_op,
|
||||
MutableHandleValue statep, MutableHandleId idp)
|
||||
{
|
||||
JS_ASSERT(IsBinaryStruct(obj));
|
||||
|
||||
RootedObject type(cx, GetType(obj));
|
||||
|
||||
FieldList *fieldList = static_cast<FieldList *>(type->getPrivate());
|
||||
JS_ASSERT(fieldList);
|
||||
|
||||
uint32_t index;
|
||||
switch (enum_op) {
|
||||
case JSENUMERATE_INIT_ALL:
|
||||
case JSENUMERATE_INIT:
|
||||
statep.setInt32(0);
|
||||
idp.set(INT_TO_JSID(fieldList->size()));
|
||||
break;
|
||||
|
||||
case JSENUMERATE_NEXT:
|
||||
index = static_cast<uint32_t>(statep.toInt32());
|
||||
|
||||
if (index < fieldList->size()) {
|
||||
idp.set(fieldList->at(index).name);
|
||||
statep.setInt32(index + 1);
|
||||
} else {
|
||||
statep.setNull();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case JSENUMERATE_DESTROY:
|
||||
statep.setNull();
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
JSBool
|
||||
BinaryStruct::obj_getGeneric(JSContext *cx, HandleObject obj,
|
||||
HandleObject receiver, HandleId id,
|
||||
|
|
|
@ -295,6 +295,11 @@ class BinaryStruct : public JSObject
|
|||
static void finalize(js::FreeOp *op, JSObject *obj);
|
||||
static void obj_trace(JSTracer *tracer, JSObject *obj);
|
||||
|
||||
static JSBool obj_enumerate(JSContext *cx, HandleObject obj,
|
||||
JSIterateOp enum_op,
|
||||
MutableHandleValue statep,
|
||||
MutableHandleId idp);
|
||||
|
||||
static JSBool obj_getGeneric(JSContext *cx, HandleObject obj,
|
||||
HandleObject receiver, HandleId id,
|
||||
MutableHandleValue vp);
|
||||
|
|
|
@ -51,6 +51,11 @@ function runTests() {
|
|||
assertEq(civic.color.g, 255);
|
||||
assertEq(civic.color.b, 255);
|
||||
|
||||
var keys = Object.keys(civic).sort();
|
||||
assertEq(keys.length, 2);
|
||||
assertEq(keys.indexOf("color"), 0);
|
||||
assertEq(keys.indexOf("weight"), 1);
|
||||
|
||||
civic.color = {r: 255, g: 0, b: 0};
|
||||
assertEq(civic.color.r, 255);
|
||||
assertEq(civic.color.g, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче