You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Last expressions result gets returned from functions when there is no return #672
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.
changed the title [-]Modified values gets returned from functions when they shouldn't[/-][+]Last expressions result gets returned from functions when there is no return[/+]on Sep 1, 2020
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 undefined, because what the parser gives to be run with the Interpreter is a StatementList.
Changing the break to an early return wouldn't change the current flow, right?
Activity
RageKnify commentedon Sep 1, 2020
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.
[-]Modified values gets returned from functions when they shouldn't[/-][+]Last expressions result gets returned from functions when there is no return[/+]RageKnify commentedon Sep 1, 2020
Problem is in: https://github.com/boa-dev/boa/blob/be20b65a9e1a2ac6d802f5c8f3f87edd149274eb/boa/src/exec/statement_list.rs
Regardless of the type of node, the value obtained from running it is used as the return value.
I think
StatementLists are used elsewhere besides function, if so it might not be as simple as removing these lines....PS: It's not as simple as removing them, I think some mantainer orientation is required.
jasonwilliams commentedon Sep 1, 2020
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.
RageKnify commentedon Sep 2, 2020
Should have been explicit on my PS, what happened when I tried removing the 3 lines was that the CLI started only returning
undefined, because what the parser gives to berunwith theInterpreteris aStatementList.Changing the
breakto an early return wouldn't change the current flow, right?JayHelton commentedon Jun 9, 2021
Hello! Is this available to work on?
jasonwilliams commentedon Jun 9, 2021
@JayHelton i believe so!