Skip to content

Increase test coverage: Array.prototype reverse #2728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ ecma_builtin_array_prototype_object_reverse (ecma_value_t this_arg) /**< this ar
ECMA_FINALIZE (put_value);
}
/* 6.j */
else if (lower_exist && !upper_exist)
else if (lower_exist)
{
ECMA_TRY_CATCH (del_value, ecma_op_object_delete (obj_p, lower_str_p, true), ret_value);
ECMA_TRY_CATCH (put_value, ecma_op_object_put (obj_p, upper_str_p, lower_value, true), ret_value);
Expand Down
96 changes: 96 additions & 0 deletions tests/jerry/array-prototype-reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,99 @@ try {
assert(e.message === "foo");
assert(e instanceof ReferenceError);
}

/* ES v5.1 15.4.4.8.1
Checking behavior when null is passed to the function */
try {
Array.prototype.reverse.call(null);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}

/* ES v5.1 15.4.4.8.3.
Checking behavior when length is not a number */
try {
var o = {};
Object.defineProperty(o, 'toString', { 'get' : function () { throw new ReferenceError ("foo"); } });
var a = { length : o};
Array.prototype.reverse.call(a);
assert(false);
} catch (e) {
assert(e instanceof ReferenceError);
assert(e.message == "foo");
}

/* ES v5.1 15.4.4.8.6.e.
Checking behavior when unable to get the last element */
var obj = { reverse : Array.prototype.reverse, length : 4 };
Object.defineProperty(obj, '3', { 'get' : function () {throw new ReferenceError ("foo"); } });

try {
obj.reverse();
assert(false);
} catch (e) {
assert(e.message === "foo");
assert(e instanceof ReferenceError);
}

/* ES v5.1 15.4.4.8.6.h.i.
Checking behavior when first 3 elements are not writable */
try {
var arr = [0, 1, 2, 3, 4, 5, 6,,,,,,,,,0, 1, 2, 3, 4, 5, 6];
Object.defineProperty(arr, '0', { writable : false });
Object.defineProperty(arr, '1', { writable : false });
Object.defineProperty(arr, '2', { writable : false });
Array.prototype.reverse.call(arr);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}

/* ES v5.1 15.4.4.8.6.h.ii.
Checking behavior when last 3 elements are not writable */
try {
var arr = [0, 1, 2, 3, 4, 5, 6,,,,,,,,,0, 1, 2, 3, 4, 5, 6];
Object.defineProperty(arr, '20', { writable : false });
Object.defineProperty(arr, '21', { writable : false });
Object.defineProperty(arr, '22', { writable : false });
Array.prototype.reverse.call(arr);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}

/* ES v5.1 15.4.4.8.6.i.i.
Checking behavior when first elements do not exist and the array is freezed */
try {
var arr = [,,,,,,,,,,,,,,,,0, 1, 2, 3, 4, 5, 6];
arr = Object.freeze(arr);
Array.prototype.reverse.call(arr);
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}

/* ES v5.1 15.4.4.8.6.i.ii.
Checking behavior when unable to get the first 2 elements */
var obj = { reverse : Array.prototype.reverse, length : 4 };
Object.defineProperty(obj, '2', { value : 0 });
Object.defineProperty(obj, '3', { value : 0 });
try {
obj.reverse();
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}

/* ES v5.1 15.4.4.8.6.j.i.
Checking behavior when unable to get the last 2 elements */
var obj = { reverse : Array.prototype.reverse, length : 4 };
Object.defineProperty(obj, '0', { value : 0 });
Object.defineProperty(obj, '1', { value : 0 });
try {
obj.reverse();
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}