mirror of
https://github.com/tlsnotary/wasm-bindgen.git
synced 2026-01-09 15:08:01 -05:00
Make catch thread safe (#3879)
This commit is contained in:
@@ -13,6 +13,11 @@
|
||||
* Copy port from headless test server when using `WASM_BINDGEN_TEST_ADDRESS`.
|
||||
[#3873](https://github.com/rustwasm/wasm-bindgen/pull/3873)
|
||||
|
||||
* Fix `catch` not being thread-safe.
|
||||
[#3879](https://github.com/rustwasm/wasm-bindgen/pull/3879)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
## [0.2.92](https://github.com/rustwasm/wasm-bindgen/compare/0.2.91...0.2.92)
|
||||
|
||||
Released 2024-03-04
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
(type (;2;) (func (param i32)))
|
||||
(type (;3;) (func (param i32) (result i32)))
|
||||
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
|
||||
(func $__wbindgen_exn_store (;1;) (type 2) (param i32))
|
||||
(func $__externref_table_dealloc (;2;) (type 2) (param i32))
|
||||
(func $exported (;3;) (type 2) (param i32))
|
||||
(func $__externref_table_alloc (;4;) (type 1) (result i32))
|
||||
(func $__externref_table_dealloc (;1;) (type 2) (param i32))
|
||||
(func $exported (;2;) (type 2) (param i32))
|
||||
(func $__externref_table_alloc (;3;) (type 1) (result i32))
|
||||
(func $__wbindgen_exn_store (;4;) (type 2) (param i32))
|
||||
(func $__wbindgen_add_to_stack_pointer (;5;) (type 3) (param i32) (result i32))
|
||||
(table (;0;) 128 externref)
|
||||
(memory (;0;) 17)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
(module
|
||||
(type (;0;) (func (param i32)))
|
||||
(type (;1;) (func (param i32) (result i32)))
|
||||
(func $__wbindgen_exn_store (;0;) (type 0) (param i32))
|
||||
(func $exported (;1;) (type 0) (param i32))
|
||||
(func $exported (;0;) (type 0) (param i32))
|
||||
(func $__wbindgen_exn_store (;1;) (type 0) (param i32))
|
||||
(func $__wbindgen_add_to_stack_pointer (;2;) (type 1) (param i32) (result i32))
|
||||
(memory (;0;) 17)
|
||||
(export "memory" (memory 0))
|
||||
|
||||
22
src/lib.rs
22
src/lib.rs
@@ -1687,26 +1687,28 @@ pub mod __rt {
|
||||
crate::externref::link_intrinsics();
|
||||
}
|
||||
|
||||
static mut GLOBAL_EXNDATA: [u32; 2] = [0; 2];
|
||||
std::thread_local! {
|
||||
static GLOBAL_EXNDATA: Cell<[u32; 2]> = Cell::new([0; 2]);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn __wbindgen_exn_store(idx: u32) {
|
||||
debug_assert_eq!(GLOBAL_EXNDATA[0], 0);
|
||||
GLOBAL_EXNDATA[0] = 1;
|
||||
GLOBAL_EXNDATA[1] = idx;
|
||||
GLOBAL_EXNDATA.with(|data| {
|
||||
debug_assert_eq!(data.get()[0], 0);
|
||||
data.set([1, idx]);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn take_last_exception() -> Result<(), super::JsValue> {
|
||||
unsafe {
|
||||
let ret = if GLOBAL_EXNDATA[0] == 1 {
|
||||
Err(super::JsValue::_new(GLOBAL_EXNDATA[1]))
|
||||
GLOBAL_EXNDATA.with(|data| {
|
||||
let ret = if data.get()[0] == 1 {
|
||||
Err(super::JsValue::_new(data.get()[1]))
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
GLOBAL_EXNDATA[0] = 0;
|
||||
GLOBAL_EXNDATA[1] = 0;
|
||||
data.set([0, 0]);
|
||||
ret
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// An internal helper trait for usage in `#[wasm_bindgen]` on `async`
|
||||
|
||||
Reference in New Issue
Block a user