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

Operator typeof evaluates operand twice #946

Closed
n1xx1 opened this issue Aug 3, 2021 · 0 comments · Fixed by #987
Closed

Operator typeof evaluates operand twice #946

n1xx1 opened this issue Aug 3, 2021 · 0 comments · Fixed by #987

Comments

@n1xx1
Copy link
Contributor

n1xx1 commented Aug 3, 2021

As discussed in #945, the current implementation of typeof expr needs to first evaluate the operand to check if it's an unresolved reference (so that it can return "undefined") and then call GetValue. This is not correct.

Correct behaviour in node:

> const fn = () => { console.log('test'); }
undefined
> typeof fn();
test
'undefined'
> 

With jint:

jint> const fn = () => { print('test'); }
undefined
jint> typeof fn();
test
test
"undefined"
jint> 

The simple fix I attempted in #945 was calling Evaluate and then using _engine.GetValue to convert to a value, but it's not correct because different expressions have different GetValue implementation and it generated tons of problems.

Unfortunately I'm not proficient enough with jint internals to handle this issue, so this is only a bug report and not a PR.

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

Successfully merging a pull request may close this issue.

1 participant