Commit 35b6aa38 authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

[js] Remove CHECK_OBJECT_COERCIBLE for Array methods

The spec got rid of `CheckObjectCoercible` a while back, and so should
we. This change is not observable in most of the affected cases since
`ToObject` is up near the top of most Array method algorithms. An
example of an observable effect of this change occurs for the following
input:

    Array.prototype.sort.call(null, 1);

Behavior before applying the patch (incorrect message):

    TypeError: Array.prototype.sort called on null or undefined

Expected behavior:

    TypeError: The comparison function must be either a function or
               undefined

This patch removes `CheckObjectCoercible` and adds tests to ensure the
few observable cases are addressed correctly.

The patch also adds a missing `ToObject(this)` to
`Array.prototype.lastIndexOf` which would otherwise become observable
as a result of `CheckObjectCoercible` being removed.

BUG=v8:3577,v8:6921

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia086095076c4bf4d8d58dab26bc28df02994ed01
Reviewed-on: https://chromium-review.googlesource.com/718577Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48800}
parent 7fc550b7
......@@ -390,8 +390,6 @@ function InnerArrayJoin(separator, array, length) {
DEFINE_METHOD(
GlobalArray.prototype,
join(separator) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join");
var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length);
......@@ -403,8 +401,6 @@ DEFINE_METHOD(
// Removes the last element from the array and returns it. See
// ECMA-262, section 15.4.4.6.
function ArrayPopFallback() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop");
var array = TO_OBJECT(this);
var n = TO_LENGTH(array.length);
if (n == 0) {
......@@ -423,8 +419,6 @@ function ArrayPopFallback() {
// Appends the arguments to the end of the array and returns the new
// length of the array. See ECMA-262, section 15.4.4.7.
function ArrayPushFallback() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push");
var array = TO_OBJECT(this);
var n = TO_LENGTH(array.length);
var m = arguments.length;
......@@ -527,8 +521,6 @@ function GenericArrayReverse(array, len) {
DEFINE_METHOD(
GlobalArray.prototype,
reverse() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length);
var isArray = IS_ARRAY(array);
......@@ -547,8 +539,6 @@ DEFINE_METHOD(
function ArrayShiftFallback() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length);
......@@ -574,8 +564,6 @@ function ArrayShiftFallback() {
function ArrayUnshiftFallback(arg1) { // length == 1
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length);
var num_arguments = arguments.length;
......@@ -598,8 +586,6 @@ function ArrayUnshiftFallback(arg1) { // length == 1
function ArraySliceFallback(start, end) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.slice");
var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length);
var start_i = TO_INTEGER(start);
......@@ -671,8 +657,6 @@ function ComputeSpliceDeleteCount(delete_count, num_arguments, len, start_i) {
function ArraySpliceFallback(start, delete_count) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice");
var num_arguments = arguments.length;
var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length);
......@@ -1010,8 +994,6 @@ function InnerArraySort(array, length, comparefn) {
DEFINE_METHOD(
GlobalArray.prototype,
sort(comparefn) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.sort");
if (!IS_UNDEFINED(comparefn) && !IS_CALLABLE(comparefn)) {
throw %make_type_error(kBadSortComparisonFunction, comparefn);
}
......@@ -1025,9 +1007,7 @@ DEFINE_METHOD(
DEFINE_METHOD_LEN(
GlobalArray.prototype,
lastIndexOf(element, index) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
var array = this;
var array = TO_OBJECT(this);
var length = TO_LENGTH(this.length);
if (length == 0) return -1;
......@@ -1086,8 +1066,6 @@ DEFINE_METHOD_LEN(
DEFINE_METHOD_LEN(
GlobalArray.prototype,
copyWithin(target, start, end) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin");
var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length);
......@@ -1160,8 +1138,6 @@ function InnerArrayFind(predicate, thisArg, array, length) {
DEFINE_METHOD_LEN(
GlobalArray.prototype,
find(predicate, thisArg) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
var array = TO_OBJECT(this);
var length = TO_INTEGER(array.length);
......@@ -1191,8 +1167,6 @@ function InnerArrayFindIndex(predicate, thisArg, array, length) {
DEFINE_METHOD_LEN(
GlobalArray.prototype,
findIndex(predicate, thisArg) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex");
var array = TO_OBJECT(this);
var length = TO_INTEGER(array.length);
......@@ -1206,8 +1180,6 @@ DEFINE_METHOD_LEN(
DEFINE_METHOD_LEN(
GlobalArray.prototype,
fill(value, start, end) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length);
......
*%(basename)s:34: TypeError: Array.prototype.sort called on null or undefined
*%(basename)s:34: TypeError: Cannot convert undefined or null to object
([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()[(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]])([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()[([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(![]+[])[+!+[]]]((![]+[])[+!+[]])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+[][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()[(![]+[])[+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()+[])[!+[]+!+[]]]((![]+[])[+!+[]]+(+[![]]+[])[+[]])[+[]]+(![]+[])[+!+[]]+(+[]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+!+[]+[+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+([]+([]+[])[([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[!+[]+!+[]+!+[]+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()[(![]+[])[+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()+[])[!+[]+!+[]]]((![]+[])[+!+[]]+[+[]])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+([][[]]+[])[!+[]+!+[]]+[][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()[(![]+[])[+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][(![]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]()+[])[!+[]+!+[]]]((+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]]+[+[]])+[])[+[]]+(![]+[])[+[]])[+[]])
^
TypeError: Array.prototype.sort called on null or undefined
TypeError: Cannot convert undefined or null to object
at sort (native)
at *%(basename)s:34:410
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
assertThrows(() => {
Array.prototype.lastIndexOf.call(null, 42);
}, TypeError);
assertThrows(() => {
Array.prototype.lastIndexOf.call(undefined, 42);
}, TypeError);
......@@ -567,3 +567,7 @@ TestSortOnNonExtensible();
})()
})();
assertThrows(() => {
Array.prototype.sort.call(undefined);
}, TypeError);
......@@ -26,7 +26,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var should_throw_on_null_and_undefined =
const should_throw_on_null_and_undefined =
[Object.prototype.toLocaleString,
Object.prototype.valueOf,
Object.prototype.hasOwnProperty,
......@@ -39,7 +39,6 @@ var should_throw_on_null_and_undefined =
Array.prototype.reverse,
Array.prototype.shift,
Array.prototype.slice,
Array.prototype.sort,
Array.prototype.splice,
Array.prototype.unshift,
Array.prototype.indexOf,
......@@ -72,7 +71,7 @@ var should_throw_on_null_and_undefined =
// Non generic natives do not work on any input other than the specific
// type, but since this change will allow call to be invoked with undefined
// or null as this we still explicitly test that we throw on these here.
var non_generic =
const non_generic =
[Array.prototype.toString,
Array.prototype.toLocaleString,
Function.prototype.toString,
......@@ -137,7 +136,7 @@ var non_generic =
// Mapping functions.
var mapping_functions =
const mapping_functions =
[Array.prototype.every,
Array.prototype.some,
Array.prototype.forEach,
......@@ -145,27 +144,27 @@ var mapping_functions =
Array.prototype.filter];
// Reduce functions.
var reducing_functions =
const reducing_functions =
[Array.prototype.reduce,
Array.prototype.reduceRight];
function checkExpectedMessage(e) {
assertTrue(e.message.indexOf("called on null or undefined") >= 0 ||
e.message.indexOf("invoked on undefined or null value") >= 0 ||
e.message.indexOf("Cannot convert undefined or null to object") >= 0);
assertTrue(e.message.includes("called on null or undefined") ||
e.message.includes("invoked on undefined or null value") ||
e.message.includes("Cannot convert undefined or null to object"));
}
// Test that all natives using the ToObject call throw the right exception.
for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
for (const fn of should_throw_on_null_and_undefined) {
// Sanity check that all functions are correct
assertEquals(typeof(should_throw_on_null_and_undefined[i]), "function");
assertEquals(typeof fn, "function");
var exception = false;
let exception = false;
try {
// We need to pass a dummy object argument ({}) to these functions because
// of Object.prototype.isPrototypeOf's special behavior, see issue 3483
// for more details.
should_throw_on_null_and_undefined[i].call(null, {});
fn.call(null, {});
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -174,7 +173,7 @@ for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
exception = false;
try {
should_throw_on_null_and_undefined[i].call(undefined, {});
fn.call(undefined, {});
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -183,7 +182,7 @@ for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
exception = false;
try {
should_throw_on_null_and_undefined[i].apply(null, [{}]);
fn.apply(null, [{}]);
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -192,7 +191,7 @@ for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
exception = false;
try {
should_throw_on_null_and_undefined[i].apply(undefined, [{}]);
fn.apply(undefined, [{}]);
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -201,13 +200,13 @@ for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
}
// Test that all natives that are non generic throw on null and undefined.
for (var i = 0; i < non_generic.length; i++) {
for (const fn of non_generic) {
// Sanity check that all functions are correct
assertEquals(typeof(non_generic[i]), "function");
assertEquals(typeof fn, "function");
exception = false;
try {
non_generic[i].call(null);
fn.call(null);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -216,7 +215,7 @@ for (var i = 0; i < non_generic.length; i++) {
exception = false;
try {
non_generic[i].call(null);
fn.call(null);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -225,7 +224,7 @@ for (var i = 0; i < non_generic.length; i++) {
exception = false;
try {
non_generic[i].apply(null);
fn.apply(null);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -234,7 +233,7 @@ for (var i = 0; i < non_generic.length; i++) {
exception = false;
try {
non_generic[i].apply(null);
fn.apply(null);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -247,14 +246,14 @@ for (var i = 0; i < non_generic.length; i++) {
// through an array mapping function.
// We need to make sure that the elements of `array` are all object values,
// see issue 3483 for more details.
var array = [{}, [], new Number, new Map, new WeakSet];
for (var j = 0; j < mapping_functions.length; j++) {
for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
const array = [{}, [], new Number, new Map, new WeakSet];
for (const mapping_function of mapping_functions) {
for (const fn of should_throw_on_null_and_undefined) {
exception = false;
try {
mapping_functions[j].call(array,
should_throw_on_null_and_undefined[i],
null);
mapping_function.call(array,
fn,
null);
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -263,9 +262,9 @@ for (var j = 0; j < mapping_functions.length; j++) {
exception = false;
try {
mapping_functions[j].call(array,
should_throw_on_null_and_undefined[i],
undefined);
mapping_function.call(array,
fn,
undefined);
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -274,13 +273,13 @@ for (var j = 0; j < mapping_functions.length; j++) {
}
}
for (var j = 0; j < mapping_functions.length; j++) {
for (var i = 0; i < non_generic.length; i++) {
for (const mapping_function of mapping_functions) {
for (const fn of non_generic) {
exception = false;
try {
mapping_functions[j].call(array,
non_generic[i],
null);
mapping_function.call(array,
fn,
null);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -289,9 +288,9 @@ for (var j = 0; j < mapping_functions.length; j++) {
exception = false;
try {
mapping_functions[j].call(array,
non_generic[i],
undefined);
mapping_function.call(array,
fn,
undefined);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -302,11 +301,11 @@ for (var j = 0; j < mapping_functions.length; j++) {
// Reduce functions do a call with null as this argument.
for (var j = 0; j < reducing_functions.length; j++) {
for (var i = 0; i < should_throw_on_null_and_undefined.length; i++) {
for (const reducing_function of reducing_functions) {
for (const fn of should_throw_on_null_and_undefined) {
exception = false;
try {
reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]);
reducing_function.call(array, fn);
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -315,7 +314,7 @@ for (var j = 0; j < reducing_functions.length; j++) {
exception = false;
try {
reducing_functions[j].call(array, should_throw_on_null_and_undefined[i]);
reducing_function.call(array, fn);
} catch (e) {
exception = true;
checkExpectedMessage(e);
......@@ -324,11 +323,11 @@ for (var j = 0; j < reducing_functions.length; j++) {
}
}
for (var j = 0; j < reducing_functions.length; j++) {
for (var i = 0; i < non_generic.length; i++) {
for (const reducing_function of reducing_functions) {
for (const fn of non_generic) {
exception = false;
try {
reducing_functions[j].call(array, non_generic[i]);
reducing_function.call(array, fn);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......@@ -337,7 +336,7 @@ for (var j = 0; j < reducing_functions.length; j++) {
exception = false;
try {
reducing_functions[j].call(array, non_generic[i]);
reducing_function.call(array, fn);
} catch (e) {
exception = true;
assertTrue(e instanceof TypeError);
......
......@@ -36,3 +36,13 @@ for (const type of types) {
assertThrows(() => { array.sort({}); }, TypeError);
assertThrows(() => { array.sort(Symbol()); }, TypeError);
}
assertThrows(() => { Array.prototype.sort.call(null, 42); }, TypeError);
try {
Array.prototype.sort.call(null, 42);
} catch (exception) {
assertEquals(
'The comparison function must be either a function or undefined',
exception.message
);
}
......@@ -83,7 +83,7 @@ test(function() {
test(function() {
Array.prototype.shift.call(null);
}, "Array.prototype.shift called on null or undefined", TypeError);
}, "Cannot convert undefined or null to object", TypeError);
test(function() {
String.prototype.trim.call(null);
......
......@@ -29,15 +29,15 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS Array.prototype.toString.call(undefined) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.toLocaleString.call(undefined) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.concat.call(undefined, []) threw exception TypeError: Array.prototype.concat called on null or undefined.
PASS Array.prototype.join.call(undefined, []) threw exception TypeError: Array.prototype.join called on null or undefined.
PASS Array.prototype.pop.call(undefined) threw exception TypeError: Array.prototype.pop called on null or undefined.
PASS Array.prototype.push.call(undefined, {}) threw exception TypeError: Array.prototype.push called on null or undefined.
PASS Array.prototype.reverse.call(undefined) threw exception TypeError: Array.prototype.reverse called on null or undefined.
PASS Array.prototype.shift.call(undefined) threw exception TypeError: Array.prototype.shift called on null or undefined.
PASS Array.prototype.slice.call(undefined, 0, 1) threw exception TypeError: Array.prototype.slice called on null or undefined.
PASS Array.prototype.sort.call(undefined) threw exception TypeError: Array.prototype.sort called on null or undefined.
PASS Array.prototype.splice.call(undefined, 0, 1) threw exception TypeError: Array.prototype.splice called on null or undefined.
PASS Array.prototype.unshift.call(undefined, {}) threw exception TypeError: Array.prototype.unshift called on null or undefined.
PASS Array.prototype.join.call(undefined, []) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.pop.call(undefined) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.push.call(undefined, {}) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.reverse.call(undefined) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.shift.call(undefined) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.slice.call(undefined, 0, 1) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.sort.call(undefined) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.splice.call(undefined, 0, 1) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.unshift.call(undefined, {}) threw exception TypeError: Cannot convert undefined or null to object.
PASS Array.prototype.every.call(undefined, toString) threw exception TypeError: Array.prototype.every called on null or undefined.
PASS Array.prototype.forEach.call(undefined, toString) threw exception TypeError: Array.prototype.forEach called on null or undefined.
PASS Array.prototype.some.call(undefined, toString) threw exception TypeError: Array.prototype.some called on null or undefined.
......
......@@ -22,7 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
description(
'This is a test case for <a https://bugs.webkit.org/show_bug.cgi?id=64679">bug 64679</a>.'
'This is a test case for <a href="https://bugs.webkit.org/show_bug.cgi?id=64679">bug 64679</a>.'
);
// These calls pass undefined as this value, and as such should throw in toObject.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment