diff options
author | Jack Karamanian <karamanian.jack@gmail.com> | 2020-05-30 01:40:49 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-30 10:33:24 +0200 |
commit | d4e97b17abc079f1bfcd689b4518a288b6a80bf8 (patch) | |
tree | 3b872ad515aaf35f9e47619a8d988d59bdbca2a1 /Libraries/LibJS | |
parent | 4a49c8412c6742f37edb429047429c6d85d4f0af (diff) | |
download | serenity-d4e97b17abc079f1bfcd689b4518a288b6a80bf8.zip |
LibJS: Use a non-arrow function to check the |this| value in the
callback for Array.prototype.{reduce,reduceRight}
Arrow functions always retain the |this| binding.
Running this code in Node:
[1, 2].reduce(() => { "use strict"; console.log(this === undefined) }
Output: false
Diffstat (limited to 'Libraries/LibJS')
-rw-r--r-- | Libraries/LibJS/Tests/Array.prototype.reduce.js | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/Array.prototype.reduceRight.js | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/Libraries/LibJS/Tests/Array.prototype.reduce.js b/Libraries/LibJS/Tests/Array.prototype.reduce.js index 5189f89aae..eeaf5a423d 100644 --- a/Libraries/LibJS/Tests/Array.prototype.reduce.js +++ b/Libraries/LibJS/Tests/Array.prototype.reduce.js @@ -31,7 +31,7 @@ try { message: "Reduce of empty array with no initial value" }); - [1, 2].reduce(() => { assert(this === undefined) }); + [1, 2].reduce(function () { assert(this === undefined) }); var callbackCalled = 0; var callback = () => { callbackCalled++; return true }; diff --git a/Libraries/LibJS/Tests/Array.prototype.reduceRight.js b/Libraries/LibJS/Tests/Array.prototype.reduceRight.js index 98c2880990..6e20d9ea48 100644 --- a/Libraries/LibJS/Tests/Array.prototype.reduceRight.js +++ b/Libraries/LibJS/Tests/Array.prototype.reduceRight.js @@ -43,7 +43,7 @@ try { } ); - [1, 2].reduceRight(() => { + [1, 2].reduceRight(function () { assert(this === undefined); }); |