Skip to main content

atmos/os_lib/web_apis/builtins/
wasm_api.rs

1// WebAssembly の JS API の土台(`__wasm` の関数群)。名前空間 `WebAssembly` 自体は `prelude/wasm.js` が組み立てる。
2//
3// 【2026-11-04】WebAssembly は丸ごと無かった(YouTube のページが window.WebAssembly を探して見つからなかった。TODO B0)。
4// 失敗は `{ __wasmErr: 種類, message }` を返し、prelude が CompileError / LinkError / RuntimeError にして投げる。
5// 取り込みの JS 関数が投げた例外はそのまま伝える。
6//
7// 再入: WASM から JS の取り込みを呼ぶ間は store を `WasmState` に戻しておく(JS の中から `memory.buffer` を読んだり
8// 別の書き出しを呼んだりできるように)。呼び出しの間だけ store を取り出す(`take_store`/`put_store`)。
9use super::*;
10
11use crate::os_lib::wasm::decode::{decode, ExportDesc, GlobalType, ImportDesc, Limits, Module, ValType};
12use crate::os_lib::wasm::exec::{Extern, Host, Store, Trap, Val};
13
14#[derive(Default)]
15pub struct WasmState {
16    pub store: Store,
17    pub modules: Vec<Rc<Module>>,
18    /// 取り込みの JS 関数(`FuncInst::Host` の id で引く)。
19    pub host_funcs: Vec<Value>,
20    /// externref の値(id で引く)。
21    pub externs: Vec<Value>,
22}
23
24fn err_obj(kind: &str, msg: &str) -> Value {
25    let o = Obj::plain();
26    {
27        let mut b = o.borrow_mut();
28        b.props.insert("__wasmErr".into(), Value::str(kind));
29        b.props.insert("message".into(), Value::str(msg));
30    }
31    Value::Object(o)
32}
33
34fn kind_name(d: &ImportDesc) -> &'static str {
35    match d {
36        ImportDesc::Func(_) => "function",
37        ImportDesc::Table(_) => "table",
38        ImportDesc::Memory(_) => "memory",
39        ImportDesc::Global(_) => "global",
40    }
41}
42
43fn valtype_of(s: &str) -> Option<ValType> {
44    Some(match s {
45        "i32" => ValType::I32,
46        "i64" => ValType::I64,
47        "f32" => ValType::F32,
48        "f64" => ValType::F64,
49        "anyfunc" | "funcref" => ValType::FuncRef,
50        "externref" => ValType::ExternRef,
51        _ => return None,
52    })
53}
54
55fn valtype_name(t: ValType) -> &'static str {
56    match t {
57        ValType::I32 => "i32",
58        ValType::I64 => "i64",
59        ValType::F32 => "f32",
60        ValType::F64 => "f64",
61        ValType::FuncRef => "anyfunc",
62        ValType::ExternRef => "externref",
63    }
64}
65
66/// バイト列(ArrayBuffer・TypedArray・DataView・配列)を取り出す。
67fn bytes_of(it: &mut Interp, v: &Value) -> Option<Vec<u8>> {
68    let Value::Object(o) = v else { return None };
69    if let ObjKind::Bytes(st) = &o.borrow().kind {
70        let es = st.elem_size();
71        let all = st.buf.borrow();
72        return all.get(st.off..st.off + st.len * es).map(|s| s.to_vec());
73    }
74    if let Some(root) = crate::os_lib::ecma::builtins::typed_array::ensure_buffer_root(it, o) {
75        if let ObjKind::Bytes(st) = &root.borrow().kind {
76            return Some(st.to_vec());
77        }
78    }
79    let items = it.iter_to_vec(v).unwrap_or_default();
80    Some(items.iter().map(|x| x.to_number() as i64 as u8).collect())
81}
82
83/// JS の値 → WASM の値(型 `t`)。
84fn to_wasm(st: &mut WasmState, v: &Value, t: ValType) -> Val {
85    match t {
86        ValType::I32 => Val::I32(crate::os_lib::ecma::interp::to_i32(v.to_number())),
87        ValType::I64 => Val::I64(match v {
88            Value::BigInt(b) => b.to_u64_truncated() as i64,
89            other => crate::os_lib::ecma::bigint::BigInt::from_f64(libm::trunc(other.to_number()))
90                .map(|b| b.to_u64_truncated() as i64)
91                .unwrap_or(0),
92        }),
93        ValType::F32 => Val::F32(v.to_number() as f32),
94        ValType::F64 => Val::F64(v.to_number()),
95        ValType::FuncRef => Val::FuncRef(match v {
96            Value::Object(o) => o.borrow().props.get("_wasmFuncAddr").map(|a| a.to_number() as u32),
97            _ => None,
98        }),
99        ValType::ExternRef => match v {
100            Value::Null => Val::ExternRef(None),
101            other => {
102                st.externs.push(other.clone());
103                Val::ExternRef(Some((st.externs.len() - 1) as u32))
104            }
105        },
106    }
107}
108
109/// WASM の値 → JS の値。funcref は `{ _wasmFuncRef: addr }`(prelude が関数にする)。
110fn from_wasm(st: &WasmState, v: Val) -> Value {
111    match v {
112        Val::I32(x) => Value::Number(x as f64),
113        Val::I64(x) => Value::bigint(crate::os_lib::ecma::bigint::BigInt::from_i64(x)),
114        Val::F32(x) => Value::Number(x as f64),
115        Val::F64(x) => Value::Number(x),
116        Val::FuncRef(None) | Val::ExternRef(None) => Value::Null,
117        Val::FuncRef(Some(a)) => {
118            let o = Obj::plain();
119            o.borrow_mut().props.insert("_wasmFuncRef".into(), Value::Number(a as f64));
120            Value::Object(o)
121        }
122        Val::ExternRef(Some(id)) => st.externs.get(id as usize).cloned().unwrap_or(Value::Undefined),
123    }
124}
125
126fn take_store(it: &Interp) -> Store {
127    core::mem::take(&mut it.wasm().borrow_mut().store)
128}
129
130fn put_store(it: &Interp, s: Store) {
131    it.wasm().borrow_mut().store = s;
132}
133
134/// WASM から JS の取り込み関数を呼ぶ。JS が投げた例外は `pending` に預けて `Trap::Host` で戻す。
135struct JsHost<'a> {
136    it: &'a mut Interp,
137    pending: Option<Value>,
138}
139
140impl Host for JsHost<'_> {
141    fn call(&mut self, store: &mut Store, id: u32, args: &[Val]) -> Result<Vec<Val>, Trap> {
142        let f = {
143            let w = self.it.wasm().borrow();
144            w.host_funcs.get(id as usize).cloned().unwrap_or(Value::Undefined)
145        };
146        let ty = store
147            .funcs
148            .iter()
149            .find_map(|fi| match fi {
150                crate::os_lib::wasm::exec::FuncInst::Host { ty, id: hid } if *hid == id => Some(ty.clone()),
151                _ => None,
152            })
153            .unwrap_or(crate::os_lib::wasm::decode::FuncType { params: Vec::new(), results: Vec::new() });
154        let js_args: Vec<Value> = {
155            let w = self.it.wasm().borrow();
156            args.iter().map(|a| from_wasm(&w, *a)).collect()
157        };
158        // JS の間は store を戻しておく(再入できるように)。
159        core::mem::swap(store, &mut self.it.wasm().borrow_mut().store);
160        let r = self.it.call_value(&f, Value::Undefined, &js_args);
161        core::mem::swap(store, &mut self.it.wasm().borrow_mut().store);
162        let v = match r {
163            Ok(v) => v,
164            Err(e) => {
165                self.pending = Some(e);
166                return Err(Trap::Host(id));
167            }
168        };
169        let mut w = self.it.wasm().borrow_mut();
170        Ok(match ty.results.len() {
171            0 => Vec::new(),
172            1 => alloc::vec![to_wasm(&mut w, &v, ty.results[0])],
173            _ => {
174                drop(w);
175                let items = self.it.iter_to_vec(&v).unwrap_or_default();
176                let mut w = self.it.wasm().borrow_mut();
177                ty.results.iter().enumerate().map(|(i, t)| to_wasm(&mut w, items.get(i).unwrap_or(&Value::Undefined), *t)).collect()
178            }
179        })
180    }
181}
182
183/// `__wasm.validate(bytes)`。
184pub(crate) fn wasm_validate(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
185    let Some(b) = bytes_of(it, &arg(a, 0)) else {
186        return Ok(Value::Bool(false));
187    };
188    Ok(Value::Bool(decode(&b).is_ok()))
189}
190
191/// `__wasm.compile(bytes)` → モジュールの番号。
192pub(crate) fn wasm_compile(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
193    let Some(b) = bytes_of(it, &arg(a, 0)) else {
194        return Ok(err_obj("TypeError", "WebAssembly.Module(): Argument 0 must be a buffer source"));
195    };
196    match decode(&b) {
197        Ok(m) => {
198            let mut w = it.wasm().borrow_mut();
199            w.modules.push(Rc::new(m));
200            Ok(Value::Number((w.modules.len() - 1) as f64))
201        }
202        Err(e) => Ok(err_obj("CompileError", &alloc::format!("WebAssembly.Module(): {}", e.0))),
203    }
204}
205
206fn module_of(it: &Interp, v: &Value) -> Option<Rc<Module>> {
207    it.wasm().borrow().modules.get(v.to_number() as usize).cloned()
208}
209
210/// `__wasm.imports(id)` → `[[module, name, kind], ...]`。
211pub(crate) fn wasm_imports(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
212    let Some(m) = module_of(it, &arg(a, 0)) else { return Ok(Value::Object(Obj::array(Vec::new()))) };
213    let rows = m
214        .imports
215        .iter()
216        .map(|i| Value::Object(Obj::array(alloc::vec![Value::str(&i.module), Value::str(&i.name), Value::str(kind_name(&i.desc))])))
217        .collect();
218    Ok(Value::Object(Obj::array(rows)))
219}
220
221/// `__wasm.exports(id)` → `[[name, kind], ...]`。
222pub(crate) fn wasm_exports(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
223    let Some(m) = module_of(it, &arg(a, 0)) else { return Ok(Value::Object(Obj::array(Vec::new()))) };
224    let rows = m
225        .exports
226        .iter()
227        .map(|e| {
228            let k = match e.desc {
229                ExportDesc::Func(_) => "function",
230                ExportDesc::Table(_) => "table",
231                ExportDesc::Memory(_) => "memory",
232                ExportDesc::Global(_) => "global",
233            };
234            Value::Object(Obj::array(alloc::vec![Value::str(&e.name), Value::str(k)]))
235        })
236        .collect();
237    Ok(Value::Object(Obj::array(rows)))
238}
239
240fn prop_addr(v: &Value, key: &str) -> Option<u32> {
241    match v {
242        Value::Object(o) => o.borrow().props.get(key).map(|a| a.to_number() as u32),
243        _ => None,
244    }
245}
246
247/// `__wasm.instantiate(id, imports)`。`imports` はモジュールの取り込みの順に並んだ JS の値。
248/// 戻り値は `[[name, kind, addr], ...]`(失敗は `{__wasmErr}`)。
249pub(crate) fn wasm_instantiate(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
250    let Some(m) = module_of(it, &arg(a, 0)) else { return Ok(err_obj("TypeError", "unknown module")) };
251    let given = it.iter_to_vec(&arg(a, 1)).unwrap_or_default();
252    let mut externs = Vec::new();
253    for (i, imp) in m.imports.iter().enumerate() {
254        let v = given.get(i).cloned().unwrap_or(Value::Undefined);
255        let what = alloc::format!("Import #{} \"{}\" \"{}\"", i, imp.module, imp.name);
256        let e = match &imp.desc {
257            ImportDesc::Func(t) => {
258                if let Some(addr) = prop_addr(&v, "_wasmFuncAddr") {
259                    Extern::Func(addr)
260                } else if matches!(&v, Value::Object(o) if o.borrow().is_callable()) {
261                    let ty = m.types.get(*t as usize).cloned().unwrap_or(crate::os_lib::wasm::decode::FuncType { params: Vec::new(), results: Vec::new() });
262                    let mut w = it.wasm().borrow_mut();
263                    w.host_funcs.push(v.clone());
264                    let id = (w.host_funcs.len() - 1) as u32;
265                    Extern::Func(w.store.alloc_host_func(ty, id))
266                } else {
267                    return Ok(err_obj("LinkError", &alloc::format!("WebAssembly.Instance(): {}: function import requires a callable", what)));
268                }
269            }
270            ImportDesc::Memory(_) => match prop_addr(&v, "_wasmMem") {
271                Some(addr) => Extern::Memory(addr),
272                None => return Ok(err_obj("LinkError", &alloc::format!("WebAssembly.Instance(): {}: memory import must be a WebAssembly.Memory object", what))),
273            },
274            ImportDesc::Table(_) => match prop_addr(&v, "_wasmTable") {
275                Some(addr) => Extern::Table(addr),
276                None => return Ok(err_obj("LinkError", &alloc::format!("WebAssembly.Instance(): {}: table import requires a WebAssembly.Table", what))),
277            },
278            ImportDesc::Global(gt) => match prop_addr(&v, "_wasmGlobal") {
279                Some(addr) => Extern::Global(addr),
280                None if !gt.mutable && matches!(&v, Value::Number(_) | Value::BigInt(_)) => {
281                    let mut w = it.wasm().borrow_mut();
282                    let val = to_wasm(&mut w, &v, gt.ty);
283                    Extern::Global(w.store.alloc_global(*gt, val))
284                }
285                None => return Ok(err_obj("LinkError", &alloc::format!("WebAssembly.Instance(): {}: global import must be a number, valid Wasm reference, or WebAssembly.Global object", what))),
286            },
287        };
288        externs.push(e);
289    }
290    let mut store = take_store(it);
291    let mut host = JsHost { it, pending: None };
292    let r = store.instantiate(&mut host, m.clone(), &externs);
293    let pending = host.pending.take();
294    put_store(it, store);
295    let inst = match r {
296        Ok(i) => i,
297        Err(Trap::Host(_)) => return Err(pending.unwrap_or(Value::Undefined)),
298        Err(Trap::Msg(msg)) => {
299            let kind = if msg.contains("import") { "LinkError" } else { "RuntimeError" };
300            return Ok(err_obj(kind, &alloc::format!("WebAssembly.Instance(): {}", msg)));
301        }
302    };
303    let w = it.wasm().borrow();
304    let rows = m
305        .exports
306        .iter()
307        .filter_map(|e| {
308            let (k, addr) = match w.store.export(inst, &e.name)? {
309                Extern::Func(a) => ("function", a),
310                Extern::Table(a) => ("table", a),
311                Extern::Memory(a) => ("memory", a),
312                Extern::Global(a) => ("global", a),
313            };
314            Some(Value::Object(Obj::array(alloc::vec![Value::str(&e.name), Value::str(k), Value::Number(addr as f64)])))
315        })
316        .collect();
317    Ok(Value::Object(Obj::array(rows)))
318}
319
320/// `__wasm.funcArity(addr)` → 引数の数。
321pub(crate) fn wasm_func_arity(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
322    let addr = arg(a, 0).to_number() as u32;
323    let n = it.wasm().borrow().store.func_type(addr).map(|t| t.params.len()).unwrap_or(0);
324    Ok(Value::Number(n as f64))
325}
326
327/// `__wasm.call(addr, args)`。結果が 1 個ならその値、複数なら配列、無ければ undefined。
328pub(crate) fn wasm_call(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
329    let addr = arg(a, 0).to_number() as u32;
330    let js_args = it.iter_to_vec(&arg(a, 1)).unwrap_or_default();
331    let Some(ty) = it.wasm().borrow().store.func_type(addr) else {
332        return Ok(err_obj("RuntimeError", "unknown function"));
333    };
334    let args: Vec<Val> = {
335        let mut w = it.wasm().borrow_mut();
336        ty.params.iter().enumerate().map(|(i, t)| to_wasm(&mut w, js_args.get(i).unwrap_or(&Value::Undefined), *t)).collect()
337    };
338    let mut store = take_store(it);
339    let mut host = JsHost { it, pending: None };
340    let r = store.invoke(&mut host, addr, &args);
341    let pending = host.pending.take();
342    put_store(it, store);
343    match r {
344        Ok(vals) => {
345            let w = it.wasm().borrow();
346            Ok(match vals.len() {
347                0 => Value::Undefined,
348                1 => from_wasm(&w, vals[0]),
349                _ => Value::Object(Obj::array(vals.iter().map(|v| from_wasm(&w, *v)).collect())),
350            })
351        }
352        Err(Trap::Host(_)) => Err(pending.unwrap_or(Value::Undefined)),
353        Err(Trap::Msg(m)) => Ok(err_obj("RuntimeError", &m)),
354    }
355}
356
357fn limits_of(initial: &Value, maximum: &Value) -> Limits {
358    Limits {
359        min: initial.to_number().max(0.0) as u32,
360        max: if matches!(maximum, Value::Undefined | Value::Null) { None } else { Some(maximum.to_number().max(0.0) as u32) },
361    }
362}
363
364/// `__wasm.memNew(initial, maximum)` → メモリの番号。
365pub(crate) fn wasm_mem_new(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
366    let lim = limits_of(&arg(a, 0), &arg(a, 1));
367    if lim.max.is_some_and(|m| m < lim.min) {
368        return Ok(err_obj("RangeError", "WebAssembly.Memory(): Property 'maximum': value is below 'initial'"));
369    }
370    match it.wasm().borrow_mut().store.alloc_memory(lim) {
371        Ok(addr) => Ok(Value::Number(addr as f64)),
372        Err(_) => Ok(err_obj("RangeError", "WebAssembly.Memory(): could not allocate memory")),
373    }
374}
375
376/// `__wasm.memBuffer(addr)` → メモリと記憶域を共有する ArrayBuffer。
377pub(crate) fn wasm_mem_buffer(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
378    let addr = arg(a, 0).to_number() as usize;
379    let Some(data) = it.wasm().borrow().store.mems.get(addr).map(|m| m.data.clone()) else {
380        return Ok(Value::Undefined);
381    };
382    let len = data.borrow().len();
383    let root = crate::os_lib::ecma::builtins::typed_array::raw_store_obj(crate::os_lib::ecma::value::ByteStore { buf: data, off: 0, len, kind: 0 });
384    let ab = Obj::plain();
385    {
386        let mut b = ab.borrow_mut();
387        b.props.insert("byteLength".into(), Value::Number(len as f64));
388        b.props.insert("_bytes".into(), Value::Object(root));
389    }
390    if let Some(Value::Object(ctor)) = it.global.borrow().vars.get("ArrayBuffer").cloned() {
391        if let Some(Value::Object(p)) = ctor.borrow().props.get("prototype").cloned() {
392            ab.borrow_mut().proto = Some(p);
393        }
394    }
395    Ok(Value::Object(ab))
396}
397
398/// `__wasm.memGrow(addr, delta)` → 前のページ数(失敗は -1)。
399pub(crate) fn wasm_mem_grow(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
400    let addr = arg(a, 0).to_number() as u32;
401    let delta = arg(a, 1).to_number().max(0.0) as u32;
402    Ok(Value::Number(it.wasm().borrow_mut().store.grow_memory(addr, delta) as f64))
403}
404
405/// `__wasm.tableNew(element, initial, maximum)` → 表の番号。
406pub(crate) fn wasm_table_new(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
407    let elem = match valtype_of(&arg(a, 0).to_js_string()) {
408        Some(t @ (ValType::FuncRef | ValType::ExternRef)) => t,
409        _ => return Ok(err_obj("TypeError", "WebAssembly.Table(): Descriptor property 'element' must be a WebAssembly reference type")),
410    };
411    let lim = limits_of(&arg(a, 1), &arg(a, 2));
412    Ok(Value::Number(it.wasm().borrow_mut().store.alloc_table(elem, lim) as f64))
413}
414
415/// `__wasm.tableOp(addr, op, i, value)`: op は "length" / "get" / "set" / "grow"。
416pub(crate) fn wasm_table_op(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
417    let addr = arg(a, 0).to_number() as usize;
418    let op = arg(a, 1).to_js_string();
419    let i = arg(a, 2).to_number().max(0.0) as usize;
420    let v = arg(a, 3);
421    let mut w = it.wasm().borrow_mut();
422    let Some(elem_ty) = w.store.tables.get(addr).map(|t| t.elem_ty) else { return Ok(Value::Undefined) };
423    let r = match &*op {
424        "length" => Value::Number(w.store.tables[addr].elems.len() as f64),
425        "get" => match w.store.tables[addr].elems.get(i).copied() {
426            Some(r) => {
427                let val = if elem_ty == ValType::ExternRef { Val::ExternRef(r) } else { Val::FuncRef(r) };
428                from_wasm(&w, val)
429            }
430            None => return Ok(err_obj("RangeError", "WebAssembly.Table.get(): invalid address")),
431        },
432        "set" | "grow" => {
433            let refv = match to_wasm(&mut w, &v, elem_ty) {
434                Val::FuncRef(r) | Val::ExternRef(r) => r,
435                _ => None,
436            };
437            let t = &mut w.store.tables[addr];
438            if op == "set" {
439                match t.elems.get_mut(i) {
440                    Some(slot) => *slot = refv,
441                    None => return Ok(err_obj("RangeError", "WebAssembly.Table.set(): invalid address")),
442                }
443                Value::Undefined
444            } else {
445                let old = t.elems.len();
446                let new = old.saturating_add(i);
447                if t.max.is_some_and(|m| new > m as usize) || new > 10_000_000 {
448                    return Ok(err_obj("RangeError", "WebAssembly.Table.grow(): failed to grow table"));
449                }
450                t.elems.resize(new, refv);
451                Value::Number(old as f64)
452            }
453        }
454        _ => Value::Undefined,
455    };
456    Ok(r)
457}
458
459/// `__wasm.globalNew(type, mutable, value)` → グローバルの番号。
460pub(crate) fn wasm_global_new(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
461    let Some(ty) = valtype_of(&arg(a, 0).to_js_string()) else {
462        return Ok(err_obj("TypeError", "WebAssembly.Global(): Descriptor property 'value' must be a WebAssembly type"));
463    };
464    let mutable = arg(a, 1).truthy();
465    let mut w = it.wasm().borrow_mut();
466    let init = arg(a, 2);
467    let val = if matches!(init, Value::Undefined) { Val::default_of(ty) } else { to_wasm(&mut w, &init, ty) };
468    Ok(Value::Number(w.store.alloc_global(GlobalType { ty, mutable }, val) as f64))
469}
470
471/// `__wasm.globalOp(addr, op, value)`: op は "get" / "set" / "type" / "mutable"。
472pub(crate) fn wasm_global_op(it: &mut Interp, _t: Value, a: &[Value]) -> Result<Value, Value> {
473    let addr = arg(a, 0).to_number() as usize;
474    let op = arg(a, 1).to_js_string();
475    let mut w = it.wasm().borrow_mut();
476    let Some((ty, mutable, cur)) = w.store.globals.get(addr).map(|g| (g.ty.ty, g.ty.mutable, g.val)) else {
477        return Ok(Value::Undefined);
478    };
479    Ok(match &*op {
480        "get" => from_wasm(&w, cur),
481        "type" => Value::str(valtype_name(ty)),
482        "mutable" => Value::Bool(mutable),
483        "set" => {
484            if !mutable {
485                return Ok(err_obj("TypeError", "WebAssembly.Global.value: Can't set the value of an immutable global."));
486            }
487            let v = to_wasm(&mut w, &arg(a, 2), ty);
488            w.store.globals[addr].val = v;
489            Value::Undefined
490        }
491        _ => Value::Undefined,
492    })
493}
494
495/// `__wasm` オブジェクト(prelude/wasm.js が使う)。
496pub(crate) fn make_wasm_natives() -> Value {
497    let o = Obj::plain();
498    {
499        let mut b = o.borrow_mut();
500        b.props.insert("validate".into(), nv("validate", wasm_validate));
501        b.props.insert("compile".into(), nv("compile", wasm_compile));
502        b.props.insert("imports".into(), nv("imports", wasm_imports));
503        b.props.insert("exports".into(), nv("exports", wasm_exports));
504        b.props.insert("instantiate".into(), nv("instantiate", wasm_instantiate));
505        b.props.insert("call".into(), nv("call", wasm_call));
506        b.props.insert("funcArity".into(), nv("funcArity", wasm_func_arity));
507        b.props.insert("memNew".into(), nv("memNew", wasm_mem_new));
508        b.props.insert("memBuffer".into(), nv("memBuffer", wasm_mem_buffer));
509        b.props.insert("memGrow".into(), nv("memGrow", wasm_mem_grow));
510        b.props.insert("tableNew".into(), nv("tableNew", wasm_table_new));
511        b.props.insert("tableOp".into(), nv("tableOp", wasm_table_op));
512        b.props.insert("globalNew".into(), nv("globalNew", wasm_global_new));
513        b.props.insert("globalOp".into(), nv("globalOp", wasm_global_op));
514    }
515    Value::Object(o)
516}