diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 41a11110..dd752fb1 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -673,8 +673,8 @@ extern "C" { /// (or an array-like object). /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply - #[wasm_bindgen(method)] - pub fn apply(this: &Function, context: &JsValue, args: &Array) -> JsValue; + #[wasm_bindgen(method, catch)] + pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Result; /// The bind() method creates a new function that, when called, has its this keyword set to the provided value, /// with a given sequence of arguments preceding any provided when the new function is called. diff --git a/crates/js-sys/tests/wasm/Function.rs b/crates/js-sys/tests/wasm/Function.rs index 258e153b..b2918caf 100644 --- a/crates/js-sys/tests/wasm/Function.rs +++ b/crates/js-sys/tests/wasm/Function.rs @@ -20,7 +20,7 @@ fn apply() { args.push(1.into()); args.push(2.into()); args.push(3.into()); - assert_eq!(MAX.apply(&JsValue::undefined(), &args), 3); + assert_eq!(MAX.apply(&JsValue::undefined(), &args).unwrap(), 3); let arr = JsValue::from(Array::new()); let args = Array::new(); diff --git a/crates/test/src/rt.rs b/crates/test/src/rt.rs index 4b4e8a72..de863a96 100644 --- a/crates/test/src/rt.rs +++ b/crates/test/src/rt.rs @@ -3,7 +3,7 @@ use std::fmt; use std::mem; use console_error_panic_hook; -use js_sys::Array; +use js_sys::{Array, Function}; use wasm_bindgen::prelude::*; /// Runtime test harness support instantiated in JS. @@ -24,11 +24,6 @@ pub struct Context { #[wasm_bindgen] extern { - // Redefined from `js_sys` so we can catch the error - pub type Function; - #[wasm_bindgen(method, catch)] - fn apply(this: &Function, new_this: &JsValue, args: &Array) -> Result; - #[wasm_bindgen(js_namespace = console, js_name = log)] #[doc(hidden)] pub fn console_log(s: &str);