Skip to content

Commit e2c98d6

Browse files
committed
Merge branch 'main' into simplify_source_map_getter
2 parents f1f6a53 + 4aa0dfa commit e2c98d6

File tree

9 files changed

+27
-37
lines changed

9 files changed

+27
-37
lines changed

core/fast_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ macro_rules! ascii_str {
442442
($str:expr) => {{
443443
const C: $crate::v8::OneByteConst =
444444
$crate::FastStaticString::create_external_onebyte_const($str.as_bytes());
445-
unsafe { std::mem::transmute::<_, $crate::FastStaticString>(&C) }
445+
$crate::FastStaticString::new(&C)
446446
}};
447447
}
448448

core/runtime/bindings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ pub(crate) fn externalize_sources(
148148
let offset = snapshot_sources.len();
149149
for (index, source) in sources.into_iter().enumerate() {
150150
externals[index + offset] =
151-
FastStaticString::create_external_onebyte_const(std::mem::transmute(
151+
FastStaticString::create_external_onebyte_const(std::mem::transmute::<
152+
&[u8],
153+
&[u8],
154+
>(
152155
source.code.as_bytes(),
153156
));
154157
let ptr = &externals[index + offset] as *const v8::OneByteConst;

core/runtime/jsrealm.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::hash::BuildHasherDefault;
2626
use std::hash::Hasher;
2727
use std::rc::Rc;
2828
use std::sync::Arc;
29-
use v8::Handle;
3029

3130
pub const CONTEXT_STATE_SLOT_INDEX: i32 = 1;
3231
pub const MODULE_MAP_SLOT_INDEX: i32 = 2;
@@ -291,10 +290,6 @@ impl JsRealm {
291290
self.0.context()
292291
}
293292

294-
pub(crate) fn context_ptr(&self) -> *mut v8::Context {
295-
unsafe { self.0.context.get_unchecked() as *const _ as _ }
296-
}
297-
298293
/// Executes traditional JavaScript code (traditional = not ES modules) in the
299294
/// realm's context.
300295
///

core/runtime/jsruntime.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ impl JsRuntime {
774774
)));
775775

776776
let external_refs: &v8::ExternalReferences =
777-
isolate_allocations.external_refs.as_ref().unwrap().as_ref();
777+
isolate_allocations.external_refs.as_ref().unwrap();
778778
// SAFETY: We attach external_refs to IsolateAllocations which will live as long as the isolate
779-
let external_refs_static = unsafe { std::mem::transmute(external_refs) };
779+
let external_refs_static = unsafe { &*(external_refs as *const _) };
780780

781781
let has_snapshot = maybe_startup_snapshot.is_some();
782782
let mut isolate = setup::create_isolate(
@@ -1067,23 +1067,6 @@ impl JsRuntime {
10671067
self.inner.main_realm.handle_scope(isolate)
10681068
}
10691069

1070-
#[inline(always)]
1071-
/// Create a scope on the stack with the given context
1072-
fn with_context_scope<'s, T>(
1073-
isolate: *mut v8::Isolate,
1074-
context: *mut v8::Context,
1075-
f: impl FnOnce(&mut v8::HandleScope<'s>) -> T,
1076-
) -> T {
1077-
// SAFETY: We know this isolate is valid and non-null at this time
1078-
let mut isolate_scope =
1079-
v8::HandleScope::new(unsafe { isolate.as_mut().unwrap_unchecked() });
1080-
// SAFETY: We know the context is valid and non-null at this time, and that a Local and pointer share the
1081-
// same representation
1082-
let context = unsafe { std::mem::transmute(context) };
1083-
let mut scope = v8::ContextScope::new(&mut isolate_scope, context);
1084-
f(&mut scope)
1085-
}
1086-
10871070
/// Create a synthetic module - `ext:core/ops` - that exports all ops registered
10881071
/// with the runtime.
10891072
fn execute_virtual_ops_module(
@@ -1725,12 +1708,13 @@ impl JsRuntime {
17251708
cx: &mut Context,
17261709
poll_options: PollEventLoopOptions,
17271710
) -> Poll<Result<(), Error>> {
1728-
let isolate = self.v8_isolate_ptr();
1729-
Self::with_context_scope(
1730-
isolate,
1731-
self.inner.main_realm.context_ptr(),
1732-
move |scope| self.poll_event_loop_inner(cx, scope, poll_options),
1733-
)
1711+
// SAFETY: We know this isolate is valid and non-null at this time
1712+
let mut isolate_scope =
1713+
v8::HandleScope::new(unsafe { &mut *self.v8_isolate_ptr() });
1714+
let context =
1715+
v8::Local::new(&mut isolate_scope, self.inner.main_realm.context());
1716+
let mut scope = v8::ContextScope::new(&mut isolate_scope, context);
1717+
self.poll_event_loop_inner(cx, &mut scope, poll_options)
17341718
}
17351719

17361720
fn poll_event_loop_inner(

core/runtime/op_driver/erased_future.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ impl<const MAX_SIZE: usize, Output> ErasedFuture<MAX_SIZE, Output> {
9494
where
9595
F: Future<Output = Output>,
9696
{
97-
F::poll(std::mem::transmute(pin), cx)
97+
F::poll(
98+
std::mem::transmute::<Pin<&mut TypeErased<MAX_SIZE>>, Pin<&mut F>>(pin),
99+
cx,
100+
)
98101
}
99102

100103
#[allow(dead_code)]

core/runtime/snapshot.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ impl SnapshotStoreDataStore {
102102
// TODO(mmastrac): v8::Global needs From/Into
103103
// SAFETY: Because we've tested that Local<Data>: From<Local<T>>, we can assume this is safe.
104104
unsafe {
105-
self.data.push(std::mem::transmute(global));
105+
self.data.push(
106+
std::mem::transmute::<v8::Global<T>, v8::Global<v8::Data>>(global),
107+
);
106108
}
107109
id as _
108110
}

core/tasks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ impl V8TaskSpawnerFactory {
8484

8585
// SAFETY: we are removing the Send trait as we return the tasks here to prevent
8686
// these tasks from accidentally leaking to another thread.
87-
let tasks = unsafe { std::mem::transmute(tasks) };
87+
let tasks =
88+
unsafe { std::mem::transmute::<Vec<SendTask>, Vec<UnsendTask>>(tasks) };
8889
Poll::Ready(tasks)
8990
}
9091

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.78.0"
2+
channel = "1.79.0"
33
components = ["rustfmt", "clippy"]

serde_v8/magic/value.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ impl ToV8 for Value<'_> {
3838
_scope: &mut v8::HandleScope<'a>,
3939
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
4040
// SAFETY: not fully safe, since lifetimes are detached from original scope
41-
Ok(unsafe { transmute(self.v8_value) })
41+
Ok(unsafe {
42+
transmute::<v8::Local<v8::Value>, v8::Local<v8::Value>>(self.v8_value)
43+
})
4244
}
4345
}
4446

0 commit comments

Comments
 (0)