pub struct BuiltInRegistry { /* private fields */ }Expand description
Registry for built-in objects and methods.
Manages all built-in JavaScript objects (Math, console, Array, etc.) and their methods. Supports plugin loading and method overrides.
§Examples
use just::runner::plugin::registry::BuiltInRegistry;
use just::runner::plugin::types::EvalContext;
// Create registry with core built-ins
let registry = BuiltInRegistry::with_core();
// Use with evaluation context
let mut ctx = EvalContext::new();
ctx.install_core_builtins(registry);Implementations§
Source§impl BuiltInRegistry
impl BuiltInRegistry
Sourcepub fn with_core() -> Self
pub fn with_core() -> Self
Create a registry with core built-in objects.
Includes: Math, console, JSON, String, Number, Array, Object, Error types. This is the most common way to create a registry.
§Examples
use just::parser::JsParser;
use just::runner::plugin::registry::BuiltInRegistry;
use just::runner::plugin::types::EvalContext;
use just::runner::eval::statement::execute_statement;
let mut ctx = EvalContext::new();
ctx.install_core_builtins(BuiltInRegistry::with_core());
// Now you can use Math, console, etc.
let code = "var x = Math.abs(-42);";
let ast = JsParser::parse_to_ast_from_str(code).unwrap();
for stmt in &ast.body {
execute_statement(stmt, &mut ctx).unwrap();
}Sourcepub fn register_object(&mut self, obj: BuiltInObject)
pub fn register_object(&mut self, obj: BuiltInObject)
Register a custom built-in object.
Use this to add your own built-in objects to the registry.
§Examples
use just::runner::plugin::registry::BuiltInRegistry;
use just::runner::plugin::types::BuiltInObject;
let mut registry = BuiltInRegistry::new();
let my_object = BuiltInObject::new("MyObject");
registry.register_object(my_object);Sourcepub fn get_object(&self, name: &str) -> Option<&BuiltInObject>
pub fn get_object(&self, name: &str) -> Option<&BuiltInObject>
Get a registered object by name.
Returns None if the object is not registered.
§Examples
use just::runner::plugin::registry::BuiltInRegistry;
let registry = BuiltInRegistry::with_core();
let math = registry.get_object("Math");
assert!(math.is_some());Sourcepub fn get_object_mut(&mut self, name: &str) -> Option<&mut BuiltInObject>
pub fn get_object_mut(&mut self, name: &str) -> Option<&mut BuiltInObject>
Get a mutable reference to a registered object.
Sourcepub fn override_method(
&mut self,
object: &str,
method: &str,
func: BuiltInFn,
) -> Result<(), PluginError>
pub fn override_method( &mut self, object: &str, method: &str, func: BuiltInFn, ) -> Result<(), PluginError>
Override an existing built-in method.
Sourcepub fn get_method(&self, object: &str, method: &str) -> Option<&BuiltInFn>
pub fn get_method(&self, object: &str, method: &str) -> Option<&BuiltInFn>
Get a built-in function for execution.
Sourcepub fn get_constructor(&self, object: &str) -> Option<&BuiltInFn>
pub fn get_constructor(&self, object: &str) -> Option<&BuiltInFn>
Get a constructor function for an object.
Sourcepub fn has_object(&self, name: &str) -> bool
pub fn has_object(&self, name: &str) -> bool
Check if an object exists in the registry.
Sourcepub fn has_method(&self, object: &str, method: &str) -> bool
pub fn has_method(&self, object: &str, method: &str) -> bool
Check if a method exists on an object.
Sourcepub fn load_native_plugin(
&mut self,
path: &Path,
) -> Result<PluginInfo, PluginError>
pub fn load_native_plugin( &mut self, path: &Path, ) -> Result<PluginInfo, PluginError>
Load native plugin from dynamic library.
Note: This is a placeholder - actual implementation requires unsafe FFI code
and the libloading crate for cross-platform support.
Sourcepub fn load_js_plugin(&mut self, path: &Path) -> Result<PluginInfo, PluginError>
pub fn load_js_plugin(&mut self, path: &Path) -> Result<PluginInfo, PluginError>
Load JavaScript plugin from file. Note: This requires the runtime to be functional to execute the JS code.
Sourcepub fn load_from_config(
&mut self,
config_path: &Path,
) -> Result<(), PluginError>
pub fn load_from_config( &mut self, config_path: &Path, ) -> Result<(), PluginError>
Load plugins from config file.
Sourcepub fn object_names(&self) -> Vec<&String>
pub fn object_names(&self) -> Vec<&String>
Get list of all registered object names.
Sourcepub fn loaded_plugins(&self) -> &[LoadedPlugin]
pub fn loaded_plugins(&self) -> &[LoadedPlugin]
Get list of all loaded plugins.