Skip to content

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

@masnagam

Description

@masnagam

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions