mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Added new test cases to improve branch coverage in Array.prototype routines. The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file. https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs. Branch coverage including pando-project#2682 and pando-project#2674: -before: 399 / 476 -after: 472 / 476 There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them. The other 14 functions are either already covered, or we could not improve the coverage of it. More information about the coverage improvement and the branches not reached: https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e While improving the coverage we found an unnecessary condition check, which can not be false in any cases. Co-authored-by: Csaba Repasi repasics@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi repasics@inf.u-szeged.hu JerryScript-DCO-1.0-Signed-off-by: Mate Dabis mdabis@inf.u-szeged.hu
126 lines
3.4 KiB
JavaScript
126 lines
3.4 KiB
JavaScript
// Copyright JS Foundation and other contributors, http://js.foundation
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
var array = []
|
|
|
|
assert(array.length === 0);
|
|
|
|
array.unshift("foo");
|
|
assert(array.length === 1);
|
|
assert(array[0] === "foo");
|
|
|
|
array.unshift(new Array())
|
|
assert(array.length === 2);
|
|
assert(array[0] instanceof Array);
|
|
assert(array[1] === "foo")
|
|
|
|
array.unshift(Infinity);
|
|
assert(array.length === 3);
|
|
assert(array[0] === Infinity);
|
|
assert(array[1] instanceof Array);
|
|
assert(array[2] === "foo")
|
|
|
|
array.unshift("bar", 0);
|
|
assert(array.length === 5);
|
|
assert(array[0] === "bar");
|
|
assert(array[1] === 0);
|
|
assert(array[2] === Infinity);
|
|
assert(array[3] instanceof Array);
|
|
assert(array[4] === "foo")
|
|
|
|
|
|
// Checking behavior when no length property defined
|
|
var obj = { unshift : Array.prototype.unshift };
|
|
|
|
assert(obj.length === undefined);
|
|
obj.unshift(1,2,3);
|
|
assert(obj.length === 3);
|
|
|
|
// Checking behavior when unable to get length
|
|
var obj = { unshift : Array.prototype.unshift };
|
|
Object.defineProperty(obj, 'length', { 'get' : function () {throw new ReferenceError ("foo"); } });
|
|
|
|
try {
|
|
obj.unshift(1);
|
|
assert(false)
|
|
} catch (e) {
|
|
assert(e.message === "foo");
|
|
assert(e instanceof ReferenceError);
|
|
}
|
|
|
|
// Checking behavior when unable to set length
|
|
var obj = { unshift : Array.prototype.unshift };
|
|
Object.defineProperty(obj, 'length', { 'set' : function () {throw new ReferenceError ("foo"); } });
|
|
|
|
try {
|
|
obj.unshift(2);
|
|
assert(false)
|
|
} catch (e) {
|
|
assert(e.message === "foo");
|
|
assert(e instanceof ReferenceError);
|
|
}
|
|
|
|
// Checking behavior when unable shift elements
|
|
var obj = { unshift : Array.prototype.unshift, length : 1 };
|
|
Object.defineProperty(obj, '0', { 'get' : function () {throw new ReferenceError ("foo"); } });
|
|
|
|
try {
|
|
obj.unshift(3);
|
|
assert(false);
|
|
} catch (e) {
|
|
assert(e.message === "foo");
|
|
assert(e instanceof ReferenceError);
|
|
}
|
|
|
|
var obj = { unshift : Array.prototype.unshift, length : 1 };
|
|
Object.defineProperty(obj, '0', { 'set' : function () {throw new ReferenceError ("foo"); } });
|
|
|
|
try {
|
|
obj.unshift(4);
|
|
assert(false);
|
|
} catch (e) {
|
|
assert(e.message === "foo");
|
|
assert(e instanceof ReferenceError);
|
|
}
|
|
|
|
// Checking behavior when a property is not defined
|
|
var obj = { '0' : "foo", '2' : "bar", length : 3, unshift : Array.prototype.unshift };
|
|
assert(obj.unshift("baz") === 4);
|
|
assert(obj[0] === "baz");
|
|
assert(obj[1] === "foo");
|
|
assert(obj[2] === undefined);
|
|
assert(obj[3] === "bar");
|
|
|
|
/* ES v5.1 15.4.4.13.6.d.ii.
|
|
Checking behavior when the array is freezed */
|
|
try {
|
|
var arr = [0, 1];
|
|
Object.freeze(arr);
|
|
Array.prototype.unshift.call(arr, 2, 3);
|
|
assert(false);
|
|
} catch (e) {
|
|
assert(e instanceof TypeError);
|
|
}
|
|
|
|
/* ES v5.1 15.4.4.13.6.e.i.
|
|
Checking behavior when the array has only one property and bigger length */
|
|
try {
|
|
var arr = { length : 9 };
|
|
Object.defineProperty(arr, '6', { value : 2 });
|
|
Array.prototype.unshift.call(arr, 2, 3);
|
|
assert(false);
|
|
} catch (e) {
|
|
assert(e instanceof TypeError);
|
|
}
|