πŸ‘‰πŸ‘ˆ 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.
1
export class Reflect {
2
public static FAILED_MATCH = 0;
3
public static SUCCESSFUL_MATCH = 1;
4
public static DEFER_MATCH = 2;
5
6
// check if two values strictly equal each other
7
public static equals<T>(
8
left: T,
9
right: T,
10
stack?: usize[], // don't pass this arg
11
cache?: usize[], // don't pass this arg
12
): i32; // return failed or success
13
14
// use reflection to report a value to the host
15
public static toReflectedValue<T>(
16
value: T,
17
seen?: Map<usize, i32>, // don't pass this arg
18
): i32;
19
20
// attach the current stack trace to a reflected value
21
public static attachStackTrace(id: i32): void;
22
}
23
​
Copied!
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 modified 1yr ago
Copy link