mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 17:51:33 +00:00
feat: add Reflect.ownKeys
This commit is contained in:
@ -1041,7 +1041,7 @@ extern "C" {
|
|||||||
///
|
///
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has
|
||||||
#[wasm_bindgen(static_method_of = Reflect, catch)]
|
#[wasm_bindgen(static_method_of = Reflect, catch)]
|
||||||
pub fn has(target: &JsValue, property_key: &JsValue) -> Result<JsValue, JsValue>;
|
pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
|
||||||
|
|
||||||
/// The static Reflect.isExtensible() method determines if an object is extensible
|
/// The static Reflect.isExtensible() method determines if an object is extensible
|
||||||
/// (whether it can have new properties added to it). It is similar to
|
/// (whether it can have new properties added to it). It is similar to
|
||||||
@ -1050,6 +1050,13 @@ extern "C" {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible
|
/// 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(static_method_of = Reflect, js_name = isExtensible, catch)]
|
||||||
pub fn is_extensible(target: &Object) -> Result<JsValue, JsValue>;
|
pub fn is_extensible(target: &Object) -> Result<JsValue, JsValue>;
|
||||||
|
|
||||||
|
/// The static Reflect.ownKeys() method returns an array of the
|
||||||
|
/// target object's own property keys.
|
||||||
|
///
|
||||||
|
/// 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: &Object) -> Result<JsValue, JsValue>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
|
@ -484,3 +484,48 @@ fn is_extensible() {
|
|||||||
)
|
)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn own_keys() {
|
||||||
|
project()
|
||||||
|
.file(
|
||||||
|
"src/lib.rs",
|
||||||
|
r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn own_keys(target: &js::Object) -> JsValue {
|
||||||
|
let result = js::Reflect::own_keys(target);
|
||||||
|
let result = match result {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_err) => "TypeError".into()
|
||||||
|
};
|
||||||
|
result
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"test.ts",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
const object = {
|
||||||
|
property: 42
|
||||||
|
};
|
||||||
|
const array: number[] = [];
|
||||||
|
|
||||||
|
assert.equal(wasm.own_keys(object)[0], "property");
|
||||||
|
assert.equal(wasm.own_keys(array)[0], "length");
|
||||||
|
|
||||||
|
assert.equal(wasm.own_keys(""), "TypeError");
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
Reference in New Issue
Block a user