[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var toObject = require('../internals/to-object');
|
---|
| 4 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
---|
| 5 | var setArrayLength = require('../internals/array-set-length');
|
---|
| 6 | var doesNotExceedSafeInteger = require('../internals/does-not-exceed-safe-integer');
|
---|
| 7 | var fails = require('../internals/fails');
|
---|
| 8 |
|
---|
| 9 | var INCORRECT_TO_LENGTH = fails(function () {
|
---|
| 10 | return [].push.call({ length: 0x100000000 }, 1) !== 4294967297;
|
---|
| 11 | });
|
---|
| 12 |
|
---|
| 13 | // V8 <= 121 and Safari <= 15.4; FF < 23 throws InternalError
|
---|
| 14 | // https://bugs.chromium.org/p/v8/issues/detail?id=12681
|
---|
| 15 | var properErrorOnNonWritableLength = function () {
|
---|
| 16 | try {
|
---|
| 17 | // eslint-disable-next-line es/no-object-defineproperty -- safe
|
---|
| 18 | Object.defineProperty([], 'length', { writable: false }).push();
|
---|
| 19 | } catch (error) {
|
---|
| 20 | return error instanceof TypeError;
|
---|
| 21 | }
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | var FORCED = INCORRECT_TO_LENGTH || !properErrorOnNonWritableLength();
|
---|
| 25 |
|
---|
| 26 | // `Array.prototype.push` method
|
---|
| 27 | // https://tc39.es/ecma262/#sec-array.prototype.push
|
---|
| 28 | $({ target: 'Array', proto: true, arity: 1, forced: FORCED }, {
|
---|
| 29 | // eslint-disable-next-line no-unused-vars -- required for `.length`
|
---|
| 30 | push: function push(item) {
|
---|
| 31 | var O = toObject(this);
|
---|
| 32 | var len = lengthOfArrayLike(O);
|
---|
| 33 | var argCount = arguments.length;
|
---|
| 34 | doesNotExceedSafeInteger(len + argCount);
|
---|
| 35 | for (var i = 0; i < argCount; i++) {
|
---|
| 36 | O[len] = arguments[i];
|
---|
| 37 | len++;
|
---|
| 38 | }
|
---|
| 39 | setArrayLength(O, len);
|
---|
| 40 | return len;
|
---|
| 41 | }
|
---|
| 42 | });
|
---|