The upvalue array you're implementing is a simplified version of Lua's real open/closed upvalue mechanism (lobject.h's UpVal struct) and CPython's cell variables that back nested-function closures. Whether a captured variable is copied at closure-creation time or shared by reference is the exact design choice that makes JavaScript's classic 'loop variable in a closure' bug possible.