Update @@search to conform to ES11 standard (#4003)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai daniel.batyai@h-lab.eu
This commit is contained in:
Dániel Bátyai
2020-07-20 12:46:49 +02:00
committed by GitHub
parent b7fa4afb66
commit f6cde17bfb
3 changed files with 112 additions and 19 deletions
+67
View File
@@ -226,3 +226,70 @@ o = {
}
assert (RegExp.prototype[Symbol.search].call (o, "str") === 0);
var r = /a/;
r.lastIndex = 3.14;
var get_calls = [];
var set_calls = [];
var handler = {
get: function(o, k) {
get_calls.push(k);
if (k === "exec") {
return (str) => r.exec(str);
}
return r[k];
},
set: function(o, k, v) {
set_calls.push(k);
r[k] = v;
}
};
var p = new Proxy(r, handler);
assert (search.call(p, "bba") === 2);
assert (get_calls.join(",") === "lastIndex,exec,lastIndex");
assert (set_calls.join(",") === "lastIndex,lastIndex");
assert (r.lastIndex === 3.14);
var o = {
get lastIndex() {
Object.defineProperty(o, "lastIndex", {
get: function () { throw "abrupt get second lastIndex"; }
});
return 1;
},
set lastIndex(v) {},
exec: () => { return null; }
}
try {
search.call(o, "str");
assert (false);
} catch (e) {
assert (e === "abrupt get second lastIndex");
}
var index = 1;
var o = {
get lastIndex() {
return index++;
},
set lastIndex(v) {
Object.defineProperty(o, "lastIndex", {
set: function (v) { throw "abrupt set second lastIndex"; }
});
},
exec: () => { return null; }
}
try {
search.call(o, "str");
assert (false);
} catch (e) {
assert (e === "abrupt set second lastIndex");
}
+2
View File
@@ -378,4 +378,6 @@
<test id="built-ins/String/prototype/trim/15.5.4.20-3-6.js"><reason>Unicode 13: 0x180E is no longer whitespace character</reason></test>
<test id="built-ins/parseFloat/S15.1.2.3_A2_T10.js"><reason>Unicode 13: 0x180E is no longer whitespace character</reason></test>
<test id="built-ins/parseInt/S15.1.2.2_A2_T10.js"><reason>Unicode 13: 0x180E is no longer whitespace character</reason></test>
<test id="built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-err.js"><reason>lastIndex handling in Symbol.search has changed since ES6</reason></test>
<test id="built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore.js"><reason>lastIndex handling in Symbol.search has changed since ES6</reason></test>
</excludeList>