* Returns the one deep proxy for this host target, creating and caching it on first use. * * @typeParam T - Host object or function type. * @param hostValue - Raw host reference (not a primitive). * @returns Cached or new proxy for `hostValue`.
(hostValue: T)
| 696 | * @returns Cached or new proxy for `hostValue`. |
| 697 | */ |
| 698 | function wrapDeep<T extends HostTarget>(hostValue: T): T { |
| 699 | if (typeof hostValue !== 'object' && typeof hostValue !== 'function') { |
| 700 | return hostValue; |
| 701 | } |
| 702 | const cached = targetToProxy.get(hostValue); |
| 703 | if (cached) { |
| 704 | return cached as T; |
| 705 | } |
| 706 | if (isOurProxy(hostValue) || isVmRealmValue(hostValue)) { |
| 707 | return hostValue as T; |
| 708 | } |
| 709 | const shadowTarget = createShadowTarget(hostValue); |
| 710 | shadowToHost.set(shadowTarget, hostValue); |
| 711 | const proxy = new Proxy(shadowTarget, DEEP_HANDLER); |
| 712 | targetToProxy.set(hostValue, proxy); |
| 713 | proxyToTarget.set(proxy, hostValue); |
| 714 | return proxy as T; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * Recursively wraps objects and functions; leaves primitives and VM-originated values unchanged; |
no test coverage detected