Skip to content

Commit 75c2971

Browse files
committed
Transform Reflect into a namespace
1 parent fe939bc commit 75c2971

File tree

2 files changed

+147
-158
lines changed

2 files changed

+147
-158
lines changed

crates/js-sys/src/lib.rs

Lines changed: 147 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,163 +2233,164 @@ extern "C" {
22332233
pub fn new(message: &str) -> ReferenceError;
22342234
}
22352235

2236-
// Reflect
2237-
#[wasm_bindgen]
2238-
extern "C" {
2239-
#[wasm_bindgen(extends = Object)]
2240-
#[derive(Clone, Debug, PartialEq, Eq)]
2241-
pub type Reflect;
2236+
#[allow(non_snake_case)]
2237+
pub mod Reflect {
2238+
use super::*;
22422239

2243-
/// The static `Reflect.apply()` method calls a target function with
2244-
/// arguments as specified.
2245-
///
2246-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
2247-
#[wasm_bindgen(static_method_of = Reflect, catch)]
2248-
pub fn apply(
2249-
target: &Function,
2250-
this_argument: &JsValue,
2251-
arguments_list: &Array,
2252-
) -> Result<JsValue, JsValue>;
2240+
// Reflect
2241+
#[wasm_bindgen]
2242+
extern "C" {
2243+
/// The static `Reflect.apply()` method calls a target function with
2244+
/// arguments as specified.
2245+
///
2246+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
2247+
#[wasm_bindgen(js_namespace = Reflect, catch)]
2248+
pub fn apply(
2249+
target: &Function,
2250+
this_argument: &JsValue,
2251+
arguments_list: &Array,
2252+
) -> Result<JsValue, JsValue>;
2253+
2254+
/// The static `Reflect.construct()` method acts like the new operator, but
2255+
/// as a function. It is equivalent to calling `new target(...args)`. It
2256+
/// gives also the added option to specify a different prototype.
2257+
///
2258+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
2259+
#[wasm_bindgen(js_namespace = Reflect, catch)]
2260+
pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>;
22532261

2254-
/// The static `Reflect.construct()` method acts like the new operator, but
2255-
/// as a function. It is equivalent to calling `new target(...args)`. It
2256-
/// gives also the added option to specify a different prototype.
2257-
///
2258-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
2259-
#[wasm_bindgen(static_method_of = Reflect, catch)]
2260-
pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>;
2262+
/// The static `Reflect.construct()` method acts like the new operator, but
2263+
/// as a function. It is equivalent to calling `new target(...args)`. It
2264+
/// gives also the added option to specify a different prototype.
2265+
///
2266+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
2267+
#[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
2268+
pub fn construct_with_new_target(
2269+
target: &Function,
2270+
arguments_list: &Array,
2271+
new_target: &Function,
2272+
) -> Result<JsValue, JsValue>;
2273+
2274+
/// The static `Reflect.defineProperty()` method is like
2275+
/// `Object.defineProperty()` but returns a `Boolean`.
2276+
///
2277+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
2278+
#[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
2279+
pub fn define_property(
2280+
target: &Object,
2281+
property_key: &JsValue,
2282+
attributes: &Object,
2283+
) -> Result<bool, JsValue>;
2284+
2285+
/// The static `Reflect.deleteProperty()` method allows to delete
2286+
/// properties. It is like the `delete` operator as a function.
2287+
///
2288+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
2289+
#[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
2290+
pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>;
22612291

2262-
/// The static `Reflect.construct()` method acts like the new operator, but
2263-
/// as a function. It is equivalent to calling `new target(...args)`. It
2264-
/// gives also the added option to specify a different prototype.
2265-
///
2266-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
2267-
#[wasm_bindgen(static_method_of = Reflect, js_name = construct, catch)]
2268-
pub fn construct_with_new_target(
2269-
target: &Function,
2270-
arguments_list: &Array,
2271-
new_target: &Function,
2272-
) -> Result<JsValue, JsValue>;
2292+
/// The static `Reflect.get()` method works like getting a property from
2293+
/// an object (`target[propertyKey]`) as a function.
2294+
///
2295+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
2296+
#[wasm_bindgen(js_namespace = Reflect, catch)]
2297+
pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
22732298

2274-
/// The static `Reflect.defineProperty()` method is like
2275-
/// `Object.defineProperty()` but returns a `Boolean`.
2276-
///
2277-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
2278-
#[wasm_bindgen(static_method_of = Reflect, js_name = defineProperty, catch)]
2279-
pub fn define_property(
2280-
target: &Object,
2281-
property_key: &JsValue,
2282-
attributes: &Object,
2283-
) -> Result<bool, JsValue>;
2299+
/// The same as [`Reflect::get`](#method.get) except the key is an `f64`, which is slightly faster.
2300+
#[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
2301+
pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
22842302

2285-
/// The static `Reflect.deleteProperty()` method allows to delete
2286-
/// properties. It is like the `delete` operator as a function.
2287-
///
2288-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
2289-
#[wasm_bindgen(static_method_of = Reflect, js_name = deleteProperty, catch)]
2290-
pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>;
2303+
/// The same as [`Reflect::get`](#method.get) except the key is a `u32`, which is slightly faster.
2304+
#[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
2305+
pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
22912306

2292-
/// The static `Reflect.get()` method works like getting a property from
2293-
/// an object (`target[propertyKey]`) as a function.
2294-
///
2295-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
2296-
#[wasm_bindgen(static_method_of = Reflect, catch)]
2297-
pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
2307+
/// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
2308+
/// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
2309+
/// of the given property if it exists on the object, `undefined` otherwise.
2310+
///
2311+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
2312+
#[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
2313+
pub fn get_own_property_descriptor(
2314+
target: &Object,
2315+
property_key: &JsValue,
2316+
) -> Result<JsValue, JsValue>;
2317+
2318+
/// The static `Reflect.getPrototypeOf()` method is almost the same
2319+
/// method as `Object.getPrototypeOf()`. It returns the prototype
2320+
/// (i.e. the value of the internal `[[Prototype]]` property) of
2321+
/// the specified object.
2322+
///
2323+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
2324+
#[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
2325+
pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
22982326

2299-
/// The same as [`Reflect::get`](#method.get) except the key is an `f64`, which is slightly faster.
2300-
#[wasm_bindgen(static_method_of = Reflect, js_name = "get", catch)]
2301-
pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
2327+
/// The static `Reflect.has()` method works like the in operator as a
2328+
/// function.
2329+
///
2330+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
2331+
#[wasm_bindgen(js_namespace = Reflect, catch)]
2332+
pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
23022333

2303-
/// The same as [`Reflect::get`](#method.get) except the key is a `u32`, which is slightly faster.
2304-
#[wasm_bindgen(static_method_of = Reflect, js_name = "get", catch)]
2305-
pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
2334+
/// The static `Reflect.isExtensible()` method determines if an object is
2335+
/// extensible (whether it can have new properties added to it). It is
2336+
/// similar to `Object.isExtensible()`, but with some differences.
2337+
///
2338+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
2339+
#[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
2340+
pub fn is_extensible(target: &Object) -> Result<bool, JsValue>;
23062341

2307-
/// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
2308-
/// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
2309-
/// of the given property if it exists on the object, `undefined` otherwise.
2310-
///
2311-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
2312-
#[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)]
2313-
pub fn get_own_property_descriptor(
2314-
target: &Object,
2315-
property_key: &JsValue,
2316-
) -> Result<JsValue, JsValue>;
2342+
/// The static `Reflect.ownKeys()` method returns an array of the
2343+
/// target object's own property keys.
2344+
///
2345+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
2346+
#[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
2347+
pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
2348+
2349+
/// The static `Reflect.preventExtensions()` method prevents new
2350+
/// properties from ever being added to an object (i.e. prevents
2351+
/// future extensions to the object). It is similar to
2352+
/// `Object.preventExtensions()`, but with some differences.
2353+
///
2354+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
2355+
#[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
2356+
pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>;
23172357

2318-
/// The static `Reflect.getPrototypeOf()` method is almost the same
2319-
/// method as `Object.getPrototypeOf()`. It returns the prototype
2320-
/// (i.e. the value of the internal `[[Prototype]]` property) of
2321-
/// the specified object.
2322-
///
2323-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
2324-
#[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf, catch)]
2325-
pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
2358+
/// The static `Reflect.set()` method works like setting a
2359+
/// property on an object.
2360+
///
2361+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
2362+
#[wasm_bindgen(js_namespace = Reflect, catch)]
2363+
pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result<bool, JsValue>;
23262364

2327-
/// The static `Reflect.has()` method works like the in operator as a
2328-
/// function.
2329-
///
2330-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
2331-
#[wasm_bindgen(static_method_of = Reflect, catch)]
2332-
pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
2333-
2334-
/// The static `Reflect.isExtensible()` method determines if an object is
2335-
/// extensible (whether it can have new properties added to it). It is
2336-
/// similar to `Object.isExtensible()`, but with some differences.
2337-
///
2338-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
2339-
#[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible, catch)]
2340-
pub fn is_extensible(target: &Object) -> Result<bool, JsValue>;
2341-
2342-
/// The static `Reflect.ownKeys()` method returns an array of the
2343-
/// target object's own property keys.
2344-
///
2345-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
2346-
#[wasm_bindgen(static_method_of = Reflect, js_name = ownKeys, catch)]
2347-
pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
2348-
2349-
/// The static `Reflect.preventExtensions()` method prevents new
2350-
/// properties from ever being added to an object (i.e. prevents
2351-
/// future extensions to the object). It is similar to
2352-
/// `Object.preventExtensions()`, but with some differences.
2353-
///
2354-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
2355-
#[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions, catch)]
2356-
pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>;
2357-
2358-
/// The static `Reflect.set()` method works like setting a
2359-
/// property on an object.
2360-
///
2361-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
2362-
#[wasm_bindgen(static_method_of = Reflect, catch)]
2363-
pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result<bool, JsValue>;
2364-
2365-
/// The same as [`Reflect::set`](#method.set) except the key is an `f64`, which is slightly faster.
2366-
#[wasm_bindgen(static_method_of = Reflect, js_name = "set", catch)]
2367-
pub fn set_f64(target: &JsValue, property_key: f64, value: &JsValue) -> Result<bool, JsValue>;
2368-
2369-
/// The same as [`Reflect::set`](#method.set) except the key is a `u32`, which is slightly faster.
2370-
#[wasm_bindgen(static_method_of = Reflect, js_name = "set", catch)]
2371-
pub fn set_u32(target: &JsValue, property_key: u32, value: &JsValue) -> Result<bool, JsValue>;
2372-
2373-
/// The static `Reflect.set()` method works like setting a
2374-
/// property on an object.
2375-
///
2376-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
2377-
#[wasm_bindgen(static_method_of = Reflect, js_name = set, catch)]
2378-
pub fn set_with_receiver(
2379-
target: &JsValue,
2380-
property_key: &JsValue,
2381-
value: &JsValue,
2382-
receiver: &JsValue,
2383-
) -> Result<bool, JsValue>;
2384-
2385-
/// The static `Reflect.setPrototypeOf()` method is the same
2386-
/// method as `Object.setPrototypeOf()`. It sets the prototype
2387-
/// (i.e., the internal `[[Prototype]]` property) of a specified
2388-
/// object to another object or to null.
2389-
///
2390-
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
2391-
#[wasm_bindgen(static_method_of = Reflect, js_name = setPrototypeOf, catch)]
2392-
pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>;
2365+
/// The same as [`Reflect::set`](#method.set) except the key is an `f64`, which is slightly faster.
2366+
#[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
2367+
pub fn set_f64(target: &JsValue, property_key: f64, value: &JsValue) -> Result<bool, JsValue>;
2368+
2369+
/// The same as [`Reflect::set`](#method.set) except the key is a `u32`, which is slightly faster.
2370+
#[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
2371+
pub fn set_u32(target: &JsValue, property_key: u32, value: &JsValue) -> Result<bool, JsValue>;
2372+
2373+
/// The static `Reflect.set()` method works like setting a
2374+
/// property on an object.
2375+
///
2376+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
2377+
#[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
2378+
pub fn set_with_receiver(
2379+
target: &JsValue,
2380+
property_key: &JsValue,
2381+
value: &JsValue,
2382+
receiver: &JsValue,
2383+
) -> Result<bool, JsValue>;
2384+
2385+
/// The static `Reflect.setPrototypeOf()` method is the same
2386+
/// method as `Object.setPrototypeOf()`. It sets the prototype
2387+
/// (i.e., the internal `[[Prototype]]` property) of a specified
2388+
/// object to another object or to null.
2389+
///
2390+
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
2391+
#[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
2392+
pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>;
2393+
}
23932394
}
23942395

23952396
// RegExp

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,6 @@ fn set_prototype_of() {
229229
);
230230
}
231231

232-
#[wasm_bindgen_test]
233-
fn reflect_extends() {
234-
#[wasm_bindgen]
235-
extern "C" {
236-
#[wasm_bindgen(js_name = Reflect)]
237-
static reflect: Reflect;
238-
}
239-
240-
assert!(reflect.is_instance_of::<Object>());
241-
let _: &Object = reflect.as_ref();
242-
}
243-
244232
#[wasm_bindgen_test]
245233
fn reflect_bindings_handle_proxies_that_just_throw_for_everything() {
246234
let p = throw_all_the_time();

0 commit comments

Comments
 (0)