-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Implement macro for setting builtin functions #206
Implement macro for setting builtin functions #206
Conversation
Do we want to call this macro make_builtin_fn so it’s explicit that’s what it’s for? |
Why does some functions, e.g. |
@Stupremee basically, that is where the idea for this macro came from. Some functions do not set the |
Ah okay. So I should set the |
src/lib/builtins/mod.rs
Outdated
$p.set_field_slice($name, $fn); | ||
}; | ||
($fn:ident, named $name:expr, of $p:ident) => { | ||
$p.set_field_slice($name, to_value($fn as NativeFunctionData)); |
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.
Are there any functions that do not have their length
set (e.g. it's undefined
)? If so, this line is fine.
But if not, I think it would be better if you set the length
to 0
by default.
@Stupremee yep |
src/lib/builtins/math.rs
Outdated
make_builtin_fn!(acos, named "acos", with length 1, of math); | ||
make_builtin_fn!(asin, named "asin", with length 1, of math); | ||
make_builtin_fn!(atan, named "atan", with length 1, of math); | ||
make_builtin_fn!(atan2, named "atan2", with length 1, of math); |
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.
The length
should be 2.
src/lib/builtins/math.rs
Outdated
make_builtin_fn!(acos, named "acos", with length 1, of math); | ||
make_builtin_fn!(asin, named "asin", with length 1, of math); | ||
make_builtin_fn!(atan, named "atan", with length 1, of math); | ||
make_builtin_fn!(atan2, named "atan2", with length 1, of math); |
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.
make_builtin_fn!(atan2, named "atan2", with length 1, of math); | |
make_builtin_fn!(atan2, named "atan2", with length 2, of math); |
src/lib/builtins/number.rs
Outdated
number_prototype.set_field_slice("toPrecision", to_value(to_precision as NativeFunctionData)); | ||
number_prototype.set_field_slice("toString", to_value(to_string as NativeFunctionData)); | ||
number_prototype.set_field_slice("valueOf", to_value(value_of as NativeFunctionData)); | ||
make_builtin_fn!(to_exponential, named "toExponential", of number_prototype); |
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.
make_builtin_fn!(to_exponential, named "toExponential", of number_prototype); | |
make_builtin_fn!(to_exponential, named "toExponential", with length 1, of number_prototype); |
src/lib/builtins/number.rs
Outdated
make_builtin_fn!(to_fixed, named "toFixed", with length 1, of number_prototype); | ||
make_builtin_fn!(to_locale_string, named "toLocaleString", of number_prototype); | ||
make_builtin_fn!(to_precision, named "toPrecision", with length 1, of number_prototype); | ||
make_builtin_fn!(to_string, named "toString", of number_prototype); |
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.
make_builtin_fn!(to_string, named "toString", of number_prototype); | |
make_builtin_fn!(to_string, named "toString", with length 1, of number_prototype); |
src/lib/builtins/string.rs
Outdated
make_builtin_fn!(index_of, named "indexOf", with length 1, of proto); | ||
make_builtin_fn!(last_index_of, named "lastIndexOf", with length 1, of proto); | ||
make_builtin_fn!(r#match, named "match", with length 1, of proto); | ||
make_builtin_fn!(pad_end, named "padEnd", with length 2, of proto); |
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.
make_builtin_fn!(pad_end, named "padEnd", with length 2, of proto); | |
make_builtin_fn!(pad_end, named "padEnd", with length 1, of proto); |
src/lib/builtins/string.rs
Outdated
make_builtin_fn!(last_index_of, named "lastIndexOf", with length 1, of proto); | ||
make_builtin_fn!(r#match, named "match", with length 1, of proto); | ||
make_builtin_fn!(pad_end, named "padEnd", with length 2, of proto); | ||
make_builtin_fn!(pad_start, named "padStart", with length 2, of proto); |
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.
make_builtin_fn!(pad_start, named "padStart", with length 2, of proto); | |
make_builtin_fn!(pad_start, named "padStart", with length 1, of proto); |
Description
This pull request introduces a new macro called
make_fn
in the builtins module,which can be used to simplify setting a builtin function and replaces every "old" way with the new macro.
Example
becomes
and
becomes
This change was requested #193