webassemblyjs
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -207,3 +207,5 @@ "use strict"; | ||
if (node.name.type === "Identifier") { | ||
internals.instantiatedFuncs[node.name.value] = addr; | ||
internals.instantiatedFuncs[node.name.value] = { | ||
addr: addr | ||
}; | ||
} | ||
@@ -238,3 +240,5 @@ } | ||
if (node.name.type === "Identifier") { | ||
internals.instantiatedTables[node.name.value] = addr; | ||
internals.instantiatedTables[node.name.value] = { | ||
addr: addr | ||
}; | ||
} | ||
@@ -310,3 +314,5 @@ } | ||
// $FlowIgnore | ||
internals.instantiatedMemories[node.id.value] = addr; | ||
internals.instantiatedMemories[node.id.value] = { | ||
addr: addr | ||
}; | ||
} | ||
@@ -364,2 +370,19 @@ } | ||
function createModuleExport(node, instantiatedItemArray, validate) { | ||
if (node.descr.id.type === "Identifier") { | ||
var instantiatedItem = instantiatedItemArray[node.descr.id.value]; | ||
validate(instantiatedItem); | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push({ | ||
name: node.name, | ||
value: { | ||
type: node.descr.type, | ||
addr: instantiatedItem.addr | ||
} | ||
}); | ||
} else { | ||
throw new CompileError("Module exports must be referenced via an Identifier"); | ||
} | ||
} | ||
(0, _ast.traverse)(n, { | ||
@@ -379,141 +402,47 @@ ModuleExport: function (_ModuleExport) { | ||
if (node.descr.type === "Func") { | ||
// Referenced by its index in the module.funcaddrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
var index = node.descr.id.value; | ||
var funcinstaddr = moduleInstance.funcaddrs[index]; | ||
if (funcinstaddr === undefined) { | ||
throw new CompileError("Unknown function"); | ||
switch (node.descr.type) { | ||
case "Func": | ||
{ | ||
createModuleExport(node, internals.instantiatedFuncs, function (instantiatedFunc) { | ||
if (typeof instantiatedFunc === "undefined") { | ||
throw new Error("unknown function"); | ||
} | ||
}); | ||
break; | ||
} | ||
var externalVal = { | ||
type: node.descr.type, | ||
addr: funcinstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, externalVal)); | ||
} // Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
var instantiatedFuncAddr = internals.instantiatedFuncs[node.descr.id.value]; | ||
if (typeof instantiatedFuncAddr === "undefined") { | ||
throw new Error("Cannot create exportinst: function " + node.descr.id.value + " was not declared or instantiated"); | ||
case "Global": | ||
{ | ||
createModuleExport(node, internals.instantiatedGlobals, function (instantiatedGlobal) { | ||
if (typeof instantiatedGlobal === "undefined") { | ||
throw new Error("unknown global"); | ||
} else if (instantiatedGlobal.type.mutability === "var") { | ||
throw new CompileError("Mutable globals cannot be exported"); | ||
} else if (instantiatedGlobal.type.valtype === "i64") { | ||
throw new LinkError("Export of globals of type i64 is not allowed"); | ||
} | ||
}); | ||
break; | ||
} | ||
var _externalVal = { | ||
type: node.descr.type, | ||
addr: instantiatedFuncAddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal)); | ||
} | ||
} | ||
if (node.descr.type === "Global") { | ||
// Referenced by its index in the module.globaladdrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
var _index = node.descr.id.value; | ||
var globalinstaddr = moduleInstance.globaladdrs[_index]; | ||
if (globalinstaddr === undefined) { | ||
throw new CompileError("Unknown global"); | ||
case "Table": | ||
{ | ||
createModuleExport(node, internals.instantiatedTables, function (instantiatedTable) { | ||
if (typeof instantiatedTable === "undefined") { | ||
throw new Error("unknown table"); | ||
} | ||
}); | ||
break; | ||
} | ||
var globalinst = allocator.get(globalinstaddr); | ||
if (globalinst.mutability === "var") { | ||
throw new CompileError("Mutable globals cannot be exported"); | ||
case "Memory": | ||
{ | ||
createModuleExport(node, internals.instantiatedMemories, function (instantiatedMemory) { | ||
if (typeof instantiatedMemory === "undefined") { | ||
throw new Error("unknown memory"); | ||
} | ||
}); | ||
break; | ||
} | ||
var _externalVal2 = { | ||
type: node.descr.type, | ||
addr: globalinstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal2)); | ||
} // Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
var instantiatedGlobal = internals.instantiatedGlobals[node.descr.id.value]; | ||
if (instantiatedGlobal.type.mutability === "var") { | ||
throw new CompileError("Mutable globals cannot be exported"); | ||
} | ||
if (instantiatedGlobal.type.valtype === "i64") { | ||
throw new LinkError("Export of globals of type i64 is not allowed"); | ||
} | ||
var _externalVal3 = { | ||
type: node.descr.type, | ||
addr: instantiatedGlobal.addr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal3)); | ||
} | ||
} | ||
if (node.descr.type === "Table") { | ||
// Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
var instantiatedTable = internals.instantiatedTables[node.descr.id.value]; | ||
var _externalVal4 = { | ||
type: node.descr.type, | ||
addr: instantiatedTable | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal4)); | ||
} // Referenced by its index in the module.tableaddrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
var _index2 = node.descr.id.value; | ||
var tableinstaddr = moduleInstance.tableaddrs[_index2]; | ||
var _externalVal5 = { | ||
type: node.descr.type, | ||
addr: tableinstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
if (tableinstaddr === undefined) { | ||
throw new CompileError("Unknown table"); | ||
} | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal5)); | ||
} | ||
} | ||
if (node.descr.type === "Memory") { | ||
// Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
var instantiatedMemory = internals.instantiatedMemories[node.descr.id.value]; | ||
var _externalVal6 = { | ||
type: node.descr.type, | ||
addr: instantiatedMemory | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal6)); | ||
} // Referenced by its index in the module.memaddrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
var _index3 = node.descr.id.value; | ||
var meminstaddr = moduleInstance.memaddrs[_index3]; | ||
var _externalVal7 = { | ||
type: node.descr.type, | ||
addr: meminstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
if (meminstaddr === undefined) { | ||
throw new CompileError("Unknown memory"); | ||
} | ||
moduleInstance.exports.push(createModuleExportIntance(node.name, _externalVal7)); | ||
} | ||
} | ||
}) | ||
@@ -550,9 +479,2 @@ }); | ||
return moduleInstance; | ||
} | ||
function createModuleExportIntance(name, value) { | ||
return { | ||
name: name, | ||
value: value | ||
}; | ||
} |
{ | ||
"name": "webassemblyjs", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"keywords": [ | ||
@@ -21,8 +21,10 @@ "webassembly", | ||
"dependencies": { | ||
"@webassemblyjs/ast": "1.2.2", | ||
"@webassemblyjs/wasm-parser": "1.2.2", | ||
"@webassemblyjs/wast-parser": "1.2.2", | ||
"long": "^3.2.0", | ||
"webassembly-floating-point-hex-parser": "0.1.2" | ||
"@webassemblyjs/ast": "1.2.3", | ||
"@webassemblyjs/wasm-parser": "1.2.3", | ||
"@webassemblyjs/wast-parser": "1.2.3", | ||
"long": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@webassemblyjs/floating-point-hex-parser": "1.2.3" | ||
}, | ||
"repository": { | ||
@@ -29,0 +31,0 @@ "type": "git", |
@@ -179,3 +179,3 @@ // @flow | ||
if (node.name.type === "Identifier") { | ||
internals.instantiatedFuncs[node.name.value] = addr; | ||
internals.instantiatedFuncs[node.name.value] = { addr }; | ||
} | ||
@@ -198,3 +198,3 @@ } | ||
if (node.name.type === "Identifier") { | ||
internals.instantiatedTables[node.name.value] = addr; | ||
internals.instantiatedTables[node.name.value] = { addr }; | ||
} | ||
@@ -248,3 +248,3 @@ } | ||
// $FlowIgnore | ||
internals.instantiatedMemories[node.id.value] = addr; | ||
internals.instantiatedMemories[node.id.value] = { addr }; | ||
} | ||
@@ -295,189 +295,86 @@ } | ||
traverse(n, { | ||
ModuleExport({ node }: NodePath<ModuleExport>) { | ||
if (node.descr.type === "Func") { | ||
// Referenced by its index in the module.funcaddrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
const index = node.descr.id.value; | ||
function createModuleExport( | ||
node: ModuleExport, | ||
instantiatedItemArray, | ||
validate: Object => void | ||
) { | ||
if (node.descr.id.type === "Identifier") { | ||
const instantiatedItem = instantiatedItemArray[node.descr.id.value]; | ||
const funcinstaddr = moduleInstance.funcaddrs[index]; | ||
validate(instantiatedItem); | ||
if (funcinstaddr === undefined) { | ||
throw new CompileError("Unknown function"); | ||
} | ||
assertNotAlreadyExported(node.name); | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: funcinstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
); | ||
moduleInstance.exports.push({ | ||
name: node.name, | ||
value: { | ||
type: node.descr.type, | ||
addr: instantiatedItem.addr | ||
} | ||
}); | ||
} else { | ||
throw new CompileError( | ||
"Module exports must be referenced via an Identifier" | ||
); | ||
} | ||
} | ||
// Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
const instantiatedFuncAddr = | ||
internals.instantiatedFuncs[node.descr.id.value]; | ||
if (typeof instantiatedFuncAddr === "undefined") { | ||
throw new Error( | ||
"Cannot create exportinst: function " + | ||
node.descr.id.value + | ||
" was not declared or instantiated" | ||
); | ||
} | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: instantiatedFuncAddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
traverse(n, { | ||
ModuleExport({ node }: NodePath<ModuleExport>) { | ||
switch (node.descr.type) { | ||
case "Func": { | ||
createModuleExport( | ||
node, | ||
internals.instantiatedFuncs, | ||
instantiatedFunc => { | ||
if (typeof instantiatedFunc === "undefined") { | ||
throw new Error("unknown function"); | ||
} | ||
} | ||
); | ||
break; | ||
} | ||
} | ||
if (node.descr.type === "Global") { | ||
// Referenced by its index in the module.globaladdrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
const index = node.descr.id.value; | ||
const globalinstaddr = moduleInstance.globaladdrs[index]; | ||
if (globalinstaddr === undefined) { | ||
throw new CompileError("Unknown global"); | ||
} | ||
const globalinst = allocator.get(globalinstaddr); | ||
if (globalinst.mutability === "var") { | ||
throw new CompileError("Mutable globals cannot be exported"); | ||
} | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: globalinstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
case "Global": { | ||
createModuleExport( | ||
node, | ||
internals.instantiatedGlobals, | ||
instantiatedGlobal => { | ||
if (typeof instantiatedGlobal === "undefined") { | ||
throw new Error("unknown global"); | ||
} else if (instantiatedGlobal.type.mutability === "var") { | ||
throw new CompileError("Mutable globals cannot be exported"); | ||
} else if (instantiatedGlobal.type.valtype === "i64") { | ||
throw new LinkError( | ||
"Export of globals of type i64 is not allowed" | ||
); | ||
} | ||
} | ||
); | ||
break; | ||
} | ||
// Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
const instantiatedGlobal = | ||
internals.instantiatedGlobals[node.descr.id.value]; | ||
if (instantiatedGlobal.type.mutability === "var") { | ||
throw new CompileError("Mutable globals cannot be exported"); | ||
} | ||
if (instantiatedGlobal.type.valtype === "i64") { | ||
throw new LinkError("Export of globals of type i64 is not allowed"); | ||
} | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: instantiatedGlobal.addr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
case "Table": { | ||
createModuleExport( | ||
node, | ||
internals.instantiatedTables, | ||
instantiatedTable => { | ||
if (typeof instantiatedTable === "undefined") { | ||
throw new Error("unknown table"); | ||
} | ||
} | ||
); | ||
break; | ||
} | ||
} | ||
if (node.descr.type === "Table") { | ||
// Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
const instantiatedTable = | ||
internals.instantiatedTables[node.descr.id.value]; | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: instantiatedTable | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
case "Memory": { | ||
createModuleExport( | ||
node, | ||
internals.instantiatedMemories, | ||
instantiatedMemory => { | ||
if (typeof instantiatedMemory === "undefined") { | ||
throw new Error("unknown memory"); | ||
} | ||
} | ||
); | ||
break; | ||
} | ||
// Referenced by its index in the module.tableaddrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
const index = node.descr.id.value; | ||
const tableinstaddr = moduleInstance.tableaddrs[index]; | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: tableinstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
if (tableinstaddr === undefined) { | ||
throw new CompileError("Unknown table"); | ||
} | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
); | ||
} | ||
} | ||
if (node.descr.type === "Memory") { | ||
// Referenced by its identifier | ||
if (node.descr.id.type === "Identifier") { | ||
const instantiatedMemory = | ||
internals.instantiatedMemories[node.descr.id.value]; | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: instantiatedMemory | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
); | ||
} | ||
// Referenced by its index in the module.memaddrs | ||
if (node.descr.id.type === "NumberLiteral") { | ||
const index = node.descr.id.value; | ||
const meminstaddr = moduleInstance.memaddrs[index]; | ||
const externalVal = { | ||
type: node.descr.type, | ||
addr: meminstaddr | ||
}; | ||
assertNotAlreadyExported(node.name); | ||
if (meminstaddr === undefined) { | ||
throw new CompileError("Unknown memory"); | ||
} | ||
moduleInstance.exports.push( | ||
createModuleExportIntance(node.name, externalVal) | ||
); | ||
} | ||
} | ||
} | ||
@@ -529,11 +426,1 @@ }); | ||
} | ||
function createModuleExportIntance( | ||
name: string, | ||
value: ExternalVal | ||
): ExportInstance { | ||
return { | ||
name, | ||
value | ||
}; | ||
} |
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
4
223990
1
6533
+ Added@webassemblyjs/ast@1.2.3(transitive)
+ Added@webassemblyjs/floating-point-hex-parser@1.2.3(transitive)
+ Added@webassemblyjs/helper-fsm@1.2.3(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.2.3(transitive)
+ Added@webassemblyjs/leb128@1.2.3(transitive)
+ Added@webassemblyjs/wasm-parser@1.2.3(transitive)
+ Added@webassemblyjs/wast-parser@1.2.3(transitive)
- Removed@webassemblyjs/ast@1.2.2(transitive)
- Removed@webassemblyjs/helper-leb128@1.2.2(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.2.2(transitive)
- Removed@webassemblyjs/wasm-parser@1.2.2(transitive)
- Removed@webassemblyjs/wast-parser@1.2.2(transitive)
- Removedwebassembly-floating-point-hex-parser@0.1.2(transitive)
Updated@webassemblyjs/ast@1.2.3