2020-01-21 11:50:06 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use crate::ops;
|
2020-02-08 14:34:31 -05:00
|
|
|
use crate::state::State;
|
2020-01-21 11:50:06 -05:00
|
|
|
use crate::worker::Worker;
|
|
|
|
use deno_core;
|
|
|
|
use deno_core::StartupData;
|
|
|
|
use std::ops::Deref;
|
|
|
|
use std::ops::DerefMut;
|
|
|
|
|
|
|
|
/// This worker is used to host TypeScript and WASM compilers.
|
|
|
|
///
|
|
|
|
/// It provides minimal set of ops that are necessary to facilitate
|
|
|
|
/// compilation.
|
|
|
|
///
|
|
|
|
/// NOTE: This worker is considered priveleged, because it may
|
|
|
|
/// access file system without permission check.
|
|
|
|
///
|
|
|
|
/// At the moment this worker is meant to be single-use - after
|
|
|
|
/// performing single compilation/bundling it should be destroyed.
|
|
|
|
///
|
|
|
|
/// TODO(bartlomieju): add support to reuse the worker - or in other
|
|
|
|
/// words support stateful TS compiler
|
|
|
|
pub struct CompilerWorker(Worker);
|
|
|
|
|
|
|
|
impl CompilerWorker {
|
2020-02-08 14:34:31 -05:00
|
|
|
pub fn new(name: String, startup_data: StartupData, state: State) -> Self {
|
2020-01-21 11:50:06 -05:00
|
|
|
let state_ = state.clone();
|
2020-02-05 02:40:38 -05:00
|
|
|
let mut worker = Worker::new(name, startup_data, state_);
|
2020-01-21 11:50:06 -05:00
|
|
|
{
|
2020-02-03 18:08:44 -05:00
|
|
|
let isolate = &mut worker.isolate;
|
|
|
|
ops::runtime::init(isolate, &state);
|
|
|
|
ops::compiler::init(isolate, &state);
|
2020-02-11 04:04:59 -05:00
|
|
|
ops::web_worker::init(isolate, &state, &worker.internal_channels.sender);
|
2020-02-03 18:08:44 -05:00
|
|
|
ops::errors::init(isolate, &state);
|
2020-01-27 21:12:25 -05:00
|
|
|
// for compatibility with Worker scope, though unused at
|
|
|
|
// the moment
|
2020-02-03 18:08:44 -05:00
|
|
|
ops::timers::init(isolate, &state);
|
|
|
|
ops::fetch::init(isolate, &state);
|
2020-01-21 11:50:06 -05:00
|
|
|
// TODO(bartlomieju): CompilerWorker should not
|
|
|
|
// depend on those ops
|
2020-02-03 18:08:44 -05:00
|
|
|
ops::os::init(isolate, &state);
|
|
|
|
ops::files::init(isolate, &state);
|
|
|
|
ops::fs::init(isolate, &state);
|
|
|
|
ops::io::init(isolate, &state);
|
2020-01-21 11:50:06 -05:00
|
|
|
}
|
|
|
|
Self(worker)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for CompilerWorker {
|
|
|
|
type Target = Worker;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for CompilerWorker {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.0
|
|
|
|
}
|
|
|
|
}
|