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

Callback parameter needs an extra check #38

Open
stathismor opened this issue Dec 29, 2021 · 0 comments
Open

Callback parameter needs an extra check #38

stathismor opened this issue Dec 29, 2021 · 0 comments

Comments

@stathismor
Copy link

My test code looks like this:

var evaluate = require('static-eval');
var parse = require('esprima').parse;

var src = 'foo(function (obj) { return obj.x })';
var ast = parse(src).body[0].expression;
var result = evaluate(ast, {
  foo: function (func) {
    return func({x: 1})
  },
});

console.log(result);

When I run it, I get:

$ node test.js
/home/stathis/src/jellyfish-jellyscript/node_modules/static-eval/index.js:134
                return obj[node.property.name];
                          ^

TypeError: Cannot read property 'x' of null
    at walk (/home/stathis/src/jellyfish-jellyscript/node_modules/static-eval/index.js:134:27)
    at walk (/home/stathis/src/jellyfish-jellyscript/node_modules/static-eval/index.js:152:20)
    at walk (/home/stathis/src/jellyfish-jellyscript/node_modules/static-eval/index.js:171:20)
    at walk (/home/stathis/src/jellyfish-jellyscript/node_modules/static-eval/index.js:112:25)
    at module.exports (/home/stathis/src/jellyfish-jellyscript/node_modules/static-eval/index.js:204:7)
    at Object.<anonymous> (/home/stathis/src/jellyfish-jellyscript/test.js:6:14)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)

whereas when I change

var src = 'foo(function (obj) { return obj.x })';`

to

var src = 'foo(function (obj) { return obj && obj.x })';`

I get a successful result:

$ node test.js
1

This looks like a bug to me, as my callback's input here is just {x: 1}, why would I need to make sure obj exists?

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

1 participant