add setTimeout to get rid of max callstack size

pull/7/head
yann300 8 years ago
parent b520ae5970
commit 12f220336e
  1. 84
      src/util/internalCallTree.js

@ -109,52 +109,54 @@ function buildTree (tree, step, scopeId, cb) {
* @param {Function} cb - callback * @param {Function} cb - callback
*/ */
function visitStep (tree, step, scopeId, subScope, cb) { function visitStep (tree, step, scopeId, subScope, cb) {
extractSourceLocation(tree, step, (error, sourceLocation) => { setTimeout(() => {
if (error) { extractSourceLocation(tree, step, (error, sourceLocation) => {
console.log(error) if (error) {
} else { cb(error)
if (sourceLocation.jump === 'i') {
buildTree(tree, step + 1, scopeId === '' ? subScope.toString() : scopeId + '.' + subScope, function (error, outStep) {
if (!error) {
visitStep(tree, outStep, scopeId, subScope + 1, cb)
} else {
cb('error computing jump')
}
})
return
} else if (sourceLocation.jump === 'o') {
tree.scopes[scopeId].lastStep = step
cb(null, step + 1)
return
} else { } else {
if (tree.includeLocalVariables) { if (sourceLocation.jump === 'i') {
var variableDeclaration = resolveVariableDeclaration(tree, step, sourceLocation) buildTree(tree, step + 1, scopeId === '' ? subScope.toString() : scopeId + '.' + subScope, function (error, outStep) {
if (variableDeclaration) { if (!error) {
tree.traceManager.getStackAt(step, (error, stack) => { visitStep(tree, outStep, scopeId, subScope + 1, cb)
if (!error) { } else {
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached cb('error computing jump')
if (!error) { }
var states = tree.solidityProxy.extractStatesDefinitions() })
tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = { return
name: variableDeclaration.attributes.name, } else if (sourceLocation.jump === 'o') {
type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName), tree.scopes[scopeId].lastStep = step
stackHeight: stack.length cb(null, step + 1)
return
} else {
if (tree.includeLocalVariables) {
var variableDeclaration = resolveVariableDeclaration(tree, step, sourceLocation)
if (variableDeclaration && !tree.scopes[scopeId].locals[variableDeclaration.attributes.name]) {
tree.traceManager.getStackAt(step, (error, stack) => {
if (!error) {
tree.solidityProxy.contractNameAt(step, (error, contractName) => { // cached
if (!error) {
var states = tree.solidityProxy.extractStatesDefinitions()
tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = {
name: variableDeclaration.attributes.name,
type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName),
stackHeight: stack.length
}
} }
} })
}) }
} })
}) }
} }
step++
}
if (tree.traceManager.inRange(step)) {
visitStep(tree, step, scopeId, subScope, cb)
} else {
cb(null, step)
} }
step++
}
if (tree.traceManager.inRange(step)) {
visitStep(tree, step, scopeId, subScope, cb)
} else {
cb(null, step)
} }
} })
}) }, 0)
} }
function extractSourceLocation (tree, step, cb) { function extractSourceLocation (tree, step, cb) {

Loading…
Cancel
Save