Пример #1
0
static bool
DecodeFunctionBodies(JSContext* cx, Decoder& d, ModuleGenerator& mg)
{
    if (!mg.startFuncDefs())
        return false;

    uint32_t sectionStart;
    if (!d.startSection(FunctionBodiesId, &sectionStart))
        return Fail(cx, d, "failed to start section");

    if (sectionStart == Decoder::NotStarted) {
        if (mg.numFuncSigs() != 0)
            return Fail(cx, d, "expected function bodies");

        return mg.finishFuncDefs();
    }

    uint32_t numFuncBodies;
    if (!d.readVarU32(&numFuncBodies))
        return Fail(cx, d, "expected function body count");

    if (numFuncBodies != mg.numFuncSigs())
        return Fail(cx, d, "function body count does not match function signature count");

    for (uint32_t funcIndex = 0; funcIndex < numFuncBodies; funcIndex++) {
        if (!DecodeFunctionBody(cx, d, mg, funcIndex))
            return false;
    }

    if (!d.finishSection(sectionStart))
        return Fail(cx, d, "function section byte size mismatch");

    return mg.finishFuncDefs();
}
Пример #2
0
static bool
DecodeExport(JSContext* cx, Decoder& d, ModuleGenerator& mg, ExportMap* exportMap)
{
    if (!d.readCStringIf(FuncSubsection))
        return Fail(cx, d, "expected 'func' tag");

    uint32_t funcIndex;
    if (!d.readVarU32(&funcIndex))
        return Fail(cx, d, "expected export internal index");

    if (funcIndex >= mg.numFuncSigs())
        return Fail(cx, d, "export function index out of range");

    uint32_t exportIndex;
    if (!mg.declareExport(funcIndex, &exportIndex))
        return false;

    MOZ_ASSERT(exportIndex <= exportMap->exportNames.length());
    if (exportIndex == exportMap->exportNames.length()) {
        UniqueChars funcName(JS_smprintf("%u", unsigned(funcIndex)));
        if (!funcName || !exportMap->exportNames.emplaceBack(Move(funcName)))
            return false;
    }

    if (!exportMap->fieldsToExports.append(exportIndex))
        return false;

    const char* chars;
    if (!d.readCString(&chars))
        return Fail(cx, d, "expected export external name string");

    return exportMap->fieldNames.emplaceBack(DuplicateString(chars));
}
Пример #3
0
static bool
DecodeCodeSection(JSContext* cx, Decoder& d, ModuleGenerator& mg)
{
    if (!mg.startFuncDefs())
        return false;

    uint32_t funcIndex = 0;
    while (d.readCStringIf(CodeSection)) {
        uint32_t sectionStart;
        if (!d.startSection(&sectionStart))
            return Fail(cx, d, "expected code section byte size");

        uint32_t numFuncs;
        if (!d.readVarU32(&numFuncs))
            return Fail(cx, d, "expected number of functions");

        if (funcIndex + numFuncs > mg.numFuncSigs())
            return Fail(cx, d, "more function definitions than declarations");

        for (uint32_t i = 0; i < numFuncs; i++) {
            if (!DecodeFunc(cx, d, mg, funcIndex++))
                return false;
        }

        if (!d.finishSection(sectionStart))
            return Fail(cx, d, "code section byte size mismatch");
    }

    if (funcIndex != mg.numFuncSigs())
        return Fail(cx, d, "fewer function definitions than declarations");

    if (!mg.finishFuncDefs())
        return false;

    return true;
}
Пример #4
0
static bool
DecodeFunctionSections(JSContext* cx, Decoder& d, ModuleGenerator& mg)
{
    if (!mg.startFuncDefs())
        return false;

    uint32_t funcIndex = 0;

    for (; d.readCStringIf(FuncLabel); funcIndex++) {
        if (funcIndex >= mg.numFuncSigs())
            return Fail(cx, d, "more function definitions than declarations");

        if (!DecodeFunctionSection(cx, d, mg, funcIndex))
            return false;
    }

    if (funcIndex < mg.numFuncSigs())
        return Fail(cx, d, "fewer function definitions than declarations");

    if (!mg.finishFuncDefs())
        return false;

    return true;
}
Пример #5
0
static bool
DecodeFunctionExport(JSContext* cx, Decoder& d, ModuleGenerator& mg, CStringSet* dupSet)
{
    uint32_t funcIndex;
    if (!d.readVarU32(&funcIndex))
        return Fail(cx, d, "expected export internal index");

    if (funcIndex >= mg.numFuncSigs())
        return Fail(cx, d, "export function index out of range");

    UniqueChars fieldName = DecodeFieldName(cx, d, dupSet);
    if (!fieldName)
        return false;

    return mg.declareExport(Move(fieldName), funcIndex);
}