Allow for retrieval of "memory" type import / export name (#449)

* Store the memory export name

When the memory export is defined in the WASM module,
store the name of the export so that it can be read by
the application.

This is necessary for implementing the JavaScript
`WebAssembly.Module.exports()` function.

* Store the memory import name

When the memory import is defined in the WASM module,
store the name of the import so that it can be read by
the application.

This is necessary for implementing the JavaScript
`WebAssembly.Module.imports()` function.

* Store the table0 export name

When the table export is defined in the WASM module,
store the name of the export so that it can be read by
the application.

This is necessary for implementing the JavaScript
`WebAssembly.Module.exports()` function.
pull/306/head^2
Nathan Rajlich 6 months ago committed by GitHub
parent c5fe08894f
commit 8f3fe3bd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -110,9 +110,12 @@ typedef struct M3Module
IM3Function * table0;
u32 table0Size;
const char* table0ExportName;
M3MemoryInfo memoryInfo;
M3ImportInfo memoryImport;
bool memoryImported;
const char* memoryExportName;
//bool hasWasmCodeCopy;

@ -184,6 +184,8 @@ _ (Module_AddFunction (io_module, typeIndex, & import))
{
_ (ParseType_Memory (& io_module->memoryInfo, & i_bytes, i_end));
io_module->memoryImported = true;
io_module->memoryImport = import;
import = clearImport;
}
break;
@ -256,6 +258,18 @@ _ (ReadLEB_u32 (& index, & i_bytes, i_end));
global->name = utf8;
utf8 = NULL; // ownership transferred to M3Global
}
else if (exportKind == d_externalKind_memory)
{
m3_Free (io_module->memoryExportName);
io_module->memoryExportName = utf8;
utf8 = NULL; // ownership transferred to M3Module
}
else if (exportKind == d_externalKind_table)
{
m3_Free (io_module->table0ExportName);
io_module->table0ExportName = utf8;
utf8 = NULL; // ownership transferred to M3Module
}
m3_Free (utf8);
}

Loading…
Cancel
Save