mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-24 18:43:33 +03:00
implements Object.preventExtensions() binding (#364)
This commit is contained in:
parent
10ffe8b3be
commit
37fc159061
@ -790,6 +790,14 @@ extern "C" {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new() -> Object;
|
||||
|
||||
/// The Object.preventExtensions() method prevents
|
||||
/// new properties from ever being added to an object
|
||||
/// (i.e. prevents future extensions to the object).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions
|
||||
#[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
|
||||
pub fn prevent_extensions(object: &Object);
|
||||
|
||||
/// The propertyIsEnumerable() method returns a Boolean indicating
|
||||
/// whether the specified property is enumerable.
|
||||
///
|
||||
|
@ -180,6 +180,39 @@ fn 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(obj: &js::Object) {
|
||||
js::Object::prevent_extensions(obj);
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const object = {};
|
||||
wasm.prevent_extensions(object);
|
||||
|
||||
assert(!Object.isExtensible(object));
|
||||
assert.throws(() => {
|
||||
'use strict';
|
||||
Object.defineProperty(object, 'foo', { value: 42 });
|
||||
}, TypeError);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn property_is_enumerable() {
|
||||
project()
|
||||
|
Loading…
Reference in New Issue
Block a user