mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
Make JsRuntimeState private (#7484)
This commit is contained in:
parent
85b98f6dd8
commit
055dfe2ff4
5 changed files with 13 additions and 22 deletions
|
@ -394,9 +394,7 @@ impl DenoInspector {
|
|||
isolate: &mut deno_core::JsRuntime,
|
||||
host: SocketAddr,
|
||||
) -> Box<Self> {
|
||||
let core_state_rc = deno_core::JsRuntime::state(isolate);
|
||||
let core_state = core_state_rc.borrow();
|
||||
|
||||
let context = isolate.global_context();
|
||||
let scope = &mut v8::HandleScope::new(&mut **isolate);
|
||||
|
||||
let (new_websocket_tx, new_websocket_rx) =
|
||||
|
@ -434,11 +432,7 @@ impl DenoInspector {
|
|||
});
|
||||
|
||||
// Tell the inspector about the global context.
|
||||
let context = core_state
|
||||
.global_context
|
||||
.as_ref()
|
||||
.map(|context| v8::Local::new(scope, context))
|
||||
.unwrap();
|
||||
let context = v8::Local::new(scope, context);
|
||||
let context_name = v8::inspector::StringView::from(&b"global context"[..]);
|
||||
self_.context_created(context, Self::CONTEXT_GROUP_ID, context_name);
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use crate::error::AnyError;
|
||||
use crate::error::JsError;
|
||||
use crate::runtime::JsRuntimeState;
|
||||
use crate::JsRuntime;
|
||||
use crate::JsRuntimeState;
|
||||
use crate::Op;
|
||||
use crate::OpId;
|
||||
use crate::OpTable;
|
||||
|
|
|
@ -45,7 +45,6 @@ pub use crate::runtime::js_check;
|
|||
pub use crate::runtime::GetErrorClassFn;
|
||||
pub use crate::runtime::HeapLimits;
|
||||
pub use crate::runtime::JsRuntime;
|
||||
pub use crate::runtime::JsRuntimeState;
|
||||
pub use crate::runtime::RuntimeOptions;
|
||||
pub use crate::runtime::Snapshot;
|
||||
pub use crate::zero_copy_buf::BufVec;
|
||||
|
|
|
@ -363,6 +363,7 @@ impl ModuleNameMap {
|
|||
}
|
||||
|
||||
/// Check if a name is an alias to another module.
|
||||
#[cfg(test)]
|
||||
pub fn is_alias(&self, name: &str) -> bool {
|
||||
let cond = self.inner.get(name);
|
||||
matches!(cond, Some(SymbolicModule::Alias(_)))
|
||||
|
@ -427,6 +428,7 @@ impl Modules {
|
|||
self.by_name.alias(name.to_owned(), target.to_owned());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn is_alias(&self, name: &str) -> bool {
|
||||
self.by_name.is_alias(name)
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ pub struct JsRuntime {
|
|||
|
||||
/// Internal state for JsRuntime which is stored in one of v8::Isolate's
|
||||
/// embedder slots.
|
||||
pub struct JsRuntimeState {
|
||||
pub(crate) struct JsRuntimeState {
|
||||
pub global_context: Option<v8::Global<v8::Context>>,
|
||||
pub(crate) shared_ab: Option<v8::Global<v8::SharedArrayBuffer>>,
|
||||
pub(crate) js_recv_cb: Option<v8::Global<v8::Function>>,
|
||||
|
@ -305,6 +305,12 @@ impl JsRuntime {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn global_context(&self) -> v8::Global<v8::Context> {
|
||||
let state = Self::state(self);
|
||||
let state = state.borrow();
|
||||
state.global_context.clone().unwrap()
|
||||
}
|
||||
|
||||
fn setup_isolate(mut isolate: v8::OwnedIsolate) -> v8::OwnedIsolate {
|
||||
isolate.set_capture_stack_trace_for_uncaught_exceptions(true, 10);
|
||||
isolate.set_promise_reject_callback(bindings::promise_reject_callback);
|
||||
|
@ -317,7 +323,7 @@ impl JsRuntime {
|
|||
isolate
|
||||
}
|
||||
|
||||
pub fn state(isolate: &v8::Isolate) -> Rc<RefCell<JsRuntimeState>> {
|
||||
pub(crate) fn state(isolate: &v8::Isolate) -> Rc<RefCell<JsRuntimeState>> {
|
||||
let s = isolate.get_slot::<Rc<RefCell<JsRuntimeState>>>().unwrap();
|
||||
s.clone()
|
||||
}
|
||||
|
@ -594,16 +600,6 @@ impl Future for JsRuntime {
|
|||
}
|
||||
|
||||
impl JsRuntimeState {
|
||||
/// Allows a callback to be set whenever a V8 exception is made. This allows
|
||||
/// the caller to wrap the JsError into an error. By default this callback
|
||||
/// is set to JsError::create.
|
||||
pub fn set_js_error_create_fn(
|
||||
&mut self,
|
||||
f: impl Fn(JsError) -> AnyError + 'static,
|
||||
) {
|
||||
self.js_error_create_fn = Box::new(f);
|
||||
}
|
||||
|
||||
// Called by V8 during `Isolate::mod_instantiate`.
|
||||
pub fn module_resolve_cb(
|
||||
&mut self,
|
||||
|
|
Loading…
Add table
Reference in a new issue