[−][src]Struct boa::Context
Javascript context. It is the primary way to interact with the runtime.
Context
s 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]
M: Into<Box<str>>,
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]
M: Into<Box<str>>,
Throws a RangeError
with the specified message.
pub fn construct_type_error<M>(&mut self, message: M) -> Value where
M: Into<Box<str>>,
[src]
M: Into<Box<str>>,
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]
M: Into<Box<str>>,
Throws a TypeError
with the specified message.
pub fn construct_reference_error<M>(&mut self, message: M) -> Value where
M: Into<Box<str>>,
[src]
M: Into<Box<str>>,
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]
M: Into<Box<str>>,
Throws a ReferenceError
with the specified message.
pub fn construct_syntax_error<M>(&mut self, message: M) -> Value where
M: Into<Box<str>>,
[src]
M: Into<Box<str>>,
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]
M: Into<Box<str>>,
Throws a SyntaxError
with the specified message.
pub fn construct_eval_error<M>(&mut self, message: M) -> Value where
M: Into<Box<str>>,
[src]
M: Into<Box<str>>,
Constructs a EvalError
with the specified message.
pub fn construct_uri_error<M>(&mut self, message: M) -> Value where
M: Into<Box<str>>,
[src]
M: Into<Box<str>>,
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]
M: Into<Box<str>>,
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]
M: Into<Box<str>>,
Throws a URIError
with the specified message.
pub fn create_builtin_function(
&mut self,
name: &str,
length: usize,
body: NativeFunction
) -> Result<GcObject>
[src]
&mut self,
name: &str,
length: usize,
body: NativeFunction
) -> Result<GcObject>
Create a new builin function.
pub fn register_global_function(
&mut self,
name: &str,
length: usize,
body: NativeFunction
) -> Result<()>
[src]
&mut self,
name: &str,
length: usize,
body: NativeFunction
) -> Result<()>
Register a global function.
pub fn register_global_class<T>(&mut self) -> Result<()> where
T: Class,
[src]
T: Class,
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]
&mut self,
key: K,
value: V,
attribute: Attribute
) where
K: Into<PropertyKey>,
V: Into<Value>,
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
Auto Trait Implementations
impl !RefUnwindSafe for Context
[src]
impl !Send for Context
[src]
impl !Sync for Context
[src]
impl Unpin for Context
[src]
impl !UnwindSafe for Context
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,