Add handling for RegExp unicode and sticky flags (#3341)

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
This commit is contained in:
Dániel Bátyai
2019-11-22 14:04:03 +01:00
committed by Zoltan Herczeg
parent fc2218e828
commit 279d4d4119
10 changed files with 310 additions and 47 deletions
+21
View File
@@ -28,3 +28,24 @@ try {
} catch (e) {
assert(e === 5);
}
r = new RegExp ("a","gimuy");
assert (r.global === true);
assert (r.ignoreCase === true);
assert (r.multiline === true);
assert (r.unicode === true);
assert (r.sticky === true);
try {
new RegExp ("a", "uu");
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
try {
new RegExp ("a", "yy");
assert (false);
} catch (e) {
assert (e instanceof SyntaxError);
}
+86
View File
@@ -0,0 +1,86 @@
// 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 r = new RegExp('a', 'gimuy');
assert (r.flags === 'gimuy');
assert (r.toString() === '/a/gimuy');
try {
Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get.call(42);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
var o = {
global: true,
unicode: true,
sticky: true,
source: "str"
}
Object.defineProperty(o, 'flags', Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'));
assert(o.flags === "guy");
assert (RegExp.prototype.toString.call (o) === "/str/guy");
Object.defineProperty(o, 'multiline', { 'get': function () {throw "abrupt flag get"; }});
try {
o.flags
assert (false);
} catch (e) {
assert (e === "abrupt flag get");
}
try {
RegExp.prototype.toString.call(42);
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
assert (RegExp.prototype.toString.call({}) === "/undefined/undefined");
var o = {};
Object.defineProperty (o, 'source', { 'get' : function () {throw "abrupt source get"; } });
try {
RegExp.prototype.toString.call(o);
assert (false);
} catch (e) {
assert (e === "abrupt source get");
}
var o = {source: {toString: function() {throw "abrupt source toString";}}};
try {
RegExp.prototype.toString.call(o);
assert (false);
} catch (e) {
assert (e === "abrupt source toString");
}
var o = {source: "str"};
Object.defineProperty (o, 'flags', { 'get' : function () {throw "abrupt flags get"; } });
try {
RegExp.prototype.toString.call(o);
assert (false);
} catch (e) {
assert (e === "abrupt flags get");
}
var o = {source: "str", flags: {toString: function() {throw "abrupt flags toString";}}};
try {
RegExp.prototype.toString.call(o);
assert (false);
} catch (e) {
assert (e === "abrupt flags toString");
}
+20
View File
@@ -0,0 +1,20 @@
// 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.
try {
RegExp.prototype.toString.call ({});
assert (false);
} catch (e) {
assert (e instanceof TypeError);
}
-9
View File
@@ -39,15 +39,6 @@ catch (e)
r = new RegExp ("a", "mig");
assert (r.toString () == "/a/gim");
try {
r.toString.call({}, "a");
assert (false)
}
catch (e)
{
assert (e instanceof TypeError);
}
/* Test continous calls to the exec method to see how does the match
* updates the lastIndex propertyand see if the match restarts.