diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp index 90642eb5b..7f0490b41 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-string-prototype.cpp @@ -1045,7 +1045,7 @@ ecma_builtin_string_prototype_object_replace_get_string (ecma_builtin_replace_se ECMA_TRY_CATCH (result_value, ecma_op_function_call_array_args (context_p->replace_function_p, - context_p->regexp_or_search_string, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), arguments_list, match_length + 2), ret_value); diff --git a/tests/jerry/string-prototype-replace.js b/tests/jerry/string-prototype-replace.js index 37ebda883..c26fc2eae 100644 --- a/tests/jerry/string-prototype-replace.js +++ b/tests/jerry/string-prototype-replace.js @@ -72,6 +72,24 @@ catch (e) assert ("\ud801\udc00".replace("\ud801", "#") === "#\udc00"); assert ("\ud801\udc00".replace("\udc00", "#") === "\ud801#"); +var global = this; + +function case1() +{ + assert(this === global); + return "y"; +} + +function case2() +{ + "use strict"; + assert(this === undefined); + return "y"; +} + +assert ("x".replace("x", case1) === "y"); +assert ("x".replace("x", case2) === "y"); + var regexp = /r/g; Object.defineProperty(regexp, "lastIndex", {