[][src]Struct boa::Context

pub struct Context { /* fields omitted */ }

Javascript context. It is the primary way to interact with the runtime.

For each Context instance a new instance of runtime is created. It means that it is safe to use different contexts in different threads, but each Context instance must be used only from a single thread.

Implementations

impl Context[src]

pub fn new() -> Self[src]

Create a new Context.

pub fn realm(&self) -> &Realm[src]

pub fn realm_mut(&mut self) -> &mut Realm[src]

pub fn executor(&mut self) -> &mut Interpreter[src]

pub fn construct_symbol(&mut self, description: Option<RcString>) -> RcSymbol[src]

Construct a new Symbol with an optional description.

pub fn construct_object(&self) -> GcObject[src]

Construct an empty object.

pub fn global_object(&self) -> &Value[src]

Return the global object.

pub fn construct_range_error<M>(&mut self, message: M) -> Value where
    M: Into<String>, 
[src]

Constructs a RangeError with the specified message.

pub fn throw_range_error<M>(&mut self, message: M) -> Result<Value> where
    M: Into<String>, 
[src]

Throws a RangeError with the specified message.

pub fn construct_type_error<M>(&mut self, message: M) -> Value where
    M: Into<String>, 
[src]

Constructs a TypeError with the specified message.

pub fn throw_type_error<M>(&mut self, message: M) -> Result<Value> where
    M: Into<String>, 
[src]

Throws a TypeError with the specified message.

pub fn construct_reference_error<M>(&mut self, message: M) -> Value where
    M: Into<String>, 
[src]

Constructs a ReferenceError with the specified message.

pub fn throw_reference_error<M>(&mut self, message: M) -> Result<Value> where
    M: Into<String>, 
[src]

Throws a ReferenceError with the specified message.

pub fn construct_syntax_error<M>(&mut self, message: M) -> Value where
    M: Into<String>, 
[src]

Constructs a SyntaxError with the specified message.

pub fn throw_syntax_error<M>(&mut self, message: M) -> Result<Value> where
    M: Into<String>, 
[src]

Throws a SyntaxError with the specified message.

pub fn create_builtin_function(
    &mut self,
    name: &str,
    length: usize,
    body: NativeFunction
) -> Result<GcObject>
[src]

Create a new builin function.

pub fn register_global_function(
    &mut self,
    name: &str,
    length: usize,
    body: NativeFunction
) -> Result<()>
[src]

Register a global function.

pub fn register_global_class<T>(&mut self) -> Result<()> where
    T: Class
[src]

Register a global class of type T, where T implemets Class.

Example

This example is not tested
#[derive(Debug, Trace, Finalize)]
struct MyClass;

impl Class for MyClass {
   // ...
}

context.register_global_class::<MyClass>();

pub fn eval(&mut self, src: &str) -> Result<Value>[src]

Evaluates the given code.

Examples

let mut context = Context::new();

let value = context.eval("1 + 3").unwrap();

assert!(value.is_number());
assert_eq!(value.as_number().unwrap(), 4.0);

pub fn well_known_symbols(&self) -> &WellKnownSymbols[src]

Returns a structure that contains the JavaScript well known symbols.

Examples

let mut context = Context::new();

let iterator = context.well_known_symbols().iterator_symbol();
assert_eq!(iterator.description(), Some("Symbol.iterator"));

This is equivalent to let iterator = Symbol.iterator in JavaScript.

Trait Implementations

impl Debug for Context[src]

impl Default for Context[src]

Auto Trait Implementations

impl !RefUnwindSafe for Context

impl !Send for Context

impl !Sync for Context

impl Unpin for Context

impl !UnwindSafe for Context

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,