Example #1
0
 globalBuilder[util.toJavaScriptName(op)] = (module, field, mutability) => {
     assert.isString(module, `Import global module should be a string, got "${module}"`);
     assert.isString(field, `Import global field should be a string, got "${field}"`);
     assert.isString(mutability, `Import global mutability should be a string, got "${mutability}"`);
     section.data.push({ globalDescription: { type: op, mutability: _normalizeMutability(mutability) }, module, field, kind: "Global" });
     return _errorHandlingProxyFor(globalBuilder);
 };
Example #2
0
 return (module, field, type) => {
     assert.isString(module, `Import function module should be a string, got "${module}"`);
     assert.isString(field, `Import function field should be a string, got "${field}"`);
     const typeSection = builder._getSection("Type");
     type = _maybeRegisterType(builder, type);
     section.data.push({ field: field, type: type, kind: "Function", module: module });
     // Imports also count in the function index space. Map them as objects to avoid clashing with Code functions' names.
     builder._registerFunctionToIndexSpace({ module: module, field: field });
     return _errorHandlingProxyFor(nextBuilder);
 };
Example #3
0
    return (field, index, type) => {
        assert.isString(field, `Export function field should be a string, got "${field}"`);
        const typeSection = builder._getSection("Type");
        if (typeof(type) !== "undefined") {
            // Exports can leave the type unspecified, letting the Code builder patch them up later.
            type = _maybeRegisterType(builder, type);
        }

        // We can't check much about "index" here because the Code section succeeds the Export section. More work is done at Code().End() time.
        switch (typeof(index)) {
        case "string": break; // Assume it's a function name which will be revealed in the Code section.
        case "number": break; // Assume it's a number in the "function index space".
        case "object":
            // Re-exporting an import.
            assert.hasObjectProperty(index, "module", `Re-exporting "${field}" from an import`);
            assert.hasObjectProperty(index, "field", `Re-exporting "${field}" from an import`);
            break;
        case "undefined":
            // Assume it's the same as the field (i.e. it's not being renamed).
            index = field;
            break;
        default: throw new Error(`Export section's index must be a string or a number, got ${index}`);
        }

        const correspondingImport = builder._getFunctionFromIndexSpace(index);
        const importSection = builder._getSection("Import");
        if (typeof(index) === "object") {
            // Re-exporting an import using its module+field name.
            assert.isNotUndef(correspondingImport, `Re-exporting "${field}" couldn't find import from module "${index.module}" field "${index.field}"`);
            index = correspondingImport;
            if (typeof(type) === "undefined")
                type = importSection.data[index].type;
            if (builder._checked)
                assert.eq(type, importSection.data[index].type, `Re-exporting import "${importSection.data[index].field}" as "${field}" has mismatching type`);
        } else if (typeof(correspondingImport) !== "undefined") {
            // Re-exporting an import using its index.
            let exportedImport;
            for (const i of importSection.data) {
                if (i.module === correspondingImport.module && i.field === correspondingImport.field) {
                    exportedImport = i;
                    break;
                }
            }
            if (typeof(type) === "undefined")
                type = exportedImport.type;
            if (builder._checked)
                assert.eq(type, exportedImport.type, `Re-exporting import "${exportedImport.field}" as "${field}" has mismatching type`);
        }
        section.data.push({ field: field, type: type, kind: "Function", index: index });
        return _errorHandlingProxyFor(nextBuilder);
    };
Example #4
0
 return (module, field, {initial, maximum, element}) => {
     assert.isString(module, `Import Table module should be a string, got "${module}"`);
     assert.isString(field, `Import Table field should be a string, got "${field}"`);
     section.data.push({module, field, kind: "Table", tableDescription: {initial, maximum, element}});
     return _errorHandlingProxyFor(nextBuilder);
 };
Example #5
0
 return (module, field, {initial, maximum}) => {
     assert.isString(module, `Import Memory module should be a string, got "${module}"`);
     assert.isString(field, `Import Memory field should be a string, got "${field}"`);
     section.data.push({module, field, kind: "Memory", memoryDescription: {initial, maximum}});
     return _errorHandlingProxyFor(nextBuilder);
 };