Closed Bug 323582 Opened 20 years ago Closed 14 years ago

JS_HasArrayLength() throws errors if there is no length property

Categories

(Core :: JavaScript Engine, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: daumling, Assigned: daumling)

Details

Attachments

(1 obsolete file)

Calling JS_HasArrayLength() should not throw any errors. Currently, ValueIsLength() (called in the process) throws errors if there is not a length property, or if the length property is not a number, or out of range.
I'll take this bug.
Assignee: general → daumling
Status: NEW → ASSIGNED
Attached patch Fix (obsolete) — Splinter Review
The fix adds a new argument reportError to ValueIsLength(). If JS_FALSE, the function does not report an error. it is only JS_FALSE in js_HasLengthProperty(). I've also cleaned up ValueIsLength() a little.
Attachment #212532 - Flags: review?(brendan)
Comment on attachment 212532 [details] [diff] [review] Fix Thanks for patching this -- nits only below. >+ValueIsLength(JSContext *cx, jsval v, jsuint *lengthp, JSBool reportError) Nit: out params after in params, generally -- so lengthp last. > { > jsint i; > jsdouble d; > > if (JSVAL_IS_INT(v)) { > i = JSVAL_TO_INT(v); >- if (i < 0) { >- JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, >- JSMSG_BAD_ARRAY_LENGTH); >- return JS_FALSE; >- } >+ if (i < 0) >+ goto bad; > *lengthp = (jsuint) i; > return JS_TRUE; Note early true return. > } > >- if (!js_ValueToNumber(cx, v, &d)) { >- JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, >- JSMSG_BAD_ARRAY_LENGTH); >- return JS_FALSE; >- } >- if (!js_DoubleToECMAUint32(cx, d, (uint32 *)lengthp)) { >- JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, >- JSMSG_BAD_ARRAY_LENGTH); >- return JS_FALSE; >- } >- if (JSDOUBLE_IS_NaN(d) || d != *lengthp) { >+ if (js_ValueToNumber(cx, v, &d) >+ && js_DoubleToECMAUint32(cx, d, (uint32 *)lengthp) >+ && !JSDOUBLE_IS_NaN(d) >+ && d == *lengthp) Nit: prevailing style puts && and || at end of line, indents terms to underhang one another (as above, but without the leading && ;-). Nit: brace the then part because the condition is multiline -- prevailing style braces when any of condition, then, or else parts are (or appear to be, even if only due to comments) multiline. >+ return JS_TRUE; Suggestion: invert the && chain's terms and use || to guard a goto bad; then part -- this allows the return true to be least-indented and also commoned with the earlier one (noted above). /be
Comment on attachment 212532 [details] [diff] [review] Fix Would prefer new patch and bug assignee (IIRC Michael is busy elsewhere). Igor, if you don't care, please obsolete the patch and put the bug into the general@js.bugs pool. /be
Attachment #212532 - Flags: review?(brendan) → review?(igor)
Attachment #212532 - Attachment is obsolete: true
Attachment #212532 - Flags: review?(igor)
To Michael Daumling: Is it still relevant? If so, I will review/land the patch as soon as there would be update against the current CVS tip.
(In reply to comment #5) > To Michael Daumling: > > Is it still relevant? If so, I will review/land the patch as soon as there > would be update against the current CVS tip. And if you are busy, I will update the patch myself, but then I need to know if it is relevant.
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: