Fix position calculations of String.startsWith (#3734)
Fixes two bugs in the index calculations that affect the result of the `String.startsWith` function: - Fixes the implementation of ECMA-262 v6, 21.1.3.18, step 14: "If searchLength+start is greater than len, return false". - Fixes the return value of the helper function `ecma_builtin_helper_string_find_index`. If it is called with a starting search position, the returned index should be not less than that. These changes fix the following test cases in the test262 suite: - built-ins/String/prototype/startsWith/return-true-if-searchstring-is-empty.js - built-ins/String/prototype/startsWith/searchstring-found-with-position.js JerryScript-DCO-1.0-Signed-off-by: Mátyás Mustoha mmatyas@inf.u-szeged.hu
This commit is contained in:
@@ -15,7 +15,10 @@
|
||||
var x = "My cat is awesome";
|
||||
assert (x.startsWith ("My"));
|
||||
assert (x.startsWith ("cat", 3));
|
||||
assert (x.startsWith ("awesome", 10));
|
||||
assert (x.startsWith (""));
|
||||
assert (x.startsWith ("", 1));
|
||||
assert (x.startsWith ("", 17));
|
||||
assert (x.startsWith ([]));
|
||||
|
||||
assert (x.startsWith ("doggo") === false);
|
||||
|
||||
Reference in New Issue
Block a user