Fix wasm sizes on nightly

Looks like the recent changes to `Vec::with_capacity` meant that our previous
codegen to avoid panics no longer avoids panics. Let's pick up the `try_reserve`
unstable feature for now and hopefully it'll be stabilized before the other
pieces in the future.
This commit is contained in:
Alex Crichton 2018-03-20 15:19:45 -07:00
parent 5638126598
commit 91295f4d16

View File

@ -5,7 +5,7 @@
//! this crate and this crate also provides JS bindings through the `JsValue`
//! interface.
#![feature(use_extern_macros)]
#![feature(use_extern_macros, try_reserve)]
extern crate wasm_bindgen_macro;
@ -399,18 +399,10 @@ pub mod __rt {
#[no_mangle]
pub extern fn __wbindgen_malloc(size: usize) -> *mut u8 {
// Any malloc request this big is bogus anyway. If this actually
// goes down to `Vec` we trigger a whole bunch of panicking
// machinery to get pulled in from libstd anyway as it'll verify
// the size passed in below.
//
// Head this all off by just aborting on too-big sizes. This
// avoids panicking (code bloat) and gives a better error
// message too hopefully.
if size >= usize::max_value() / 2 {
let mut ret = Vec::new();
if ret.try_reserve_exact(size).is_err() {
super::throw("invalid malloc request");
}
let mut ret = Vec::with_capacity(size);
let ptr = ret.as_mut_ptr();
mem::forget(ret);
return ptr