---
# System prepended metadata

title: Untitled

---

### Reference tracking

Perhaps, one way to work around this Reference Discontinuity would be the given Realm API to provide a reference symbol for each evaluation. That's not much necessary for primitive values, but important for translating the correct references.

```javascript
const realm = new Realm();

const refObj = realm.eval('globalThis.foo = { x: 1 }');

// refObj {
//   reference: Symbol // a Symbol reference to the 
//   getValue(); // clones the existing value from the realm
//   setValue(value); // updates the value of the given reference
// }

// the reference should be mapped so it always returns the same value, even if the structured clone changes
const otherRef = realm.eval('globalThis.foo');

console.assert(refObj === otherRef);

const value = refObj.getValue(); // yields to { x: 1 }
const other = otherRef.getValue(); // yields to { x: 1 }

// That's still a challenge for values previously resolved, the clone is always new
console.assert(value !== other);

// But still tracks changes when capturing references and re-cloning values
realm.eval('foo.y = 2');

// value and other remains like { x: 1 }


// Still the same reference
const yetAnotherRef = realm.eval('foo');

console.assert(refObj === yetAnotherRef);

const yetAnotherValue = yetAnotherRef.getValue();

// yetAnotherValue is a new { x: 1, y: 2}
```

This adds a lot of complexity, but it's necessary way to deal with the reference discontinuity.
