Fix the this argument passed to string replace callbacks.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg@inf.u-szeged.hu
This commit is contained in:
Zoltan Herczeg
2015-08-11 04:07:34 -07:00
parent c6b4510c9a
commit f2c846d960
2 changed files with 19 additions and 1 deletions
@@ -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);
+18
View File
@@ -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", {