From b0ca537a341d06a047ebdafef9704a4abb3da4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20G=C3=A1l?= Date: Fri, 15 Jan 2021 20:48:13 +0100 Subject: [PATCH] Correctly release values in Proxy.[[Get]] (#4477) In Proxy.[[Get]] if the target.[[GetOwnPropertyDescriptor]] fails the trap result should be freed. Fixes: #4466 JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.usz@partner.samsung.com --- .../ecma/operations/ecma-proxy-object.c | 1 + .../es.next/regression-test-issue-4466.js | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/jerry/es.next/regression-test-issue-4466.js diff --git a/jerry-core/ecma/operations/ecma-proxy-object.c b/jerry-core/ecma/operations/ecma-proxy-object.c index 4bd655e76..a9010b0dc 100644 --- a/jerry-core/ecma/operations/ecma-proxy-object.c +++ b/jerry-core/ecma/operations/ecma-proxy-object.c @@ -1158,6 +1158,7 @@ ecma_proxy_object_get (ecma_object_t *obj_p, /**< proxy object */ /* 12. */ if (ECMA_IS_VALUE_ERROR (status)) { + ecma_free_value (trap_result); return status; } diff --git a/tests/jerry/es.next/regression-test-issue-4466.js b/tests/jerry/es.next/regression-test-issue-4466.js new file mode 100644 index 000000000..856193d6e --- /dev/null +++ b/tests/jerry/es.next/regression-test-issue-4466.js @@ -0,0 +1,35 @@ +// 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 called_get = false; +var targetProxy = new Proxy({}, { + getOwnPropertyDescriptor: function(target, key) { + throw new URIError("Generate error"); + } +}); + +var px = new Proxy(targetProxy, { + get: function(target, key) { + called_get = true; + return { debug: 1 }; + } +}); + +try { + px.abc; + assert(false); +} catch (ex) { + assert(ex instanceof URIError); + assert(called_get === true); +}