From a2bd551b57ec15c0efb6bff8e0879b0bcef0e64d Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Fri, 28 Apr 2006 00:20:44 +0000 Subject: [PATCH] Fixed another JSVERSION_1_2 removal botch that broke splice (325951 regression, but see 326466 for the report). git-svn-id: svn://10.0.0.236/trunk@195617 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/jsarray.c | 53 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/mozilla/js/src/jsarray.c b/mozilla/js/src/jsarray.c index 429a953ec4e..ae249835191 100644 --- a/mozilla/js/src/jsarray.c +++ b/mozilla/js/src/jsarray.c @@ -1262,36 +1262,35 @@ array_splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) argv++; } + + /* + * Create a new array value to return. Our ECMA v2 proposal specs + * that splice always returns an array value, even when given no + * arguments. We think this is best because it eliminates the need + * for callers to do an extra test to handle the empty splice case. + */ + obj2 = js_NewArrayObject(cx, 0, NULL); + if (!obj2) + return JS_FALSE; + *rval = OBJECT_TO_JSVAL(obj2); + + /* If there are elements to remove, put them into the return value. */ if (count > 0) { - /* - * Create a new array value to return. Our ECMA v2 proposal specs - * that splice always returns an array value, even when given no - * arguments. We think this is best because it eliminates the need - * for callers to do an extra test to handle the empty splice case. - */ - obj2 = js_NewArrayObject(cx, 0, NULL); - if (!obj2) - return JS_FALSE; - *rval = OBJECT_TO_JSVAL(obj2); - - /* If there are elements to remove, put them into the return value. */ - if (count > 0) { - for (last = begin; last < end; last++) { - if (!IndexToExistingId(cx, obj, last, &id)) - return JS_FALSE; - if (id == JSID_HOLE) - continue; /* don't fill holes in the new array */ - if (!OBJ_GET_PROPERTY(cx, obj, id, vp)) - return JS_FALSE; - if (!IndexToId(cx, last - begin, &id2)) - return JS_FALSE; - if (!OBJ_SET_PROPERTY(cx, obj2, id2, vp)) - return JS_FALSE; - } - - if (!js_SetLengthProperty(cx, obj2, end - begin)) + for (last = begin; last < end; last++) { + if (!IndexToExistingId(cx, obj, last, &id)) + return JS_FALSE; + if (id == JSID_HOLE) + continue; /* don't fill holes in the new array */ + if (!OBJ_GET_PROPERTY(cx, obj, id, vp)) + return JS_FALSE; + if (!IndexToId(cx, last - begin, &id2)) + return JS_FALSE; + if (!OBJ_SET_PROPERTY(cx, obj2, id2, vp)) return JS_FALSE; } + + if (!js_SetLengthProperty(cx, obj2, end - begin)) + return JS_FALSE; } /* Find the direction (up or down) to copy and make way for argv. */