Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseTable(): Table {
let name = t.identifier(getUniqueName("table"));
let limit = t.limit(0);
const elemIndices = [];
const elemType = "anyfunc";
if (token.type === tokens.string || token.type === tokens.identifier) {
name = identifierFromToken(token);
eatToken();
} else {
name = t.withRaw(name, ""); // preserve anonymous
}
while (token.type !== tokens.closeParen) {
/**
* Maybe export
*/
if (lookaheadAndCheck(tokens.openParen, keywords.elem)) {
eatToken(); // (
eatToken(); // elem
while (token.type === tokens.identifier) {
elemIndices.push(t.identifier(token.value));
eatToken();
}
eatTokenOfType(tokens.closeParen);
function parseMemory() {
var id = t.identifier(getUniqueName("memory"));
var limits = t.limit(0);
if (token.type === tokens.string || token.type === tokens.identifier) {
id = t.identifier(token.value);
eatToken();
} else {
id = t.withRaw(id, ""); // preserve anonymous
}
/**
* Maybe data
*/
if (lookaheadAndCheck(tokens.openParen, keywords.data)) {
eatToken(); // (
eatToken(); // data
// TODO(sven): do something with the data collected here
var stringInitializer = token.value;
eatTokenOfType(tokens.string); // Update limits accordingly
limits = t.limit(stringInitializer.length);
function parseTable() {
var name = t.identifier(getUniqueName("table"));
var limit = t.limit(0);
var elemIndices = [];
var elemType = "anyfunc";
if (token.type === tokens.string || token.type === tokens.identifier) {
name = identifierFromToken(token);
eatToken();
} else {
name = t.withRaw(name, ""); // preserve anonymous
}
while (token.type !== tokens.closeParen) {
/**
* Maybe export
*/
if (lookaheadAndCheck(tokens.openParen, keywords.elem)) {
eatToken(); // (
eatToken(); // elem
while (token.type === tokens.identifier) {
elemIndices.push(t.identifier(token.value));
eatToken();
}
function parseTableType(index) {
var name = t.withRaw(t.identifier(getUniqueName("table")), String(index));
var elementTypeByte = readByte();
eatBytes(1);
dump([elementTypeByte], "element type");
var elementType = constants.tableTypes[elementTypeByte];
if (typeof elementType === "undefined") {
throw new CompileError("Unknown element type in table: " + toHex(elementType));
}
var limits = parseLimits();
return t.table(elementType, limits, name);
} // https://webassembly.github.io/spec/binary/types.html#global-types
function parseTableType(index) {
var name = t.withRaw(t.identifier(getUniqueName("table")), String(index));
var elementTypeByte = readByte();
eatBytes(1);
dump([elementTypeByte], "element type");
var elementType = tableTypes[elementTypeByte];
if (typeof elementType === "undefined") {
throw new _helperApiError.CompileError("Unknown element type in table: " + toHex(elementType));
}
var limits = parseLimits();
return t.table(elementType, limits, name);
} // https://webassembly.github.io/spec/binary/types.html#global-types
function parseFuncSection(numberOfFunctions) {
dump([numberOfFunctions], "num funcs");
for (var i = 0; i < numberOfFunctions; i++) {
var indexU32 = readU32();
var typeindex = indexU32.value;
eatBytes(indexU32.nextIndex);
dump([typeindex], "type index");
var signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new CompileError("function signature not found (".concat(typeindex, ")"));
} // preserve anonymous, a name might be resolved later
var id = t.withRaw(t.identifier(getUniqueName("func")), "");
state.functionsInModule.push({
id: id,
signature: signature,
isExternal: false
});
}
} // Export section
// https://webassembly.github.io/spec/binary/modules.html#export-section
if (instruction.name === "loop") {
var _startLoc7 = getPosition();
var blocktypeByte = readByte();
eatBytes(1);
var blocktype = constants.blockTypes[blocktypeByte];
dump([blocktypeByte], "blocktype");
if (typeof blocktype === "undefined") {
throw new CompileError("Unexpected blocktype: " + toHex(blocktypeByte));
}
var instr = [];
parseInstructionBlock(instr); // preserve anonymous
var label = t.withRaw(t.identifier(getUniqueName("loop")), "");
var loopNode = function () {
var endLoc = getPosition();
return t.withLoc(t.loopInstruction(label, blocktype, instr), endLoc, _startLoc7);
}();
code.push(loopNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "if") {
var _startLoc8 = getPosition();
var _blocktypeByte = readByte();
eatBytes(1);
var _blocktype = constants.blockTypes[_blocktypeByte];
dump([_blocktypeByte], "blocktype");
var _startLoc9 = getPosition();
var _blocktypeByte2 = readByte();
eatBytes(1);
var _blocktype2 = constants.blockTypes[_blocktypeByte2];
dump([_blocktypeByte2], "blocktype");
if (typeof _blocktype2 === "undefined") {
throw new CompileError("Unexpected blocktype: " + toHex(_blocktypeByte2));
}
var _instr2 = [];
parseInstructionBlock(_instr2); // preserve anonymous
var _label = t.withRaw(t.identifier(getUniqueName("block")), "");
var blockNode = function () {
var endLoc = getPosition();
return t.withLoc(t.blockInstruction(_label, _instr2, _blocktype2), endLoc, _startLoc9);
}();
code.push(blockNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "call") {
var indexu32 = readU32();
var index = indexu32.value;
eatBytes(indexu32.nextIndex);
dump([index], "index");
var callNode = function () {
var endLoc = getPosition();
function parseFunc() {
var fnName = t.identifier(getUniqueName("func"));
var typeRef;
var fnBody = [];
var fnParams = [];
var fnResult = []; // name
if (token.type === tokens.identifier) {
fnName = identifierFromToken(token);
eatToken();
} else {
fnName = t.withRaw(fnName, ""); // preserve anonymous
}
maybeIgnoreComment();
while (token.type === tokens.openParen || token.type === tokens.name || token.type === tokens.valtype) {
// Instructions without parens
if (token.type === tokens.name || token.type === tokens.valtype) {
fnBody.push(parseFuncInstr());
continue;
}
eatToken();
if (lookaheadAndCheck(keywords.param) === true) {
eatToken();
fnParams.push.apply(fnParams, _toConsumableArray(parseFuncParam()));
function parseLoop() {
var label = t.identifier(getUniqueName("loop"));
var blockResult;
var instr = [];
if (token.type === tokens.identifier) {
label = identifierFromToken(token);
eatToken();
} else {
label = t.withRaw(label, ""); // preserve anonymous
}
while (token.type === tokens.openParen) {
eatToken();
if (lookaheadAndCheck(keywords.result) === true) {
eatToken();
blockResult = token.value;
eatToken();
} else if (lookaheadAndCheck(tokens.name) === true || lookaheadAndCheck(tokens.valtype) === true || token.type === "keyword" // is any keyword
) {
// Instruction
instr.push(parseFuncInstr());
} else {
throw function () {
return new Error("\n" + codeFrameFromSource(source, token.loc) + "\n" + "Unexpected token in loop body" + ", given " + tokenToString(token));