Struct deno_runtime::permissions::PermissionsContainer
source · pub struct PermissionsContainer(pub Arc<Mutex<Permissions>>);
Expand description
Wrapper struct for Permissions
that can be shared across threads.
We need a way to have internal mutability for permissions as they might get passed to a future that will prompt the user for permission (and in such case might need to be mutated). Also for the Web Worker API we need a way to send permissions to a new thread.
Tuple Fields§
§0: Arc<Mutex<Permissions>>
Implementations§
source§impl PermissionsContainer
impl PermissionsContainer
pub fn new(perms: Permissions) -> Self
sourcepub fn allow_all() -> Self
pub fn allow_all() -> Self
Examples found in repository?
examples/hello_runtime.rs (line 74)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
async fn main() -> Result<(), AnyError> {
let module_loader = Rc::new(FsModuleLoader);
let create_web_worker_cb = Arc::new(|_| {
todo!("Web workers are not supported in the example");
});
let web_worker_event_cb = Arc::new(|_| {
todo!("Web workers are not supported in the example");
});
let options = WorkerOptions {
bootstrap: BootstrapOptions {
args: vec![],
cpu_count: 1,
debug_flag: false,
enable_testing_features: false,
locale: deno_core::v8::icu::get_language_tag(),
location: None,
no_color: false,
is_tty: false,
runtime_version: "x".to_string(),
ts_version: "x".to_string(),
unstable: false,
user_agent: "hello_runtime".to_string(),
inspect: false,
},
extensions: vec![],
startup_snapshot: None,
unsafely_ignore_certificate_errors: None,
root_cert_store: None,
seed: None,
source_map_getter: None,
format_js_error_fn: None,
web_worker_preload_module_cb: web_worker_event_cb.clone(),
web_worker_pre_execute_module_cb: web_worker_event_cb,
create_web_worker_cb,
maybe_inspector_server: None,
should_break_on_first_statement: false,
should_wait_for_inspector_session: false,
module_loader,
npm_resolver: None,
get_error_class_fn: Some(&get_error_class_name),
cache_storage_dir: None,
origin_storage_dir: None,
blob_store: BlobStore::default(),
broadcast_channel: InMemoryBroadcastChannel::default(),
shared_array_buffer_store: None,
compiled_wasm_module_store: None,
stdio: Default::default(),
leak_isolate: true,
};
let js_path =
Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/hello_runtime.js");
let main_module = deno_core::resolve_path(&js_path.to_string_lossy())?;
let permissions = PermissionsContainer::allow_all();
let mut worker = MainWorker::bootstrap_from_options(
main_module.clone(),
permissions,
options,
);
worker.execute_main_module(&main_module).await?;
worker.run_event_loop(false).await?;
Ok(())
}
pub fn check_specifier( &self, specifier: &ModuleSpecifier ) -> Result<(), AnyError>
pub fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>
pub fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>
pub fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>
pub fn check_write(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>
pub fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>
pub fn check_run(&mut self, cmd: &str, api_name: &str) -> Result<(), AnyError>
pub fn check_run_all(&mut self, api_name: &str) -> Result<(), AnyError>
pub fn check_sys(&mut self, kind: &str, api_name: &str) -> Result<(), AnyError>
pub fn check_env(&mut self, var: &str) -> Result<(), AnyError>
pub fn check_env_all(&mut self) -> Result<(), AnyError>
Trait Implementations§
source§impl Clone for PermissionsContainer
impl Clone for PermissionsContainer
source§fn clone(&self) -> PermissionsContainer
fn clone(&self) -> PermissionsContainer
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more