Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when getting the CFG #17

Open
sabaa opened this issue Jul 31, 2018 · 3 comments
Open

Error when getting the CFG #17

sabaa opened this issue Jul 31, 2018 · 3 comments

Comments

@sabaa
Copy link

sabaa commented Jul 31, 2018

Hello,

I get an exception when I try to get the CFG for the following code:

const fs = require('fs');
fs.open('/open/some/file.txt', 'r', (err, fd) => {
  if (err) throw err;
  fs.close(fd, (err) => {
    if (err) throw err;
  });
});

The error is:

TypeError: Cannot set property 'nextSibling' of undefined
    at backToFront (node_modules/esgraph/lib/index.js:369:56)
    at BlockOrProgram (node_modules/esgraph/lib/index.js:374:7)
    at recurse (node_modules/walkes/index.js:20:10)
    at /Users/saba/Documents/northeastern/research/async-miner/node_modules/walkes/index.js:40:10
    at Array.forEach (<anonymous>)
    at checkProps (node_modules/walkes/index.js:34:20)
    at recurse (node_modules/walkes/index.js:20:10)
    at Array.map (<anonymous>)
    at /Users/saba/Documents/northeastern/research/async-miner/node_modules/walkes/index.js:38:15
    at Array.forEach (<anonymous>)
    at checkProps (node_modules/walkes/index.js:34:20)
    at recurse (node_modules/walkes/index.js:20:10)
    at /Users/saba/Documents/northeastern/research/async-miner/node_modules/walkes/index.js:40:10
    at Array.forEach (<anonymous>)
    at checkProps (node_modules/walkes/index.js:34:20)
    at recurse (node_modules/walkes/index.js:20:10)
    at backToFront (node_modules/esgraph/lib/index.js:370:9)
    at BlockOrProgram (node_modules/esgraph/lib/index.js:374:7)
    at recurse (node_modules/walkes/index.js:20:10)
    at walker (node_modules/walkes/index.js:24:9)
    at linkSiblings (node_modules/esgraph/lib/index.js:376:5)
    at ControlFlowGraph (node_modules/esgraph/lib/index.js:47:3)
    at Parser.getCfg (app/parser.js:25:17)

I don't have any issues for calls that are not nested. E.g., if the fs.close() is not included, I won't have any issues.

I'd appreciate any help.

@byteSamurai
Copy link

a few years later:
I am playing with this library at the moment a bit. What I found for your example:

  • it seems to work, if you replace all the arrow functions with normal functions with bounded context:

    const fs = require('fs');
    fs.open('/open/some/file.txt', 'r', (function(err, fd) {
      if (err) throw err;
      fs.close(fd, (function(err){
        if (err) throw err;
      })).bind(this);
    })).bind(this);
    image
  • Once you replace the inner functions with an arrow functions, is not detected correctly:

    const fs = require('fs');
    fs.open('/open/some/file.txt', 'r', (function(err, fd) {
      if (err) throw err;
      fs.close(fd, (err)=>{
        if (err) throw err;
      });
    })).bind(this);
    image

    Quickfix: replace all the arrow functions with bounded functions. Somehow the arrow functions are not processed correctly

@Swatinem
Copy link
Owner

Swatinem commented Feb 6, 2022

Well yes, this project is pretty much abandoned, and was never updated to work with newer JS syntax.

@byteSamurai
Copy link

Well, this is the (open source) way. A possible alternative is maybe Styx but it lacks of some features as well, but the software design is nice.

If you don't want to maintain esgraph, maybe flag the project and link to Styx? However both projects have their pros and cons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants