Minor fix to RegExp.prototype.compile (#4112)

Fixed tests from the exclude list:
<test id="annexB/built-ins/RegExp/prototype/compile/length.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/prototype/compile/pattern-regexp-flags-defined.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/prototype/compile/pattern-regexp-immutable-lastindex.js"><reason></reason></test>

JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu
This commit is contained in:
Szilagyi Adam 2020-08-26 15:16:55 +02:00 committed by GitHub
parent 09c8d28b2c
commit 138151832a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 23 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -14,9 +14,6 @@
<test id="annexB/built-ins/RegExp/named-groups/groups-object.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/named-groups/non-unicode-malformed-lookbehind.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/named-groups/non-unicode-malformed.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/prototype/compile/length.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/prototype/compile/pattern-regexp-flags-defined.js"><reason></reason></test>
<test id="annexB/built-ins/RegExp/prototype/compile/pattern-regexp-immutable-lastindex.js"><reason></reason></test>
<test id="annexB/built-ins/String/prototype/anchor/B.2.3.2.js"><reason></reason></test>
<test id="annexB/built-ins/String/prototype/anchor/attr-tostring-err.js"><reason></reason></test>
<test id="annexB/built-ins/String/prototype/anchor/length.js"><reason></reason></test>