Skip to content

Commit e34ab90

Browse files
committed
RegExp: treat undefined argument as empty.
new RegExp() and new RegExp(undefined) calls now results in the same 'source' pattern. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
1 parent 336db40 commit e34ab90

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-regexp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
7878
}
7979
}
8080

81-
if (arguments_list_len == 0)
81+
if (arguments_list_len == 0 || ecma_is_value_undefined (arguments_list_p[0]))
8282
{
8383
ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP);
8484
ret_value = ecma_op_create_regexp_object (magic_str_p, NULL);

tests/jerry/regexp-construct.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,15 @@ assert (r.ignoreCase == true);
8686
assert (r.multiline == true);
8787

8888
assert(Object.prototype.toString.call(RegExp.prototype) === '[object RegExp]');
89+
90+
91+
/* The 'undefined' argument for the RegExp constructor should not be converted to string,
92+
* and it should behave just like when there is no argument.
93+
*/
94+
r1 = new RegExp();
95+
r2 = new RegExp(undefined);
96+
var foo;
97+
r3 = new RegExp(foo)
98+
99+
assert (r1.source === r2.source);
100+
assert (r2.source === r3.source);

0 commit comments

Comments
 (0)