[][src]Struct boa::Context

pub struct Context { /* fields omitted */ }

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

Contexts constructed in a thread share the same runtime, therefore it is possible to share objects from one context to another context, but they have to be in the same 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) -> &GcObject[src]

Return the global object.

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

Constructs a RangeError with the specified message.

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

Throws a RangeError with the specified message.

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

Constructs a TypeError with the specified message.

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

Throws a TypeError with the specified message.

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

Constructs a ReferenceError with the specified message.

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

Throws a ReferenceError with the specified message.

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

Constructs a SyntaxError with the specified message.

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

Throws a SyntaxError with the specified message.

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

Constructs a EvalError with the specified message.

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

Constructs a URIError with the specified message.

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

Throws a EvalError with the specified message.

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

Throws a URIError 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 implements Class.

Example

#[derive(Debug, Trace, Finalize)]
struct MyClass;

impl Class for MyClass {
   // ...
}

context.register_global_class::<MyClass>();

pub fn register_global_property<K, V>(
    &mut self,
    key: K,
    value: V,
    attribute: Attribute
) where
    K: Into<PropertyKey>,
    V: Into<Value>, 
[src]

Register a global property.

Example

use boa::{Context, property::Attribute, object::ObjectInitializer};

let mut context = Context::new();

context.register_global_property("myPrimitiveProperty", 10, Attribute::all());

let object = ObjectInitializer::new(&mut context)
   .property("x", 0, Attribute::all())
   .property("y", 1, Attribute::all())
   .build();
context.register_global_property("myObjectProperty", object, Attribute::all());

pub fn eval<T: AsRef<[u8]>>(&mut self, src: T) -> 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.

pub fn iterator_prototypes(&self) -> &IteratorPrototypes[src]

Return the cached iterator prototypes.

pub fn standard_objects(&self) -> &StandardObjects[src]

Return the core standard objects.

Trait Implementations

impl Debug for Context[src]

impl Default for Context[src]

Auto Trait Implementations

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>,