Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[submodule "wasm-bindgen"]
path = wasm-bindgen
url = https://github.com/wasm-bindgen/wasm-bindgen
[submodule "wasm-streams"]
path = wasm-streams
url = https://github.com/guybedford/wasm-streams
[submodule "ts-gen"]
path = ts-gen
url = https://github.com/wasm-bindgen/ts-gen
[submodule "gloo"]
path = gloo
url = https://github.com/guybedford/gloo
branch = fix-gloo-timers-unwind-safety
28 changes: 13 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 19 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ exclude = [
"examples/axum",
"templates/*",
"wasm-bindgen",
"wasm-streams",
"gloo",
"generated",
]
resolver = "2"
Expand All @@ -27,7 +29,7 @@ chrono = { version = "0.4.41", default-features = false, features = [
futures-channel = "0.3.31"
futures-util = { version = "0.3.31", default-features = false }
http = "1.3"
js-sys = { version = "0.3.98" }
js-sys = { version = "0.3.99" }
serde = { version = "1.0.164", features = ["derive"] }
strum = { version = "0.27", features = ["derive"] }
serde_json = "1.0.140"
Expand All @@ -36,14 +38,14 @@ syn = "2.0.17"
trybuild = "1.0"
proc-macro2 = "1.0.60"
quote = "1.0.28"
wasm-bindgen = { version = "0.2.121" }
wasm-bindgen-cli-support = { version = "0.2.121" }
wasm-bindgen-futures = { version = "0.4.71" }
wasm-bindgen-macro-support = { version = "0.2.121" }
wasm-bindgen-shared = { version = "0.2.121" }
wasm-bindgen-test = { version = "0.3.71" }
wasm-streams = { version = "0.5.0" }
web-sys = { version = "0.3.98", features = [
wasm-bindgen = { version = "0.2.122" }
wasm-bindgen-cli-support = { version = "0.2.122" }
wasm-bindgen-futures = { version = "0.4.72" }
wasm-bindgen-macro-support = { version = "0.2.122" }
wasm-bindgen-shared = { version = "0.2.122" }
wasm-bindgen-test = { version = "0.3.72" }
wasm-streams = { version = "0.6.0" }
web-sys = { version = "0.3.99", features = [
"AbortController",
"AbortSignal",
"BinaryType",
Expand Down Expand Up @@ -105,11 +107,11 @@ opt-level = "z"
# These are local patches we use to test against local wasm bindgen
# We always align on the exact stable wasm bindgen version for releases
[patch.crates-io]
js-sys = { version = "0.3.98", path = './wasm-bindgen/crates/js-sys' }
wasm-bindgen = { version = "0.2.121", path = './wasm-bindgen' }
wasm-bindgen-cli-support = { version = "0.2.121", path = "./wasm-bindgen/crates/cli-support" }
wasm-bindgen-futures = { version = "0.4.71", path = './wasm-bindgen/crates/futures' }
wasm-bindgen-macro-support = { version = "0.2.121", path = "./wasm-bindgen/crates/macro-support" }
wasm-bindgen-shared = { version = "0.2.121", path = "./wasm-bindgen/crates/shared" }
wasm-bindgen-test = { version = "0.3.71", path = "./wasm-bindgen/crates/test" }
web-sys = { version = "0.3.98", path = './wasm-bindgen/crates/web-sys' }
js-sys = { version = "0.3.99", path = './wasm-bindgen/crates/js-sys' }
wasm-bindgen = { version = "0.2.122", path = './wasm-bindgen' }
wasm-bindgen-cli-support = { version = "0.2.122", path = "./wasm-bindgen/crates/cli-support" }
wasm-bindgen-futures = { version = "0.4.72", path = './wasm-bindgen/crates/futures' }
wasm-bindgen-macro-support = { version = "0.2.122", path = "./wasm-bindgen/crates/macro-support" }
wasm-bindgen-shared = { version = "0.2.122", path = "./wasm-bindgen/crates/shared" }
wasm-bindgen-test = { version = "0.3.72", path = "./wasm-bindgen/crates/test" }
web-sys = { version = "0.3.99", path = './wasm-bindgen/crates/web-sys' }
8 changes: 8 additions & 0 deletions chompfile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ deps = ['install:ts-gen']
# `Env` / `ExecutionContext` are project-specific re-exports that ts-gen
# can't infer; everything else (`ReadableStream`, `Headers`, `Event`, …)
# resolves through ts-gen's built-in web_sys defaults.
#
# `--export cloudflare:email` lifts the module's declarations to global
# scope so consumers see `worker::EmailMessage` directly (rather than
# `worker::bindings::email::email::EmailMessage`). The file `--export`
# is required alongside because once any `--export` is specified the
# implicit "every input is its own export" default is disabled.
run = '''ts-gen --input types/email.d.ts --output worker/src/bindings/email.rs \
--errors-as-error \
--export types/email.d.ts \
--export cloudflare:email \
--external "Env=crate::Env" \
--external "ExecutionContext=crate::Context"'''

Expand Down
2 changes: 1 addition & 1 deletion examples/rpc-client/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Calculator for CalculatorService {
async fn add(&self, a: u32, b: u32) -> ::worker::Result<u32> {
let promise = self.0.add(a, b)?;
let fut = ::worker::send::SendFuture::new(
::worker::wasm_bindgen_futures::JsFuture::from(promise),
::worker::js_sys::futures::JsFuture::from(promise),
);
let output = fut.await?;
Ok(::serde_wasm_bindgen::from_value(output)?)
Expand Down
1 change: 1 addition & 0 deletions gloo
Submodule gloo added at d73276
5 changes: 2 additions & 3 deletions test/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::time::Duration;

use futures_util::StreamExt;
use wasm_bindgen::{throw_str, UnwrapThrowExt};
use wasm_bindgen_futures::spawn_local;
use worker::*;

use crate::SomeSharedData;
Expand All @@ -29,7 +28,7 @@ impl DurableObject for EchoContainer {
}
let ready = Arc::new(AtomicBool::new(false));
let ready_clone = Arc::clone(&ready);
spawn_local(async move {
js_sys::futures::spawn_local(async move {
for _ in 0..10 {
match container
.get_tcp_port(8080)
Expand Down Expand Up @@ -112,7 +111,7 @@ pub async fn handle_container(
None => return Response::error("Expected websocket response", 500),
};
ws.accept()?;
spawn_local(redir_websocket(ws, server));
js_sys::futures::spawn_local(redir_websocket(ws, server));
Response::from_websocket(client)
}
_ => Response::error("Container method not allowed", 405),
Expand Down
38 changes: 20 additions & 18 deletions test/src/counter.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
use std::cell::RefCell;
use std::cell::Cell;
use std::panic::AssertUnwindSafe;
use tokio_stream::{StreamExt, StreamMap};
use worker::{
durable_object, wasm_bindgen, wasm_bindgen_futures, DurableObject, Env, Error, Method, Request,
Response, ResponseBuilder, Result, State, WebSocket, WebSocketIncomingMessage, WebSocketPair,
durable_object, js_sys, wasm_bindgen, DurableObject, Env, Error, Method, Request, Response,
ResponseBuilder, Result, State, WebSocket, WebSocketIncomingMessage, WebSocketPair,
WebsocketEvent,
};

use crate::SomeSharedData;

#[durable_object]
pub struct Counter {
count: RefCell<usize>,
unstored_count: RefCell<usize>,
count: AssertUnwindSafe<Cell<usize>>,
unstored_count: AssertUnwindSafe<Cell<usize>>,
state: State,
initialized: RefCell<bool>,
initialized: AssertUnwindSafe<Cell<bool>>,
env: Env,
}

impl DurableObject for Counter {
fn new(state: State, env: Env) -> Self {
Self {
count: RefCell::new(0),
unstored_count: RefCell::new(0),
initialized: RefCell::new(false),
count: AssertUnwindSafe(Cell::new(0)),
unstored_count: AssertUnwindSafe(Cell::new(0)),
initialized: AssertUnwindSafe(Cell::new(false)),
state,
env,
}
}

async fn fetch(&self, req: Request) -> Result<Response> {
if !*self.initialized.borrow() {
*self.initialized.borrow_mut() = true;
*self.count.borrow_mut() = self.state.storage().get("count").await?.unwrap_or(0);
if !self.initialized.get() {
self.initialized.set(true);
self.count
.set(self.state.storage().get("count").await?.unwrap_or(0));
}

if req.path().eq("/ws") {
Expand All @@ -49,15 +51,15 @@ impl DurableObject for Counter {
.empty());
}

*self.unstored_count.borrow_mut() += 1;
*self.count.borrow_mut() += 10;
let count = *self.count.borrow();
self.unstored_count.set(self.unstored_count.get() + 1);
self.count.set(self.count.get() + 10);
let count = self.count.get();
self.state.storage().put("count", count).await?;

Response::ok(format!(
"[durable_object]: self.count: {}, self.unstored_count: {}, secret value: {}",
self.count.borrow(),
self.unstored_count.borrow(),
self.count.get(),
self.unstored_count.get(),
self.env.secret("SOME_SECRET")?
))
}
Expand Down Expand Up @@ -134,7 +136,7 @@ pub async fn handle_websocket(req: Request, env: Env, _data: SomeSharedData) ->
let do_ws = res.websocket().expect("server did not accept websocket");
do_ws.accept()?;

wasm_bindgen_futures::spawn_local(async move {
js_sys::futures::spawn_local(async move {
let event_stream = server.events().expect("could not open stream");
let do_event_stream = do_ws.events().expect("could not open stream");

Expand Down
Loading
Loading