Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3354x 3354x 3354x 3354x 1863x 3354x 1863x 1863x 81x 81x 81x 81x 81x 79x 79x 79x 79x 79x 79x 79x 79x 79x 81x 1784x 1784x 1784x 1863x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 12x 12x 12x 12x 12x 12x 1725x 1713x 1713x 1713x 1713x 1037x 1037x 1713x 1713x 1725x 1725x 1725x 1725x 1863x 1550x 1550x 1550x 2x 2x 2x 2x 2x 148x 148x 148x 2x 2x 2x 2x 2x 2x 2x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 26x 26x 26x 26x 26x 26x 30x 30x 30x 30x 30x 30x 30x 2x 2x 2x 4488x 198x 198x 4290x 4290x 4290x 4290x 4290x 4290x 4488x 957x 957x 957x 4290x 4488x 3942x 3942x 3942x 348x 348x 2x 2x 2x 258x 258x 242x 242x 242x 242x 242x 99x 99x 242x 258x 258x 2x 2x 2x 757x 305x 305x 452x 452x 452x 452x 452x 452x 756x 161x 757x 396x 105x 105x 105x 396x 396x 217x 217x 396x 235x 2x 2x 2x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 100x 100x 100x 100x 1012x 1006x 1006x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 1012x 108x 33x 33x 33x 108x 1012x 1012x 1012x 1012x 1012x 6x 1012x 1006x 1006x 1012x 1012x 118x 118x 118x 118x 118x 90x 90x 90x 86x 86x 90x 118x 118x 1012x 1012x 2x 2x 2x 246x 246x 246x 246x 246x 246x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1824186x 16x 16x 16x 16x 16x 1824170x 1824170x 2x 2x 2x 2x 2x 2x 570x 570x | /** @import { ProxyMetadata, ProxyStateObject, Source } from '#client' */ import { DEV } from 'esm-env'; import { get, current_component_context, untrack, current_effect } from './runtime.js'; import { array_prototype, define_property, get_descriptor, get_prototype_of, is_array, is_frozen, object_prototype } from '../shared/utils.js'; import { check_ownership, widen_ownership } from './dev/ownership.js'; import { source, set } from './reactivity/sources.js'; import { STATE_FROZEN_SYMBOL, STATE_SYMBOL } from './constants.js'; import { UNINITIALIZED } from '../../constants.js'; import * as e from './errors.js'; /** * @template T * @param {T} value * @param {ProxyMetadata | null} [parent] * @param {Source<T>} [prev] dev mode only * @returns {ProxyStateObject<T> | T} */ export function proxy(value, parent = null, prev) { if ( typeof value === 'object' && value != null && !is_frozen(value) && !(STATE_FROZEN_SYMBOL in value) ) { // If we have an existing proxy, return it... if (STATE_SYMBOL in value) { const metadata = /** @type {ProxyMetadata<T>} */ (value[STATE_SYMBOL]); // ...unless the proxy belonged to a different object, because // someone copied the state symbol using `Reflect.ownKeys(...)` if (metadata.t === value || metadata.p === value) { if (DEV) { // Since original parent relationship gets lost, we need to copy over ancestor owners // into current metadata. The object might still exist on both, so we need to widen it. widen_ownership(metadata, metadata); metadata.parent = parent; } return metadata.p; } } const prototype = get_prototype_of(value); if (prototype === object_prototype || prototype === array_prototype) { const proxy = new Proxy(value, state_proxy_handler); define_property(value, STATE_SYMBOL, { value: /** @type {ProxyMetadata} */ ({ s: new Map(), v: source(0), a: is_array(value), p: proxy, t: value }), writable: true, enumerable: false }); if (DEV) { // @ts-expect-error value[STATE_SYMBOL].parent = parent; if (prev) { // Reuse owners from previous state; necessary because reassignment is not guaranteed to have correct component context. // If no previous proxy exists we play it safe and assume ownerless state // @ts-expect-error const prev_owners = prev?.v?.[STATE_SYMBOL]?.owners; // @ts-expect-error value[STATE_SYMBOL].owners = prev_owners ? new Set(prev_owners) : null; } else { // @ts-expect-error value[STATE_SYMBOL].owners = parent === null ? current_component_context !== null ? new Set([current_component_context.function]) : null : new Set(); } } return proxy; } } return value; } /** * @param {Source<number>} signal * @param {1 | -1} [d] */ function update_version(signal, d = 1) { set(signal, signal.v + d); } /** @type {ProxyHandler<ProxyStateObject<any>>} */ const state_proxy_handler = { defineProperty(target, prop, descriptor) { if (descriptor.value) { /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; const s = metadata.s.get(prop); if (s !== undefined) set(s, proxy(descriptor.value, metadata)); } return Reflect.defineProperty(target, prop, descriptor); }, deleteProperty(target, prop) { /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; const s = metadata.s.get(prop); const is_array = metadata.a; const boolean = delete target[prop]; // If we have mutated an array directly, and the deletion // was successful we will also need to update the length // before updating the field or the version. This is to // ensure any effects observing length can execute before // effects that listen to the fields – otherwise they will // operate an an index that no longer exists. if (is_array && boolean) { const ls = metadata.s.get('length'); const length = target.length - 1; if (ls !== undefined && ls.v !== length) { set(ls, length); } } if (s !== undefined) set(s, UNINITIALIZED); if (boolean) { update_version(metadata.v); } return boolean; }, get(target, prop, receiver) { if (prop === STATE_SYMBOL) { return Reflect.get(target, STATE_SYMBOL); } /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; let s = metadata.s.get(prop); // create a source, but only if it's an own property and not a prototype property if (s === undefined && (!(prop in target) || get_descriptor(target, prop)?.writable)) { s = source(proxy(target[prop], metadata)); metadata.s.set(prop, s); } if (s !== undefined) { const value = get(s); return value === UNINITIALIZED ? undefined : value; } return Reflect.get(target, prop, receiver); }, getOwnPropertyDescriptor(target, prop) { const descriptor = Reflect.getOwnPropertyDescriptor(target, prop); if (descriptor && 'value' in descriptor) { /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; const s = metadata.s.get(prop); if (s) { descriptor.value = get(s); } } return descriptor; }, has(target, prop) { if (prop === STATE_SYMBOL) { return true; } /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; const has = Reflect.has(target, prop); let s = metadata.s.get(prop); if ( s !== undefined || (current_effect !== null && (!has || get_descriptor(target, prop)?.writable)) ) { if (s === undefined) { s = source(has ? proxy(target[prop], metadata) : UNINITIALIZED); metadata.s.set(prop, s); } const value = get(s); if (value === UNINITIALIZED) { return false; } } return has; }, set(target, prop, value, receiver) { /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; let s = metadata.s.get(prop); // If we haven't yet created a source for this property, we need to ensure // we do so otherwise if we read it later, then the write won't be tracked and // the heuristics of effects will be different vs if we had read the proxied // object property before writing to that property. if (s === undefined) { // the read creates a signal untrack(() => receiver[prop]); s = metadata.s.get(prop); } if (s !== undefined) { set(s, proxy(value, metadata)); } const is_array = metadata.a; const not_has = !(prop in target); if (DEV) { /** @type {ProxyMetadata | undefined} */ const prop_metadata = value?.[STATE_SYMBOL]; if (prop_metadata && prop_metadata?.parent !== metadata) { widen_ownership(metadata, prop_metadata); } check_ownership(metadata); } // variable.length = value -> clear all signals with index >= value if (is_array && prop === 'length') { for (let i = value; i < target.length; i += 1) { const s = metadata.s.get(i + ''); if (s !== undefined) set(s, UNINITIALIZED); } } var descriptor = Reflect.getOwnPropertyDescriptor(target, prop); // Set the new value before updating any signals so that any listeners get the new value if (descriptor?.set) { descriptor.set.call(receiver, value); } else { target[prop] = value; } if (not_has) { // If we have mutated an array directly, we might need to // signal that length has also changed. Do it before updating metadata // to ensure that iterating over the array as a result of a metadata update // will not cause the length to be out of sync. if (is_array) { const ls = metadata.s.get('length'); const length = target.length; if (ls !== undefined && ls.v !== length) { set(ls, length); } } update_version(metadata.v); } return true; }, ownKeys(target) { /** @type {ProxyMetadata} */ const metadata = target[STATE_SYMBOL]; get(metadata.v); return Reflect.ownKeys(target); } }; if (DEV) { state_proxy_handler.setPrototypeOf = () => { e.state_prototype_fixed(); }; } /** * @param {any} value */ export function get_proxied_value(value) { if (value !== null && typeof value === 'object' && STATE_SYMBOL in value) { var metadata = value[STATE_SYMBOL]; if (metadata) { return metadata.p; } } return value; } /** * @param {any} a * @param {any} b */ export function is(a, b) { return Object.is(get_proxied_value(a), get_proxied_value(b)); } |