Merge pull request #1638 from ThomasdenH/master

Add is_truthy, is_falsy
This commit is contained in:
Alex Crichton
2019-08-08 12:35:01 -05:00
committed by GitHub
5 changed files with 54 additions and 0 deletions

View File

@ -85,6 +85,9 @@ intrinsics! {
#[symbol = "__wbindgen_is_string"]
#[signature = fn(ref_anyref()) -> Boolean]
IsString,
#[symbol = "__wbindgen_is_falsy"]
#[signature = fn(ref_anyref()) -> Boolean]
IsFalsy,
#[symbol = "__wbindgen_object_clone_ref"]
#[signature = fn(ref_anyref()) -> Anyref]
ObjectCloneRef,

View File

@ -2464,6 +2464,11 @@ impl<'a> Context<'a> {
format!("typeof({}) === 'string'", args[0])
}
Intrinsic::IsFalsy => {
assert_eq!(args.len(), 1);
format!("!{}", args[0])
}
Intrinsic::ObjectCloneRef => {
assert_eq!(args.len(), 1);
args[0].clone()