Ejemplo n.º 1
0
inline bool
JSONParserBase::finishArray(MutableHandleValue vp, ElementVector& elements)
{
    MOZ_ASSERT(&elements == &stack.back().elements());

    JSObject* obj = ObjectGroup::newArrayObject(cx, elements.begin(), elements.length(),
                                                GenericObject);
    if (!obj)
        return false;

    vp.setObject(*obj);
    if (!freeElements.append(&elements))
        return false;
    stack.popBack();

    if (!stack.empty() && stack.back().state == FinishArrayElement) {
        const ElementVector& elements = stack.back().elements();
        if (!CombineArrayElementTypes(cx, obj, elements.begin(), elements.length()))
            return false;
    }

    return true;
}
Ejemplo n.º 2
0
inline bool
JSONParser::finishArray(MutableHandleValue vp, ElementVector &elements)
{
    JS_ASSERT(&elements == &stack.back().elements());

    JSObject *obj = NewDenseCopiedArray(cx, elements.length(), elements.begin());
    if (!obj)
        return false;

    /* Try to assign a new type to the array according to its elements. */
    cx->compartment()->types.fixArrayType(cx, obj);

    vp.setObject(*obj);
    if (!freeElements.append(&elements))
        return false;
    stack.popBack();
    return true;
}