From b7508c636cfce08daca7955b9f54f64fc6321454 Mon Sep 17 00:00:00 2001 From: Szilagyi Adam Date: Wed, 27 Nov 2019 11:06:51 +0100 Subject: [PATCH] Fix value release in ecma_op_is_concat_spreadable (#3346) Fixes #3356 Fixes #3361 JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi aszilagy@inf.u-szeged.hu --- jerry-core/ecma/operations/ecma-objects.c | 4 +++- .../es2015/regression-test-issue-3356.js | 19 +++++++++++++++++++ .../es2015/regression-test-issue-3361.js | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/jerry/es2015/regression-test-issue-3356.js create mode 100644 tests/jerry/es2015/regression-test-issue-3361.js diff --git a/jerry-core/ecma/operations/ecma-objects.c b/jerry-core/ecma/operations/ecma-objects.c index 8f01811b8..2401d5c53 100644 --- a/jerry-core/ecma/operations/ecma-objects.c +++ b/jerry-core/ecma/operations/ecma-objects.c @@ -2571,7 +2571,9 @@ ecma_op_is_concat_spreadable (ecma_value_t arg) /**< argument */ if (!ecma_is_value_undefined (spreadable)) { - return ecma_make_boolean_value (ecma_op_to_boolean (spreadable)); + const bool to_bool = ecma_op_to_boolean (spreadable); + ecma_free_value (spreadable); + return ecma_make_boolean_value (to_bool); } return (ecma_make_boolean_value (ecma_is_value_array (arg))); diff --git a/tests/jerry/es2015/regression-test-issue-3356.js b/tests/jerry/es2015/regression-test-issue-3356.js new file mode 100644 index 000000000..6ea607fd3 --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-3356.js @@ -0,0 +1,19 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var alpha = []; +var $ = {[$] : $} +obj = {} +obj[ Symbol.isConcatSpreadable ] = "\O" +alpha.concat(obj) diff --git a/tests/jerry/es2015/regression-test-issue-3361.js b/tests/jerry/es2015/regression-test-issue-3361.js new file mode 100644 index 000000000..38dc1e929 --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-3361.js @@ -0,0 +1,17 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var fakeArray = { [ Symbol ] : 0}; +fakeArray[ Symbol.isConcatSpreadable ] = 2.756; +[].concat(fakeArray);