Logo
Explore Help
Sign In
fluencelabs/wasm-bindgen
1
0
Fork 0
You've already forked wasm-bindgen
mirror of https://github.com/fluencelabs/wasm-bindgen synced 2025-05-08 20:12:16 +00:00
Code Issues Projects Releases Wiki Activity
wasm-bindgen/crates/webidl-tests/dictionary.js

23 lines
504 B
JavaScript
Raw Normal View History

Implement support for WebIDL dictionaries This commit adds support for generating bindings for dictionaries defined in WebIDL. Dictionaries are associative arrays which are simply objects in JS with named keys and some values. In Rust given a dictionary like: dictionary Foo { long field; }; we'll generate a struct like: pub struct Foo { obj: js_sys::Object, } impl Foo { pub fn new() -> Foo { /* make a blank object */ } pub fn field(&mut self, val: i32) -> &mut Self { // set the field using `js_sys::Reflect` } } // plus a bunch of AsRef, From, and wasm abi impls At the same time this adds support for partial dictionaries and dictionary inheritance. All dictionary fields are optional by default and hence only have builder-style setters, but dictionaries can also have required fields. Required fields are exposed as arguments to the `new` constructor. Closes #241
2018-08-14 10:16:18 -07:00
const assert = require('assert');
global.assert_dict_c = function(c) {
assert.strictEqual(c.a, 1);
assert.strictEqual(c.b, 2);
assert.strictEqual(c.c, 3);
assert.strictEqual(c.d, 4);
assert.strictEqual(c.e, 5);
assert.strictEqual(c.f, 6);
assert.strictEqual(c.g, 7);
assert.strictEqual(c.h, 8);
};
global.mk_dict_a = function() {
return {};
};
global.assert_dict_required = function(c) {
assert.strictEqual(c.a, 3);
assert.strictEqual(c.b, "a");
assert.strictEqual(c.c, 4);
};
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.7 Page: 112ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API