From 98b90ba69710e27fcea6fa37e9922ebabc85dfc1 Mon Sep 17 00:00:00 2001 From: rwalczyna Date: Tue, 18 Feb 2020 19:22:08 +0100 Subject: [PATCH] Fix third parameter of forEach callback function in Map and Set (#3565) There was a problem with passing third parameter to callback. This patch fixes #3564 JerryScript-DCO-1.0-Signed-off-by: Rafal Walczyna r.walczyna@samsung.com --- jerry-core/ecma/operations/ecma-container-object.c | 4 ++-- tests/jerry/es2015/map-prototype-foreach.js | 10 ++++++++++ tests/jerry/es2015/set.js | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/jerry-core/ecma/operations/ecma-container-object.c b/jerry-core/ecma/operations/ecma-container-object.c index 94628e0a0..339ec3f2c 100644 --- a/jerry-core/ecma/operations/ecma-container-object.c +++ b/jerry-core/ecma/operations/ecma-container-object.c @@ -591,9 +591,9 @@ ecma_op_container_foreach (ecma_value_t this_arg, /**< this argument */ } } - ecma_value_t call_args[] = { value, key_arg }; + ecma_value_t call_args[] = { value, key_arg, this_arg }; - ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 2); + ecma_value_t call_value = ecma_op_function_call (func_object_p, predicate_this_arg, call_args, 3); ecma_free_value (value); diff --git a/tests/jerry/es2015/map-prototype-foreach.js b/tests/jerry/es2015/map-prototype-foreach.js index 300f20c82..218b064cd 100644 --- a/tests/jerry/es2015/map-prototype-foreach.js +++ b/tests/jerry/es2015/map-prototype-foreach.js @@ -106,3 +106,13 @@ var object = { map.forEach (function (value, key) { assert (this._secret === 42); }, object); + +/* Test third argument of callback */ +map = new Map(); +map.set('foo', 42); +map.set('bar', 84); + +map.forEach(function(value, key, thisArg) { + assert (typeof thisArg === "object"); + assert (thisArg === map); +}); diff --git a/tests/jerry/es2015/set.js b/tests/jerry/es2015/set.js index fe443bbb9..5c1bb345f 100644 --- a/tests/jerry/es2015/set.js +++ b/tests/jerry/es2015/set.js @@ -118,3 +118,11 @@ try { Set.prototype.add = add; assert(closed === true); + +/* Test third argument of callback */ +var s = new Set([1, 2, 3]); + +s.forEach(function(value, key, thisArg) { + assert (typeof thisArg === "object"); + assert(thisArg === s); +});