Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Func({ node }) {
const funcHasThisIntr =
node.body.find(n => n === newNode) !== undefined;
// Update func's body size if needed
if (funcHasThisIntr === true) {
// These are the old functions locations informations
assertHasLoc(node);
const oldNodeSize = encodeNode(oldNode).length;
const bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;
if (bodySizeDeltaBytes !== 0) {
const newValue = node.metadata.bodySize + bodySizeDeltaBytes;
const newByteArray = encodeU32(newValue);
// function body size byte
// FIXME(sven): only handles one byte u32
const start = node.loc.start.column;
const end = start + 1;
uint8Buffer = overrideBytesInBuffer(
uint8Buffer,
start,
end,
newByteArray
Func({ node }) {
const funcHasThisIntr =
node.body.find(n => n === newNode) !== undefined;
// Update func's body size if needed
if (funcHasThisIntr === true) {
// These are the old functions locations informations
assertHasLoc(node);
const oldNodeSize = encodeNode(oldNode).length;
const bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;
if (bodySizeDeltaBytes !== 0) {
const newValue = node.metadata.bodySize + bodySizeDeltaBytes;
const newByteArray = encodeU32(newValue);
debug("resize func body newValue=%d", newValue);
// function body size byte
// FIXME(sven): only handles one byte u32
const start = node.loc.start.column;
const end = start + 1;
uint8Buffer = overrideBytesInBuffer(
uint8Buffer,
start,
Func: function Func(_ref3) {
var node = _ref3.node;
var funcHasThisIntr = node.body.find(function (n) {
return n === newNode;
}) !== undefined; // Update func's body size if needed
if (funcHasThisIntr === true) {
// These are the old functions locations informations
assertHasLoc(node);
var oldNodeSize = encodeNode(oldNode).length;
var bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;
if (bodySizeDeltaBytes !== 0) {
var newValue = node.metadata.bodySize + bodySizeDeltaBytes;
var newByteArray = encodeU32(newValue); // function body size byte
// FIXME(sven): only handles one byte u32
var start = node.loc.start.column;
var end = start + 1;
uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newByteArray);
}
}
}
});
* check that the expressions were ended
*/
if (isFunc(node)) {
// $FlowIgnore
CHECK_END(node.body);
}
if (isGlobal(node)) {
// $FlowIgnore
CHECK_END(node.init);
}
/**
* Add nodes
*/
const newByteArray = encodeNode(node);
// The size of the section doesn't include the storage of the size itself
// we need to manually add it here
const start = getEndOfSection(sectionMetadata);
const end = start;
/**
* Update section
*/
const deltaBytes = newByteArray.length;
uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newByteArray);
node.loc = {
start: { line: -1, column: start },
const sectionName = getSectionForNode(node);
let sectionMetadata = getSectionMetadata(ast, sectionName);
// Section doesn't exists, we create an empty one
if (typeof sectionMetadata === "undefined") {
const res = createEmptySection(ast, uint8Buffer, sectionName);
uint8Buffer = res.uint8Buffer;
sectionMetadata = res.sectionMetadata;
}
/**
* Add nodes
*/
const newByteArray = encodeNode(node);
// The size of the section doesn't include the storage of the size itself
// we need to manually add it here
const start = getEndOfSection(sectionMetadata);
const end = start;
/**
* Update section
*/
const deltaBytes = newByteArray.length;
debug(
"add node=%s section=%s after=%d deltaBytes=%s deltaElements=%s",
node.type,
sectionName,
Func: function Func(_ref3) {
var node = _ref3.node;
var funcHasThisIntr = node.body.find(function (n) {
return n === newNode;
}) !== undefined; // Update func's body size if needed
if (funcHasThisIntr === true) {
// These are the old functions locations informations
assertHasLoc(node);
var oldNodeSize = encodeNode(oldNode).length;
var bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;
if (bodySizeDeltaBytes !== 0) {
var newValue = node.metadata.bodySize + bodySizeDeltaBytes;
var newByteArray = encodeU32(newValue); // function body size byte
// FIXME(sven): only handles one byte u32
var start = node.loc.start.column;
var end = start + 1;
uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newByteArray);
}
}
}
});
function applyUpdate(
ast: Program,
uint8Buffer: Uint8Array,
[oldNode, newNode]: [Node, Node]
): State {
const deltaElements = 0;
assertHasLoc(oldNode);
const sectionName = getSectionForNode(newNode);
const replacementByteArray = encodeNode(newNode);
/**
* Replace new node as bytes
*/
uint8Buffer = overrideBytesInBuffer(
uint8Buffer,
// $FlowIgnore: assertHasLoc ensures that
oldNode.loc.start.column,
// $FlowIgnore: assertHasLoc ensures that
oldNode.loc.end.column,
replacementByteArray
);
/**
* Update function body size if needed
*/
function applyUpdate(ast, uint8Buffer, _ref) {
var _ref2 = _slicedToArray(_ref, 2),
oldNode = _ref2[0],
newNode = _ref2[1];
var deltaElements = 0;
assertHasLoc(oldNode);
var sectionName = getSectionForNode(newNode);
var replacementByteArray = encodeNode(newNode);
/**
* Replace new node as bytes
*/
uint8Buffer = overrideBytesInBuffer(uint8Buffer, // $FlowIgnore: assertHasLoc ensures that
oldNode.loc.start.column, // $FlowIgnore: assertHasLoc ensures that
oldNode.loc.end.column, replacementByteArray);
/**
* Update function body size if needed
*/
if (sectionName === "code") {
// Find the parent func
traverse(ast, {
Func: function Func(_ref3) {
var node = _ref3.node;