Skip to main content

Bundle

Struct Bundle 

Source
pub struct Bundle {
    pub code: BundleCode,
    pub source_map: Option<Arc<str>>,
    pub policy: Policy,
}
Expand description

An app bundle: its code plus, in development, a source map.

Fields§

§code: BundleCode

The code.

§source_map: Option<Arc<str>>

Source map (JSON) used to show app source locations in stack traces.

§policy: Policy

What the code may do.

Implementations§

Source§

impl Bundle

Source

pub unsafe fn bytecode(bytes: Vec<u8>) -> Self

A bytecode bundle.

§Safety

bytes must be bytecode from nsh_js::compile_bytecode for this runtime’s BYTECODE_VERSION, from a trusted source: QuickJS does not validate bytecode, and loading crafted bytecode corrupts memory. Trusted are the app’s own signed resources, a development server the developer pointed the host at, and verified packages (Bundle::from_package).

Source

pub fn source(code: String) -> Self

A JS source bundle.

Source

pub fn with_source_map(self, map: impl Into<Arc<str>>) -> Self

Attaches a source map.

Source

pub fn with_policy(self, policy: Policy) -> Self

Replaces the policy.

Source

pub fn read(path: &Path) -> Result<Bundle>

Reads a JS source bundle written by nsh build (bundle.js), plus bundle.js.map and the app’s capabilities.json next to it if present. Bytecode (bundle.nshc) is refused: files can be replaced, and only Bundle::read_trusted (the app’s own resources) or a verified package may load bytecode.

Source

pub unsafe fn read_trusted(path: &Path) -> Result<Bundle>

Like Bundle::read, also reading bundle.nshc as bytecode.

§Safety

A .nshc file must be trusted as Bundle::bytecode requires (e.g. inside the app’s own signed bundle).

Source§

impl Bundle

Source

pub fn from_package(package: &VerifiedPackage) -> Result<Bundle, String>

The bundle of a verified package: its bytecode when it was compiled for this runtime (else its source), its source map and its declared capabilities.

Source§

impl Bundle

Source

pub fn with_capabilities_json(self, json: Option<&str>) -> Result<Self, String>

The declared capabilities from their JSON form, if any.

Trait Implementations§

Source§

impl Clone for Bundle

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bundle

Source§

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

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

impl From<Bundle> for App

Source§

fn from(bundle: Bundle) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> ParallelSend for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.