From eb993d57ed9fcebabf469bd664a9b657b22f56eb Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Wed, 8 May 2019 15:14:21 +0200 Subject: [PATCH] DataView object underlying ArrayBuffer should be marked during GC. (#2849) This patch fixes #2848 and fixes #2850 as well. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu --- jerry-core/ecma/base/ecma-gc.c | 8 ++++++ .../es2015/regression-test-issue-2848.js | 17 ++++++++++++ .../es2015/regression-test-issue-2850.js | 26 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/jerry/es2015/regression-test-issue-2848.js create mode 100644 tests/jerry/es2015/regression-test-issue-2850.js diff --git a/jerry-core/ecma/base/ecma-gc.c b/jerry-core/ecma/base/ecma-gc.c index ec7e6d344..a78712bda 100644 --- a/jerry-core/ecma/base/ecma-gc.c +++ b/jerry-core/ecma/base/ecma-gc.c @@ -296,6 +296,14 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */ break; } #endif /* ENABLED (JERRY_ES2015_BUILTIN_PROMISE) */ +#if ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) + case LIT_MAGIC_STRING_DATAVIEW_UL: + { + ecma_dataview_object_t *dataview_p = (ecma_dataview_object_t *) object_p; + ecma_gc_set_object_visited (dataview_p->buffer_p); + break; + } +#endif /* ENABLED (JERRY_ES2015_BUILTIN_DATAVIEW) */ default: { break; diff --git a/tests/jerry/es2015/regression-test-issue-2848.js b/tests/jerry/es2015/regression-test-issue-2848.js new file mode 100644 index 000000000..ecdb4d4bd --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-2848.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 arrayBuffer = new ArrayBuffer; +var dataView = new DataView(arrayBuffer); +assert (dataView.buffer === arrayBuffer); diff --git a/tests/jerry/es2015/regression-test-issue-2850.js b/tests/jerry/es2015/regression-test-issue-2850.js new file mode 100644 index 000000000..0f5d2be72 --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-2850.js @@ -0,0 +1,26 @@ +// 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. + +try { + (function () { + var d = new DataView(new ArrayBuffer()) + for (var $; ;) { + d.setInt8(0) + } + })() + assert (false); +} catch (e) { + assert (e instanceof RangeError); +} +