-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add math-related intrinsics/functions for JsValue
s
#2629
Changes from 26 commits
40d38f3
6277e62
098aef7
2587439
9184409
9aee606
945bcfd
cd65747
073dd08
2b59886
6a5681f
09ebff7
5bcb6da
d304dec
55a22d3
2157e95
1cc0f5b
118dab0
11c7de3
747459a
f976076
7185873
5455ae3
589532e
087d291
76b8065
2dc02ff
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 |
---|---|---|
|
@@ -85,6 +85,9 @@ intrinsics! { | |
#[symbol = "__wbindgen_jsval_eq"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
JsvalEq, | ||
#[symbol = "__wbindgen_jsval_loose_eq"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
JsvalLooseEq, | ||
#[symbol = "__wbindgen_is_function"] | ||
#[signature = fn(ref_externref()) -> Boolean] | ||
IsFunction, | ||
|
@@ -103,9 +106,81 @@ intrinsics! { | |
#[symbol = "__wbindgen_is_string"] | ||
#[signature = fn(ref_externref()) -> Boolean] | ||
IsString, | ||
#[symbol = "__wbindgen_is_bigint"] | ||
#[signature = fn(ref_externref()) -> Boolean] | ||
IsBigInt, | ||
#[symbol = "__wbindgen_typeof"] | ||
#[signature = fn(ref_externref()) -> Externref] | ||
Typeof, | ||
#[symbol = "__wbindgen_in"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
In, | ||
#[symbol = "__wbindgen_is_falsy"] | ||
#[signature = fn(ref_externref()) -> Boolean] | ||
IsFalsy, | ||
#[symbol = "__wbindgen_as_number"] | ||
#[signature = fn(ref_externref()) -> F64] | ||
AsNumber, | ||
#[symbol = "__wbindgen_try_into_number"] | ||
#[signature = fn(ref_externref()) -> Externref] | ||
TryIntoNumber, | ||
#[symbol = "__wbindgen_neg"] | ||
#[signature = fn(ref_externref()) -> Externref] | ||
Neg, | ||
#[symbol = "__wbindgen_bit_and"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
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. These bitwise operators always return an i32, besides unsigned_shr, which yields u32. But, on another note, these are already native Rust operators, why use the significantly slower, more unsound JS operators? Is there anything that can't be done without these? 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. @crimsoncodes0 These operators only return 32-bit ints when passed JS |
||
BitAnd, | ||
#[symbol = "__wbindgen_bit_or"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
BitOr, | ||
#[symbol = "__wbindgen_bit_xor"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
BitXor, | ||
#[symbol = "__wbindgen_bit_not"] | ||
#[signature = fn(ref_externref()) -> Externref] | ||
BitNot, | ||
#[symbol = "__wbindgen_shl"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Shl, | ||
#[symbol = "__wbindgen_shr"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Shr, | ||
#[symbol = "__wbindgen_unsigned_shr"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> U32] | ||
UnsignedShr, | ||
#[symbol = "__wbindgen_add"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Add, | ||
#[symbol = "__wbindgen_sub"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Sub, | ||
#[symbol = "__wbindgen_div"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Div, | ||
#[symbol = "__wbindgen_checked_div"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
CheckedDiv, | ||
#[symbol = "__wbindgen_mul"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Mul, | ||
#[symbol = "__wbindgen_rem"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Rem, | ||
#[symbol = "__wbindgen_pow"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Externref] | ||
Pow, | ||
#[symbol = "__wbindgen_lt"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
LT, | ||
#[symbol = "__wbindgen_le"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
LE, | ||
#[symbol = "__wbindgen_ge"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
GE, | ||
#[symbol = "__wbindgen_gt"] | ||
#[signature = fn(ref_externref(), ref_externref()) -> Boolean] | ||
GT, | ||
#[symbol = "__wbindgen_object_clone_ref"] | ||
#[signature = fn(ref_externref()) -> Externref] | ||
ObjectCloneRef, | ||
|
@@ -118,6 +193,9 @@ intrinsics! { | |
#[symbol = "__wbindgen_number_new"] | ||
#[signature = fn(F64) -> Externref] | ||
NumberNew, | ||
#[symbol = "__wbindgen_bigint_new"] | ||
#[signature = fn(ref_string()) -> Externref] | ||
BigIntNew, | ||
#[symbol = "__wbindgen_string_new"] | ||
#[signature = fn(ref_string()) -> Externref] | ||
StringNew, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,13 @@ edition = "2018" | |
test = false | ||
doctest = false | ||
|
||
[features] | ||
rust-num = ["num-bigint", "num-traits"] | ||
|
||
[dependencies] | ||
wasm-bindgen = { path = "../..", version = "0.2.76" } | ||
num-bigint = { version = "0.4.1", optional = true } | ||
num-traits = { version = "0.2.14", optional = true } | ||
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. Sorry but personally I do not want to add new public dependencies to these crates. There is no story for landing breaking changes to js-sys at this time and having new public dependencies increases the risk that a breaking change may be needed (in case these deps have a major-version-bump) I realize these are optional but it's still part of the public API and something that I'm not willing to commit to. |
||
|
||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies] | ||
wasm-bindgen-test = { path = '../test', version = '=0.3.26' } | ||
|
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.
Why special-case this? __wbindgen_typeof can be used to implement this.
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.
@crimsoncodes0 The other types are already special-cased, so I special-cased this one too for consistency
Edit: also, maybe JS engines might have special optimizations for
typeof
to avoid a full string comparison? (No idea, but presumably they could do this)