diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 55e44986..8d8e0911 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2233,163 +2233,164 @@ extern "C" { pub fn new(message: &str) -> ReferenceError; } -// Reflect -#[wasm_bindgen] -extern "C" { - #[wasm_bindgen(extends = Object)] - #[derive(Clone, Debug, PartialEq, Eq)] - pub type Reflect; +#[allow(non_snake_case)] +pub mod Reflect { + use super::*; - /// The static `Reflect.apply()` method calls a target function with - /// arguments as specified. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply) - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn apply( - target: &Function, - this_argument: &JsValue, - arguments_list: &Array, - ) -> Result; + // Reflect + #[wasm_bindgen] + extern "C" { + /// The static `Reflect.apply()` method calls a target function with + /// arguments as specified. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply) + #[wasm_bindgen(js_namespace = Reflect, catch)] + pub fn apply( + target: &Function, + this_argument: &JsValue, + arguments_list: &Array, + ) -> Result; - /// The static `Reflect.construct()` method acts like the new operator, but - /// as a function. It is equivalent to calling `new target(...args)`. It - /// gives also the added option to specify a different prototype. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct) - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn construct(target: &Function, arguments_list: &Array) -> Result; + /// The static `Reflect.construct()` method acts like the new operator, but + /// as a function. It is equivalent to calling `new target(...args)`. It + /// gives also the added option to specify a different prototype. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct) + #[wasm_bindgen(js_namespace = Reflect, catch)] + pub fn construct(target: &Function, arguments_list: &Array) -> Result; - /// The static `Reflect.construct()` method acts like the new operator, but - /// as a function. It is equivalent to calling `new target(...args)`. It - /// gives also the added option to specify a different prototype. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct) - #[wasm_bindgen(static_method_of = Reflect, js_name = construct, catch)] - pub fn construct_with_new_target( - target: &Function, - arguments_list: &Array, - new_target: &Function, - ) -> Result; + /// The static `Reflect.construct()` method acts like the new operator, but + /// as a function. It is equivalent to calling `new target(...args)`. It + /// gives also the added option to specify a different prototype. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct) + #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)] + pub fn construct_with_new_target( + target: &Function, + arguments_list: &Array, + new_target: &Function, + ) -> Result; - /// The static `Reflect.defineProperty()` method is like - /// `Object.defineProperty()` but returns a `Boolean`. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty) - #[wasm_bindgen(static_method_of = Reflect, js_name = defineProperty, catch)] - pub fn define_property( - target: &Object, - property_key: &JsValue, - attributes: &Object, - ) -> Result; + /// The static `Reflect.defineProperty()` method is like + /// `Object.defineProperty()` but returns a `Boolean`. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty) + #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)] + pub fn define_property( + target: &Object, + property_key: &JsValue, + attributes: &Object, + ) -> Result; - /// The static `Reflect.deleteProperty()` method allows to delete - /// properties. It is like the `delete` operator as a function. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty) - #[wasm_bindgen(static_method_of = Reflect, js_name = deleteProperty, catch)] - pub fn delete_property(target: &Object, key: &JsValue) -> Result; + /// The static `Reflect.deleteProperty()` method allows to delete + /// properties. It is like the `delete` operator as a function. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty) + #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)] + pub fn delete_property(target: &Object, key: &JsValue) -> Result; - /// The static `Reflect.get()` method works like getting a property from - /// an object (`target[propertyKey]`) as a function. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get) - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn get(target: &JsValue, key: &JsValue) -> Result; + /// The static `Reflect.get()` method works like getting a property from + /// an object (`target[propertyKey]`) as a function. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get) + #[wasm_bindgen(js_namespace = Reflect, catch)] + pub fn get(target: &JsValue, key: &JsValue) -> Result; - /// The same as [`Reflect::get`](#method.get) except the key is an `f64`, which is slightly faster. - #[wasm_bindgen(static_method_of = Reflect, js_name = "get", catch)] - pub fn get_f64(target: &JsValue, key: f64) -> Result; + /// The same as [`Reflect::get`](#method.get) except the key is an `f64`, which is slightly faster. + #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)] + pub fn get_f64(target: &JsValue, key: f64) -> Result; - /// The same as [`Reflect::get`](#method.get) except the key is a `u32`, which is slightly faster. - #[wasm_bindgen(static_method_of = Reflect, js_name = "get", catch)] - pub fn get_u32(target: &JsValue, key: u32) -> Result; + /// The same as [`Reflect::get`](#method.get) except the key is a `u32`, which is slightly faster. + #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)] + pub fn get_u32(target: &JsValue, key: u32) -> Result; - /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to - /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor - /// of the given property if it exists on the object, `undefined` otherwise. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) - #[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)] - pub fn get_own_property_descriptor( - target: &Object, - property_key: &JsValue, - ) -> Result; + /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to + /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor + /// of the given property if it exists on the object, `undefined` otherwise. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) + #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)] + pub fn get_own_property_descriptor( + target: &Object, + property_key: &JsValue, + ) -> Result; - /// The static `Reflect.getPrototypeOf()` method is almost the same - /// method as `Object.getPrototypeOf()`. It returns the prototype - /// (i.e. the value of the internal `[[Prototype]]` property) of - /// the specified object. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf) - #[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf, catch)] - pub fn get_prototype_of(target: &JsValue) -> Result; + /// The static `Reflect.getPrototypeOf()` method is almost the same + /// method as `Object.getPrototypeOf()`. It returns the prototype + /// (i.e. the value of the internal `[[Prototype]]` property) of + /// the specified object. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf) + #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)] + pub fn get_prototype_of(target: &JsValue) -> Result; - /// The static `Reflect.has()` method works like the in operator as a - /// function. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has) - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn has(target: &JsValue, property_key: &JsValue) -> Result; + /// The static `Reflect.has()` method works like the in operator as a + /// function. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has) + #[wasm_bindgen(js_namespace = Reflect, catch)] + pub fn has(target: &JsValue, property_key: &JsValue) -> Result; - /// The static `Reflect.isExtensible()` method determines if an object is - /// extensible (whether it can have new properties added to it). It is - /// similar to `Object.isExtensible()`, but with some differences. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible) - #[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible, catch)] - pub fn is_extensible(target: &Object) -> Result; + /// The static `Reflect.isExtensible()` method determines if an object is + /// extensible (whether it can have new properties added to it). It is + /// similar to `Object.isExtensible()`, but with some differences. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible) + #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)] + pub fn is_extensible(target: &Object) -> Result; - /// The static `Reflect.ownKeys()` method returns an array of the - /// target object's own property keys. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys) - #[wasm_bindgen(static_method_of = Reflect, js_name = ownKeys, catch)] - pub fn own_keys(target: &JsValue) -> Result; + /// The static `Reflect.ownKeys()` method returns an array of the + /// target object's own property keys. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys) + #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)] + pub fn own_keys(target: &JsValue) -> Result; - /// The static `Reflect.preventExtensions()` method prevents new - /// properties from ever being added to an object (i.e. prevents - /// future extensions to the object). It is similar to - /// `Object.preventExtensions()`, but with some differences. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions) - #[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions, catch)] - pub fn prevent_extensions(target: &Object) -> Result; + /// The static `Reflect.preventExtensions()` method prevents new + /// properties from ever being added to an object (i.e. prevents + /// future extensions to the object). It is similar to + /// `Object.preventExtensions()`, but with some differences. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions) + #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)] + pub fn prevent_extensions(target: &Object) -> Result; - /// The static `Reflect.set()` method works like setting a - /// property on an object. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result; + /// The static `Reflect.set()` method works like setting a + /// property on an object. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) + #[wasm_bindgen(js_namespace = Reflect, catch)] + pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result; - /// The same as [`Reflect::set`](#method.set) except the key is an `f64`, which is slightly faster. - #[wasm_bindgen(static_method_of = Reflect, js_name = "set", catch)] - pub fn set_f64(target: &JsValue, property_key: f64, value: &JsValue) -> Result; + /// The same as [`Reflect::set`](#method.set) except the key is an `f64`, which is slightly faster. + #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)] + pub fn set_f64(target: &JsValue, property_key: f64, value: &JsValue) -> Result; - /// The same as [`Reflect::set`](#method.set) except the key is a `u32`, which is slightly faster. - #[wasm_bindgen(static_method_of = Reflect, js_name = "set", catch)] - pub fn set_u32(target: &JsValue, property_key: u32, value: &JsValue) -> Result; + /// The same as [`Reflect::set`](#method.set) except the key is a `u32`, which is slightly faster. + #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)] + pub fn set_u32(target: &JsValue, property_key: u32, value: &JsValue) -> Result; - /// The static `Reflect.set()` method works like setting a - /// property on an object. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) - #[wasm_bindgen(static_method_of = Reflect, js_name = set, catch)] - pub fn set_with_receiver( - target: &JsValue, - property_key: &JsValue, - value: &JsValue, - receiver: &JsValue, - ) -> Result; + /// The static `Reflect.set()` method works like setting a + /// property on an object. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) + #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)] + pub fn set_with_receiver( + target: &JsValue, + property_key: &JsValue, + value: &JsValue, + receiver: &JsValue, + ) -> Result; - /// The static `Reflect.setPrototypeOf()` method is the same - /// method as `Object.setPrototypeOf()`. It sets the prototype - /// (i.e., the internal `[[Prototype]]` property) of a specified - /// object to another object or to null. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf) - #[wasm_bindgen(static_method_of = Reflect, js_name = setPrototypeOf, catch)] - pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result; + /// The static `Reflect.setPrototypeOf()` method is the same + /// method as `Object.setPrototypeOf()`. It sets the prototype + /// (i.e., the internal `[[Prototype]]` property) of a specified + /// object to another object or to null. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf) + #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)] + pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result; + } } // RegExp diff --git a/crates/js-sys/tests/wasm/Reflect.rs b/crates/js-sys/tests/wasm/Reflect.rs index c9243c3d..564a4d49 100644 --- a/crates/js-sys/tests/wasm/Reflect.rs +++ b/crates/js-sys/tests/wasm/Reflect.rs @@ -229,18 +229,6 @@ fn set_prototype_of() { ); } -#[wasm_bindgen_test] -fn reflect_extends() { - #[wasm_bindgen] - extern "C" { - #[wasm_bindgen(js_name = Reflect)] - static reflect: Reflect; - } - - assert!(reflect.is_instance_of::()); - let _: &Object = reflect.as_ref(); -} - #[wasm_bindgen_test] fn reflect_bindings_handle_proxies_that_just_throw_for_everything() { let p = throw_all_the_time();