fix: String.lastIndexOf's offset argument must default to the string's length

This commit is contained in:
TopchetoEU 2025-01-09 00:08:14 +02:00
parent 7058a689a2
commit 12cff84666
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4

View File

@ -41,8 +41,9 @@ export const String = (() => {
offset = +offset; offset = +offset;
return string.indexOf(self, search, offset, false); return string.indexOf(self, search, offset, false);
} }
public lastIndexOf(search: string, offset = 0) { public lastIndexOf(search: string, offset?: number) {
const self = unwrapThis(this, "string", String, "String.prototype.lastIndexOf"); const self = unwrapThis(this, "string", String, "String.prototype.lastIndexOf");
if (offset == null) offset = self.length;
offset = +offset; offset = +offset;
return string.indexOf(self, search, offset, true); return string.indexOf(self, search, offset, true);
} }