Skip to content

Commit

Permalink
Add bindings for WebAssembly.Tag and WebAssembly.Exception (#3484)
Browse files Browse the repository at this point in the history
  • Loading branch information
allsey87 committed Jun 16, 2023
1 parent e84fd83 commit 165ad00
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Extend `AudioContext` with unstable features supporting audio sink configuration.
[#3433](https://github.com/rustwasm/wasm-bindgen/pull/3433)

* Add bindings for `WebAssembly.Tag` and `WebAssembly.Exception`.
[#3484](https://github.com/rustwasm/wasm-bindgen/pull/3484)

### Changed

* Updated the WebGPU WebIDL.
Expand Down
58 changes: 58 additions & 0 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4467,6 +4467,64 @@ pub mod WebAssembly {
pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
}

// WebAssembly.Tag
#[wasm_bindgen]
extern "C" {
/// The `WebAssembly.Tag()` constructor creates a new `Tag` object
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type Tag;

/// The `WebAssembly.Tag()` constructor creates a new `Tag` object
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
#[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
}

// WebAssembly.Exception
#[wasm_bindgen]
extern "C" {
/// The `WebAssembly.Exception()` constructor creates a new `Exception` object
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type Exception;

/// The `WebAssembly.Exception()` constructor creates a new `Exception` object
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
#[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;

/// The `WebAssembly.Exception()` constructor creates a new `Exception` object
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
#[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
pub fn new_with_options(
tag: &Tag,
payload: &Array,
options: &Object,
) -> Result<Exception, JsValue>;

/// The `is()` prototype method of the `WebAssembly.Exception` can be used to
/// test if the Exception matches a given tag.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
#[wasm_bindgen(method, js_namespace = WebAssembly)]
pub fn is(this: &Exception, tag: &Tag) -> bool;

/// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
/// to get the value of a specified item in the exception's data arguments
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
#[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
}

// WebAssembly.Global
#[wasm_bindgen]
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/ui-tests/async-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ error[E0277]: the trait bound `wasm_bindgen::JsValue: From<BadType>` is not sati
<wasm_bindgen::JsValue as From<JsError>>
<wasm_bindgen::JsValue as From<MyType>>
<wasm_bindgen::JsValue as From<Option<T>>>
and 72 others
and 74 others
= note: required for `BadType` to implement `Into<wasm_bindgen::JsValue>`
= note: required for `BadType` to implement `IntoJsResult`
= note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down

0 comments on commit 165ad00

Please sign in to comment.