about summary refs log tree commit diff stats
path: root/js/scripting-lang/baba-yaga-c/src/function.c
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/baba-yaga-c/src/function.c')
-rw-r--r--js/scripting-lang/baba-yaga-c/src/function.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/js/scripting-lang/baba-yaga-c/src/function.c b/js/scripting-lang/baba-yaga-c/src/function.c
index 82b4eb2..57910cc 100644
--- a/js/scripting-lang/baba-yaga-c/src/function.c
+++ b/js/scripting-lang/baba-yaga-c/src/function.c
@@ -133,7 +133,7 @@ Value baba_yaga_value_function(const char* name, Value (*body)(Value*, int),
 }
 
 Value baba_yaga_function_call(const Value* func, const Value* args, 
-                             int arg_count) {
+                             int arg_count, Scope* scope) {
     if (func == NULL || func->type != VAL_FUNCTION || args == NULL) {
         return baba_yaga_value_nil();
     }
@@ -159,7 +159,9 @@ Value baba_yaga_function_call(const Value* func, const Value* args,
         /* Execute user-defined function */
         if (func_value->body.user_body.ast_node != NULL) {
             /* Create new scope for function execution */
-            Scope* func_scope = scope_create(NULL); /* TODO: Pass parent scope for closures */
+            /* According to JS team requirements: function calls create local scopes that inherit from global scope */
+            Scope* global_scope = scope_get_global(scope);
+            Scope* func_scope = scope_create(global_scope); /* Pass global scope as parent for local function scope */
             if (func_scope == NULL) {
                 DEBUG_ERROR("Failed to create function scope");
                 return baba_yaga_value_nil();