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

fix(jsruntime): the runtime crashes when the number of arguments is less than the number of formal parameters #331

Open
masnagam opened this issue Oct 19, 2024 · 0 comments

Comments

@masnagam
Copy link
Member

masnagam commented Oct 19, 2024

an access to an out-of-range argument should return undefined.
but it's not supported at this time and the runtime crashes.

(function(a) {
  print(a); ///=Value::UNDEFINED
})();

currently, the arguments are passed by using a pointer to a list of Values allocated on the stack.
and the length of the list is equal to the number of arguments which may be less than the number of formal parameters.
as a result, the out-of-range access occurs.

there are multiple solutions to solve this issue.
but we don't know which one is the best at this point.

  1. allocating the list of Values which has an enough number of elements (min(#arguments, #formal-parameters))
    • some kind of trick is needed because the arguments should be evaluated before evaliating the function itself
  2. checking the number of arguments before accessing an element
    • this solution may increase execution time
  3. generating an lamba function for each possible number of arguments
    • in the function body, every access to an out-of-range argument is returned undefined without checking the number of argument at runtime
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