diff --git a/src/js.rs b/src/js.rs index 9ed038c1..fcf9bc85 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1042,6 +1042,14 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has #[wasm_bindgen(static_method_of = Reflect, catch)] pub fn has(target: &JsValue, property_key: &JsValue) -> Result; + + /// The static Reflect.isExtensible() method determines if an object is extensible + /// (whether it can have new properties added to it). It is similar to + /// Object.isExtensible(), but with some differences. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible + #[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible, catch)] + pub fn is_extensible(target: &Object) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 9e572877..50ee68d8 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -433,4 +433,54 @@ fn has() { "#, ) .test() +} + +#[test] +fn is_extensible() { + 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 is_extensible(target: &js::Object) -> JsValue { + let result = js::Reflect::is_extensible(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 + }; + + assert.equal(wasm.is_extensible(object), true); + + Reflect.preventExtensions(object); + + assert.equal(wasm.is_extensible(object), false); + + const object2 = Object.seal({}); + + assert.equal(wasm.is_extensible(object2), false); + assert.equal(wasm.is_extensible(""), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file