File tree 4 files changed +38
-4
lines changed
crates/cli-support/src/js
4 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -633,13 +633,33 @@ impl<'a> Context<'a> {
633
633
self . global ( & format ! ( "
634
634
let stack = [];
635
635
" ) ) ;
636
+ if self . config . debug {
637
+ self . export ( "assertStackEmpty" , "
638
+ function() {
639
+ if (stack.length === 0)
640
+ return;
641
+ throw new Error('stack is not currently empty');
642
+ }
643
+ " ) ;
644
+ }
636
645
}
637
646
638
647
fn expose_global_slab ( & mut self ) {
639
648
if !self . exposed_globals . insert ( "slab" ) {
640
649
return ;
641
650
}
642
651
self . global ( & format ! ( "let slab = [];" ) ) ;
652
+ if self . config . debug {
653
+ self . export ( "assertSlabEmpty" , "
654
+ function() {
655
+ for (let i = 0; i < slab.length; i++) {
656
+ if (typeof(slab[i]) === 'number')
657
+ continue;
658
+ throw new Error('slab is not currently empty');
659
+ }
660
+ }
661
+ " ) ;
662
+ }
643
663
}
644
664
645
665
fn expose_global_slab_next ( & mut self ) {
@@ -882,14 +902,14 @@ impl<'a> Context<'a> {
882
902
return ;
883
903
}
884
904
self . expose_get_array_u32_from_wasm ( ) ;
885
- self . expose_get_object ( ) ;
905
+ self . expose_take_object ( ) ;
886
906
self . global ( & format ! ( "
887
907
function getArrayJsValueFromWasm(ptr, len) {{
888
908
const mem = getUint32Memory();
889
909
const slice = mem.slice(ptr / 4, ptr / 4 + len);
890
910
const result = [];
891
911
for (let i = 0; i < slice.length; i++) {{
892
- result.push(getObject (slice[i]))
912
+ result.push(takeObject (slice[i]))
893
913
}}
894
914
return result;
895
915
}}
Original file line number Diff line number Diff line change @@ -283,6 +283,7 @@ fn free_imports() {
283
283
#[ test]
284
284
fn import_a_field ( ) {
285
285
project ( )
286
+ . debug ( false )
286
287
. file ( "src/lib.rs" , r#"
287
288
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
288
289
Original file line number Diff line number Diff line change @@ -48,11 +48,18 @@ fn project() -> Project {
48
48
49
49
( "run.js" . to_string( ) , r#"
50
50
import * as process from "process";
51
+ let wasm = import('./out');
51
52
52
53
const test = import("./test");
53
54
54
- test.then(test => {
55
+ Promise.all([test, wasm]).then(results => {
56
+ let [test, wasm] = results;
55
57
test.test();
58
+
59
+ if (wasm.assertStackEmpty)
60
+ wasm.assertStackEmpty();
61
+ if (wasm.assertSlabEmpty)
62
+ wasm.assertSlabEmpty();
56
63
}).catch(error => {
57
64
console.error(error);
58
65
process.exit(1);
Original file line number Diff line number Diff line change @@ -216,7 +216,7 @@ fn no_std() {
216
216
217
217
use wasm_bindgen::prelude::*;
218
218
219
- #[wasm_bindgen]
219
+ #[wasm_bindgen(module = "./foo") ]
220
220
extern {
221
221
fn test(a: &str);
222
222
@@ -238,6 +238,12 @@ fn no_std() {
238
238
wasm.foo(1);
239
239
}
240
240
"# )
241
+ . file ( "foo.js" , r#"
242
+ export class Js {
243
+ init() {
244
+ }
245
+ }
246
+ "# )
241
247
. test ( ) ;
242
248
}
243
249
You can’t perform that action at this time.
0 commit comments