-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Last expressions result gets returned from functions when there is no return #672
Comments
This can be generalized, it seems that when the last statement in a function is an expression the expression's result is returned rather than undefined. >> function z() { 0 }
undefined
>> z()
0 |
Problem is in: https://github.com/boa-dev/boa/blob/be20b65a9e1a2ac6d802f5c8f3f87edd149274eb/boa/src/exec/statement_list.rs if i + 1 == self.statements().len() {
obj = val;
} Regardless of the type of node, the value obtained from running it is used as the return value. I think PS: It's not as simple as removing them, I think some mantainer orientation is required. |
Seeing that all returns in JavaScript are explicit anyway, I wonder if StatementList can Ok(undefined), it should be safe as any return will change the interpreter state so it wouldn’t get that far. You could return Ok(val) directly from the return state branch in that link @RageKnify posted. It’s something worth playing with, but it should work. |
Should have been explicit on my PS, what happened when I tried removing the 3 lines was that the CLI started only returning Changing the |
Hello! Is this available to work on? |
@JayHelton i believe so! |
When non returning functions mutates a property of another object that modified object gets returned even though we dont use the return statement
In the repl
y() should not return anything
The text was updated successfully, but these errors were encountered: