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 7a8504d4a..705a79e2c 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c @@ -48,15 +48,6 @@ enum /** These routines must be in this order */ ECMA_REGEXP_PROTOTYPE_ROUTINE_START = ECMA_BUILTIN_ID__COUNT - 1, ECMA_REGEXP_PROTOTYPE_ROUTINE_EXEC, -#if ENABLED (JERRY_ESNEXT) - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE, - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL, - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE, - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE, - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY, - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE, - ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL, -#endif /* ENABLED (JERRY_ESNEXT) */ #if ENABLED (JERRY_BUILTIN_ANNEXB) ECMA_REGEXP_PROTOTYPE_ROUTINE_COMPILE, #endif /* ENABLED (JERRY_BUILTIN_ANNEXB) */ @@ -64,8 +55,16 @@ enum ECMA_REGEXP_PROTOTYPE_ROUTINE_TEST, ECMA_REGEXP_PROTOTYPE_ROUTINE_TO_STRING, #if ENABLED (JERRY_ESNEXT) + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE, ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_FLAGS, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_IGNORE_CASE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_MULTILINE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_STICKY, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE, + ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL, + ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_SEARCH, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_MATCH, ECMA_REGEXP_PROTOTYPE_ROUTINE_SYMBOL_REPLACE, @@ -603,8 +602,17 @@ ecma_builtin_regexp_prototype_dispatch_routine (uint16_t builtin_routine_id, /** } case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_SOURCE: { - ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p; + if (!ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL)) + { + if (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)) + { + return ecma_make_magic_string_value (LIT_MAGIC_STRING_EMPTY_NON_CAPTURE_GROUP); + } + return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object")); + } + + ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p; return ecma_builtin_regexp_prototype_get_source (re_obj_p); } case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_GLOBAL: @@ -614,8 +622,17 @@ ecma_builtin_regexp_prototype_dispatch_routine (uint16_t builtin_routine_id, /** case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_UNICODE: case ECMA_REGEXP_PROTOTYPE_ROUTINE_GET_DOT_ALL: { - ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p; + if (!ecma_object_class_is (obj_p, LIT_MAGIC_STRING_REGEXP_UL)) + { + if (ecma_builtin_is (obj_p, ECMA_BUILTIN_ID_REGEXP_PROTOTYPE)) + { + return ECMA_VALUE_UNDEFINED; + } + return ecma_raise_type_error (ECMA_ERR_MSG ("'this' is not a RegExp object")); + } + + ecma_extended_object_t *re_obj_p = (ecma_extended_object_t *) obj_p; return ecma_builtin_regexp_prototype_flags_helper (re_obj_p, builtin_routine_id); } #endif /* ENABLED (JERRY_ESNEXT) */ diff --git a/tests/jerry/es.next/builtin-prototypes.js b/tests/jerry/es.next/builtin-prototypes.js index 3266c5a94..058fb927a 100644 --- a/tests/jerry/es.next/builtin-prototypes.js +++ b/tests/jerry/es.next/builtin-prototypes.js @@ -50,44 +50,11 @@ try { assert (e instanceof TypeError); } -try { - RegExp.prototype.source; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} - -try { - RegExp.prototype.global; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} - -try { - RegExp.prototype.ignoreCase; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} - -try { - RegExp.prototype.multiline; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} - -try { - RegExp.prototype.sticky; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} - -try { - RegExp.prototype.unicode; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} +assert (RegExp.prototype.source === '(?:)'); +assert (RegExp.prototype.global === undefined); +assert (RegExp.prototype.ignoreCase === undefined); +assert (RegExp.prototype.multiline === undefined); +assert (RegExp.prototype.sticky === undefined); +assert (RegExp.prototype.unicode === undefined); +assert (RegExp.prototype.dotAll === undefined); +assert (RegExp.prototype.flags === ''); diff --git a/tests/jerry/es.next/regexp-flags.js b/tests/jerry/es.next/regexp-flags.js index df66a2d6f..4256dad87 100644 --- a/tests/jerry/es.next/regexp-flags.js +++ b/tests/jerry/es.next/regexp-flags.js @@ -61,12 +61,7 @@ var r = /abc/yg; m = r.exec ("strabcstr"); assert (m === null); -try { - RegExp.prototype.flags; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} +assert (RegExp.prototype.flags === ""); var flagsProp = Object.getOwnPropertyDescriptor (RegExp.prototype, "flags"); assert(flagsProp.get.call({}) === ''); diff --git a/tests/jerry/es.next/regexp-prototype-source.js b/tests/jerry/es.next/regexp-prototype-source.js index 70927961f..a521c0a85 100644 --- a/tests/jerry/es.next/regexp-prototype-source.js +++ b/tests/jerry/es.next/regexp-prototype-source.js @@ -39,12 +39,7 @@ assert(new RegExp('/\n/').source.length === 6); assert(new RegExp(/\/\//).source === '\\/\\/'); assert(new RegExp(/\?\//g).source === '\\?\\/'); -try { - RegExp.prototype.source; - assert (false); -} catch (e) { - assert (e instanceof TypeError); -} +assert (RegExp.prototype.source === '(?:)') var sourceProp = Object.getOwnPropertyDescriptor (RegExp.prototype, "source"); try { diff --git a/tests/test262-es6-excludelist.xml b/tests/test262-es6-excludelist.xml index 950a74389..e59d6dbad 100644 --- a/tests/test262-es6-excludelist.xml +++ b/tests/test262-es6-excludelist.xml @@ -353,4 +353,8 @@ Unicode 13: 0x180E is no longer whitespace character lastIndex handling in Symbol.search has changed since ES6 lastIndex handling in Symbol.search has changed since ES6 + RegExp accessors should no longer throw when called on the RegExp prototype + RegExp accessors should no longer throw when called on the RegExp prototype + RegExp accessors should no longer throw when called on the RegExp prototype + RegExp accessors should no longer throw when called on the RegExp prototype diff --git a/tests/test262-esnext-excludelist.xml b/tests/test262-esnext-excludelist.xml index 580038431..ae665cb12 100644 --- a/tests/test262-esnext-excludelist.xml +++ b/tests/test262-esnext-excludelist.xml @@ -1876,20 +1876,12 @@ - - - - - - - -