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

source

pub fn new(perms: Permissions) -> Self

source

pub fn allow_all() -> Self

Examples found in repository?
examples/hello_runtime.rs (line 77)
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
85
86
87
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(),
  };

  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(),
    &std::env::current_dir().context("Unable to get CWD")?,
  )?;
  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(())
}
source

pub fn check_specifier( &self, specifier: &ModuleSpecifier ) -> Result<(), AnyError>

source

pub fn check_read( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>

source

pub fn check_write( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>

source

pub fn check_run(&mut self, cmd: &str, api_name: &str) -> Result<(), AnyError>

source

pub fn check_run_all(&mut self, api_name: &str) -> Result<(), AnyError>

source

pub fn check_sys(&mut self, kind: &str, api_name: &str) -> Result<(), AnyError>

source

pub fn check_env(&mut self, var: &str) -> Result<(), AnyError>

source

pub fn check_env_all(&mut self) -> Result<(), AnyError>

Trait Implementations§

source§

impl Clone for PermissionsContainer

source§

fn clone(&self) -> PermissionsContainer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PermissionsContainer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FetchPermissions for PermissionsContainer

source§

fn check_net_url(&mut self, url: &Url, api_name: &str) -> Result<(), AnyError>

source§

fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

impl FfiPermissions for PermissionsContainer

source§

fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError>

source§

impl FlashPermissions for PermissionsContainer

source§

fn check_net<T: AsRef<str>>( &mut self, host: &(T, Option<u16>), api_name: &str ) -> Result<(), AnyError>

source§

impl FsPermissions for PermissionsContainer

source§

fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>

source§

fn check_write(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>

source§

fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>

source§

impl NapiPermissions for PermissionsContainer

source§

fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError>

source§

impl NetPermissions for PermissionsContainer

source§

fn check_net<T: AsRef<str>>( &mut self, host: &(T, Option<u16>), api_name: &str ) -> Result<(), AnyError>

source§

fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_write(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

impl NodePermissions for PermissionsContainer

source§

fn check_read(&mut self, path: &Path) -> Result<(), AnyError>

source§

impl SqliteDbHandlerPermissions for PermissionsContainer

source§

fn check_read(&mut self, p: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_write(&mut self, p: &Path, api_name: &str) -> Result<(), AnyError>

source§

impl TimersPermission for PermissionsContainer

source§

fn allow_hrtime(&mut self) -> bool

source§

fn check_unstable(&self, state: &OpState, api_name: &'static str)

source§

impl WebSocketPermissions for PermissionsContainer

source§

fn check_net_url(&mut self, url: &Url, api_name: &str) -> Result<(), AnyError>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more