From 20a1345bbe7ba0efc04963326c4b408d41480941 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 24 Jun 2020 15:51:03 +0300 Subject: [PATCH] Add Array.prototype.lastIndexOf test --- .../length-zero-returns-minus-one.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/built-ins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js diff --git a/test/built-ins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js b/test/built-ins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js new file mode 100644 index 0000000000..4d22b4869c --- /dev/null +++ b/test/built-ins/Array/prototype/lastIndexOf/length-zero-returns-minus-one.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.lastindexof +description: > + Returns -1 if length is 0. +info: | + Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + 3. If len is 0, return -1. +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error("Length should be checked before ToInteger(fromIndex)."); + }, +}; + +assert.sameValue([].lastIndexOf(1), -1); +assert.sameValue([].lastIndexOf(2, fromIndex), -1);