Title: [289780] trunk
- Revision
- 289780
- Author
- [email protected]
- Date
- 2022-02-14 16:14:28 -0800 (Mon, 14 Feb 2022)
Log Message
`Array#{ groupBy, groupByToMap }` should throw a `TypeError` when `this` is `null` or `undefined`
https://bugs.webkit.org/show_bug.cgi?id=236541
Reviewed by Alexey Shvayka.
JSTests:
* stress/array-group-by-null-or-undefined.js: Added.
(shouldThrow):
Source/_javascript_Core:
While we are correctly using @toObject, these functions missed "use strict", which enforces a function
to change a non object |this| to an object (in this case, global object). This patch adds "use strict",
to make these function strict code.
* builtins/ArrayPrototype.js:
(groupBy):
(groupByToMap):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (289779 => 289780)
--- trunk/JSTests/ChangeLog 2022-02-15 00:09:10 UTC (rev 289779)
+++ trunk/JSTests/ChangeLog 2022-02-15 00:14:28 UTC (rev 289780)
@@ -1,3 +1,13 @@
+2022-02-14 Yusuke Suzuki <[email protected]>
+
+ `Array#{ groupBy, groupByToMap }` should throw a `TypeError` when `this` is `null` or `undefined`
+ https://bugs.webkit.org/show_bug.cgi?id=236541
+
+ Reviewed by Alexey Shvayka.
+
+ * stress/array-group-by-null-or-undefined.js: Added.
+ (shouldThrow):
+
2022-02-09 Angelos Oikonomopoulos <[email protected]>
Skip failing shadow realms tests on MIPS
Added: trunk/JSTests/stress/array-group-by-null-or-undefined.js (0 => 289780)
--- trunk/JSTests/stress/array-group-by-null-or-undefined.js (rev 0)
+++ trunk/JSTests/stress/array-group-by-null-or-undefined.js 2022-02-15 00:14:28 UTC (rev 289780)
@@ -0,0 +1,30 @@
+//@ requireOptions("--useArrayGroupByMethod=1")
+
+function shouldThrow(func, errorMessage) {
+ var errorThrown = false;
+ var error = null;
+ try {
+ func();
+ } catch (e) {
+ errorThrown = true;
+ error = e;
+ }
+ if (!errorThrown)
+ throw new Error('not thrown');
+ if (String(error) !== errorMessage)
+ throw new Error(`bad error: ${String(error)}`);
+}
+
+shouldThrow(() => {
+ Array.prototype.groupBy.call(null, () => { /* empty */ })
+}, `TypeError: Array.prototype.groupBy requires that |this| not be null or undefined`);
+shouldThrow(() => {
+ Array.prototype.groupBy.call(undefined, () => { /* empty */ })
+}, `TypeError: Array.prototype.groupBy requires that |this| not be null or undefined`);
+
+shouldThrow(() => {
+ Array.prototype.groupByToMap.call(null, () => { /* empty */ })
+}, `TypeError: Array.prototype.groupByToMap requires that |this| not be null or undefined`);
+shouldThrow(() => {
+ Array.prototype.groupByToMap.call(undefined, () => { /* empty */ })
+}, `TypeError: Array.prototype.groupByToMap requires that |this| not be null or undefined`);
Modified: trunk/Source/_javascript_Core/ChangeLog (289779 => 289780)
--- trunk/Source/_javascript_Core/ChangeLog 2022-02-15 00:09:10 UTC (rev 289779)
+++ trunk/Source/_javascript_Core/ChangeLog 2022-02-15 00:14:28 UTC (rev 289780)
@@ -1,3 +1,18 @@
+2022-02-14 Yusuke Suzuki <[email protected]>
+
+ `Array#{ groupBy, groupByToMap }` should throw a `TypeError` when `this` is `null` or `undefined`
+ https://bugs.webkit.org/show_bug.cgi?id=236541
+
+ Reviewed by Alexey Shvayka.
+
+ While we are correctly using @toObject, these functions missed "use strict", which enforces a function
+ to change a non object |this| to an object (in this case, global object). This patch adds "use strict",
+ to make these function strict code.
+
+ * builtins/ArrayPrototype.js:
+ (groupBy):
+ (groupByToMap):
+
2022-02-14 Don Olmstead <[email protected]>
[CMake] Remove uses of add_definitions in _javascript_Core build
Modified: trunk/Source/_javascript_Core/builtins/ArrayPrototype.js (289779 => 289780)
--- trunk/Source/_javascript_Core/builtins/ArrayPrototype.js 2022-02-15 00:09:10 UTC (rev 289779)
+++ trunk/Source/_javascript_Core/builtins/ArrayPrototype.js 2022-02-15 00:14:28 UTC (rev 289780)
@@ -158,6 +158,8 @@
function groupBy(callback /*, thisArg */)
{
+ "use strict";
+
var array = @toObject(this, "Array.prototype.groupBy requires that |this| not be null or undefined");
var length = @toLength(array.length);
@@ -182,6 +184,8 @@
function groupByToMap(callback /*, thisArg */)
{
+ "use strict";
+
var array = @toObject(this, "Array.prototype.groupByToMap requires that |this| not be null or undefined");
var length = @toLength(array.length);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes