Merge pull request #1521 from fitzgen/anyref-heap-live-count

Utility for counting the number of live JsValues in the wasm-bindgen heap
This commit is contained in:
Nick Fitzgerald
2019-05-09 16:22:06 -07:00
committed by GitHub
5 changed files with 168 additions and 38 deletions

View File

@ -636,6 +636,37 @@ impl<'a> Context<'a> {
))
})?;
self.bind("__wbindgen_anyref_heap_live_count", &|me| {
if me.config.anyref {
// Eventually we should add support to the anyref-xform to
// re-write calls to the imported
// `__wbindgen_anyref_heap_live_count` function into calls to
// the exported `__wbindgen_anyref_heap_live_count_impl`
// function, and to un-export that function.
//
// But for now, we just bounce wasm -> js -> wasm because it is
// easy.
Ok("function() {{ return wasm.__wbindgen_anyref_heap_live_count_impl(); }}".into())
} else {
me.expose_global_heap();
Ok(format!(
"
function() {{
let free_count = 0;
let next = heap_next;
while (next < heap.length) {{
free_count += 1;
next = heap[next];
}}
return heap.length - free_count - {} - {};
}}
",
INITIAL_HEAP_OFFSET,
INITIAL_HEAP_VALUES.len(),
))
}
})?;
self.bind("__wbindgen_debug_string", &|me| {
me.expose_pass_string_to_wasm()?;
me.expose_uint32_memory();