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: BundleCodeThe code.
source_map: Option<Arc<str>>Source map (JSON) used to show app source locations in stack traces.
policy: PolicyWhat the code may do.
Implementations§
Source§impl Bundle
impl Bundle
Sourcepub unsafe fn bytecode(bytes: Vec<u8>) -> Self
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).
Sourcepub fn with_source_map(self, map: impl Into<Arc<str>>) -> Self
pub fn with_source_map(self, map: impl Into<Arc<str>>) -> Self
Attaches a source map.
Sourcepub fn with_policy(self, policy: Policy) -> Self
pub fn with_policy(self, policy: Policy) -> Self
Replaces the policy.
Sourcepub fn read(path: &Path) -> Result<Bundle>
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.
Sourcepub unsafe fn read_trusted(path: &Path) -> Result<Bundle>
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
impl Bundle
Sourcepub fn from_package(package: &VerifiedPackage) -> Result<Bundle, String>
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.