Make Array.prototype.unshift method conform to ES11 (#4128)

Changes:
- Since ES6 Array.prototype.unshift shouldn't iterate
over the array elements if argument count is 0.
- Add proper guard for a check introduced in ES6.
- Update comments to reference to ES5.1 and ES11 specs too.

JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác csaba.osztrogonac@h-lab.eu
This commit is contained in:
Csaba Osztrogonác
2020-08-13 10:09:25 +02:00
committed by GitHub
parent 5ce95be174
commit ea07052869
4 changed files with 96 additions and 47 deletions
@@ -0,0 +1,17 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var arrayLike = {get 5() { throw "shouldn't throw"; }};
arrayLike.length = 10;
Array.prototype.unshift.call(arrayLike);
@@ -0,0 +1,22 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
var arrayLike = {get 5() { throw "should throw"; }};
arrayLike.length = 10;
try {
Array.prototype.unshift.call(arrayLike);
assert(false);
} catch (error) {
assert(error == "should throw");
}
-1
View File
@@ -170,7 +170,6 @@
<test id="built-ins/Array/prototype/splice/create-species.js"><reason></reason></test>
<test id="built-ins/Array/prototype/splice/property-traps-order-with-species.js"><reason></reason></test>
<test id="built-ins/Array/prototype/splice/throws-if-integer-limit-exceeded.js"><reason></reason></test>
<test id="built-ins/Array/prototype/unshift/clamps-to-integer-limit.js"><reason></reason></test>
<test id="built-ins/ArrayBuffer/data-allocation-after-object-creation.js"><reason></reason></test>
<test id="built-ins/ArrayBuffer/proto-from-ctor-realm.js"><reason></reason></test>
<test id="built-ins/ArrayBuffer/prototype-from-newtarget.js"><reason></reason></test>