Skip to content

Commit 604c036

Browse files
authored
Merge pull request #1645 from derekdreery/fix_futures_0_3_hack
Add in (unsafe and incorrect) impls of Send/Sync that are now required.
2 parents 16fc059 + 2541507 commit 604c036

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

crates/cli-support/src/js/binding.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ impl<'a, 'b> Builder<'a, 'b> {
130130
// returning data through.
131131
if binding.return_via_outptr.is_some() {
132132
drop(webidl_params.next());
133-
self.args_prelude
134-
.push_str("const retptr = 8;\n");
133+
self.args_prelude.push_str("const retptr = 8;\n");
135134
arg_names.push("retptr".to_string());
136135
}
137136

crates/futures/src/futures_0_3.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use wasm_bindgen::prelude::*;
2626
pub struct JsFuture {
2727
resolved: oneshot::Receiver<JsValue>,
2828
rejected: oneshot::Receiver<JsValue>,
29-
_cb_resolve: Closure<FnMut(JsValue)>,
30-
_cb_reject: Closure<FnMut(JsValue)>,
29+
_cb_resolve: Closure<dyn FnMut(JsValue)>,
30+
_cb_reject: Closure<dyn FnMut(JsValue)>,
3131
}
3232

3333
impl fmt::Debug for JsFuture {
@@ -143,6 +143,10 @@ where
143143
is_queued: Cell<bool>,
144144
}
145145

146+
// TODO This is only safe because JS is currently single-threaded
147+
unsafe impl Send for Task {}
148+
unsafe impl Sync for Task {}
149+
146150
impl Task {
147151
#[inline]
148152
fn new<F>(future: F) -> Arc<Self>

crates/js-sys/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ extern "C" {
10791079
#[wasm_bindgen(method, js_name = bind)]
10801080
pub fn bind(this: &Function, context: &JsValue) -> Function;
10811081

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

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

11131103
/// The bind() method creates a new function that, when called, has its this keyword set to the provided value,
11141104
/// with a given sequence of arguments preceding any provided when the new function is called.

crates/js-sys/tests/wasm/Function.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ fn bind2() {
9090
#[wasm_bindgen_test]
9191
fn bind3() {
9292
let a_list = list();
93-
let prepended_list = a_list.bind3(&JsValue::NULL, &JsValue::from(2), &JsValue::from(3), &JsValue::from(4));
93+
let prepended_list = a_list.bind3(
94+
&JsValue::NULL,
95+
&JsValue::from(2),
96+
&JsValue::from(3),
97+
&JsValue::from(4),
98+
);
9499

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

src/convert/slices.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::prelude::v1::*;
44
use core::slice;
55
use core::str;
66

7-
use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi};
87
use crate::convert::OptionIntoWasmAbi;
8+
use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi};
99

1010
if_std! {
1111
use core::mem;

0 commit comments

Comments
 (0)