Support exports of globals in assembler

This commit is contained in:
2026-03-19 19:53:29 +00:00
parent 67fc1d8d7b
commit 812443d6ee

25
asm.js
View File

@@ -888,6 +888,7 @@ const Section = Object.freeze({
const Kind = Object.freeze({
FUNC: 0x00,
MEM: 0x02,
GLOBAL: 0x03,
});
export class Assembler {
@@ -942,8 +943,28 @@ export class Assembler {
}
action_export(action) {
const index = Object.keys(this.funcs).indexOf(action.name);
this.exports[action.name] = { kind: Kind.FUNC, index };
const func_index = Object.keys(this.funcs).indexOf(action.name);
if (func_index != -1) {
this.exports[action.name] = {
kind: Kind.FUNC,
index: func_index,
};
return;
}
const global_index = Object.keys(this.globals).indexOf(action.name);
if (global_index != -1) {
this.exports[action.name] = {
kind: Kind.GLOBAL,
index: global_index,
};
return;
}
console.error(
`ERROR: Unable to resolve export ${action.name} `
+ "(only functions and globals currently supported)"
);
}
action_func(action) {