ferrijs-std 0.2.1

Node and web standard library for the ferrijs QuickJS runtime: WHATWG Streams, Events, AbortController, Buffer, crypto, fs, os, url, zlib and the capability model they enforce (partly derived from awslabs/llrt, Apache-2.0).
Documentation
//! Node modules with no usable upstream in llrt, written here so the
//! runtime has exactly one implementation of each.

use rquickjs::{Ctx, Object, Value};

pub mod assert;
pub mod bytes;
pub mod deep_equal;
pub mod inspect;
pub mod path;
pub mod process;
pub mod require_resolve;
pub mod timers;
pub mod util;

/// Throw an `Error` carrying a specific `name` (`TypeError`,
/// `RangeError`, ...). QuickJS's own constructors are used so the thrown
/// value is a real `Error` with a stack.
pub fn throw_named<'js>(ctx: &Ctx<'js>, name: &str, message: impl Into<String>) -> rquickjs::Error {
  let message = message.into();
  let built: rquickjs::Result<Value<'js>> = (|| {
    let ctor: rquickjs::function::Constructor<'js> = ctx.globals().get("Error")?;
    let err: Object<'js> = ctor.construct((message.as_str(),))?;
    err.set("name", name)?;
    Ok(err.into_value())
  })();
  match built {
    Ok(v) => ctx.throw(v),
    Err(_) => rquickjs::Exception::throw_message(ctx, &message),
  }
}