String.prototype.lastIndexOf returns numbers smaller than -1 on failure

VERIFIED FIXED in mozilla1.8beta2

Status

()

Core
JavaScript Engine
P1
normal
VERIFIED FIXED
13 years ago
12 years ago

People

(Reporter: Sjoerd Visscher, Assigned: brendan)

Tracking

({js1.5})

Trunk
mozilla1.8beta2
x86
Windows XP
js1.5
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

13 years ago
a.lastIndexOf(b, c) should return -1 when there is no match, but it returns
a.length - b.length when a is shorter than b and c is, or can be converted to, a
number.

Example: 
"".lastIndexOf("hello", 0) returns -5
"".lastIndexOf("hello") returns -1
(Assignee)

Comment 1

13 years ago
Thanks, this bug is almost ten years old!  Fix forthwith.

/be
Assignee: general → brendan
Keywords: js1.5
Priority: -- → P1
Target Milestone: --- → mozilla1.8beta2
(Assignee)

Comment 2

13 years ago
Created attachment 175454 [details] [diff] [review]
fix

Conserving the original code structure, but if you follow ECMA-262 Edition 3,
the code would be

	    d = js_DoubleToInteger(d);
	    i = (jsint) JS_MIN(JS_MAX(d, 0), textlen);

Checking in now.

/be
Attachment #175454 - Flags: review+
(Assignee)

Comment 3

13 years ago
Sjoerd, thanks very much!

Surprising that the testsuite didn't insist on -1 for patlen > textlen, but
there it is: a hole in test coverage.  Not the last one, either!

/be
Status: NEW → RESOLVED
Last Resolved: 13 years ago
QA Contact: pschwartau → moz
Resolution: --- → FIXED
(Reporter)

Comment 4

13 years ago
Well, if you write code for Mozilla, the whole world is your testsuite. 
My "Find previous" code always found matches on empty lines!

But thanks for the quick response. Maybe if you have time you could add a
comment (just a comment, not a fix) to bug 274888 too.
js/tests/js1_5/Regress/regress-283477.js checked in.
Flags: testcase+
verified fixed 1.8.x and trunk.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.