- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
[embind] Change how the number of arguments are verified. #22591
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
Conversation
| assert.equal(-1, value); | ||
| }); | ||
|  | ||
| test("std::optional args can be omitted", function() { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about arguments that have default values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embind doesn't really support default C++ arguments. Functions with default arguments just look like regular functions to embind. e.g. foo(int a = 100) is just foo(int a) in embind's view of things.
| if (arguments.length !== ${argCount}) { | ||
| throwBindingError('function ' + humanName + ' called with ' + arguments.length + ' arguments, expected ${argCount}'); | ||
| }`; | ||
| var invokerFnBody = `return function (${argsList}) {\n`; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a followup can this be arrow function in some cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into it. This is also used in constructors so having the scope bound, may be an issue.
This is really two changes, but they both will affect the same code so I did them at once: - The number of arguments is now only verified with ASSERTIONS enabled. This will help code size and the speed of embind invoker functions. - Allow optional arguments to be omitted. Fixes emscripten-core#22389
b427b4e    to
    13b11be      
    Compare
  
    
This is really two changes, but they both will affect the same code so I did them at once:
Fixes #22389