Skip to content

Commit 333c579

Browse files
committed
Merge branch 'main' into source_map_getter
2 parents ec8e4f1 + b5218a5 commit 333c579

File tree

11 files changed

+36
-65
lines changed

11 files changed

+36
-65
lines changed

core/extension_set.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::ModuleCodeString;
2222
use crate::OpDecl;
2323
use crate::OpMetricsFactoryFn;
2424
use crate::OpState;
25-
use crate::SourceMapGetter;
2625

2726
/// Contribute to the `OpState` from each extension.
2827
pub fn setup_op_state(op_state: &mut OpState, extensions: &mut [Extension]) {
@@ -242,7 +241,7 @@ impl<'a> IntoIterator for &'a mut LoadedSources {
242241
fn load(
243242
transpiler: Option<&ExtensionTranspiler>,
244243
source: &ExtensionFileSource,
245-
source_mapper: &mut SourceMapper<Rc<dyn SourceMapGetter>>,
244+
source_mapper: &mut SourceMapper,
246245
load_callback: &mut impl FnMut(&ExtensionFileSource),
247246
) -> Result<ModuleCodeString, AnyError> {
248247
load_callback(source);
@@ -263,7 +262,7 @@ fn load(
263262
pub fn into_sources(
264263
transpiler: Option<&ExtensionTranspiler>,
265264
extensions: &[Extension],
266-
source_mapper: &mut SourceMapper<Rc<dyn SourceMapGetter>>,
265+
source_mapper: &mut SourceMapper,
267266
mut load_callback: impl FnMut(&ExtensionFileSource),
268267
) -> Result<LoadedSources, AnyError> {
269268
let mut sources = LoadedSources::default();

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: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub type CompiledWasmModuleStore = CrossIsolateStore<v8::CompiledWasmModule>;
407407
/// Internal state for JsRuntime which is stored in one of v8::Isolate's
408408
/// embedder slots.
409409
pub struct JsRuntimeState {
410-
pub(crate) source_mapper: RefCell<SourceMapper<Rc<dyn SourceMapGetter>>>,
410+
pub(crate) source_mapper: RefCell<SourceMapper>,
411411
pub(crate) op_state: Rc<RefCell<OpState>>,
412412
pub(crate) shared_array_buffer_store: Option<SharedArrayBufferStore>,
413413
pub(crate) compiled_wasm_module_store: Option<CompiledWasmModuleStore>,
@@ -672,8 +672,7 @@ impl JsRuntime {
672672

673673
// Load the sources and source maps
674674
let mut files_loaded = Vec::with_capacity(128);
675-
let mut source_mapper: SourceMapper<Rc<dyn SourceMapGetter>> =
676-
SourceMapper::new(options.source_map_getter);
675+
let mut source_mapper = SourceMapper::new(options.source_map_getter);
677676
let mut sources = extension_set::into_sources(
678677
options.extension_transpiler.as_deref(),
679678
&extensions,
@@ -775,9 +774,9 @@ impl JsRuntime {
775774
)));
776775

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

782781
let has_snapshot = maybe_startup_snapshot.is_some();
783782
let mut isolate = setup::create_isolate(
@@ -1073,23 +1072,6 @@ impl JsRuntime {
10731072
self.inner.main_realm.handle_scope(isolate)
10741073
}
10751074

1076-
#[inline(always)]
1077-
/// Create a scope on the stack with the given context
1078-
fn with_context_scope<'s, T>(
1079-
isolate: *mut v8::Isolate,
1080-
context: *mut v8::Context,
1081-
f: impl FnOnce(&mut v8::HandleScope<'s>) -> T,
1082-
) -> T {
1083-
// SAFETY: We know this isolate is valid and non-null at this time
1084-
let mut isolate_scope =
1085-
v8::HandleScope::new(unsafe { isolate.as_mut().unwrap_unchecked() });
1086-
// SAFETY: We know the context is valid and non-null at this time, and that a Local and pointer share the
1087-
// same representation
1088-
let context = unsafe { std::mem::transmute(context) };
1089-
let mut scope = v8::ContextScope::new(&mut isolate_scope, context);
1090-
f(&mut scope)
1091-
}
1092-
10931075
/// Create a synthetic module - `ext:core/ops` - that exports all ops registered
10941076
/// with the runtime.
10951077
fn execute_virtual_ops_module(
@@ -1731,12 +1713,13 @@ impl JsRuntime {
17311713
cx: &mut Context,
17321714
poll_options: PollEventLoopOptions,
17331715
) -> Poll<Result<(), Error>> {
1734-
let isolate = self.v8_isolate_ptr();
1735-
Self::with_context_scope(
1736-
isolate,
1737-
self.inner.main_realm.context_ptr(),
1738-
move |scope| self.poll_event_loop_inner(cx, scope, poll_options),
1739-
)
1716+
// SAFETY: We know this isolate is valid and non-null at this time
1717+
let mut isolate_scope =
1718+
v8::HandleScope::new(unsafe { &mut *self.v8_isolate_ptr() });
1719+
let context =
1720+
v8::Local::new(&mut isolate_scope, self.inner.main_realm.context());
1721+
let mut scope = v8::ContextScope::new(&mut isolate_scope, context);
1722+
self.poll_event_loop_inner(cx, &mut scope, poll_options)
17401723
}
17411724

17421725
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/source_map.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,6 @@ pub trait SourceMapGetter {
2525
) -> Option<String>;
2626
}
2727

28-
impl<T> SourceMapGetter for Rc<T>
29-
where
30-
T: SourceMapGetter + ?Sized,
31-
{
32-
fn get_source_map(&self, file_name: &str) -> Option<Vec<u8>> {
33-
(**self).get_source_map(file_name)
34-
}
35-
36-
fn get_source_line(
37-
&self,
38-
file_name: &str,
39-
line_number: usize,
40-
) -> Option<String> {
41-
(**self).get_source_line(file_name, line_number)
42-
}
43-
}
44-
4528
#[derive(Debug)]
4629
pub enum SourceMapApplication {
4730
/// No mapping was applied, the location is unchanged.
@@ -61,19 +44,19 @@ pub enum SourceMapApplication {
6144

6245
pub type SourceMapData = Cow<'static, [u8]>;
6346

64-
pub struct SourceMapper<G: SourceMapGetter> {
47+
pub struct SourceMapper {
6548
maps: HashMap<String, Option<SourceMap>>,
6649
source_lines: HashMap<(String, i64), Option<String>>,
67-
getter: Option<G>,
50+
getter: Option<Rc<dyn SourceMapGetter>>,
6851
pub(crate) ext_source_maps: HashMap<String, SourceMapData>,
6952
// This is not the right place for this, but it's the easiest way to make
7053
// op_apply_source_map a fast op. This stashing should happen in #[op2].
7154
pub(crate) stashed_file_name: Option<String>,
7255
pub(crate) maybe_module_map: Option<Rc<ModuleMap>>,
7356
}
7457

75-
impl<G: SourceMapGetter> SourceMapper<G> {
76-
pub fn new(getter: Option<G>) -> Self {
58+
impl SourceMapper {
59+
pub fn new(getter: Option<Rc<dyn SourceMapGetter>>) -> Self {
7760
Self {
7861
maps: Default::default(),
7962
source_lines: Default::default(),
@@ -88,7 +71,7 @@ impl<G: SourceMapGetter> SourceMapper<G> {
8871
assert!(self.maybe_module_map.replace(module_map).is_none());
8972
}
9073

91-
pub fn has_user_sources(&self) -> bool {
74+
pub(crate) fn has_user_sources(&self) -> bool {
9275
self.getter.is_some()
9376
}
9477

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"]

0 commit comments

Comments
 (0)