Skip to content

Parameter Validation for Callback functions passed to bundles #560

@leeyi45

Description

@leeyi45

Consider the following program:

import { draw_connected, make_point } from 'curve';

draw_connected((t, _) => make_point(0.5, t));

draw_connected expects a callback that only takes 1 parameter, so when the curve is evaluated the function is called with a single parameter.

js-slang checks that every function is called with an expected number of parameters, so at the point of curve evaluation an error is thrown because the callback gets called with only 1 parameter:

Image

As seen above, the error isn't very informative.

In accordance with the principle that modules should keep their implementation details hidden, it might be necessary for bundle functions to implement checks to ensure that callback functions have the correct number of parameters:

function isValidCallback(f: unknown): f is (arg0: unknown, arg1: unknown) => unknown {
   return typeof f === 'function' && f.length === 2;
}

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