feat: add Reflect.deleteProperty

This commit is contained in:
Jannik Keye
2018-07-04 12:24:52 +02:00
parent 07a726b9dc
commit 5fa18f8f40
2 changed files with 56 additions and 1 deletions

View File

@@ -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()
}