ballObjectSetField function

void ballObjectSetField(
  1. Object? target,
  2. String fieldName,
  3. Object? val
)

Write fieldName on a live instance map (BallObject or type map). Emitted as a call to preamble ball_object_set_field in C++ self-host.

Implementation

void ballObjectSetField(Object? target, String fieldName, Object? val) {
  if (target is BallObject) {
    target.setField(fieldName, val);
    return;
  }
  if (target is BallMap) {
    if (target.entries.containsKey('__type__')) {
      target[fieldName] = val;
    }
    return;
  }
  if (target is Map<String, Object?> && target.containsKey('__type__')) {
    target[fieldName] = val;
  }
}