File tree 4 files changed +33
-0
lines changed
crates/cli-support/src/js
4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -783,6 +783,14 @@ impl<'a> Context<'a> {
783
783
) )
784
784
} ) ?;
785
785
786
+ self . bind ( "__wbindgen_function_table" , & |me| {
787
+ me. function_table_needed = true ;
788
+ Ok ( format ! (
789
+ "function() {{ return {}; }}" ,
790
+ me. add_heap_object( "wasm.__wbg_function_table" )
791
+ ) )
792
+ } ) ?;
793
+
786
794
self . bind ( "__wbindgen_rethrow" , & |me| {
787
795
Ok ( format ! (
788
796
"function(idx) {{ throw {}; }}" ,
Original file line number Diff line number Diff line change @@ -517,6 +517,7 @@ externs! {
517
517
518
518
fn __wbindgen_memory( ) -> u32 ;
519
519
fn __wbindgen_module( ) -> u32 ;
520
+ fn __wbindgen_function_table( ) -> u32 ;
520
521
}
521
522
}
522
523
@@ -736,6 +737,12 @@ pub fn memory() -> JsValue {
736
737
unsafe { JsValue :: _new ( __wbindgen_memory ( ) ) }
737
738
}
738
739
740
+ /// Returns a handle to this wasm instance's `WebAssembly.Table` which is the
741
+ /// indirect function table used by Rust
742
+ pub fn function_table ( ) -> JsValue {
743
+ unsafe { JsValue :: _new ( __wbindgen_function_table ( ) ) }
744
+ }
745
+
739
746
#[ doc( hidden) ]
740
747
pub mod __rt {
741
748
use core:: cell:: { Cell , UnsafeCell } ;
Original file line number Diff line number Diff line change @@ -55,3 +55,9 @@ exports.debug_values = () => ([
55
55
( ) => ( null ) ,
56
56
new Set ( ) ,
57
57
] ) ;
58
+
59
+ exports . assert_function_table = ( x , i ) => {
60
+ const rawWasm = require ( 'wasm-bindgen-test_bg.js' ) ;
61
+ assert . ok ( x instanceof WebAssembly . Table ) ;
62
+ assert . strictEqual ( x . get ( i ) , rawWasm . function_table_lookup ) ;
63
+ } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ extern "C" {
9
9
fn js_eq_works ( ) ;
10
10
fn assert_null ( v : JsValue ) ;
11
11
fn debug_values ( ) -> JsValue ;
12
+ fn assert_function_table ( a : JsValue , b : usize ) ;
12
13
}
13
14
14
15
#[ wasm_bindgen_test]
@@ -171,3 +172,14 @@ fn debug_output() {
171
172
assert_eq ! ( format!( "{:?}" , test. unwrap( ) ) , expected) ;
172
173
}
173
174
}
175
+
176
+ #[ wasm_bindgen_test]
177
+ fn function_table_is ( ) {
178
+ assert_function_table (
179
+ wasm_bindgen:: function_table ( ) ,
180
+ function_table_lookup as usize ,
181
+ ) ;
182
+ }
183
+
184
+ #[ no_mangle]
185
+ pub extern "C" fn function_table_lookup ( ) { }
You can’t perform that action at this time.
0 commit comments