Socket
Socket
Sign inDemoInstall

@webassemblyjs/wasm-gen

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webassemblyjs/wasm-gen - npm Package Compare versions

Comparing version 1.1.2-y.6 to 1.1.2-y.7

test/index.js

79

lib/encoder/index.js

@@ -21,2 +21,5 @@ "use strict";

exports.encodeInstr = encodeInstr;
exports.encodeGlobal = encodeGlobal;
exports.encodeFuncBody = encodeFuncBody;
exports.encodeIndexInFuncSection = encodeIndexInFuncSection;

@@ -225,16 +228,74 @@ var _helperWasmBytecode = _interopRequireDefault(require("@webassemblyjs/helper-wasm-bytecode"));

return out;
} // FIXME(sven): find a better way for doing that
}
function encodeInstr(n) {
switch (n.id) {
case "get_global":
return [0x23].concat(_toConsumableArray(encodeU32(n.args[0].value)));
var out = [];
var instructionName = n.id;
case "set_global":
return [0x24].concat(_toConsumableArray(encodeU32(n.args[0].value)));
if (typeof n.object === "string") {
instructionName = "".concat(n.object, ".").concat(n.id);
}
default:
throw new Error("encodeInstr: unknown instruction " + JSON.stringify(n.id));
var byteString = _helperWasmBytecode.default.symbolsByName[instructionName];
if (typeof byteString === "undefined") {
throw new Error("encodeInstr: unknown instruction " + JSON.stringify(instructionName));
}
var byte = parseInt(byteString, 10);
out.push(byte);
if (n.args) {
n.args.forEach(function (arg) {
if (arg.type === "NumberLiteral") {
out.push.apply(out, _toConsumableArray(encodeU32(arg.value)));
} else {
throw new Error("Unsupported instruction argument encoding " + JSON.stringify(arg.type));
}
});
}
return out;
}
function encodeExpr(instrs) {
var out = [];
instrs.forEach(function (instr) {
// $FlowIgnore
var n = encodeInstr(instr);
out.push.apply(out, _toConsumableArray(n));
});
out.push(0x0b); // end
return out;
}
function encodeGlobal(n) {
var out = [];
var _n$globalType = n.globalType,
valtype = _n$globalType.valtype,
mutability = _n$globalType.mutability;
out.push(encodeValtype(valtype));
out.push(encodeMutability(mutability));
out.push.apply(out, _toConsumableArray(encodeExpr(n.init)));
return out;
}
function encodeFuncBody(n) {
var out = [];
out.push(-1); // temporary function body size
// FIXME(sven): get the func locals?
var localBytes = encodeVec([]);
out.push.apply(out, _toConsumableArray(localBytes));
var funcBodyBytes = encodeExpr(n.body);
out[0] = funcBodyBytes.length + localBytes.length;
out.push.apply(out, _toConsumableArray(funcBodyBytes));
return out;
}
function encodeIndexInFuncSection(n) {
assertNotIdentifierNode(n.index); // $FlowIgnore
return encodeU32(n.index.value);
}

@@ -35,2 +35,3 @@ "use strict";

case "Instr":
// $FlowIgnore
return encoder.encodeInstr(n);

@@ -42,2 +43,12 @@

case "Global":
// $FlowIgnore
return encoder.encodeGlobal(n);
case "Func":
return encoder.encodeFuncBody(n);
case "IndexInFuncSection":
return encoder.encodeIndexInFuncSection(n);
default:

@@ -44,0 +55,0 @@ throw new Error("Unsupported encoding for node of type: " + JSON.stringify(n.type));

8

package.json
{
"name": "@webassemblyjs/wasm-gen",
"version": "1.1.2-y.6",
"version": "1.1.2-y.7",
"description": "",

@@ -19,6 +19,6 @@ "main": "lib/index.js",

"dependencies": {
"@webassemblyjs/ast": "1.1.2-y.6",
"@webassemblyjs/helper-leb128": "1.1.2-y.6",
"@webassemblyjs/helper-wasm-bytecode": "1.1.2-y.6"
"@webassemblyjs/ast": "1.1.2-y.7",
"@webassemblyjs/helper-leb128": "1.1.2-y.7",
"@webassemblyjs/helper-wasm-bytecode": "1.1.2-y.7"
}
}

@@ -223,14 +223,91 @@ // @flow

// FIXME(sven): find a better way for doing that
export function encodeInstr(n: Instruction) {
switch (n.id) {
case "get_global":
return [0x23, ...encodeU32(n.args[0].value)];
case "set_global":
return [0x24, ...encodeU32(n.args[0].value)];
default:
throw new Error(
"encodeInstr: unknown instruction " + JSON.stringify(n.id)
);
export function encodeInstr(
n: GenericInstruction | ObjectInstruction
): Array<Byte> {
const out = [];
let instructionName = n.id;
if (typeof n.object === "string") {
instructionName = `${n.object}.${n.id}`;
}
const byteString = constants.symbolsByName[instructionName];
if (typeof byteString === "undefined") {
throw new Error(
"encodeInstr: unknown instruction " + JSON.stringify(instructionName)
);
}
const byte = parseInt(byteString, 10);
out.push(byte);
if (n.args) {
n.args.forEach(arg => {
if (arg.type === "NumberLiteral") {
out.push(...encodeU32(arg.value));
} else {
throw new Error(
"Unsupported instruction argument encoding " +
JSON.stringify(arg.type)
);
}
});
}
return out;
}
function encodeExpr(instrs: Array<Instruction>): Array<Byte> {
const out = [];
instrs.forEach(instr => {
// $FlowIgnore
const n = encodeInstr(instr);
out.push(...n);
});
out.push(0x0b); // end
return out;
}
export function encodeGlobal(n: Global): Array<Byte> {
const out = [];
const { valtype, mutability } = n.globalType;
out.push(encodeValtype(valtype));
out.push(encodeMutability(mutability));
out.push(...encodeExpr(n.init));
return out;
}
export function encodeFuncBody(n: Func): Array<Byte> {
const out = [];
out.push(-1); // temporary function body size
// FIXME(sven): get the func locals?
const localBytes = encodeVec([]);
out.push(...localBytes);
const funcBodyBytes = encodeExpr(n.body);
out[0] = funcBodyBytes.length + localBytes.length;
out.push(...funcBodyBytes);
return out;
}
export function encodeIndexInFuncSection(n: IndexInFuncSection): Array<Byte> {
assertNotIdentifierNode(n.index);
// $FlowIgnore
return encodeU32(n.index.value);
}

@@ -27,2 +27,3 @@ // @flow

case "Instr":
// $FlowIgnore
return encoder.encodeInstr(n);

@@ -34,2 +35,12 @@

case "Global":
// $FlowIgnore
return encoder.encodeGlobal(n);
case "Func":
return encoder.encodeFuncBody(n);
case "IndexInFuncSection":
return encoder.encodeIndexInFuncSection(n);
default:

@@ -36,0 +47,0 @@ throw new Error(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc