@webassemblyjs/wasm-parser
Advanced tools
Comparing version 1.7.11 to 1.8.0
@@ -328,3 +328,4 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
for (var i = 0; i < numberOfTypes; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc = getPosition(); | ||
dumpSep("type " + i); | ||
@@ -347,4 +348,6 @@ var type = readByte(); | ||
}); | ||
var endLoc = getPosition(); | ||
typeInstructionNodes.push(t.withLoc(t.typeInstruction(undefined, t.signature(params, result)), endLoc, startLoc)); | ||
typeInstructionNodes.push(function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.typeInstruction(undefined, t.signature(params, result)), endLoc, _startLoc); | ||
}()); | ||
state.typesInModule.push({ | ||
@@ -369,3 +372,4 @@ params: params, | ||
dumpSep("import header " + i); | ||
var startLoc = getPosition(); | ||
var _startLoc2 = getPosition(); | ||
/** | ||
@@ -375,2 +379,3 @@ * Module name | ||
var moduleName = readUTF8String(); | ||
@@ -433,4 +438,6 @@ eatBytes(moduleName.nextIndex); | ||
var endLoc = getPosition(); | ||
imports.push(t.withLoc(t.moduleImport(moduleName.value, name.value, importDescr), endLoc, startLoc)); | ||
imports.push(function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.moduleImport(moduleName.value, name.value, importDescr), endLoc, _startLoc2); | ||
}()); | ||
} | ||
@@ -473,3 +480,3 @@ | ||
for (var i = 0; i < numberOfExport; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc3 = getPosition(); | ||
/** | ||
@@ -479,2 +486,3 @@ * Name | ||
var name = readUTF8String(); | ||
@@ -501,3 +509,3 @@ eatBytes(name.nextIndex); | ||
if (typeof func === "undefined") { | ||
throw new CompileError("entry not found at index ".concat(index, " in function section")); | ||
throw new CompileError("unknown function (".concat(index, ")")); | ||
} | ||
@@ -511,3 +519,3 @@ | ||
if (typeof table === "undefined") { | ||
throw new CompileError("entry not found at index ".concat(index, " in table section")); | ||
throw new CompileError("unknown table ".concat(index)); | ||
} | ||
@@ -521,3 +529,3 @@ | ||
if (typeof memNode === "undefined") { | ||
throw new CompileError("entry not found at index ".concat(index, " in memory section")); | ||
throw new CompileError("unknown memory ".concat(index)); | ||
} | ||
@@ -531,3 +539,3 @@ | ||
if (typeof global === "undefined") { | ||
throw new CompileError("entry not found at index ".concat(index, " in global section")); | ||
throw new CompileError("unknown global ".concat(index)); | ||
} | ||
@@ -550,3 +558,3 @@ | ||
endLoc: endLoc, | ||
startLoc: startLoc | ||
startLoc: _startLoc3 | ||
}); | ||
@@ -562,3 +570,4 @@ } | ||
for (var i = 0; i < numberOfFuncs; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc4 = getPosition(); | ||
dumpSep("function body " + i); // the u32 size of the function code in bytes | ||
@@ -582,2 +591,4 @@ // Ignore it for now | ||
for (var _i = 0; _i < funcLocalNum; _i++) { | ||
var _startLoc5 = getPosition(); | ||
var localCountU32 = readU32(); | ||
@@ -590,3 +601,9 @@ var localCount = localCountU32.value; | ||
var type = constants.valtypes[valtypeByte]; | ||
locals.push(type); | ||
var localNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.instruction("local", [t.valtypeLiteral(type)]), endLoc, _startLoc5); | ||
}(); | ||
locals.push(localNode); | ||
dump([valtypeByte], type); | ||
@@ -597,9 +614,7 @@ | ||
} | ||
} // Decode instructions until the end | ||
} | ||
code.push.apply(code, locals); // Decode instructions until the end | ||
parseInstructionBlock(code); | ||
code.unshift.apply(code, _toConsumableArray(locals.map(function (l) { | ||
return t.instruction("local", [t.valtypeLiteral(l)]); | ||
}))); | ||
var endLoc = getPosition(); | ||
@@ -610,3 +625,3 @@ state.elementsInCodeSection.push({ | ||
endLoc: endLoc, | ||
startLoc: startLoc, | ||
startLoc: _startLoc4, | ||
bodySize: bodySizeU32.value | ||
@@ -619,3 +634,4 @@ }); | ||
while (true) { | ||
var startLoc = getPosition(); | ||
var _startLoc6 = getPosition(); | ||
var instructionAlreadyCreated = false; | ||
@@ -646,2 +662,8 @@ var instructionByte = readByte(); | ||
if (instruction.name === "end") { | ||
var node = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.instruction(instruction.name), endLoc, _startLoc6); | ||
}(); | ||
code.push(node); | ||
break; | ||
@@ -653,2 +675,4 @@ } | ||
if (instruction.name === "loop") { | ||
var _startLoc7 = getPosition(); | ||
var blocktypeByte = readByte(); | ||
@@ -667,6 +691,13 @@ eatBytes(1); | ||
var label = t.withRaw(t.identifier(getUniqueName("loop")), ""); | ||
var loopNode = t.loopInstruction(label, blocktype, instr); | ||
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(); | ||
@@ -700,6 +731,13 @@ | ||
var testInstrs = []; | ||
var ifNode = t.ifInstruction(testIndex, testInstrs, _blocktype, consequentInstr, alternate); | ||
var ifNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.ifInstruction(testIndex, testInstrs, _blocktype, consequentInstr, alternate), endLoc, _startLoc8); | ||
}(); | ||
code.push(ifNode); | ||
instructionAlreadyCreated = true; | ||
} else if (instruction.name === "block") { | ||
var _startLoc9 = getPosition(); | ||
var _blocktypeByte2 = readByte(); | ||
@@ -720,3 +758,7 @@ | ||
var blockNode = t.blockInstruction(_label, _instr2, _blocktype2); | ||
var blockNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.blockInstruction(_label, _instr2, _blocktype2), endLoc, _startLoc9); | ||
}(); | ||
code.push(blockNode); | ||
@@ -729,3 +771,8 @@ instructionAlreadyCreated = true; | ||
dump([index], "index"); | ||
var callNode = t.callInstruction(t.indexLiteral(index)); | ||
var callNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.callInstruction(t.indexLiteral(index)), endLoc, _startLoc6); | ||
}(); | ||
code.push(callNode); | ||
@@ -823,3 +870,3 @@ instructionAlreadyCreated = true; | ||
low = _value2.low; | ||
var node = { | ||
var _node = { | ||
type: "LongNumberLiteral", | ||
@@ -831,3 +878,3 @@ value: { | ||
}; | ||
args.push(node); | ||
args.push(_node); | ||
} | ||
@@ -842,3 +889,3 @@ | ||
_low = _value3.low; | ||
var _node = { | ||
var _node2 = { | ||
type: "LongNumberLiteral", | ||
@@ -850,3 +897,3 @@ value: { | ||
}; | ||
args.push(_node); | ||
args.push(_node2); | ||
} | ||
@@ -882,9 +929,15 @@ | ||
if (typeof instruction.object === "string") { | ||
code.push(t.objectInstruction(instruction.name, instruction.object, args)); | ||
var _node3 = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.objectInstruction(instruction.name, instruction.object, args), endLoc, _startLoc6); | ||
}(); | ||
code.push(_node3); | ||
} else { | ||
var endLoc = getPosition(); | ||
var _node4 = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.instruction(instruction.name, args), endLoc, _startLoc6); | ||
}(); | ||
var _node2 = t.withLoc(t.instruction(instruction.name, args), endLoc, startLoc); | ||
code.push(_node2); | ||
code.push(_node4); | ||
} | ||
@@ -1074,3 +1127,4 @@ } | ||
for (var i = 0; i < numberOfGlobals; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc10 = getPosition(); | ||
var globalType = parseGlobalType(); | ||
@@ -1083,4 +1137,8 @@ /** | ||
parseInstructionBlock(init); | ||
var endLoc = getPosition(); | ||
var node = t.withLoc(t.global(globalType, init), endLoc, startLoc); | ||
var node = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.global(globalType, init), endLoc, _startLoc10); | ||
}(); | ||
globals.push(node); | ||
@@ -1098,3 +1156,4 @@ state.globalsInModule.push(node); | ||
for (var i = 0; i < numberOfElements; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc11 = getPosition(); | ||
var tableindexu32 = readU32(); | ||
@@ -1128,4 +1187,7 @@ var tableindex = tableindexu32.value; | ||
var endLoc = getPosition(); | ||
var elemNode = t.withLoc(t.elem(t.indexLiteral(tableindex), instr, indexValues), endLoc, startLoc); | ||
var elemNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.elem(t.indexLiteral(tableindex), instr, indexValues), endLoc, _startLoc11); | ||
}(); | ||
elems.push(elemNode); | ||
@@ -1178,4 +1240,6 @@ } | ||
dump([startFuncIndex], "index"); | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.start(t.indexLiteral(startFuncIndex)), endLoc, startLoc); | ||
return function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.start(t.indexLiteral(startFuncIndex)), endLoc, startLoc); | ||
}(); | ||
} // https://webassembly.github.io/spec/binary/modules.html#data-section | ||
@@ -1195,4 +1259,7 @@ | ||
parseInstructionBlock(instrs); | ||
var hasExtraInstrs = instrs.filter(function (i) { | ||
return i.id !== "end"; | ||
}).length !== 1; | ||
if (instrs.length !== 1) { | ||
if (hasExtraInstrs) { | ||
throw new CompileError("data section offset must be a single instruction"); | ||
@@ -1224,9 +1291,12 @@ } | ||
var startOffset = offset; | ||
var startPosition = getPosition(); | ||
var startLoc = getPosition(); | ||
var u32 = readU32(); | ||
var sectionSizeInBytes = u32.value; | ||
eatBytes(u32.nextIndex); | ||
var sectionSizeInBytesEndLoc = getPosition(); | ||
var sectionSizeInBytesNode = t.withLoc(t.numberLiteralFromRaw(sectionSizeInBytes), sectionSizeInBytesEndLoc, startPosition); | ||
var sectionSizeInBytesNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(sectionSizeInBytes), endLoc, startLoc); | ||
}(); | ||
switch (sectionId) { | ||
@@ -1239,3 +1309,3 @@ case constants.sections.type: | ||
var _startPosition = getPosition(); | ||
var _startLoc12 = getPosition(); | ||
@@ -1246,5 +1316,7 @@ var _u = readU32(); | ||
eatBytes(_u.nextIndex); | ||
var endPosition = getPosition(); | ||
var _metadata = t.sectionMetadata("type", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfTypes), endPosition, _startPosition)); | ||
var _metadata = t.sectionMetadata("type", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfTypes), endLoc, _startLoc12); | ||
}()); | ||
@@ -1266,3 +1338,3 @@ var _nodes = parseTypeSection(numberOfTypes); | ||
var _startPosition2 = getPosition(); | ||
var _startLoc13 = getPosition(); | ||
@@ -1273,8 +1345,8 @@ var _u2 = readU32(); | ||
eatBytes(_u2.nextIndex); | ||
var _endPosition = getPosition(); | ||
dump([numberOfTable], "num tables"); | ||
var _metadata2 = t.sectionMetadata("table", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfTable), _endPosition, _startPosition2)); | ||
var _metadata2 = t.sectionMetadata("table", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfTable), endLoc, _startLoc13); | ||
}()); | ||
@@ -1296,3 +1368,3 @@ var _nodes2 = parseTableSection(numberOfTable); | ||
var _startPosition3 = getPosition(); | ||
var _startLoc14 = getPosition(); | ||
@@ -1302,8 +1374,8 @@ var numberOfImportsu32 = readU32(); | ||
eatBytes(numberOfImportsu32.nextIndex); | ||
var _endPosition2 = getPosition(); | ||
dump([numberOfImports], "number of imports"); | ||
var _metadata3 = t.sectionMetadata("import", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfImports), _endPosition2, _startPosition3)); | ||
var _metadata3 = t.sectionMetadata("import", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfImports), endLoc, _startLoc14); | ||
}()); | ||
@@ -1325,3 +1397,3 @@ var _nodes3 = parseImportSection(numberOfImports); | ||
var _startPosition4 = getPosition(); | ||
var _startLoc15 = getPosition(); | ||
@@ -1332,6 +1404,7 @@ var numberOfFunctionsu32 = readU32(); | ||
var _endPosition3 = getPosition(); | ||
var _metadata4 = t.sectionMetadata("func", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfFunctions), endLoc, _startLoc15); | ||
}()); | ||
var _metadata4 = t.sectionMetadata("func", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfFunctions), _endPosition3, _startPosition4)); | ||
parseFuncSection(numberOfFunctions); | ||
@@ -1352,3 +1425,3 @@ var _nodes4 = []; | ||
var _startPosition5 = getPosition(); | ||
var _startLoc16 = getPosition(); | ||
@@ -1360,6 +1433,7 @@ var _u3 = readU32(); | ||
var _endPosition4 = getPosition(); | ||
var _metadata5 = t.sectionMetadata("export", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfExport), endLoc, _startLoc16); | ||
}()); | ||
var _metadata5 = t.sectionMetadata("export", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfExport), _endPosition4, _startPosition5)); | ||
parseExportSection(numberOfExport); | ||
@@ -1380,3 +1454,3 @@ var _nodes5 = []; | ||
var _startPosition6 = getPosition(); | ||
var _startLoc17 = getPosition(); | ||
@@ -1388,6 +1462,7 @@ var _u4 = readU32(); | ||
var _endPosition5 = getPosition(); | ||
var _metadata6 = t.sectionMetadata("code", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfFuncs), endLoc, _startLoc17); | ||
}()); | ||
var _metadata6 = t.sectionMetadata("code", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfFuncs), _endPosition5, _startPosition6)); | ||
if (opts.ignoreCodeSection === true) { | ||
@@ -1430,3 +1505,3 @@ var remainingBytes = sectionSizeInBytes - _u4.nextIndex; | ||
var _startPosition7 = getPosition(); | ||
var _startLoc18 = getPosition(); | ||
@@ -1437,6 +1512,7 @@ var numberOfElementsu32 = readU32(); | ||
var _endPosition6 = getPosition(); | ||
var _metadata8 = t.sectionMetadata("element", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfElements), endLoc, _startLoc18); | ||
}()); | ||
var _metadata8 = t.sectionMetadata("element", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfElements), _endPosition6, _startPosition7)); | ||
var _nodes8 = parseElemSection(numberOfElements); | ||
@@ -1457,3 +1533,3 @@ | ||
var _startPosition8 = getPosition(); | ||
var _startLoc19 = getPosition(); | ||
@@ -1464,6 +1540,7 @@ var numberOfGlobalsu32 = readU32(); | ||
var _endPosition7 = getPosition(); | ||
var _metadata9 = t.sectionMetadata("global", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfGlobals), endLoc, _startLoc19); | ||
}()); | ||
var _metadata9 = t.sectionMetadata("global", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfGlobals), _endPosition7, _startPosition8)); | ||
var _nodes9 = parseGlobalSection(numberOfGlobals); | ||
@@ -1484,3 +1561,3 @@ | ||
var _startPosition9 = getPosition(); | ||
var _startLoc20 = getPosition(); | ||
@@ -1492,6 +1569,7 @@ var _numberOfElementsu = readU32(); | ||
var _endPosition8 = getPosition(); | ||
var _metadata10 = t.sectionMetadata("memory", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(_numberOfElements), endLoc, _startLoc20); | ||
}()); | ||
var _metadata10 = t.sectionMetadata("memory", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(_numberOfElements), _endPosition8, _startPosition9)); | ||
var _nodes10 = parseMemorySection(_numberOfElements); | ||
@@ -1514,3 +1592,3 @@ | ||
var _startPosition10 = getPosition(); | ||
var _startLoc21 = getPosition(); | ||
@@ -1522,6 +1600,7 @@ var _numberOfElementsu2 = readU32(); | ||
var _endPosition9 = getPosition(); | ||
_metadata11.vectorOfSize = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(_numberOfElements2), endLoc, _startLoc21); | ||
}(); | ||
_metadata11.vectorOfSize = t.withLoc(t.numberLiteralFromRaw(_numberOfElements2), _endPosition9, _startPosition10); | ||
if (opts.ignoreDataSection === true) { | ||
@@ -1654,6 +1733,6 @@ var _remainingBytes = sectionSizeInBytes - _numberOfElementsu2.nextIndex; | ||
if (opts.ignoreCodeSection === false) { | ||
var startLoc = decodedElementInCodeSection.startLoc, | ||
var _startLoc22 = decodedElementInCodeSection.startLoc, | ||
endLoc = decodedElementInCodeSection.endLoc, | ||
bodySize = decodedElementInCodeSection.bodySize; | ||
funcNode = t.withLoc(funcNode, endLoc, startLoc); | ||
funcNode = t.withLoc(funcNode, endLoc, _startLoc22); | ||
funcNode.metadata = { | ||
@@ -1660,0 +1739,0 @@ bodySize: bodySize |
import * as decoder from "./decoder"; | ||
import * as t from "@webassemblyjs/ast"; | ||
/** | ||
* TODO(sven): I added initial props, but we should rather fix | ||
* https://github.com/xtuc/webassemblyjs/issues/405 | ||
*/ | ||
var defaultDecoderOpts = { | ||
@@ -49,3 +54,5 @@ dump: false, | ||
if (functionName) { | ||
nodeName.value = functionName.name; // $FlowIgnore | ||
var oldValue = nodeName.value; | ||
nodeName.value = functionName.name; | ||
nodeName.numeric = oldValue; // $FlowIgnore | ||
@@ -127,3 +134,5 @@ delete nodeName.raw; | ||
if (functionName) { | ||
node.index = t.identifier(functionName.name); // $FlowIgnore | ||
var oldValue = node.index; | ||
node.index = t.identifier(functionName.name); | ||
node.numeric = oldValue; // $FlowIgnore | ||
@@ -130,0 +139,0 @@ delete node.raw; |
@@ -344,3 +344,4 @@ "use strict"; | ||
for (var i = 0; i < numberOfTypes; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc = getPosition(); | ||
dumpSep("type " + i); | ||
@@ -363,4 +364,6 @@ var type = readByte(); | ||
}); | ||
var endLoc = getPosition(); | ||
typeInstructionNodes.push(t.withLoc(t.typeInstruction(undefined, t.signature(params, result)), endLoc, startLoc)); | ||
typeInstructionNodes.push(function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.typeInstruction(undefined, t.signature(params, result)), endLoc, _startLoc); | ||
}()); | ||
state.typesInModule.push({ | ||
@@ -385,3 +388,4 @@ params: params, | ||
dumpSep("import header " + i); | ||
var startLoc = getPosition(); | ||
var _startLoc2 = getPosition(); | ||
/** | ||
@@ -391,2 +395,3 @@ * Module name | ||
var moduleName = readUTF8String(); | ||
@@ -449,4 +454,6 @@ eatBytes(moduleName.nextIndex); | ||
var endLoc = getPosition(); | ||
imports.push(t.withLoc(t.moduleImport(moduleName.value, name.value, importDescr), endLoc, startLoc)); | ||
imports.push(function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.moduleImport(moduleName.value, name.value, importDescr), endLoc, _startLoc2); | ||
}()); | ||
} | ||
@@ -489,3 +496,3 @@ | ||
for (var i = 0; i < numberOfExport; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc3 = getPosition(); | ||
/** | ||
@@ -495,2 +502,3 @@ * Name | ||
var name = readUTF8String(); | ||
@@ -517,3 +525,3 @@ eatBytes(name.nextIndex); | ||
if (typeof func === "undefined") { | ||
throw new _helperApiError.CompileError("entry not found at index ".concat(index, " in function section")); | ||
throw new _helperApiError.CompileError("unknown function (".concat(index, ")")); | ||
} | ||
@@ -527,3 +535,3 @@ | ||
if (typeof table === "undefined") { | ||
throw new _helperApiError.CompileError("entry not found at index ".concat(index, " in table section")); | ||
throw new _helperApiError.CompileError("unknown table ".concat(index)); | ||
} | ||
@@ -537,3 +545,3 @@ | ||
if (typeof memNode === "undefined") { | ||
throw new _helperApiError.CompileError("entry not found at index ".concat(index, " in memory section")); | ||
throw new _helperApiError.CompileError("unknown memory ".concat(index)); | ||
} | ||
@@ -547,3 +555,3 @@ | ||
if (typeof global === "undefined") { | ||
throw new _helperApiError.CompileError("entry not found at index ".concat(index, " in global section")); | ||
throw new _helperApiError.CompileError("unknown global ".concat(index)); | ||
} | ||
@@ -566,3 +574,3 @@ | ||
endLoc: endLoc, | ||
startLoc: startLoc | ||
startLoc: _startLoc3 | ||
}); | ||
@@ -578,3 +586,4 @@ } | ||
for (var i = 0; i < numberOfFuncs; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc4 = getPosition(); | ||
dumpSep("function body " + i); // the u32 size of the function code in bytes | ||
@@ -598,2 +607,4 @@ // Ignore it for now | ||
for (var _i = 0; _i < funcLocalNum; _i++) { | ||
var _startLoc5 = getPosition(); | ||
var localCountU32 = readU32(); | ||
@@ -606,3 +617,9 @@ var localCount = localCountU32.value; | ||
var type = _helperWasmBytecode.default.valtypes[valtypeByte]; | ||
locals.push(type); | ||
var localNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.instruction("local", [t.valtypeLiteral(type)]), endLoc, _startLoc5); | ||
}(); | ||
locals.push(localNode); | ||
dump([valtypeByte], type); | ||
@@ -613,9 +630,7 @@ | ||
} | ||
} // Decode instructions until the end | ||
} | ||
code.push.apply(code, locals); // Decode instructions until the end | ||
parseInstructionBlock(code); | ||
code.unshift.apply(code, _toConsumableArray(locals.map(function (l) { | ||
return t.instruction("local", [t.valtypeLiteral(l)]); | ||
}))); | ||
var endLoc = getPosition(); | ||
@@ -626,3 +641,3 @@ state.elementsInCodeSection.push({ | ||
endLoc: endLoc, | ||
startLoc: startLoc, | ||
startLoc: _startLoc4, | ||
bodySize: bodySizeU32.value | ||
@@ -635,3 +650,4 @@ }); | ||
while (true) { | ||
var startLoc = getPosition(); | ||
var _startLoc6 = getPosition(); | ||
var instructionAlreadyCreated = false; | ||
@@ -662,2 +678,8 @@ var instructionByte = readByte(); | ||
if (instruction.name === "end") { | ||
var node = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.instruction(instruction.name), endLoc, _startLoc6); | ||
}(); | ||
code.push(node); | ||
break; | ||
@@ -669,2 +691,4 @@ } | ||
if (instruction.name === "loop") { | ||
var _startLoc7 = getPosition(); | ||
var blocktypeByte = readByte(); | ||
@@ -683,6 +707,13 @@ eatBytes(1); | ||
var label = t.withRaw(t.identifier(getUniqueName("loop")), ""); | ||
var loopNode = t.loopInstruction(label, blocktype, instr); | ||
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(); | ||
@@ -716,6 +747,13 @@ | ||
var testInstrs = []; | ||
var ifNode = t.ifInstruction(testIndex, testInstrs, _blocktype, consequentInstr, alternate); | ||
var ifNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.ifInstruction(testIndex, testInstrs, _blocktype, consequentInstr, alternate), endLoc, _startLoc8); | ||
}(); | ||
code.push(ifNode); | ||
instructionAlreadyCreated = true; | ||
} else if (instruction.name === "block") { | ||
var _startLoc9 = getPosition(); | ||
var _blocktypeByte2 = readByte(); | ||
@@ -736,3 +774,7 @@ | ||
var blockNode = t.blockInstruction(_label, _instr2, _blocktype2); | ||
var blockNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.blockInstruction(_label, _instr2, _blocktype2), endLoc, _startLoc9); | ||
}(); | ||
code.push(blockNode); | ||
@@ -745,3 +787,8 @@ instructionAlreadyCreated = true; | ||
dump([index], "index"); | ||
var callNode = t.callInstruction(t.indexLiteral(index)); | ||
var callNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.callInstruction(t.indexLiteral(index)), endLoc, _startLoc6); | ||
}(); | ||
code.push(callNode); | ||
@@ -839,3 +886,3 @@ instructionAlreadyCreated = true; | ||
low = _value2.low; | ||
var node = { | ||
var _node = { | ||
type: "LongNumberLiteral", | ||
@@ -847,3 +894,3 @@ value: { | ||
}; | ||
args.push(node); | ||
args.push(_node); | ||
} | ||
@@ -858,3 +905,3 @@ | ||
_low = _value3.low; | ||
var _node = { | ||
var _node2 = { | ||
type: "LongNumberLiteral", | ||
@@ -866,3 +913,3 @@ value: { | ||
}; | ||
args.push(_node); | ||
args.push(_node2); | ||
} | ||
@@ -898,9 +945,15 @@ | ||
if (typeof instruction.object === "string") { | ||
code.push(t.objectInstruction(instruction.name, instruction.object, args)); | ||
var _node3 = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.objectInstruction(instruction.name, instruction.object, args), endLoc, _startLoc6); | ||
}(); | ||
code.push(_node3); | ||
} else { | ||
var endLoc = getPosition(); | ||
var _node4 = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.instruction(instruction.name, args), endLoc, _startLoc6); | ||
}(); | ||
var _node2 = t.withLoc(t.instruction(instruction.name, args), endLoc, startLoc); | ||
code.push(_node2); | ||
code.push(_node4); | ||
} | ||
@@ -1090,3 +1143,4 @@ } | ||
for (var i = 0; i < numberOfGlobals; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc10 = getPosition(); | ||
var globalType = parseGlobalType(); | ||
@@ -1099,4 +1153,8 @@ /** | ||
parseInstructionBlock(init); | ||
var endLoc = getPosition(); | ||
var node = t.withLoc(t.global(globalType, init), endLoc, startLoc); | ||
var node = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.global(globalType, init), endLoc, _startLoc10); | ||
}(); | ||
globals.push(node); | ||
@@ -1114,3 +1172,4 @@ state.globalsInModule.push(node); | ||
for (var i = 0; i < numberOfElements; i++) { | ||
var startLoc = getPosition(); | ||
var _startLoc11 = getPosition(); | ||
var tableindexu32 = readU32(); | ||
@@ -1144,4 +1203,7 @@ var tableindex = tableindexu32.value; | ||
var endLoc = getPosition(); | ||
var elemNode = t.withLoc(t.elem(t.indexLiteral(tableindex), instr, indexValues), endLoc, startLoc); | ||
var elemNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.elem(t.indexLiteral(tableindex), instr, indexValues), endLoc, _startLoc11); | ||
}(); | ||
elems.push(elemNode); | ||
@@ -1194,4 +1256,6 @@ } | ||
dump([startFuncIndex], "index"); | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.start(t.indexLiteral(startFuncIndex)), endLoc, startLoc); | ||
return function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.start(t.indexLiteral(startFuncIndex)), endLoc, startLoc); | ||
}(); | ||
} // https://webassembly.github.io/spec/binary/modules.html#data-section | ||
@@ -1211,4 +1275,7 @@ | ||
parseInstructionBlock(instrs); | ||
var hasExtraInstrs = instrs.filter(function (i) { | ||
return i.id !== "end"; | ||
}).length !== 1; | ||
if (instrs.length !== 1) { | ||
if (hasExtraInstrs) { | ||
throw new _helperApiError.CompileError("data section offset must be a single instruction"); | ||
@@ -1240,9 +1307,12 @@ } | ||
var startOffset = offset; | ||
var startPosition = getPosition(); | ||
var startLoc = getPosition(); | ||
var u32 = readU32(); | ||
var sectionSizeInBytes = u32.value; | ||
eatBytes(u32.nextIndex); | ||
var sectionSizeInBytesEndLoc = getPosition(); | ||
var sectionSizeInBytesNode = t.withLoc(t.numberLiteralFromRaw(sectionSizeInBytes), sectionSizeInBytesEndLoc, startPosition); | ||
var sectionSizeInBytesNode = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(sectionSizeInBytes), endLoc, startLoc); | ||
}(); | ||
switch (sectionId) { | ||
@@ -1255,3 +1325,3 @@ case _helperWasmBytecode.default.sections.type: | ||
var _startPosition = getPosition(); | ||
var _startLoc12 = getPosition(); | ||
@@ -1262,5 +1332,7 @@ var _u = readU32(); | ||
eatBytes(_u.nextIndex); | ||
var endPosition = getPosition(); | ||
var _metadata = t.sectionMetadata("type", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfTypes), endPosition, _startPosition)); | ||
var _metadata = t.sectionMetadata("type", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfTypes), endLoc, _startLoc12); | ||
}()); | ||
@@ -1282,3 +1354,3 @@ var _nodes = parseTypeSection(numberOfTypes); | ||
var _startPosition2 = getPosition(); | ||
var _startLoc13 = getPosition(); | ||
@@ -1289,8 +1361,8 @@ var _u2 = readU32(); | ||
eatBytes(_u2.nextIndex); | ||
var _endPosition = getPosition(); | ||
dump([numberOfTable], "num tables"); | ||
var _metadata2 = t.sectionMetadata("table", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfTable), _endPosition, _startPosition2)); | ||
var _metadata2 = t.sectionMetadata("table", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfTable), endLoc, _startLoc13); | ||
}()); | ||
@@ -1312,3 +1384,3 @@ var _nodes2 = parseTableSection(numberOfTable); | ||
var _startPosition3 = getPosition(); | ||
var _startLoc14 = getPosition(); | ||
@@ -1318,8 +1390,8 @@ var numberOfImportsu32 = readU32(); | ||
eatBytes(numberOfImportsu32.nextIndex); | ||
var _endPosition2 = getPosition(); | ||
dump([numberOfImports], "number of imports"); | ||
var _metadata3 = t.sectionMetadata("import", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfImports), _endPosition2, _startPosition3)); | ||
var _metadata3 = t.sectionMetadata("import", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfImports), endLoc, _startLoc14); | ||
}()); | ||
@@ -1341,3 +1413,3 @@ var _nodes3 = parseImportSection(numberOfImports); | ||
var _startPosition4 = getPosition(); | ||
var _startLoc15 = getPosition(); | ||
@@ -1348,6 +1420,7 @@ var numberOfFunctionsu32 = readU32(); | ||
var _endPosition3 = getPosition(); | ||
var _metadata4 = t.sectionMetadata("func", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfFunctions), endLoc, _startLoc15); | ||
}()); | ||
var _metadata4 = t.sectionMetadata("func", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfFunctions), _endPosition3, _startPosition4)); | ||
parseFuncSection(numberOfFunctions); | ||
@@ -1368,3 +1441,3 @@ var _nodes4 = []; | ||
var _startPosition5 = getPosition(); | ||
var _startLoc16 = getPosition(); | ||
@@ -1376,6 +1449,7 @@ var _u3 = readU32(); | ||
var _endPosition4 = getPosition(); | ||
var _metadata5 = t.sectionMetadata("export", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfExport), endLoc, _startLoc16); | ||
}()); | ||
var _metadata5 = t.sectionMetadata("export", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfExport), _endPosition4, _startPosition5)); | ||
parseExportSection(numberOfExport); | ||
@@ -1396,3 +1470,3 @@ var _nodes5 = []; | ||
var _startPosition6 = getPosition(); | ||
var _startLoc17 = getPosition(); | ||
@@ -1404,6 +1478,7 @@ var _u4 = readU32(); | ||
var _endPosition5 = getPosition(); | ||
var _metadata6 = t.sectionMetadata("code", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfFuncs), endLoc, _startLoc17); | ||
}()); | ||
var _metadata6 = t.sectionMetadata("code", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfFuncs), _endPosition5, _startPosition6)); | ||
if (opts.ignoreCodeSection === true) { | ||
@@ -1446,3 +1521,3 @@ var remainingBytes = sectionSizeInBytes - _u4.nextIndex; | ||
var _startPosition7 = getPosition(); | ||
var _startLoc18 = getPosition(); | ||
@@ -1453,6 +1528,7 @@ var numberOfElementsu32 = readU32(); | ||
var _endPosition6 = getPosition(); | ||
var _metadata8 = t.sectionMetadata("element", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfElements), endLoc, _startLoc18); | ||
}()); | ||
var _metadata8 = t.sectionMetadata("element", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfElements), _endPosition6, _startPosition7)); | ||
var _nodes8 = parseElemSection(numberOfElements); | ||
@@ -1473,3 +1549,3 @@ | ||
var _startPosition8 = getPosition(); | ||
var _startLoc19 = getPosition(); | ||
@@ -1480,6 +1556,7 @@ var numberOfGlobalsu32 = readU32(); | ||
var _endPosition7 = getPosition(); | ||
var _metadata9 = t.sectionMetadata("global", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(numberOfGlobals), endLoc, _startLoc19); | ||
}()); | ||
var _metadata9 = t.sectionMetadata("global", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(numberOfGlobals), _endPosition7, _startPosition8)); | ||
var _nodes9 = parseGlobalSection(numberOfGlobals); | ||
@@ -1500,3 +1577,3 @@ | ||
var _startPosition9 = getPosition(); | ||
var _startLoc20 = getPosition(); | ||
@@ -1508,6 +1585,7 @@ var _numberOfElementsu = readU32(); | ||
var _endPosition8 = getPosition(); | ||
var _metadata10 = t.sectionMetadata("memory", startOffset, sectionSizeInBytesNode, function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(_numberOfElements), endLoc, _startLoc20); | ||
}()); | ||
var _metadata10 = t.sectionMetadata("memory", startOffset, sectionSizeInBytesNode, t.withLoc(t.numberLiteralFromRaw(_numberOfElements), _endPosition8, _startPosition9)); | ||
var _nodes10 = parseMemorySection(_numberOfElements); | ||
@@ -1530,3 +1608,3 @@ | ||
var _startPosition10 = getPosition(); | ||
var _startLoc21 = getPosition(); | ||
@@ -1538,6 +1616,7 @@ var _numberOfElementsu2 = readU32(); | ||
var _endPosition9 = getPosition(); | ||
_metadata11.vectorOfSize = function () { | ||
var endLoc = getPosition(); | ||
return t.withLoc(t.numberLiteralFromRaw(_numberOfElements2), endLoc, _startLoc21); | ||
}(); | ||
_metadata11.vectorOfSize = t.withLoc(t.numberLiteralFromRaw(_numberOfElements2), _endPosition9, _startPosition10); | ||
if (opts.ignoreDataSection === true) { | ||
@@ -1670,6 +1749,6 @@ var _remainingBytes = sectionSizeInBytes - _numberOfElementsu2.nextIndex; | ||
if (opts.ignoreCodeSection === false) { | ||
var startLoc = decodedElementInCodeSection.startLoc, | ||
var _startLoc22 = decodedElementInCodeSection.startLoc, | ||
endLoc = decodedElementInCodeSection.endLoc, | ||
bodySize = decodedElementInCodeSection.bodySize; | ||
funcNode = t.withLoc(funcNode, endLoc, startLoc); | ||
funcNode = t.withLoc(funcNode, endLoc, _startLoc22); | ||
funcNode.metadata = { | ||
@@ -1676,0 +1755,0 @@ bodySize: bodySize |
@@ -14,2 +14,6 @@ "use strict"; | ||
/** | ||
* TODO(sven): I added initial props, but we should rather fix | ||
* https://github.com/xtuc/webassemblyjs/issues/405 | ||
*/ | ||
var defaultDecoderOpts = { | ||
@@ -61,3 +65,5 @@ dump: false, | ||
if (functionName) { | ||
nodeName.value = functionName.name; // $FlowIgnore | ||
var oldValue = nodeName.value; | ||
nodeName.value = functionName.name; | ||
nodeName.numeric = oldValue; // $FlowIgnore | ||
@@ -139,3 +145,5 @@ delete nodeName.raw; | ||
if (functionName) { | ||
node.index = t.identifier(functionName.name); // $FlowIgnore | ||
var oldValue = node.index; | ||
node.index = t.identifier(functionName.name); | ||
node.numeric = oldValue; // $FlowIgnore | ||
@@ -142,0 +150,0 @@ delete node.raw; |
{ | ||
"name": "@webassemblyjs/wasm-parser", | ||
"version": "1.7.11", | ||
"version": "1.8.0", | ||
"keywords": [ | ||
@@ -20,8 +20,8 @@ "webassembly", | ||
"dependencies": { | ||
"@webassemblyjs/ast": "1.7.11", | ||
"@webassemblyjs/helper-api-error": "1.7.11", | ||
"@webassemblyjs/helper-wasm-bytecode": "1.7.11", | ||
"@webassemblyjs/ieee754": "1.7.11", | ||
"@webassemblyjs/leb128": "1.7.11", | ||
"@webassemblyjs/utf8": "1.7.11" | ||
"@webassemblyjs/ast": "1.8.0", | ||
"@webassemblyjs/helper-api-error": "1.8.0", | ||
"@webassemblyjs/helper-wasm-bytecode": "1.8.0", | ||
"@webassemblyjs/ieee754": "1.8.0", | ||
"@webassemblyjs/leb128": "1.8.0", | ||
"@webassemblyjs/utf8": "1.8.0" | ||
}, | ||
@@ -36,10 +36,11 @@ "repository": { | ||
"devDependencies": { | ||
"@webassemblyjs/helper-buffer": "1.7.11", | ||
"@webassemblyjs/helper-test-framework": "1.7.11", | ||
"@webassemblyjs/helper-buffer": "1.8.0", | ||
"@webassemblyjs/helper-test-framework": "1.8.0", | ||
"@webassemblyjs/helper-wasm-bytecode": "1.7.7", | ||
"@webassemblyjs/wasm-gen": "1.7.11", | ||
"@webassemblyjs/wast-parser": "1.7.11", | ||
"@webassemblyjs/wasm-gen": "1.8.0", | ||
"@webassemblyjs/wast-parser": "1.8.0", | ||
"mamacro": "^0.0.3", | ||
"wabt": "1.0.0-nightly.20180421" | ||
}, | ||
"gitHead": "4291990bfc4648bc6676091a955d12dc3c7e5909" | ||
"gitHead": "8b2d1afa793ea81f20ec63416134c201e39694eb" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139939
3155
7
+ Added@webassemblyjs/ast@1.8.0(transitive)
+ Added@webassemblyjs/floating-point-hex-parser@1.8.0(transitive)
+ Added@webassemblyjs/helper-api-error@1.8.0(transitive)
+ Added@webassemblyjs/helper-code-frame@1.8.0(transitive)
+ Added@webassemblyjs/helper-fsm@1.8.0(transitive)
+ Added@webassemblyjs/helper-module-context@1.8.0(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.8.0(transitive)
+ Added@webassemblyjs/ieee754@1.8.0(transitive)
+ Added@webassemblyjs/leb128@1.8.0(transitive)
+ Added@webassemblyjs/utf8@1.8.0(transitive)
+ Added@webassemblyjs/wast-parser@1.8.0(transitive)
+ Added@webassemblyjs/wast-printer@1.8.0(transitive)
- Removed@webassemblyjs/ast@1.7.11(transitive)
- Removed@webassemblyjs/floating-point-hex-parser@1.7.11(transitive)
- Removed@webassemblyjs/helper-api-error@1.7.11(transitive)
- Removed@webassemblyjs/helper-code-frame@1.7.11(transitive)
- Removed@webassemblyjs/helper-fsm@1.7.11(transitive)
- Removed@webassemblyjs/helper-module-context@1.7.11(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.7.11(transitive)
- Removed@webassemblyjs/ieee754@1.7.11(transitive)
- Removed@webassemblyjs/leb128@1.7.11(transitive)
- Removed@webassemblyjs/utf8@1.7.11(transitive)
- Removed@webassemblyjs/wast-parser@1.7.11(transitive)
- Removed@webassemblyjs/wast-printer@1.7.11(transitive)
Updated@webassemblyjs/ast@1.8.0
Updated@webassemblyjs/ieee754@1.8.0
Updated@webassemblyjs/leb128@1.8.0
Updated@webassemblyjs/utf8@1.8.0