Transform Reflect into a namespace

This commit is contained in:
Ingvar Stepanyan
2019-04-13 02:11:44 +01:00
parent fe939bc911
commit 75c2971ab9
2 changed files with 139 additions and 150 deletions

View File

@ -2233,18 +2233,18 @@ extern "C" {
pub fn new(message: &str) -> ReferenceError;
}
#[allow(non_snake_case)]
pub mod Reflect {
use super::*;
// Reflect
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type Reflect;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, catch)]
pub fn apply(
target: &Function,
this_argument: &JsValue,
@ -2256,7 +2256,7 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, catch)]
pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>;
/// The static `Reflect.construct()` method acts like the new operator, but
@ -2264,7 +2264,7 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
pub fn construct_with_new_target(
target: &Function,
arguments_list: &Array,
@ -2275,7 +2275,7 @@ extern "C" {
/// `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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
pub fn define_property(
target: &Object,
property_key: &JsValue,
@ -2286,22 +2286,22 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, catch)]
pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
/// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
@ -2309,7 +2309,7 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
pub fn get_own_property_descriptor(
target: &Object,
property_key: &JsValue,
@ -2321,14 +2321,14 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, catch)]
pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
/// The static `Reflect.isExtensible()` method determines if an object is
@ -2336,14 +2336,14 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
pub fn is_extensible(target: &Object) -> Result<bool, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
/// The static `Reflect.preventExtensions()` method prevents new
@ -2352,29 +2352,29 @@ extern "C" {
/// `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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, catch)]
pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result<bool, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
pub fn set_f64(target: &JsValue, property_key: f64, value: &JsValue) -> Result<bool, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
pub fn set_u32(target: &JsValue, property_key: u32, value: &JsValue) -> Result<bool, JsValue>;
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
pub fn set_with_receiver(
target: &JsValue,
property_key: &JsValue,
@ -2388,9 +2388,10 @@ extern "C" {
/// 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)]
#[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>;
}
}
// RegExp
#[wasm_bindgen]

View File

@ -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::<Object>());
let _: &Object = reflect.as_ref();
}
#[wasm_bindgen_test]
fn reflect_bindings_handle_proxies_that_just_throw_for_everything() {
let p = throw_all_the_time();