* Creates a clean shadow target matching the structural kind of `hostTarget` (function, array, * or plain object) so V8 Proxy invariants are checked against the shadow target while keeping * its prototype aligned with `SAFE_LOOKUP_TARGET`. * * For constructible functions, uses a bound function `
(hostTarget: HostTarget)
| 348 | * target has `[[Construct]]` without a fabricated non-configurable own `.prototype` property. |
| 349 | */ |
| 350 | function createShadowTarget(hostTarget: HostTarget): HostTarget { |
| 351 | let shadow: HostTarget; |
| 352 | if (typeof hostTarget === 'function') { |
| 353 | shadow = isConstructibleFunction(hostTarget as HostCallable) ? function () {}.bind(null) : () => {}; |
| 354 | } else if (Array.isArray(hostTarget)) { |
| 355 | shadow = []; |
| 356 | } else { |
| 357 | shadow = {}; |
| 358 | } |
| 359 | Reflect.setPrototypeOf(shadow, SAFE_LOOKUP_TARGET); |
| 360 | return shadow; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Clones a host property descriptor so `value` / `get` / `set` are wrapped for the VM while |
no test coverage detected