Skip to main content

SuperGlobalEnvironment

Struct SuperGlobalEnvironment 

Source
pub struct SuperGlobalEnvironment { /* private fields */ }
Expand description

The super-global environment for lazy resolution of built-in objects.

This is the outermost scope in the resolution chain, sitting below even the global scope. It provides built-in objects (Math, console, etc.) and plugin-provided objects through a lazy resolution mechanism.

§Key Features

  • Lazy Resolution: Objects are only materialized when first accessed
  • Caching: Once resolved, values are cached for fast subsequent access
  • Read-Only: JavaScript code cannot create or modify super-global bindings
  • Plugin System: Multiple resolvers can be registered, queried in order
  • Method Dispatch: Efficient method calls without object materialization

§Resolution Order

When a name is looked up:

  1. Check if it’s in the cache → return cached value
  2. Query each resolver’s has_binding() in registration order
  3. First resolver that claims the name wins
  4. Call resolver’s resolve() to materialize the value
  5. Cache the value and resolver index
  6. Return the value

§Method Call Optimization

For method calls like Math.abs(-5), the super-global can dispatch directly to the resolver’s call_method() without materializing the Math object, providing better performance for built-in method calls.

§Thread Safety

This struct is typically wrapped in Rc<RefCell<>> (see SharedSuperGlobal) to allow shared mutable access across the evaluation context.

Implementations§

Source§

impl SuperGlobalEnvironment

Source

pub fn new() -> Self

Source

pub fn add_resolver(&mut self, resolver: Box<dyn PluginResolver>)

Register a plugin resolver. Resolvers are queried in registration order.

Source

pub fn call_method( &self, object_name: &str, method_name: &str, ctx: &mut EvalContext, this: JsValue, args: Vec<JsValue>, ) -> Option<Result<JsValue, JErrorType>>

Call a method on a super-global object, dispatching to the owning resolver.

Returns None if no resolver owns object_name or the resolver doesn’t provide the method (allowing fallback to property lookup).

Source

pub fn call_constructor( &self, object_name: &str, ctx: &mut EvalContext, args: Vec<JsValue>, ) -> Option<Result<JsValue, JErrorType>>

Call a constructor on a super-global object.

Source

pub fn has_name(&self, name: &str) -> bool

Check if any resolver provides the given name.

Source

pub fn resolve_binding( &mut self, name: &str, ctx: &mut EvalContext, ) -> Result<JsValue, JErrorType>

Resolve a name, caching the result. ctx is needed because some resolvers may need it during materialization.

Source

pub fn resolvers(&self) -> &[Box<dyn PluginResolver>]

Get a reference to the resolvers (for inspection/testing).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.