Skip to content

Commit

Permalink
Merge pull request rustwasm#1645 from derekdreery/fix_futures_0_3_hack
Browse files Browse the repository at this point in the history
Add in (unsafe and incorrect) impls of Send/Sync that are now required.
  • Loading branch information
alexcrichton committed Jul 8, 2019
2 parents 16fc059 + 2541507 commit 604c036
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions crates/cli-support/src/js/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ impl<'a, 'b> Builder<'a, 'b> {
// returning data through.
if binding.return_via_outptr.is_some() {
drop(webidl_params.next());
self.args_prelude
.push_str("const retptr = 8;\n");
self.args_prelude.push_str("const retptr = 8;\n");
arg_names.push("retptr".to_string());
}

Expand Down
8 changes: 6 additions & 2 deletions crates/futures/src/futures_0_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use wasm_bindgen::prelude::*;
pub struct JsFuture {
resolved: oneshot::Receiver<JsValue>,
rejected: oneshot::Receiver<JsValue>,
_cb_resolve: Closure<FnMut(JsValue)>,
_cb_reject: Closure<FnMut(JsValue)>,
_cb_resolve: Closure<dyn FnMut(JsValue)>,
_cb_reject: Closure<dyn FnMut(JsValue)>,
}

impl fmt::Debug for JsFuture {
Expand Down Expand Up @@ -143,6 +143,10 @@ where
is_queued: Cell<bool>,
}

// TODO This is only safe because JS is currently single-threaded
unsafe impl Send for Task {}
unsafe impl Sync for Task {}

impl Task {
#[inline]
fn new<F>(future: F) -> Arc<Self>
Expand Down
14 changes: 2 additions & 12 deletions crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ extern "C" {
#[wasm_bindgen(method, js_name = bind)]
pub fn bind(this: &Function, context: &JsValue) -> Function;


/// The bind() method creates a new function that, when called, has its this keyword set to the provided value,
/// with a given sequence of arguments preceding any provided when the new function is called.
///
Expand All @@ -1092,23 +1091,14 @@ extern "C" {
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
#[wasm_bindgen(method, js_name = bind)]
pub fn bind1(
this: &Function,
context: &JsValue,
arg1: &JsValue,
) -> Function;
pub fn bind1(this: &Function, context: &JsValue, arg1: &JsValue) -> Function;

/// The bind() method creates a new function that, when called, has its this keyword set to the provided value,
/// with a given sequence of arguments preceding any provided when the new function is called.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
#[wasm_bindgen(method, js_name = bind)]
pub fn bind2(
this: &Function,
context: &JsValue,
arg1: &JsValue,
arg2: &JsValue,
) -> Function;
pub fn bind2(this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue) -> Function;

/// The bind() method creates a new function that, when called, has its this keyword set to the provided value,
/// with a given sequence of arguments preceding any provided when the new function is called.
Expand Down
7 changes: 6 additions & 1 deletion crates/js-sys/tests/wasm/Function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ fn bind2() {
#[wasm_bindgen_test]
fn bind3() {
let a_list = list();
let prepended_list = a_list.bind3(&JsValue::NULL, &JsValue::from(2), &JsValue::from(3), &JsValue::from(4));
let prepended_list = a_list.bind3(
&JsValue::NULL,
&JsValue::from(2),
&JsValue::from(3),
&JsValue::from(4),
);

let arr = Array::from(&call_function(&prepended_list));

Expand Down
2 changes: 1 addition & 1 deletion src/convert/slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::prelude::v1::*;
use core::slice;
use core::str;

use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi};
use crate::convert::OptionIntoWasmAbi;
use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi};

if_std! {
use core::mem;
Expand Down

0 comments on commit 604c036

Please sign in to comment.