mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-08 21:28:07 +00:00
implements bindings for Object.is (#537)
* implements bindings for Object.is * adds counterpart test cases for non-equal values
This commit is contained in:
parent
82c2dfa7b2
commit
de0ba29abc
@ -1712,6 +1712,12 @@ extern "C" {
|
|||||||
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
||||||
pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
|
pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
|
||||||
|
|
||||||
|
/// The Object.is() method determines whether two values are the same value.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
||||||
|
#[wasm_bindgen(static_method_of = Object)]
|
||||||
|
pub fn is(value_1: &JsValue, value_2: &JsValue) -> bool;
|
||||||
|
|
||||||
/// The `Object.isExtensible()` method determines if an object is extensible
|
/// The `Object.isExtensible()` method determines if an object is extensible
|
||||||
/// (whether it can have new properties added to it).
|
/// (whether it can have new properties added to it).
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
use std::f64::NAN;
|
||||||
use js_sys::*;
|
use js_sys::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -48,6 +49,25 @@ fn to_string() {
|
|||||||
assert_eq!(foo_42().to_string(), "[object Object]");
|
assert_eq!(foo_42().to_string(), "[object Object]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn is() {
|
||||||
|
let object = JsValue::from(Object::new());
|
||||||
|
assert!(Object::is(&object, &object));
|
||||||
|
assert!(Object::is(&JsValue::undefined(), &JsValue::undefined()));
|
||||||
|
assert!(Object::is(&JsValue::null(), &JsValue::null()));
|
||||||
|
assert!(Object::is(&JsValue::TRUE, &JsValue::TRUE));
|
||||||
|
assert!(Object::is(&JsValue::FALSE, &JsValue::FALSE));
|
||||||
|
assert!(Object::is(&"foo".into(), &"foo".into()));
|
||||||
|
assert!(Object::is(&JsValue::from(42), &JsValue::from(42)));
|
||||||
|
assert!(Object::is(&JsValue::from(NAN), &JsValue::from(NAN)));
|
||||||
|
|
||||||
|
let another_object = JsValue::from(Object::new());
|
||||||
|
assert!(!Object::is(&object, &another_object));
|
||||||
|
assert!(!Object::is(&JsValue::TRUE, &JsValue::FALSE));
|
||||||
|
assert!(!Object::is(&"foo".into(), &"bar".into()));
|
||||||
|
assert!(!Object::is(&JsValue::from(23), &JsValue::from(42)));
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn is_extensible() {
|
fn is_extensible() {
|
||||||
let object = Object::new();
|
let object = Object::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user