diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
index 705a79e2c..3aaab5710 100644
--- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
@@ -265,7 +265,7 @@ ecma_builtin_regexp_prototype_get_source (ecma_extended_object_t *re_obj_p) /**<
* The RegExp.prototype object's 'compile' routine
*
* See also:
- * ECMA-262 v5, B.2.5.1
+ * ECMA-262 v11, B.2.5.1
*
* @return undefined - if compiled successfully
* error ecma value - otherwise
@@ -289,17 +289,6 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this */
re_compiled_code_t *old_bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
re_obj_p->u.class_prop.u.value);
- ecma_value_t status = ecma_builtin_helper_def_prop (this_obj_p,
- ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
- ecma_make_uint32_value (0),
- ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_IS_THROW);
-
- if (ECMA_IS_VALUE_ERROR (status))
- {
- return status;
- }
-
- JERRY_ASSERT (ecma_is_value_true (status));
ecma_value_t ret_value;
if (ecma_object_is_regexp_object (pattern_arg))
@@ -313,19 +302,28 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this */
re_compiled_code_t *bc_p = ECMA_GET_INTERNAL_VALUE_POINTER (re_compiled_code_t,
pattern_obj_p->u.class_prop.u.value);
- ecma_ref_object (this_obj_p);
ret_value = ecma_op_create_regexp_from_bytecode (this_obj_p, bc_p);
-
- ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
- return ret_value;
}
-
- ret_value = ecma_op_create_regexp_from_pattern (this_obj_p, pattern_arg, flags_arg);
+ else
+ {
+ ret_value = ecma_op_create_regexp_from_pattern (this_obj_p, pattern_arg, flags_arg);
+ }
if (!ECMA_IS_VALUE_ERROR (ret_value))
{
- ecma_ref_object (this_obj_p);
+ ecma_value_t status = ecma_builtin_helper_def_prop (this_obj_p,
+ ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
+ ecma_make_uint32_value (0),
+ ECMA_PROPERTY_FLAG_WRITABLE | ECMA_PROP_IS_THROW);
+
ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
+
+ if (ECMA_IS_VALUE_ERROR (status))
+ {
+ return status;
+ }
+
+ ecma_ref_object (this_obj_p);
}
return ret_value;
diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h
index 3d023cb53..6809ac8eb 100644
--- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h
+++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.inc.h
@@ -91,7 +91,7 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LASTINDEX_UL,
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_BUILTIN_ANNEXB)
-ROUTINE (LIT_MAGIC_STRING_COMPILE, ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE, 2, 1)
+ROUTINE (LIT_MAGIC_STRING_COMPILE, ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE, 2, 2)
#endif /* ENABLED (JERRY_BUILTIN_ANNEXB) */
ROUTINE (LIT_MAGIC_STRING_EXEC, ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC, 1, 1)
ROUTINE (LIT_MAGIC_STRING_TEST, ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST, 1, 1)
diff --git a/tests/jerry/es.next/regexp-routines.js b/tests/jerry/es.next/regexp-routines.js
index 7a750ba1f..53a0c0210 100644
--- a/tests/jerry/es.next/regexp-routines.js
+++ b/tests/jerry/es.next/regexp-routines.js
@@ -144,3 +144,69 @@ assert (r.lastIndex === 0);
assert (RegExp.prototype[Symbol.match].call(/a/y, "aaa").length === 1);
assert (RegExp.prototype[Symbol.match].call(/a/gy, "aaa").length === 3);
+
+var length = Object.getOwnPropertyDescriptor(RegExp.prototype.compile, "length");
+assert(!length.enumerable);
+assert(!length.writable);
+assert(length.configurable);
+assert(length.value === 2);
+
+var re = /./;
+re.lastIndex = 23;
+
+try {
+ re.compile(re, null);
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+try {
+ re.compile(re, 0);
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+try {
+ re.compile(re, '');
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+try {
+ re.compile(re, false);
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+try {
+ re.compile(re, {});
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+try {
+ re.compile(re, []);
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+assert(re.lastIndex === 23);
+
+var subject = /initial/;
+Object.defineProperty(subject, 'lastIndex', { value: 45, writable: false });
+
+try {
+ subject.compile(/updated/gi);
+ assert(false);
+} catch (e) {
+ assert(e instanceof TypeError);
+}
+
+assert(subject.toString() === new RegExp('updated', 'gi').toString());
+assert(subject.lastIndex === 45);
diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml
index 04d54a78e..5bcba5a72 100644
--- a/tests/test262-esnext-excludelist.xml
+++ b/tests/test262-esnext-excludelist.xml
@@ -14,9 +14,6 @@
-
-
-