You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
1.3 KiB

'use strict';
var $ = require('../internals/export');
var toObject = require('../internals/to-object');
var lengthOfArrayLike = require('../internals/length-of-array-like');
var doesNotExceedSafeInteger = require('../internals/does-not-exceed-safe-integer');
var fails = require('../internals/fails');
var INCORRECT_TO_LENGTH = fails(function () {
return [].push.call({ length: 0x100000000 }, 1) !== 4294967297;
});
// V8 and Safari <= 15.4, FF < 23 throws InternalError
// https://bugs.chromium.org/p/v8/issues/detail?id=12681
var SILENT_ON_NON_WRITABLE_LENGTH = !function () {
try {
// eslint-disable-next-line es-x/no-object-defineproperty -- safe
Object.defineProperty([], 'length', { writable: false }).push();
} catch (error) {
return error instanceof TypeError;
}
}();
// `Array.prototype.push` method
// https://tc39.es/ecma262/#sec-array.prototype.push
$({ target: 'Array', proto: true, arity: 1, forced: INCORRECT_TO_LENGTH || SILENT_ON_NON_WRITABLE_LENGTH }, {
// eslint-disable-next-line no-unused-vars -- required for `.length`
push: function push(item) {
var O = toObject(this);
var len = lengthOfArrayLike(O);
var argCount = arguments.length;
doesNotExceedSafeInteger(len + argCount);
for (var i = 0; i < argCount; i++) {
O[len] = arguments[i];
len++;
}
O.length = len;
return len;
}
});