Skip to main content

just_engine/runner/eval/
function.rs

1//! Function call execution.
2//!
3//! This module provides function call execution logic for the JavaScript interpreter.
4
5use crate::parser::ast::FunctionData;
6use crate::runner::ds::error::JErrorType;
7use crate::runner::ds::value::JsValue;
8use crate::runner::plugin::types::EvalContext;
9use crate::runner::plugin::registry::BuiltInRegistry;
10
11use super::types::ValueResult;
12
13/// Call a function with the given arguments.
14pub fn call_function(
15    _func: &FunctionData,
16    _this_value: JsValue,
17    _args: Vec<JsValue>,
18    _ctx: &mut EvalContext,
19) -> ValueResult {
20    // TODO: Implement proper function calls
21    // 1. Create new execution context
22    // 2. Bind parameters to arguments
23    // 3. Execute function body
24    // 4. Return result
25
26    Err(JErrorType::TypeError("Function calls not yet fully implemented".to_string()))
27}
28
29/// Call a built-in function from the registry.
30pub fn call_builtin(
31    registry: &BuiltInRegistry,
32    object: &str,
33    method: &str,
34    this_value: JsValue,
35    args: Vec<JsValue>,
36    ctx: &mut EvalContext,
37) -> ValueResult {
38    if let Some(builtin_fn) = registry.get_method(object, method) {
39        builtin_fn.call(ctx, this_value, args)
40    } else {
41        Err(JErrorType::TypeError(format!(
42            "{}.{} is not a function",
43            object, method
44        )))
45    }
46}
47
48/// Check if a value is callable.
49pub fn is_callable(value: &JsValue) -> bool {
50    match value {
51        JsValue::Object(_obj) => {
52            // TODO: Check if object has [[Call]] internal method
53            false
54        }
55        _ => false,
56    }
57}
58
59/// Check if a value is a constructor.
60pub fn is_constructor(value: &JsValue) -> bool {
61    match value {
62        JsValue::Object(_obj) => {
63            // TODO: Check if object has [[Construct]] internal method
64            false
65        }
66        _ => false,
67    }
68}