pub struct Context(/* private fields */);
Expand description
A single execution context with its own global variables and stack.
Can share objects with other contexts of the same runtime.
Implementations§
source§impl Context
impl Context
sourcepub unsafe fn from_raw(ctx: NonNull<JSContext>, rt: Runtime) -> Context
pub unsafe fn from_raw(ctx: NonNull<JSContext>, rt: Runtime) -> Context
Create a unused context from a raw context pointer.
§Safety
Pointer must point to a context from the given runtime. The context must also have valid reference count, one which can be decremented when this object is dropped without going negative.
pub fn as_raw(&self) -> NonNull<JSContext>
sourcepub fn base(runtime: &Runtime) -> Result<Context, Error>
pub fn base(runtime: &Runtime) -> Result<Context, Error>
Creates a base context with only the required functions registered.
If additional functions are required use Context::custom
,
Context::builder
or Context::full
.
sourcepub fn custom<I>(runtime: &Runtime) -> Result<Context, Error>where
I: Intrinsic,
pub fn custom<I>(runtime: &Runtime) -> Result<Context, Error>where
I: Intrinsic,
Creates a context with only the required intrinsics registered.
If additional functions are required use Context::custom
,
Context::builder
or Context::full
.
sourcepub fn full(runtime: &Runtime) -> Result<Context, Error>
pub fn full(runtime: &Runtime) -> Result<Context, Error>
Creates a context with all standard available intrinsics registered.
If precise control is required of which functions are available use
Context::custom
or Context::builder
.
sourcepub fn builder() -> ContextBuilder<()>
pub fn builder() -> ContextBuilder<()>
Create a context builder for creating a context with a specific set of intrinsics
pub fn enable_big_num_ext(&self, enable: bool)
sourcepub fn with<F, R>(&self, f: F) -> R
pub fn with<F, R>(&self, f: F) -> R
A entry point for manipulating and using JavaScript objects and scripts. The api is structured this way to avoid repeated locking the runtime when ever any function is called. This way the runtime is locked once before executing the callback. Furthermore, this way it is impossible to use values from different runtimes in this context which would otherwise be undefined behavior.
This is the only way to get a Ctx
object.