Skip to content

Commit cb2749f

Browse files
feat(extends): extend promise
1 parent 045138f commit cb2749f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

crates/js-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3783,6 +3783,7 @@ extern {
37833783
/// an asynchronous operation, and its resulting value.
37843784
///
37853785
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
3786+
#[wasm_bindgen(extends = Object)]
37863787
pub type Promise;
37873788

37883789
/// Creates a new `Promise` with the provided executor `cb`

crates/js-sys/tests/wasm/Promise.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use wasm_bindgen_test::*;
2+
use wasm_bindgen::JsCast;
3+
use js_sys::*;
4+
5+
#[wasm_bindgen_test]
6+
fn promise_inheritance() {
7+
let promise = Promise::new(&mut |_, _| ());
8+
assert!(promise.is_instance_of::<Promise>());
9+
assert!(promise.is_instance_of::<Object>());
10+
let _: &Object = promise.as_ref();
11+
}

crates/js-sys/tests/wasm/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod MapIterator;
2626
pub mod Math;
2727
pub mod Number;
2828
pub mod Object;
29+
pub mod Promise;
2930
pub mod Proxy;
3031
pub mod RangeError;
3132
pub mod ReferenceError;

0 commit comments

Comments
 (0)