Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: array.lastIndexOf without second argument #11766

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-stingrays-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: `array.lastIndexOf` without second argument
12 changes: 10 additions & 2 deletions packages/svelte/src/internal/client/dev/equality.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ export function init_array_prototype_warnings() {
};

array_prototype.lastIndexOf = function (item, from_index) {
const index = lastIndexOf.call(this, 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) {
const test = lastIndexOf.call(get_proxied_value(this), get_proxied_value(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 test = lastIndexOf.call(
get_proxied_value(this),
get_proxied_value(item),
from_index ?? this.length - 1
);

if (test !== -1) {
w.state_proxy_equality_mismatch('array.lastIndexOf(...)');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ok, test } from '../../test';
import { flushSync } from 'svelte';

export default test({
mode: ['client'],
async test({ assert, logs }) {
assert.equal(logs[0], logs[1]);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
const arr = [0, 1, 2];
console.log(arr.lastIndexOf(2));
console.log(arr.lastIndexOf(2, arr.length - 1));
</script>
Loading