Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseGlobalSection(numberOfGlobals) {
var globals = [];
dump([numberOfGlobals], "num globals");
for (var i = 0; i < numberOfGlobals; i++) {
var startLoc = getPosition();
var globalType = parseGlobalType();
/**
* Global expressions
*/
var init = [];
parseInstructionBlock(init);
var endLoc = getPosition();
var node = t.withLoc(t.global(globalType, init), endLoc, startLoc);
globals.push(node);
state.globalsInModule.push(node);
}
return globals;
}
init.push(
t.moduleImport(importing.module, importing.name, importing.descr)
);
}
/**
* instr*
*/
while (token.type === tokens.openParen) {
eatToken();
init.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
return t.global(type, init, name);
}
ModuleImport(path) {
if (t.isGlobalType(path.node.descr) === true) {
const globalType = path.node.descr;
globalType.mutability = "var";
const init = createDefaultInitForGlobal(globalType);
newGlobals.push(t.global(globalType, [init]));
path.remove();
}
},
var signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new CompileError("function signature not found (".concat(typeindex, ")"));
}
var id = getUniqueName("func");
importDescr = t.funcImportDescr(id, t.signature(signature.params, signature.result));
state.functionsInModule.push({
id: t.identifier(name.value),
signature: signature,
isExternal: true
});
} else if (descrType === "global") {
importDescr = parseGlobalType();
var globalNode = t.global(importDescr, []);
state.globalsInModule.push(globalNode);
} else if (descrType === "table") {
importDescr = parseTableType(i);
} else if (descrType === "mem") {
var memoryNode = parseMemoryType(0);
state.memoriesInModule.push(memoryNode);
importDescr = memoryNode;
} else {
throw new CompileError("Unsupported import of type: " + descrType);
}
imports.push(function () {
var endLoc = getPosition();
return t.withLoc(t.moduleImport(moduleName.value, name.value, importDescr), endLoc, _startLoc2);
}());
}
ModuleImport(path) {
if (t.isGlobalType(path.node.descr) === true) {
const globalType = path.node.descr;
globalType.mutability = "var";
const init = createDefaultInitForGlobal(globalType);
newGlobals.push(t.global(globalType, [init]));
path.remove();
}
},
if (importing != null) {
importing.descr = type;
init.push(t.moduleImport(importing.module, importing.name, importing.descr));
}
/**
* instr*
*/
while (token.type === tokens.openParen) {
eatToken();
init.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
return t.global(type, init, name);
}
/**
var node = function () {
var endLoc = getPosition();
return t.withLoc(t.global(globalType, init), endLoc, _startLoc11);
}();
if (importing != null) {
importing.descr = type;
init.push(t.moduleImport(importing.module, importing.name, importing.descr));
}
/**
* instr*
*/
while (token.type === tokens.openParen) {
eatToken();
init.push(parseFuncInstr());
eatTokenOfType(tokens.closeParen);
}
return t.global(type, init, name);
}
/**
function parseGlobalSection(numberOfGlobals) {
var globals = [];
dump([numberOfGlobals], "num globals");
for (var i = 0; i < numberOfGlobals; i++) {
var startLoc = getPosition();
var globalType = parseGlobalType();
/**
* Global expressions
*/
var init = [];
parseInstructionBlock(init);
var endLoc = getPosition();
var node = t.withLoc(t.global(globalType, init), endLoc, startLoc);
globals.push(node);
state.globalsInModule.push(node);
}
return globals;
}
var signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new CompileError("function signature not found (".concat(typeindex, ")"));
}
var id = getUniqueName("func");
importDescr = t.funcImportDescr(id, t.signature(signature.params, signature.result));
state.functionsInModule.push({
id: t.identifier(name.value),
signature: signature,
isExternal: true
});
} else if (descrType === "global") {
importDescr = parseGlobalType();
var globalNode = t.global(importDescr, []);
state.globalsInModule.push(globalNode);
} else if (descrType === "table") {
importDescr = parseTableType(i);
} else if (descrType === "mem") {
var memoryNode = parseMemoryType(0);
state.memoriesInModule.push(memoryNode);
importDescr = memoryNode;
} else {
throw new CompileError("Unsupported import of type: " + descrType);
}
imports.push(function () {
var endLoc = getPosition();
return t.withLoc(t.moduleImport(moduleName.value, name.value, importDescr), endLoc, _startLoc2);
}());
}