All files / src/internal/client/dev equality.js

71.84% Statements 74/103
69.23% Branches 9/13
83.33% Functions 5/6
71.28% Lines 72/101

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 1022x 2x 2x 2x 4x 4x 4x 4x 4x 831439x 831439x 304910x 304910x 304910x 304910x 304910x 304910x 304910x           304910x 831439x 4x 4x 4x 4x 4x 37756x 37756x 6x 6x 6x 6x 6x 6x 6x           6x 37756x 4x 4x 4x 4x 4x 1068457x 1068457x 545730x 545730x 545730x 545730x 545730x 545730x 545730x           545730x 1068457x 4x 4x 2x 2x 2x 2x 2x 2x 2x 8x           8x 8x 8x 2x 2x 2x 2x 2x 2x 2x                    
import * as w from '../warnings.js';
import { get_proxied_value } from '../proxy.js';
 
export function init_array_prototype_warnings() {
	const array_prototype = Array.prototype;
 
	const original_index_of = array_prototype.indexOf;
 
	array_prototype.indexOf = function (search_element, from_index) {
		const index = original_index_of.call(this, search_element, from_index);
		if (index === -1) {
			if (
				original_index_of.call(
					get_proxied_value(this),
					get_proxied_value(search_element),
					from_index
				) !== -1
			) {
				w.state_proxy_equality_mismatch('Array.indexOf');

				// eslint-disable-next-line no-console
				console.trace();
			}
		}
		return index;
	};
 
	const original_last_index_of = array_prototype.lastIndexOf;
 
	array_prototype.lastIndexOf = function (search_element, from_index) {
		const index = original_last_index_of.call(this, search_element, from_index);
		if (index === -1) {
			if (
				original_last_index_of.call(
					get_proxied_value(this),
					get_proxied_value(search_element),
					from_index
				) !== -1
			) {
				w.state_proxy_equality_mismatch('Array.lastIndexOf');

				// eslint-disable-next-line no-console
				console.trace();
			}
		}
		return index;
	};
 
	const original_includes = array_prototype.includes;
 
	array_prototype.includes = function (search_element, from_index) {
		const has = original_includes.call(this, search_element, from_index);
		if (!has) {
			if (
				original_includes.call(
					get_proxied_value(this),
					get_proxied_value(search_element),
					from_index
				)
			) {
				w.state_proxy_equality_mismatch('Array.includes');

				// eslint-disable-next-line no-console
				console.trace();
			}
		}
		return has;
	};
}
 
/**
 * @param {any} a
 * @param {any} b
 * @returns {boolean}
 */
export function strict_equals(a, b) {
	if (a !== b && get_proxied_value(a) === get_proxied_value(b)) {
		w.state_proxy_equality_mismatch('=== operator');

		// eslint-disable-next-line no-console
		console.trace();
	}
 
	return a === b;
}
 
/**
 * @param {any} a
 * @param {any} b
 * @returns {boolean}
 */
export function equals(a, b) {
	if (a != b && get_proxied_value(a) == get_proxied_value(b)) {
		w.state_proxy_equality_mismatch('== operator');

		// eslint-disable-next-line no-console
		console.trace();
	}

	return a == b;
}