Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
n.args.forEach(function (arg) {
var encoder = encodeU32; // find correct encoder
if (n.object === "i32") {
encoder = encodeI32;
}
if (n.object === "i64") {
encoder = encodeI64;
}
if (n.object === "f32") {
encoder = ieee754.encodeF32;
}
if (n.object === "f64") {
encoder = ieee754.encodeF64;
}
if (arg.type === "NumberLiteral" || arg.type === "FloatLiteral" || arg.type === "LongNumberLiteral") {
// $FlowIgnore
out.push.apply(out, _toConsumableArray(encoder(arg.value)));
} else {
throw new Error("Unsupported instruction argument encoding " + JSON.stringify(arg.type));
}
});
}
n.args.forEach(arg => {
let encoder = encodeU32;
// find correct encoder
if (n.object === "i32") {
encoder = encodeI32;
}
if (n.object === "i64") {
encoder = encodeI64;
}
if (n.object === "f32") {
encoder = ieee754.encodeF32;
}
if (n.object === "f64") {
encoder = ieee754.encodeF64;
}
if (
arg.type === "NumberLiteral" ||
arg.type === "FloatLiteral" ||
arg.type === "LongNumberLiteral"
) {
// $FlowIgnore
out.push(...encoder(arg.value));
} else {
throw new Error(
"Unsupported instruction argument encoding " +
n.args.forEach(function (arg) {
var encoder = encodeU32; // find correct encoder
if (n.object === "i32") {
encoder = encodeI32;
}
if (n.object === "i64") {
encoder = encodeI64;
}
if (n.object === "f32") {
encoder = ieee754.encodeF32;
}
if (n.object === "f64") {
encoder = ieee754.encodeF64;
}
if (arg.type === "NumberLiteral" || arg.type === "FloatLiteral" || arg.type === "LongNumberLiteral") {
// $FlowIgnore
out.push.apply(out, _toConsumableArray(encoder(arg.value)));
} else {
throw new Error("Unsupported instruction argument encoding " + JSON.stringify(arg.type));
}
});
}
var encoder = encodeU32; // find correct encoder
if (n.object === "i32") {
encoder = encodeI32;
}
if (n.object === "i64") {
encoder = encodeI64;
}
if (n.object === "f32") {
encoder = ieee754.encodeF32;
}
if (n.object === "f64") {
encoder = ieee754.encodeF64;
}
if (arg.type === "NumberLiteral" || arg.type === "FloatLiteral" || arg.type === "LongNumberLiteral") {
// $FlowIgnore
out.push.apply(out, _toConsumableArray(encoder(arg.value)));
} else {
throw new Error("Unsupported instruction argument encoding " + JSON.stringify(arg.type));
}
});
}
var encoder = encodeU32; // find correct encoder
if (n.object === "i32") {
encoder = encodeI32;
}
if (n.object === "i64") {
encoder = encodeI64;
}
if (n.object === "f32") {
encoder = ieee754.encodeF32;
}
if (n.object === "f64") {
encoder = ieee754.encodeF64;
}
if (arg.type === "NumberLiteral" || arg.type === "FloatLiteral" || arg.type === "LongNumberLiteral") {
// $FlowIgnore
out.push.apply(out, _toConsumableArray(encoder(arg.value)));
} else {
throw new Error("Unsupported instruction argument encoding " + JSON.stringify(arg.type));
}
});
}
// find correct encoder
if (n.object === "i32") {
encoder = encodeI32;
}
if (n.object === "i64") {
encoder = encodeI64;
}
if (n.object === "f32") {
encoder = ieee754.encodeF32;
}
if (n.object === "f64") {
encoder = ieee754.encodeF64;
}
if (
arg.type === "NumberLiteral" ||
arg.type === "FloatLiteral" ||
arg.type === "LongNumberLiteral"
) {
// $FlowIgnore
out.push(...encoder(arg.value));
} else {
throw new Error(
"Unsupported instruction argument encoding " +
JSON.stringify(arg.type)
);
}
});
function readF32() {
var bytes = readBytes(ieee754.NUMBER_OF_BYTE_F32);
var value = ieee754.decodeF32(bytes);
if (Math.sign(value) * value === Infinity) {
return {
value: Math.sign(value),
inf: true,
nextIndex: ieee754.NUMBER_OF_BYTE_F32
};
}
if (isNaN(value)) {
var sign = bytes[bytes.length - 1] >> 7 ? -1 : 1;
var mantissa = 0;
for (var i = 0; i < bytes.length - 2; ++i) {
mantissa += bytes[i] * Math.pow(256, i);
function readF32(): DecodedF32 {
const bytes = readBytes(ieee754.NUMBER_OF_BYTE_F32);
const value = ieee754.decodeF32(bytes);
if (Math.sign(value) * value === Infinity) {
return {
value: Math.sign(value),
inf: true,
nextIndex: ieee754.NUMBER_OF_BYTE_F32
};
}
if (isNaN(value)) {
const sign = bytes[bytes.length - 1] >> 7 ? -1 : 1;
let mantissa = 0;
for (let i = 0; i < bytes.length - 2; ++i) {
mantissa += bytes[i] * 256 ** i;
}
let mantissa = 0;
for (let i = 0; i < bytes.length - 2; ++i) {
mantissa += bytes[i] * 256 ** i;
}
mantissa += (bytes[bytes.length - 2] % 128) * 256 ** (bytes.length - 2);
return {
value: sign * mantissa,
nan: true,
nextIndex: ieee754.NUMBER_OF_BYTE_F32
};
}
return {
value,
nextIndex: ieee754.NUMBER_OF_BYTE_F32
};
}
function readF32() {
var bytes = readBytes(ieee754.NUMBER_OF_BYTE_F32);
var value = ieee754.decodeF32(bytes);
if (Math.sign(value) * value === Infinity) {
return {
value: Math.sign(value),
inf: true,
nextIndex: ieee754.NUMBER_OF_BYTE_F32
};
}
if (isNaN(value)) {
var sign = bytes[bytes.length - 1] >> 7 ? -1 : 1;
var mantissa = 0;
for (var i = 0; i < bytes.length - 2; ++i) {
mantissa += bytes[i] * Math.pow(256, i);
}
mantissa += bytes[bytes.length - 2] % 128 * Math.pow(256, bytes.length - 2);
return {
value: sign * mantissa,
nan: true,
nextIndex: ieee754.NUMBER_OF_BYTE_F32