( proxy: ResolverProxy<T, R>, context: AnyObject, subProxy?: ResolverProxy<T, R>, descriptorDefaults?: DescriptorDefaults )
| 116 | * @private |
| 117 | */ |
| 118 | export function _attachContext< |
| 119 | T extends AnyObject[] = AnyObject[], |
| 120 | R extends AnyObject[] = T |
| 121 | >( |
| 122 | proxy: ResolverProxy<T, R>, |
| 123 | context: AnyObject, |
| 124 | subProxy?: ResolverProxy<T, R>, |
| 125 | descriptorDefaults?: DescriptorDefaults |
| 126 | ) { |
| 127 | const cache: ContextCache<T, R> = { |
| 128 | _cacheable: false, |
| 129 | _proxy: proxy, |
| 130 | _context: context, |
| 131 | _subProxy: subProxy, |
| 132 | _stack: new Set(), |
| 133 | _descriptors: _descriptors(proxy, descriptorDefaults), |
| 134 | setContext: (ctx: AnyObject) => _attachContext(proxy, ctx, subProxy, descriptorDefaults), |
| 135 | override: (scope: AnyObject) => _attachContext(proxy.override(scope), context, subProxy, descriptorDefaults) |
| 136 | }; |
| 137 | return new Proxy(cache, { |
| 138 | /** |
| 139 | * A trap for the delete operator. |
| 140 | */ |
| 141 | deleteProperty(target, prop) { |
| 142 | delete target[prop]; // remove from cache |
| 143 | delete proxy[prop]; // remove from proxy |
| 144 | return true; |
| 145 | }, |
| 146 | |
| 147 | /** |
| 148 | * A trap for getting property values. |
| 149 | */ |
| 150 | get(target, prop: string, receiver) { |
| 151 | return _cached(target, prop, |
| 152 | () => _resolveWithContext(target, prop, receiver)); |
| 153 | }, |
| 154 | |
| 155 | /** |
| 156 | * A trap for Object.getOwnPropertyDescriptor. |
| 157 | * Also used by Object.hasOwnProperty. |
| 158 | */ |
| 159 | getOwnPropertyDescriptor(target, prop) { |
| 160 | return target._descriptors.allKeys |
| 161 | ? Reflect.has(proxy, prop) ? {enumerable: true, configurable: true} : undefined |
| 162 | : Reflect.getOwnPropertyDescriptor(proxy, prop); |
| 163 | }, |
| 164 | |
| 165 | /** |
| 166 | * A trap for Object.getPrototypeOf. |
| 167 | */ |
| 168 | getPrototypeOf() { |
| 169 | return Reflect.getPrototypeOf(proxy); |
| 170 | }, |
| 171 | |
| 172 | /** |
| 173 | * A trap for the in operator. |
| 174 | */ |
| 175 | has(target, prop) { |
no test coverage detected