mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
js: Add bindings to Object.keys
This commit is contained in:
parent
21fa3beabd
commit
eb04d15a65
@ -293,6 +293,13 @@ extern {
|
||||
#[wasm_bindgen(method, js_name = isPrototypeOf)]
|
||||
pub fn is_prototype_of(this: &Object, value: &JsValue) -> bool;
|
||||
|
||||
/// The Object.keys() method returns an array of a given object's property
|
||||
/// names, in the same order as we get with a normal loop.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
|
||||
#[wasm_bindgen(static_method_of = Object)]
|
||||
pub fn keys(object: &Object) -> Array;
|
||||
|
||||
/// The Object constructor creates an object wrapper.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||
|
@ -123,6 +123,33 @@ fn is_prototype_of() {
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn 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 keys(obj: &js::Object) -> js::Array {
|
||||
js::Object::keys(obj)
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const obj = { a: 1, b: 2, c: 3 };
|
||||
assert.deepStrictEqual(wasm.keys(obj), ["a", "b", "c"]);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn property_is_enumerable() {
|
||||
project()
|
||||
|
Loading…
x
Reference in New Issue
Block a user