From 6ed38226e3b1b98a931c9452fd9e3d13ebe2b277 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Mon, 9 Dec 2024 01:28:38 +0100 Subject: [PATCH] bye bye closures --- crates/cli/tests/reference/closure.d.ts | 3 - crates/cli/tests/reference/closure.js | 132 ------------------------ crates/cli/tests/reference/closure.rs | 20 ---- crates/cli/tests/reference/closure.wat | 20 ---- 4 files changed, 175 deletions(-) delete mode 100644 crates/cli/tests/reference/closure.d.ts delete mode 100644 crates/cli/tests/reference/closure.js delete mode 100644 crates/cli/tests/reference/closure.rs delete mode 100644 crates/cli/tests/reference/closure.wat diff --git a/crates/cli/tests/reference/closure.d.ts b/crates/cli/tests/reference/closure.d.ts deleted file mode 100644 index 091dbcc51a6..00000000000 --- a/crates/cli/tests/reference/closure.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export function exported(): void; diff --git a/crates/cli/tests/reference/closure.js b/crates/cli/tests/reference/closure.js deleted file mode 100644 index 5782c14ad13..00000000000 --- a/crates/cli/tests/reference/closure.js +++ /dev/null @@ -1,132 +0,0 @@ -let wasm; -export function __wbg_set_wasm(val) { - wasm = val; -} - - -const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') - ? { register: () => {}, unregister: () => {} } - : new FinalizationRegistry(state => { - wasm.__wbindgen_export_0.get(state.dtor)(state.a, state.b) -}); - -function makeMutClosure(arg0, arg1, dtor, f) { - const state = { a: arg0, b: arg1, cnt: 1, dtor }; - const real = (...args) => { - // First up with a closure we increment the internal reference - // count. This ensures that the Rust closure environment won't - // be deallocated while we're invoking it. - state.cnt++; - const a = state.a; - state.a = 0; - try { - return f(a, state.b, ...args); - } finally { - if (--state.cnt === 0) { - wasm.__wbindgen_export_0.get(state.dtor)(a, state.b); - CLOSURE_DTORS.unregister(state); - } else { - state.a = a; - } - } - }; - real.original = state; - CLOSURE_DTORS.register(real, state, state); - return real; -} - -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - -cachedTextDecoder.decode(); - -let cachedUint8ArrayMemory0 = null; - -function getUint8ArrayMemory0() { - if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { - cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); - } - return cachedUint8ArrayMemory0; -} - -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); -} - -export function exported() { - wasm.exported(); -} - -function __wbg_adapter_8(arg0, arg1) { - wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h08d04a92620849c7(arg0, arg1); -} - -function __wbg_adapter_9(arg0, arg1) { - wasm.wasm_bindgen__convert__closures__invoke0__h0558a7c8fc0aaaa4(arg0, arg1); -} - -export function __wbg_setInterval_dcabc54c1b7f2a8c(arg0, arg1) { - const ret = setInterval(arg0, arg1 >>> 0); - return ret; -}; - -export function __wbg_takesimmutableclosure_19e990abb85ab0b6(arg0, arg1) { - try { - var state = {a: arg0, b: arg1}; - const cb = () => __wbg_adapter_9(state.a, state.b, ); - takes_immutable_closure(cb); - } finally { - state.a = state.b = 0; - } -}; - -export function __wbg_takesmutableclosure_792efe9eb99346a2(arg0, arg1) { - try { - var state = {a: arg0, b: arg1}; - const cb = () => { - const a = state.a; - state.a = 0; - try { - return __wbg_adapter_8(a, state.b, ); - } finally { - state.a = a; - } - }; - takes_mutable_closure(cb); - } finally { - state.a = state.b = 0; - } -}; - -export function __wbindgen_cb_drop(arg0) { - const obj = arg0.original; - if (obj.cnt-- == 1) { - obj.a = 0; - return true; - } - const ret = false; - return ret; -}; - -export function __wbindgen_closure_wrapper57(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 4, __wbg_adapter_8); - return ret; -}; - -export function __wbindgen_init_externref_table() { - const table = wasm.__wbindgen_export_1; - const offset = table.grow(4); - table.set(0, undefined); - table.set(offset + 0, undefined); - table.set(offset + 1, null); - table.set(offset + 2, true); - table.set(offset + 3, false); - ; -}; - -export function __wbindgen_throw(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); -}; - diff --git a/crates/cli/tests/reference/closure.rs b/crates/cli/tests/reference/closure.rs deleted file mode 100644 index 98479cee726..00000000000 --- a/crates/cli/tests/reference/closure.rs +++ /dev/null @@ -1,20 +0,0 @@ -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -extern "C" { - // stack - fn takes_immutable_closure(f: &dyn Fn()); - fn takes_mutable_closure(f: &mut dyn FnMut()); - - // heap - fn setInterval(closure: &Closure, millis: u32) -> f64; -} - -#[wasm_bindgen] -pub fn exported() { - takes_immutable_closure(&|| {}); - takes_mutable_closure(&mut || {}); - - let closure = Closure::new(|| {}); - setInterval(&closure, 1000); -} diff --git a/crates/cli/tests/reference/closure.wat b/crates/cli/tests/reference/closure.wat deleted file mode 100644 index caebc285a2f..00000000000 --- a/crates/cli/tests/reference/closure.wat +++ /dev/null @@ -1,20 +0,0 @@ -(module $reference_test.wasm - (type (;0;) (func)) - (type (;1;) (func (param i32 i32))) - (import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0))) - (func $"+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h08d04a92620849c7" (;1;) (type 1) (param i32 i32)) - (func $wasm_bindgen::convert::closures::invoke0::h0558a7c8fc0aaaa4 (;2;) (type 1) (param i32 i32)) - (func $exported (;3;) (type 0)) - (table (;0;) 37 37 funcref) - (table (;1;) 128 externref) - (memory (;0;) 17) - (export "memory" (memory 0)) - (export "exported" (func $exported)) - (export "__wbindgen_export_0" (table 0)) - (export "__wbindgen_export_1" (table 1)) - (export "_dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h08d04a92620849c7" (func $"+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h08d04a92620849c7")) - (export "wasm_bindgen__convert__closures__invoke0__h0558a7c8fc0aaaa4" (func $wasm_bindgen::convert::closures::invoke0::h0558a7c8fc0aaaa4)) - (export "__wbindgen_start" (func 0)) - (@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext") -) -