Bug 952890 part 1. Make WebIDL sequence JS to C++ conversions use for-of iteration, not length/index gets. r=peterv

This commit is contained in:
Boris Zbarsky 2014-02-14 10:46:09 -05:00
parent e802c76f4b
commit fcf1f55974

View File

@ -3094,31 +3094,35 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
arrayRef = "${declName}"
# NOTE: Keep this in sync with variadic conversions as needed
templateBody = ("""JS::Rooted<JSObject*> seq(cx, &${val}.toObject());\n
if (!IsArrayLike(cx, seq)) {
templateBody = ("""JS::ForOfIterator iter(cx);
if (!iter.init(${val}, JS::ForOfIterator::AllowNonIterable)) {
%s
}
uint32_t length;
// JS_GetArrayLength actually works on all objects
if (!JS_GetArrayLength(cx, seq, &length)) {
if (!iter.valueIsIterable()) {
%s
}
%s &arr = %s;
if (!arr.SetCapacity(length)) {
JS_ReportOutOfMemory(cx);
%s
}
for (uint32_t i = 0; i < length; ++i) {
JS::Rooted<JS::Value> temp(cx);
if (!JS_GetElement(cx, seq, i, &temp)) {
JS::Rooted<JS::Value> temp(cx);
while (true) {
bool done;
if (!iter.next(&temp, &done)) {
%s
}
%s& slot = *arr.AppendElement();
""" % (CGIndenter(CGGeneric(notSequence)).define(),
exceptionCodeIndented.define(),
if (done) {
break;
}
%s* slotPtr = arr.AppendElement();
if (!slotPtr) {
JS_ReportOutOfMemory(cx);
%s
}
%s& slot = *slotPtr;
""" % (exceptionCodeIndented.define(),
CGIndenter(CGGeneric(notSequence)).define(),
sequenceType,
arrayRef,
exceptionCodeIndented.define(),
CGIndenter(exceptionCodeIndented).define(),
elementInfo.declType.define(),
CGIndenter(exceptionCodeIndented).define(),
elementInfo.declType.define()))
@ -3185,12 +3189,7 @@ for (uint32_t i = 0; i < length; ++i) {
arrayObjectMemberTypes = filter(lambda t: t.isArray() or t.isSequence(), memberTypes)
if len(arrayObjectMemberTypes) > 0:
assert len(arrayObjectMemberTypes) == 1
memberType = arrayObjectMemberTypes[0]
name = memberType.name
arrayObject = CGGeneric("done = (failed = !%s.TrySetTo%s(cx, ${val}, ${mutableVal}, tryNext)) || !tryNext;" % (unionArgumentObj, name))
arrayObject = CGIfWrapper(arrayObject, "IsArrayLike(cx, argObj)")
names.append(name)
raise TypeError("Bug 767924: We don't support sequences in unions yet")
else:
arrayObject = None