summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/wasm-bindgen/src')
-rw-r--r--vendor/wasm-bindgen/src/cast.rs2
-rw-r--r--vendor/wasm-bindgen/src/closure.rs2
-rw-r--r--vendor/wasm-bindgen/src/convert/closures.rs2
-rw-r--r--vendor/wasm-bindgen/src/convert/slices.rs2
-rw-r--r--vendor/wasm-bindgen/src/convert/traits.rs6
-rw-r--r--vendor/wasm-bindgen/src/externref.rs2
-rw-r--r--vendor/wasm-bindgen/src/lib.rs107
7 files changed, 86 insertions, 37 deletions
diff --git a/vendor/wasm-bindgen/src/cast.rs b/vendor/wasm-bindgen/src/cast.rs
index 6be56a2d7..e462cf836 100644
--- a/vendor/wasm-bindgen/src/cast.rs
+++ b/vendor/wasm-bindgen/src/cast.rs
@@ -3,7 +3,7 @@ use crate::{describe::WasmDescribe, JsValue};
/// A trait for checked and unchecked casting between JS types.
///
/// Specified [in an RFC][rfc] this trait is intended to provide support for
-/// casting JS values between differnet types of one another. In JS there aren't
+/// casting JS values between different types of one another. In JS there aren't
/// many static types but we've ascribed JS values with static types in Rust,
/// yet they often need to be switched to other types temporarily! This trait
/// provides both checked and unchecked casting into various kinds of values.
diff --git a/vendor/wasm-bindgen/src/closure.rs b/vendor/wasm-bindgen/src/closure.rs
index c8d2ba225..a498d6d25 100644
--- a/vendor/wasm-bindgen/src/closure.rs
+++ b/vendor/wasm-bindgen/src/closure.rs
@@ -4,6 +4,8 @@
//! closures" from Rust to JS. Some more details can be found on the `Closure`
//! type itself.
+#![allow(clippy::fn_to_numeric_cast)]
+
use std::fmt;
use std::mem::{self, ManuallyDrop};
use std::prelude::v1::*;
diff --git a/vendor/wasm-bindgen/src/convert/closures.rs b/vendor/wasm-bindgen/src/convert/closures.rs
index 9137065a2..02527173d 100644
--- a/vendor/wasm-bindgen/src/convert/closures.rs
+++ b/vendor/wasm-bindgen/src/convert/closures.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::fn_to_numeric_cast)]
+
use core::mem;
use crate::convert::slices::WasmSlice;
diff --git a/vendor/wasm-bindgen/src/convert/slices.rs b/vendor/wasm-bindgen/src/convert/slices.rs
index 58608b8c5..40ea6edc7 100644
--- a/vendor/wasm-bindgen/src/convert/slices.rs
+++ b/vendor/wasm-bindgen/src/convert/slices.rs
@@ -364,7 +364,7 @@ if_std! {
let ptr = <*mut JsValue>::from_abi(js.ptr);
let len = js.len as usize;
let vec: Vec<T> = Vec::from_raw_parts(ptr, len, len).drain(..).map(|js_value| T::unchecked_from_js(js_value)).collect();
- return vec.into_boxed_slice();
+ vec.into_boxed_slice()
}
}
diff --git a/vendor/wasm-bindgen/src/convert/traits.rs b/vendor/wasm-bindgen/src/convert/traits.rs
index 17b72a837..fe31aab63 100644
--- a/vendor/wasm-bindgen/src/convert/traits.rs
+++ b/vendor/wasm-bindgen/src/convert/traits.rs
@@ -120,9 +120,11 @@ pub trait OptionFromWasmAbi: FromWasmAbi {
/// An unsafe trait which represents types that are ABI-safe to pass via wasm
/// arguments.
///
+/// # Safety
+///
/// This is an unsafe trait to implement as there's no guarantee the type is
/// actually safe to transfer across the was boundary, it's up to you to
-/// guarantee this so codegen works correctly.
+/// guarantee this, so codegen works correctly.
pub unsafe trait WasmAbi {}
unsafe impl WasmAbi for u32 {}
@@ -132,7 +134,7 @@ unsafe impl WasmAbi for i64 {}
unsafe impl WasmAbi for f32 {}
unsafe impl WasmAbi for f64 {}
-/// A trait representing how to interepret the return value of a function for
+/// A trait representing how to interpret the return value of a function for
/// the wasm ABI.
///
/// This is very similar to the `IntoWasmAbi` trait and in fact has a blanket
diff --git a/vendor/wasm-bindgen/src/externref.rs b/vendor/wasm-bindgen/src/externref.rs
index a7e5f3ebc..340fdcbeb 100644
--- a/vendor/wasm-bindgen/src/externref.rs
+++ b/vendor/wasm-bindgen/src/externref.rs
@@ -43,7 +43,7 @@ impl Slab {
if self.base == 0 {
self.base = r as usize;
} else if self.base + self.data.len() != r as usize {
- internal_error("someone else allocated table entires?")
+ internal_error("someone else allocated table entries?")
}
// poor man's `try_reserve_exact` until that's stable
diff --git a/vendor/wasm-bindgen/src/lib.rs b/vendor/wasm-bindgen/src/lib.rs
index f8576ed4c..fd2feae6f 100644
--- a/vendor/wasm-bindgen/src/lib.rs
+++ b/vendor/wasm-bindgen/src/lib.rs
@@ -95,7 +95,7 @@ pub struct JsValue {
}
const JSIDX_OFFSET: u32 = 128; // keep in sync with js/mod.rs
-const JSIDX_UNDEFINED: u32 = JSIDX_OFFSET + 0;
+const JSIDX_UNDEFINED: u32 = JSIDX_OFFSET;
const JSIDX_NULL: u32 = JSIDX_OFFSET + 1;
const JSIDX_TRUE: u32 = JSIDX_OFFSET + 2;
const JSIDX_FALSE: u32 = JSIDX_OFFSET + 3;
@@ -103,31 +103,19 @@ const JSIDX_RESERVED: u32 = JSIDX_OFFSET + 4;
impl JsValue {
/// The `null` JS value constant.
- pub const NULL: JsValue = JsValue {
- idx: JSIDX_NULL,
- _marker: marker::PhantomData,
- };
+ pub const NULL: JsValue = JsValue::_new(JSIDX_NULL);
/// The `undefined` JS value constant.
- pub const UNDEFINED: JsValue = JsValue {
- idx: JSIDX_UNDEFINED,
- _marker: marker::PhantomData,
- };
+ pub const UNDEFINED: JsValue = JsValue::_new(JSIDX_UNDEFINED);
/// The `true` JS value constant.
- pub const TRUE: JsValue = JsValue {
- idx: JSIDX_TRUE,
- _marker: marker::PhantomData,
- };
+ pub const TRUE: JsValue = JsValue::_new(JSIDX_TRUE);
/// The `false` JS value constant.
- pub const FALSE: JsValue = JsValue {
- idx: JSIDX_FALSE,
- _marker: marker::PhantomData,
- };
+ pub const FALSE: JsValue = JsValue::_new(JSIDX_FALSE);
#[inline]
- fn _new(idx: u32) -> JsValue {
+ const fn _new(idx: u32) -> JsValue {
JsValue {
idx,
_marker: marker::PhantomData,
@@ -138,6 +126,7 @@ impl JsValue {
///
/// The utf-8 string provided is copied to the JS heap and the string will
/// be owned by the JS garbage collector.
+ #[allow(clippy::should_implement_trait)] // cannot fix without breaking change
#[inline]
pub fn from_str(s: &str) -> JsValue {
unsafe { JsValue::_new(__wbindgen_string_new(s.as_ptr(), s.len())) }
@@ -166,7 +155,7 @@ impl JsValue {
/// This function creates a JS object representing a boolean (a heap
/// allocated boolean) and returns a handle to the JS version of it.
#[inline]
- pub fn from_bool(b: bool) -> JsValue {
+ pub const fn from_bool(b: bool) -> JsValue {
if b {
JsValue::TRUE
} else {
@@ -176,13 +165,13 @@ impl JsValue {
/// Creates a new JS value representing `undefined`.
#[inline]
- pub fn undefined() -> JsValue {
+ pub const fn undefined() -> JsValue {
JsValue::UNDEFINED
}
/// Creates a new JS value representing `null`.
#[inline]
- pub fn null() -> JsValue {
+ pub const fn null() -> JsValue {
JsValue::NULL
}
@@ -620,10 +609,10 @@ impl TryFrom<&JsValue> for f64 {
#[inline]
fn try_from(val: &JsValue) -> Result<Self, Self::Error> {
let jsval = unsafe { JsValue::_new(__wbindgen_try_into_number(val.idx)) };
- return match jsval.as_f64() {
+ match jsval.as_f64() {
Some(num) => Ok(num),
None => Err(jsval),
- };
+ }
}
}
@@ -1082,6 +1071,7 @@ externs! {
fn __wbindgen_not(idx: u32) -> u32;
+ fn __wbindgen_exports() -> u32;
fn __wbindgen_memory() -> u32;
fn __wbindgen_module() -> u32;
fn __wbindgen_function_table() -> u32;
@@ -1308,17 +1298,31 @@ pub fn anyref_heap_live_count() -> u32 {
pub trait UnwrapThrowExt<T>: Sized {
/// Unwrap this `Option` or `Result`, but instead of panicking on failure,
/// throw an exception to JavaScript.
+ #[cfg_attr(debug_assertions, track_caller)]
fn unwrap_throw(self) -> T {
- self.expect_throw("`unwrap_throw` failed")
+ if cfg!(all(debug_assertions, feature = "std")) {
+ let loc = core::panic::Location::caller();
+ let msg = std::format!(
+ "`unwrap_throw` failed ({}:{}:{})",
+ loc.file(),
+ loc.line(),
+ loc.column()
+ );
+ self.expect_throw(&msg)
+ } else {
+ self.expect_throw("`unwrap_throw` failed")
+ }
}
/// Unwrap this container's `T` value, or throw an error to JS with the
/// given message if the `T` value is unavailable (e.g. an `Option<T>` is
/// `None`).
+ #[cfg_attr(debug_assertions, track_caller)]
fn expect_throw(self, message: &str) -> T;
}
impl<T> UnwrapThrowExt<T> for Option<T> {
+ #[cfg_attr(debug_assertions, track_caller)]
fn expect_throw(self, message: &str) -> T {
if cfg!(all(target_arch = "wasm32", not(target_os = "emscripten"))) {
match self {
@@ -1335,6 +1339,7 @@ impl<T, E> UnwrapThrowExt<T> for Result<T, E>
where
E: core::fmt::Debug,
{
+ #[cfg_attr(debug_assertions, track_caller)]
fn expect_throw(self, message: &str) -> T {
if cfg!(all(target_arch = "wasm32", not(target_os = "emscripten"))) {
match self {
@@ -1358,6 +1363,11 @@ pub fn module() -> JsValue {
unsafe { JsValue::_new(__wbindgen_module()) }
}
+/// Returns a handle to this wasm instance's `WebAssembly.Instance.prototype.exports`
+pub fn exports() -> JsValue {
+ unsafe { JsValue::_new(__wbindgen_exports()) }
+}
+
/// Returns a handle to this wasm instance's `WebAssembly.Memory`
pub fn memory() -> JsValue {
unsafe { JsValue::_new(__wbindgen_memory()) }
@@ -1374,6 +1384,7 @@ pub mod __rt {
use crate::JsValue;
use core::borrow::{Borrow, BorrowMut};
use core::cell::{Cell, UnsafeCell};
+ use core::convert::Infallible;
use core::ops::{Deref, DerefMut};
pub extern crate core;
@@ -1555,11 +1566,9 @@ pub mod __rt {
if_std! {
use std::alloc::{alloc, dealloc, realloc, Layout};
- use std::mem;
#[no_mangle]
- pub extern "C" fn __wbindgen_malloc(size: usize) -> *mut u8 {
- let align = mem::align_of::<usize>();
+ pub extern "C" fn __wbindgen_malloc(size: usize, align: usize) -> *mut u8 {
if let Ok(layout) = Layout::from_size_align(size, align) {
unsafe {
if layout.size() > 0 {
@@ -1577,8 +1586,7 @@ pub mod __rt {
}
#[no_mangle]
- pub unsafe extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 {
- let align = mem::align_of::<usize>();
+ pub unsafe extern "C" fn __wbindgen_realloc(ptr: *mut u8, old_size: usize, new_size: usize, align: usize) -> *mut u8 {
debug_assert!(old_size > 0);
debug_assert!(new_size > 0);
if let Ok(layout) = Layout::from_size_align(old_size, align) {
@@ -1600,13 +1608,12 @@ pub mod __rt {
}
#[no_mangle]
- pub unsafe extern "C" fn __wbindgen_free(ptr: *mut u8, size: usize) {
+ pub unsafe extern "C" fn __wbindgen_free(ptr: *mut u8, size: usize, align: usize) {
// This happens for zero-length slices, and in that case `ptr` is
// likely bogus so don't actually send this to the system allocator
if size == 0 {
return
}
- let align = mem::align_of::<usize>();
let layout = Layout::from_size_align_unchecked(size, align);
dealloc(ptr, layout);
}
@@ -1667,7 +1674,7 @@ pub mod __rt {
};
GLOBAL_EXNDATA[0] = 0;
GLOBAL_EXNDATA[1] = 0;
- return ret;
+ ret
}
}
@@ -1728,6 +1735,42 @@ pub mod __rt {
}
}
}
+
+ /// An internal helper struct for usage in `#[wasm_bindgen(main)]`
+ /// functions to throw the error (if it is `Err`).
+ pub struct MainWrapper<T>(pub Option<T>);
+
+ pub trait Main {
+ fn __wasm_bindgen_main(&mut self);
+ }
+
+ impl Main for &mut &mut MainWrapper<()> {
+ #[inline]
+ fn __wasm_bindgen_main(&mut self) {}
+ }
+
+ impl Main for &mut &mut MainWrapper<Infallible> {
+ #[inline]
+ fn __wasm_bindgen_main(&mut self) {}
+ }
+
+ impl<E: Into<JsValue>> Main for &mut &mut MainWrapper<Result<(), E>> {
+ #[inline]
+ fn __wasm_bindgen_main(&mut self) {
+ if let Err(e) = self.0.take().unwrap() {
+ crate::throw_val(e.into());
+ }
+ }
+ }
+
+ impl<E: std::fmt::Debug> Main for &mut MainWrapper<Result<(), E>> {
+ #[inline]
+ fn __wasm_bindgen_main(&mut self) {
+ if let Err(e) = self.0.take().unwrap() {
+ crate::throw_str(&std::format!("{:?}", e));
+ }
+ }
+ }
}
/// A wrapper type around slices and vectors for binding the `Uint8ClampedArray`