๐Ÿ‘‰๐Ÿ‘ˆ Reflection

Take a deep look into yourself, and compare it against what you want yourself to be.

The new Reflect api is a set of functions that allow the developer to perform deep object comparisons.

The following functions and properties are exposed publicly and globally but should never really be used anywhere except internally, because this api is subject to change.

export class Reflect {
  public static FAILED_MATCH = 0;
  public static SUCCESSFUL_MATCH = 1;
  public static DEFER_MATCH = 2;
  // check if two values strictly equal each other
  public static equals<T>(
    left: T,
    right: T,
    stack?: usize[], // don't pass this arg
    cache?: usize[], // don't pass this arg
  ): i32; // return failed or success
  // use reflection to report a value to the host
  public static toReflectedValue<T>(
    value: T,
    seen?: Map<usize, i32>, // don't pass this arg
  ): i32;
  // attach the current stack trace to a reflected value
  public static attachStackTrace(id: i32): void;

The equals<T>() function is a very specialized method designed to traverse a complex tree of objects including Map, Set, Array, TypedArray, ArrayLike, ArrayBuffer, and custom class values. Once traversed, equality is determined on a reference by reference basis.

Last updated