Overhaul the conversion traits

This commit overhauls the conversion traits used for types crossing the Rust/JS
boundary. Previously there were a few ad-hoc traits but now there've been
slightly reduced and decoupled.

Conversion from Rust values to JS values is now exclusively done through
`IntoWasmAbi` with no special treatment for references. Conversion from JS to
Rust is a bit trickier as we want to create references in Rust which have
implications in terms of safety. As a result there are now three traits for
this, `FromWasmAbi`, `RefFromWasmAbi`, and `RefMutFromWasmAbi`. These three
traits are implemented for various types and specially dispatched to depending
on the type of argument in the code generator.

The goal of this commit is to lay the groundwork for using these traits in
closures with straightforward-ish definitions.
This commit is contained in:
Alex Crichton
2018-04-13 22:58:35 -07:00
parent 9976971e7e
commit 0e6325d833
6 changed files with 261 additions and 298 deletions

View File

@ -13,7 +13,7 @@ use std::cell::UnsafeCell;
use std::ops::Deref;
use std::ptr;
use convert::WasmBoundary;
use convert::FromWasmAbi;
/// A module which is typically glob imported from:
///
@ -295,7 +295,7 @@ pub struct JsStatic<T> {
unsafe impl<T: Sync> Sync for JsStatic<T> {}
unsafe impl<T: Send> Send for JsStatic<T> {}
impl<T: WasmBoundary> Deref for JsStatic<T> {
impl<T: FromWasmAbi + 'static> Deref for JsStatic<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe {