-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
Changes from 8 commits
353f8a3
b776dab
f3c0363
132961b
a4bd434
1aa80d0
6554b51
c2d6442
8f64309
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -203,24 +203,24 @@ pub fn create_constructor(global: &Value) -> Value { | |||||
math.set_field_slice("SQRT1_2", to_value(0.5_f64.sqrt())); | ||||||
math.set_field_slice("SQRT2", to_value(f64::consts::SQRT_2)); | ||||||
math.set_field_slice("PI", to_value(f64::consts::PI)); | ||||||
math.set_field_slice("abs", to_value(abs as NativeFunctionData)); | ||||||
math.set_field_slice("acos", to_value(acos as NativeFunctionData)); | ||||||
math.set_field_slice("asin", to_value(asin as NativeFunctionData)); | ||||||
math.set_field_slice("atan", to_value(atan as NativeFunctionData)); | ||||||
math.set_field_slice("atan2", to_value(atan2 as NativeFunctionData)); | ||||||
math.set_field_slice("cbrt", to_value(cbrt as NativeFunctionData)); | ||||||
math.set_field_slice("ceil", to_value(ceil as NativeFunctionData)); | ||||||
math.set_field_slice("cos", to_value(cos as NativeFunctionData)); | ||||||
math.set_field_slice("exp", to_value(exp as NativeFunctionData)); | ||||||
math.set_field_slice("floor", to_value(floor as NativeFunctionData)); | ||||||
math.set_field_slice("log", to_value(log as NativeFunctionData)); | ||||||
math.set_field_slice("max", to_value(max as NativeFunctionData)); | ||||||
math.set_field_slice("min", to_value(min as NativeFunctionData)); | ||||||
math.set_field_slice("pow", to_value(pow as NativeFunctionData)); | ||||||
math.set_field_slice("random", to_value(_random as NativeFunctionData)); | ||||||
math.set_field_slice("round", to_value(round as NativeFunctionData)); | ||||||
math.set_field_slice("sin", to_value(sin as NativeFunctionData)); | ||||||
math.set_field_slice("sqrt", to_value(sqrt as NativeFunctionData)); | ||||||
math.set_field_slice("tan", to_value(tan as NativeFunctionData)); | ||||||
make_builtin_fn!(abs, named "abs", with length 1, of math); | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
make_builtin_fn!(cbrt, named "cbrt", with length 1, of math); | ||||||
make_builtin_fn!(ceil, named "ceil", with length 1, of math); | ||||||
make_builtin_fn!(cos, named "cos", with length 1, of math); | ||||||
make_builtin_fn!(exp, named "exp", with length 1, of math); | ||||||
make_builtin_fn!(floor, named "floor", with length 1, of math); | ||||||
make_builtin_fn!(log, named "log", with length 1, of math); | ||||||
make_builtin_fn!(max, named "max", with length 2, of math); | ||||||
make_builtin_fn!(min, named "min", with length 2, of math); | ||||||
make_builtin_fn!(pow, named "pow", with length 2, of math); | ||||||
make_builtin_fn!(_random, named "random", of math); | ||||||
make_builtin_fn!(round, named "round", with length 1, of math); | ||||||
make_builtin_fn!(sin, named "sin", with length 1, of math); | ||||||
make_builtin_fn!(sqrt, named "sqrt", with length 1, of math); | ||||||
make_builtin_fn!(tan, named "tan", with length 1, of math); | ||||||
math | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -145,18 +145,12 @@ pub fn create_constructor(global: &Value) -> Value { | |||||
|
||||||
number_prototype.set_internal_slot("NumberData", to_value(0)); | ||||||
|
||||||
number_prototype.set_field_slice( | ||||||
"toExponential", | ||||||
to_value(to_exponential as NativeFunctionData), | ||||||
); | ||||||
number_prototype.set_field_slice("toFixed", to_value(to_fixed as NativeFunctionData)); | ||||||
number_prototype.set_field_slice( | ||||||
"toLocaleString", | ||||||
to_value(to_locale_string as NativeFunctionData), | ||||||
); | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
make_builtin_fn!(value_of, named "valueOf", of number_prototype); | ||||||
|
||||||
let number = to_value(number_constructor); | ||||||
number_prototype.set_field_slice("constructor", number.clone()); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -744,28 +744,28 @@ pub fn create_constructor(global: &Value) -> Value { | |||||
let prop = Property::default().get(to_value(get_string_length as NativeFunctionData)); | ||||||
|
||||||
proto.set_prop_slice("length", prop); | ||||||
proto.set_field_slice("charAt", to_value(char_at as NativeFunctionData)); | ||||||
proto.set_field_slice("charCodeAt", to_value(char_code_at as NativeFunctionData)); | ||||||
proto.set_field_slice("toString", to_value(to_string as NativeFunctionData)); | ||||||
proto.set_field_slice("concat", to_value(concat as NativeFunctionData)); | ||||||
proto.set_field_slice("repeat", to_value(repeat as NativeFunctionData)); | ||||||
proto.set_field_slice("slice", to_value(slice as NativeFunctionData)); | ||||||
proto.set_field_slice("startsWith", to_value(starts_with as NativeFunctionData)); | ||||||
proto.set_field_slice("endsWith", to_value(ends_with as NativeFunctionData)); | ||||||
proto.set_field_slice("includes", to_value(includes as NativeFunctionData)); | ||||||
proto.set_field_slice("indexOf", to_value(index_of as NativeFunctionData)); | ||||||
proto.set_field_slice("lastIndexOf", to_value(last_index_of as NativeFunctionData)); | ||||||
proto.set_field_slice("match", to_value(r#match as NativeFunctionData)); | ||||||
proto.set_field_slice("padEnd", to_value(pad_end as NativeFunctionData)); | ||||||
proto.set_field_slice("padStart", to_value(pad_start as NativeFunctionData)); | ||||||
proto.set_field_slice("trim", to_value(trim as NativeFunctionData)); | ||||||
proto.set_field_slice("trimStart", to_value(trim_start as NativeFunctionData)); | ||||||
proto.set_field_slice("toLowerCase", to_value(to_lowercase as NativeFunctionData)); | ||||||
proto.set_field_slice("toUpperCase", to_value(to_uppercase as NativeFunctionData)); | ||||||
proto.set_field_slice("substring", to_value(substring as NativeFunctionData)); | ||||||
proto.set_field_slice("substr", to_value(substr as NativeFunctionData)); | ||||||
proto.set_field_slice("valueOf", to_value(value_of as NativeFunctionData)); | ||||||
proto.set_field_slice("matchAll", to_value(match_all as NativeFunctionData)); | ||||||
make_builtin_fn!(char_at, named "charAt", with length 1, of proto); | ||||||
make_builtin_fn!(char_code_at, named "charCodeAt", with length 1, of proto); | ||||||
make_builtin_fn!(to_string, named "toString", of proto); | ||||||
make_builtin_fn!(concat, named "concat", with length 1, of proto); | ||||||
make_builtin_fn!(repeat, named "repeat", with length 1, of proto); | ||||||
make_builtin_fn!(slice, named "slice", with length 2, of proto); | ||||||
make_builtin_fn!(starts_with, named "startsWith", with length 1, of proto); | ||||||
make_builtin_fn!(ends_with, named "endsWith", with length 1, of proto); | ||||||
make_builtin_fn!(includes, named "includes", with length 1, of proto); | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
make_builtin_fn!(trim, named "trim", of proto); | ||||||
make_builtin_fn!(trim_start, named "trimStart", of proto); | ||||||
make_builtin_fn!(to_lowercase, named "toLowerCase", of proto); | ||||||
make_builtin_fn!(to_uppercase, named "toUpperCase", of proto); | ||||||
make_builtin_fn!(substring, named "substring", with length 2, of proto); | ||||||
make_builtin_fn!(substr, named "substr", with length 2, of proto); | ||||||
make_builtin_fn!(value_of, named "valueOf", of proto); | ||||||
make_builtin_fn!(match_all, named "matchAll", with length 1, of proto); | ||||||
|
||||||
let string = to_value(string_constructor); | ||||||
proto.set_field_slice("constructor", string.clone()); | ||||||
|
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.