mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-07-31 03:51:56 +00:00
feat: add Reflect.deleteProperty
This commit is contained in:
@@ -203,4 +203,52 @@ fn define_property() {
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_property() {
|
||||
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 delete_property(target: &JsValue, property_key: &JsValue) -> JsValue {
|
||||
let result = js::Reflect::delete_property(target, property_key);
|
||||
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
|
||||
};
|
||||
|
||||
wasm.delete_property(object, 'property');
|
||||
|
||||
assert.equal(object.property, undefined);
|
||||
|
||||
const array = [1, 2, 3, 4, 5];
|
||||
wasm.delete_property(array, 3);
|
||||
|
||||
assert.equal(array[3], undefined);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
Reference in New Issue
Block a user