From d64d8cad2e69ef62bfeb69e49afe1a3cd51e4db5 Mon Sep 17 00:00:00 2001 From: Yulia Startsev Date: Tue, 1 Feb 2022 09:04:02 +0000 Subject: [PATCH] Bug 1749477 - new array methods should be unscopable; r=evilpie Differential Revision: https://phabricator.services.mozilla.com/D137281 --- js/src/builtin/Array.cpp | 9 +++++++++ js/src/tests/non262/Array/unscopables.js | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/js/src/builtin/Array.cpp b/js/src/builtin/Array.cpp index 46068590c8dc..9034aa72fe1c 100644 --- a/js/src/builtin/Array.cpp +++ b/js/src/builtin/Array.cpp @@ -4128,6 +4128,15 @@ static bool array_proto_finish(JSContext* cx, JS::HandleObject ctor, return false; } +#ifdef NIGHTLY_BUILD + if (cx->realm()->creationOptions().getArrayGroupingEnabled()) { + if (!DefineDataProperty(cx, unscopables, cx->names().groupBy, value) || + !DefineDataProperty(cx, unscopables, cx->names().groupByToMap, value)) { + return false; + } + } +#endif + #ifdef ENABLE_CHANGE_ARRAY_BY_COPY if (cx->options().changeArrayByCopy()) { if (!DefineDataProperty(cx, unscopables, cx->names().withAt, value) || diff --git a/js/src/tests/non262/Array/unscopables.js b/js/src/tests/non262/Array/unscopables.js index 7f17a4b37a09..226b7314dab1 100644 --- a/js/src/tests/non262/Array/unscopables.js +++ b/js/src/tests/non262/Array/unscopables.js @@ -44,6 +44,11 @@ if (getBuildConfiguration()['change-array-by-copy'] && getRealmConfiguration().e expectedKeys.push("withAt", "withReversed", "withSorted", "withSpliced"); } +if (!getBuildConfiguration().release_or_beta && getRealmConfiguration().enableArrayGrouping) { + expectedKeys.push("groupBy", "groupByToMap"); + expectedKeys.sort(); +} + assertDeepEq(keys, expectedKeys); for (let key of keys)