Remove Config struct from core (#2502)

It's unnecessary indirection and is preventing the ability to easily
pass isolate references into the dispatch and dyn_import closures.

Note: this changes how StartupData::Script is executed. It's no longer done
during Isolate::new() but rather lazily on first poll or execution.
This commit is contained in:
Ryan Dahl 2019-06-12 10:53:24 -07:00 committed by GitHub
parent 8693d0e0a7
commit 2a5138a516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 78 deletions

View file

@ -5,7 +5,6 @@ use crate::js_errors;
use crate::state::ThreadSafeState;
use crate::tokio_util;
use deno;
use deno::Config;
use deno::JSError;
use deno::StartupData;
use futures::Async;
@ -18,7 +17,7 @@ use url::Url;
/// high-level module loading
#[derive(Clone)]
pub struct Worker {
inner: Arc<Mutex<deno::Isolate>>,
isolate: Arc<Mutex<deno::Isolate>>,
pub state: ThreadSafeState,
}
@ -29,14 +28,14 @@ impl Worker {
state: ThreadSafeState,
) -> Worker {
let state_ = state.clone();
let mut config = Config::default();
config.dispatch(move |control_buf, zero_copy_buf| {
state_.dispatch(control_buf, zero_copy_buf)
});
Self {
inner: Arc::new(Mutex::new(deno::Isolate::new(startup_data, config))),
state,
let isolate = Arc::new(Mutex::new(deno::Isolate::new(startup_data, false)));
{
let mut i = isolate.lock().unwrap();
i.set_dispatch(move |control_buf, zero_copy_buf| {
state_.dispatch(control_buf, zero_copy_buf)
});
}
Self { isolate, state }
}
/// Same as execute2() but the filename defaults to "<anonymous>".
@ -51,7 +50,7 @@ impl Worker {
js_filename: &str,
js_source: &str,
) -> Result<(), JSError> {
let mut isolate = self.inner.lock().unwrap();
let mut isolate = self.isolate.lock().unwrap();
isolate.execute(js_filename, js_source)
}
@ -64,7 +63,7 @@ impl Worker {
let worker = self.clone();
let worker_ = worker.clone();
let loader = self.state.clone();
let isolate = self.inner.clone();
let isolate = self.isolate.clone();
let modules = self.state.modules.clone();
let recursive_load =
deno::RecursiveLoad::new(js_url.as_str(), loader, isolate, modules);
@ -74,7 +73,7 @@ impl Worker {
if is_prefetch {
Ok(())
} else {
let mut isolate = worker.inner.lock().unwrap();
let mut isolate = worker.isolate.lock().unwrap();
let result = isolate.mod_evaluate(id);
if let Err(err) = result {
Err(deno::JSErrorOr::JSError(err))
@ -166,7 +165,7 @@ impl Future for Worker {
type Error = JSError;
fn poll(&mut self) -> Result<Async<()>, Self::Error> {
let mut isolate = self.inner.lock().unwrap();
let mut isolate = self.isolate.lock().unwrap();
isolate.poll().map_err(|err| self.apply_source_map(err))
}
}