Skip to content

Commit 0c7f83e

Browse files
authored
chore: bump Rust and cargo update (#735)
We bump Rust to 1.78, but for the tests to pass we need to remove the UB that we've been relying on: 1. Opaque pointers no longer rely on values on the stack (!) 2. We no longer take a `&mut` from a u64 that comes from a `&` (UB) 3. ToV8Buffer gets a RefCell for proper interior mutability Lots of sketchiness left in serde_v8 but hopefully this fixes the major fire. serde_v8 is considered deprecated so we're likely not going to touch this code much more than this band-aid.
1 parent d898f71 commit 0c7f83e

File tree

16 files changed

+143
-150
lines changed

16 files changed

+143
-150
lines changed

Cargo.lock

Lines changed: 98 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/async_cancel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ mod internal {
529529
..
530530
} => {
531531
if !waker.will_wake(new_waker) {
532-
*waker = new_waker.clone();
532+
waker.clone_from(new_waker);
533533
}
534534
Ok(())
535535
}

core/gotham_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl GothamState {
2525
/// Determines if the current value exists in `GothamState` storage.
2626
pub fn has<T: 'static>(&self) -> bool {
2727
let type_id = TypeId::of::<T>();
28-
self.data.get(&type_id).is_some()
28+
self.data.contains_key(&type_id)
2929
}
3030

3131
/// Tries to borrow a value from the `GothamState` storage.

core/web_timeout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl MutableSleep {
167167
// Already have this waker
168168
let waker = cx.waker();
169169
if !external.will_wake(waker) {
170-
*external = waker.clone();
170+
external.clone_from(waker);
171171
}
172172
Poll::Pending
173173
} else {

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.77.2"
2+
channel = "1.78.0"
33
components = ["rustfmt", "clippy"]

serde_v8/magic/any_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl_magic!(AnyValue);
2323

2424
impl ToV8 for AnyValue {
2525
fn to_v8<'a>(
26-
&mut self,
26+
&self,
2727
scope: &mut v8::HandleScope<'a>,
2828
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
2929
match self {

serde_v8/magic/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl DerefMut for BigInt {
3131

3232
impl ToV8 for BigInt {
3333
fn to_v8<'a>(
34-
&mut self,
34+
&self,
3535
scope: &mut v8::HandleScope<'a>,
3636
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
3737
let (sign, words) = self.0.to_u64_digits();

serde_v8/magic/buffer.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22

3+
use std::cell::RefCell;
34
use std::fmt::Debug;
45
use std::ops::Deref;
56
use std::ops::DerefMut;
@@ -79,19 +80,19 @@ impl From<V8Slice<u8>> for JsBuffer {
7980
// NOTE(bartlomieju): we use Option here, because `to_v8()` uses `&mut self`
8081
// instead of `self` which is dictated by the `serde` API.
8182
#[derive(Debug)]
82-
pub struct ToJsBuffer(Option<Box<[u8]>>);
83+
pub struct ToJsBuffer(RefCell<Option<Box<[u8]>>>);
8384

8485
impl_magic!(ToJsBuffer);
8586

8687
impl ToJsBuffer {
8788
pub fn empty() -> Self {
88-
ToJsBuffer(Some(vec![0_u8; 0].into_boxed_slice()))
89+
ToJsBuffer(Some(vec![0_u8; 0].into_boxed_slice()).into())
8990
}
9091
}
9192

9293
impl From<Box<[u8]>> for ToJsBuffer {
9394
fn from(buf: Box<[u8]>) -> Self {
94-
ToJsBuffer(Some(buf))
95+
ToJsBuffer(Some(buf).into())
9596
}
9697
}
9798

@@ -103,10 +104,11 @@ impl From<Vec<u8>> for ToJsBuffer {
103104

104105
impl ToV8 for ToJsBuffer {
105106
fn to_v8<'a>(
106-
&mut self,
107+
&self,
107108
scope: &mut v8::HandleScope<'a>,
108109
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
109-
let buf: Box<[u8]> = self.0.take().expect("RustToV8Buf was empty");
110+
let buf: Box<[u8]> =
111+
self.0.borrow_mut().take().expect("RustToV8Buf was empty");
110112

111113
if buf.is_empty() {
112114
let ab = v8::ArrayBuffer::new(scope, 0);

serde_v8/magic/bytestring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const _: () =
5252

5353
impl ToV8 for ByteString {
5454
fn to_v8<'a>(
55-
&mut self,
55+
&self,
5656
scope: &mut v8::HandleScope<'a>,
5757
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
5858
let v =

serde_v8/magic/detached_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl DerefMut for DetachedBuffer {
4141

4242
impl ToV8 for DetachedBuffer {
4343
fn to_v8<'a>(
44-
&mut self,
44+
&self,
4545
scope: &mut v8::HandleScope<'a>,
4646
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
4747
let buffer = v8::ArrayBuffer::with_backing_store(scope, &self.0.store);

0 commit comments

Comments
 (0)