equality.js — svelte Source File
Architecture documentation for equality.js, a javascript file in the svelte codebase. 3 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 9fcf2863_565e_f328_30b3_46748f0e7489["equality.js"] df278ca2_0a6c_fefe_09f2_b397500fe3c2["warnings.js"] 9fcf2863_565e_f328_30b3_46748f0e7489 --> df278ca2_0a6c_fefe_09f2_b397500fe3c2 71020d3b_ab64_9fea_2a06_dab93412f92f["proxy.js"] 9fcf2863_565e_f328_30b3_46748f0e7489 --> 71020d3b_ab64_9fea_2a06_dab93412f92f 26dfb8f0_9124_b0f3_036d_7fac50a771b5["get_proxied_value"] 9fcf2863_565e_f328_30b3_46748f0e7489 --> 26dfb8f0_9124_b0f3_036d_7fac50a771b5 9a9bbc27_46b6_021c_6d77_f736ed4b40f0["operations.js"] 9a9bbc27_46b6_021c_6d77_f736ed4b40f0 --> 9fcf2863_565e_f328_30b3_46748f0e7489 style 9fcf2863_565e_f328_30b3_46748f0e7489 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import * as w from '../warnings.js';
import { get_proxied_value } from '../proxy.js';
export function init_array_prototype_warnings() {
const array_prototype = Array.prototype;
// The REPL ends up here over and over, and this prevents it from adding more and more patches
// of the same kind to the prototype, which would slow down everything over time.
// @ts-expect-error
const cleanup = Array.__svelte_cleanup;
if (cleanup) {
cleanup();
}
const { indexOf, lastIndexOf, includes } = array_prototype;
array_prototype.indexOf = function (item, from_index) {
const index = indexOf.call(this, item, from_index);
if (index === -1) {
for (let i = from_index ?? 0; i < this.length; i += 1) {
if (get_proxied_value(this[i]) === item) {
w.state_proxy_equality_mismatch('array.indexOf(...)');
break;
}
}
}
return index;
};
array_prototype.lastIndexOf = function (item, from_index) {
// we need to specify this.length - 1 because it's probably using something like
// `arguments` inside so passing undefined is different from not passing anything
const index = lastIndexOf.call(this, item, from_index ?? this.length - 1);
if (index === -1) {
for (let i = 0; i <= (from_index ?? this.length - 1); i += 1) {
if (get_proxied_value(this[i]) === item) {
w.state_proxy_equality_mismatch('array.lastIndexOf(...)');
break;
}
}
}
return index;
};
array_prototype.includes = function (item, from_index) {
const has = includes.call(this, item, from_index);
if (!has) {
for (let i = 0; i < this.length; i += 1) {
if (get_proxied_value(this[i]) === item) {
w.state_proxy_equality_mismatch('array.includes(...)');
break;
}
}
}
return has;
};
// @ts-expect-error
Array.__svelte_cleanup = () => {
array_prototype.indexOf = indexOf;
array_prototype.lastIndexOf = lastIndexOf;
array_prototype.includes = includes;
};
}
/**
* @param {any} a
* @param {any} b
* @param {boolean} equal
* @returns {boolean}
*/
export function strict_equals(a, b, equal = true) {
// try-catch needed because this tries to read properties of `a` and `b`,
// which could be disallowed for example in a secure context
try {
if ((a === b) !== (get_proxied_value(a) === get_proxied_value(b))) {
w.state_proxy_equality_mismatch(equal ? '===' : '!==');
}
} catch {}
return (a === b) === equal;
}
/**
* @param {any} a
* @param {any} b
* @param {boolean} equal
* @returns {boolean}
*/
export function equals(a, b, equal = true) {
if ((a == b) !== (get_proxied_value(a) == get_proxied_value(b))) {
w.state_proxy_equality_mismatch(equal ? '==' : '!=');
}
return (a == b) === equal;
}
Domain
Subdomains
Dependencies
Source
Frequently Asked Questions
What does equality.js do?
equality.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in equality.js?
equality.js defines 3 function(s): equals, init_array_prototype_warnings, strict_equals.
What does equality.js depend on?
equality.js imports 3 module(s): get_proxied_value, proxy.js, warnings.js.
What files import equality.js?
equality.js is imported by 1 file(s): operations.js.
Where is equality.js in the architecture?
equality.js is located at packages/svelte/src/internal/client/dev/equality.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dev).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free