define method

void define(
  1. String name,
  2. dynamic function
)

Defines an exported function or constant under name.

Plain Dart callables and BuiltinFunction instances are wrapped once in a Value during registration so repeated global lookups do not allocate new wrappers.

Implementation

void define(String name, dynamic function) {
  // Wrap builtin functions in Value objects once during registration
  // to avoid creating new Value wrappers on every identifier access.
  // This prevents temporary Value allocations that affect collectgarbage("count").
  if ((function is BuiltinFunction || function is Function) &&
      function is! Value) {
    _functionMap[name] = Value(function, functionName: name);
  } else {
    _functionMap[name] = function;
  }
}