Skip to content

Commit e196062

Browse files
authored
Add new target support to RegExp object (#3723)
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi [email protected]
1 parent a4659a8 commit e196062

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@
4545

4646
static ecma_value_t
4747
ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**< arguments list */
48-
ecma_length_t arguments_list_len, /**< number of arguments */
49-
ecma_object_t *new_target_p) /**< pointer to the new target object */
48+
ecma_length_t arguments_list_len) /**< number of arguments */
5049
{
5150
ecma_value_t pattern_value = ECMA_VALUE_UNDEFINED;
5251
ecma_value_t flags_value = ECMA_VALUE_UNDEFINED;
5352
#if ENABLED (JERRY_ES2015)
5453
bool create_regexp_from_bc = false;
5554
bool free_arguments = false;
55+
ecma_object_t *new_target_p = JERRY_CONTEXT (current_new_target);
56+
#else /* !ENABLED (JERRY_ES2015) */
57+
ecma_object_t *new_target_p = NULL;
5658
#endif /* ENABLED (JERRY_ES2015) */
5759

5860
if (arguments_list_len > 0)
@@ -206,8 +208,7 @@ ecma_builtin_regexp_dispatch_call (const ecma_value_t *arguments_list_p, /**< ar
206208
ecma_length_t arguments_list_len) /**< number of arguments */
207209
{
208210
return ecma_builtin_regexp_dispatch_helper (arguments_list_p,
209-
arguments_list_len,
210-
NULL);
211+
arguments_list_len);
211212
} /* ecma_builtin_regexp_dispatch_call */
212213

213214
/**
@@ -221,8 +222,7 @@ ecma_builtin_regexp_dispatch_construct (const ecma_value_t *arguments_list_p, /*
221222
ecma_length_t arguments_list_len) /**< number of arguments */
222223
{
223224
return ecma_builtin_regexp_dispatch_helper (arguments_list_p,
224-
arguments_list_len,
225-
ecma_builtin_get (ECMA_BUILTIN_ID_REGEXP));
225+
arguments_list_len);
226226
} /* ecma_builtin_regexp_dispatch_construct */
227227

228228
#if ENABLED (JERRY_ES2015)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function F(){}
16+
var obj = Reflect.construct(RegExp, ["baz","g"], F);
17+
assert(RegExp.prototype.exec.call(obj, "foobarbaz")[0] === "baz")
18+
assert(obj.lastIndex === 9)
19+
assert(obj instanceof F);

0 commit comments

Comments
 (0)