mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-25 11:41:21 +00:00
feat: add Reflect.preventExtensions
This commit is contained in:
parent
e36f982391
commit
fc82ba4ec3
@ -1057,6 +1057,15 @@ extern "C" {
|
||||
/// 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>;
|
||||
|
||||
/// The static Reflect.preventExtensions() method prevents new
|
||||
/// properties from ever being added to an object (i.e. prevents
|
||||
/// future extensions to the object). It is similar to
|
||||
/// Object.preventExtensions(), but with some differences.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions
|
||||
#[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions, catch)]
|
||||
pub fn prevent_extensions(target: &Object) -> Result<JsValue, JsValue>;
|
||||
}
|
||||
|
||||
// Set
|
||||
|
@ -529,3 +529,44 @@ fn own_keys() {
|
||||
)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prevent_extensions() {
|
||||
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 prevent_extensions(target: &js::Object) -> JsValue {
|
||||
let result = js::Reflect::prevent_extensions(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() {
|
||||
var object1 = {};
|
||||
|
||||
wasm.prevent_extensions(object1);
|
||||
|
||||
assert.equal(Reflect.isExtensible(object1), false);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user