Struct chakracore::context::Context [] [src]

pub struct Context(_);

A sandboxed execution context with its own set of built-in objects and functions.

The majority of APIs require an active context.

In a browser or Node.JS environment, the task of executing promises is handled by the runtime. This is not the case with ChakraCore. To run promise chains, execute_tasks must be called at a regular interval. This is done using the ContextGuard.

Methods

impl Context
[src]

Creates a new context and returns a handle to it.

Binds the context to the current scope.

Returns the active context in the current thread.

This is unsafe because there should be little reason to use it in idiomatic code.

Usage patterns should utilize ContextGuard or exec_with_current instead.

This ContextGuard does not reset the current context upon destruction, in contrast to a normally allocated ContextGuard. This is merely a hollow reference.

Binds the context to the closure's scope.

let result = context.exec_with(|guard| script::eval(guard, "1 + 1")).unwrap();

Executes a closure with the thread's active context.

This is a safe alternative to get_current. It will either return the closures result wrapped in Some, or None, if no context is currently active.

Set user data associated with the context.

  • Only one value per type.
  • The internal implementation uses AnyMap.
  • Returns a previous value if applicable.
  • The data will live as long as the runtime keeps the context.

Remove user data associated with the context.

Get user data associated with the context.

Get mutable user data associated with the context.

impl Context
[src]

Creates an instance from a raw pointer.

This is used for managing the lifetime of JSRT objects. They are tracked using reference counting; incrementing with from_raw, and decrementing with drop.

This is required to support items stored on the heap, since the JSRT runtime only observes the stack.

If used in conjunction with a Property or any Value, it is assumed a Context is active.

Returns the underlying raw pointer.

Trait Implementations

impl Debug for Context
[src]

Formats the value using the given formatter.

impl PartialEq for Context
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Clone for Context
[src]

Duplicates a reference counted type.

The underlying pointer will be copied, and its reference count will be incremented, returned wrapped as the type.

Performs copy-assignment from source. Read more

impl Drop for Context
[src]

Decrements the reference counter.