implements Object.preventExtensions() binding (#364)

This commit is contained in:
Marcin Baraniecki 2018-07-02 17:31:40 +02:00 committed by Alex Crichton
parent 10ffe8b3be
commit 37fc159061
2 changed files with 41 additions and 0 deletions

View File

@ -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.
///

View File

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