Skip to content

Commit 5ee7eb6

Browse files
committed
fix: FeatureChecker was swapped with Arc<FeatureChecker>, breaking broadcast_channel (7)
1 parent 13b9429 commit 5ee7eb6

4 files changed

Lines changed: 83 additions & 34 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["@rscarson"]
44
description = "Effortless JS Integration for Rust"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
7-
version = "0.12.2"
7+
version = "0.12.3"
88
repository = "https://github.com/rscarson/rustyscript"
99

1010
keywords = ["rust", "javascript", "deno", "runtime", "embedding"]

src/ext/broadcast_channel/mod.rs

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,79 @@
1-
use deno_broadcast_channel::InMemoryBroadcastChannel;
2-
use deno_core::{extension, Extension};
3-
4-
use super::ExtensionTrait;
5-
6-
mod wrapper;
7-
pub use wrapper::BroadcastChannelWrapper;
8-
9-
extension!(
10-
init_broadcast_channel,
11-
deps = [rustyscript],
12-
esm_entry_point = "ext:init_broadcast_channel/init_broadcast_channel.js",
13-
esm = [ dir "src/ext/broadcast_channel", "init_broadcast_channel.js" ],
14-
);
15-
impl ExtensionTrait<()> for init_broadcast_channel {
16-
fn init((): ()) -> Extension {
17-
init_broadcast_channel::init()
18-
}
19-
}
20-
impl ExtensionTrait<InMemoryBroadcastChannel> for deno_broadcast_channel::deno_broadcast_channel {
21-
fn init(channel: InMemoryBroadcastChannel) -> Extension {
22-
deno_broadcast_channel::deno_broadcast_channel::init(channel)
23-
}
24-
}
25-
26-
pub fn extensions(channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> {
27-
vec![
28-
deno_broadcast_channel::deno_broadcast_channel::build(channel, is_snapshot),
29-
init_broadcast_channel::build((), is_snapshot),
30-
]
31-
}
1+
use deno_broadcast_channel::InMemoryBroadcastChannel;
2+
use deno_core::{extension, Extension};
3+
4+
use super::ExtensionTrait;
5+
6+
mod wrapper;
7+
pub use wrapper::BroadcastChannelWrapper;
8+
9+
extension!(
10+
init_broadcast_channel,
11+
deps = [rustyscript],
12+
esm_entry_point = "ext:init_broadcast_channel/init_broadcast_channel.js",
13+
esm = [ dir "src/ext/broadcast_channel", "init_broadcast_channel.js" ],
14+
);
15+
impl ExtensionTrait<()> for init_broadcast_channel {
16+
fn init((): ()) -> Extension {
17+
init_broadcast_channel::init()
18+
}
19+
}
20+
impl ExtensionTrait<InMemoryBroadcastChannel> for deno_broadcast_channel::deno_broadcast_channel {
21+
fn init(channel: InMemoryBroadcastChannel) -> Extension {
22+
deno_broadcast_channel::deno_broadcast_channel::init(channel)
23+
}
24+
}
25+
26+
pub fn extensions(channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> {
27+
vec![
28+
deno_broadcast_channel::deno_broadcast_channel::build(channel, is_snapshot),
29+
init_broadcast_channel::build((), is_snapshot),
30+
]
31+
}
32+
33+
#[cfg(test)]
34+
mod test {
35+
use deno_core::PollEventLoopOptions;
36+
37+
use crate::{module, BroadcastChannelWrapper, Module, Runtime, RuntimeOptions};
38+
39+
static TEST_MOD: Module = module!(
40+
"test.js",
41+
"
42+
const channel = new BroadcastChannel('my_channel');
43+
channel.onmessage = (event) => {
44+
channel.postMessage('Received: ' + event.data);
45+
};
46+
"
47+
);
48+
49+
#[test]
50+
fn test_broadcast_channel() {
51+
let options = RuntimeOptions::default();
52+
let channel = options.extension_options.broadcast_channel.clone();
53+
54+
let mut runtime = Runtime::new(options).unwrap();
55+
let tokio_runtime = runtime.tokio_runtime();
56+
57+
let channel = BroadcastChannelWrapper::new(&channel, "my_channel").unwrap();
58+
59+
tokio_runtime
60+
.block_on(runtime.load_module_async(&TEST_MOD))
61+
.unwrap();
62+
63+
channel.send_sync(&mut runtime, "foo").unwrap();
64+
65+
runtime
66+
.block_on_event_loop(
67+
PollEventLoopOptions::default(),
68+
Some(std::time::Duration::from_secs(1)),
69+
)
70+
.unwrap();
71+
72+
let value = channel
73+
.recv_sync::<String>(&mut runtime, Some(std::time::Duration::from_secs(1)))
74+
.unwrap()
75+
.unwrap();
76+
77+
assert_eq!(value, "Received: foo");
78+
}
79+
}

src/inner_runtime.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
path::{Path, PathBuf},
44
pin::Pin,
55
rc::Rc,
6+
sync::Arc,
67
task::Poll,
78
time::Duration,
89
};
@@ -265,7 +266,7 @@ impl<RT: RuntimeTrait> InnerRuntime<RT> {
265266
.rt_mut()
266267
.op_state()
267268
.borrow_mut()
268-
.put(feature_checker);
269+
.put(Arc::new(feature_checker));
269270

270271
// Add a callback to terminate the runtime if the max_heap_size limit is approached
271272
if options.max_heap_size.is_some() {

0 commit comments

Comments
 (0)