Bug 647385 - Implement a ToInteger helper that corresponds to the spec method (rather than inlining its contents everywhere it can be trivially used). Also fixes a couple bugs in one place that should have used ToInteger but didn't. r=cdleary

This commit is contained in:
Jeff Walden
2011-04-02 11:33:20 -07:00
parent 5c48abb0b8
commit b3f34db032
9 changed files with 96 additions and 69 deletions

View File

@@ -2400,9 +2400,8 @@ array_splice(JSContext *cx, uintN argc, Value *vp)
/* Convert the first argument into a starting index. */
jsdouble d;
if (!ValueToNumber(cx, *argv, &d))
if (!ToInteger(cx, *argv, &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (d < 0) {
d += length;
if (d < 0)
@@ -2420,9 +2419,8 @@ array_splice(JSContext *cx, uintN argc, Value *vp)
count = delta;
end = length;
} else {
if (!ValueToNumber(cx, *argv, &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, *argv, &d))
return false;
if (d < 0)
d = 0;
else if (d > delta)
@@ -2644,9 +2642,8 @@ array_slice(JSContext *cx, uintN argc, Value *vp)
if (argc > 0) {
jsdouble d;
if (!ValueToNumber(cx, argv[0], &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, argv[0], &d))
return false;
if (d < 0) {
d += length;
if (d < 0)
@@ -2657,9 +2654,8 @@ array_slice(JSContext *cx, uintN argc, Value *vp)
begin = (jsuint)d;
if (argc > 1 && !argv[1].isUndefined()) {
if (!ValueToNumber(cx, argv[1], &d))
return JS_FALSE;
d = js_DoubleToInteger(d);
if (!ToInteger(cx, argv[1], &d))
return false;
if (d < 0) {
d += length;
if (d < 0)
@@ -2727,9 +2723,8 @@ array_indexOfHelper(JSContext *cx, JSBool isLast, uintN argc, Value *vp)
jsdouble start;
tosearch = vp[2];
if (!ValueToNumber(cx, vp[3], &start))
return JS_FALSE;
start = js_DoubleToInteger(start);
if (!ToInteger(cx, vp[3], &start))
return false;
if (start < 0) {
start += length;
if (start < 0) {