Node-Red configuration
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.

es.array.unshift.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 deletePropertyOrThrow = require('../internals/delete-property-or-throw');
  7. var doesNotExceedSafeInteger = require('../internals/does-not-exceed-safe-integer');
  8. // IE8-
  9. var INCORRECT_RESULT = [].unshift(0) !== 1;
  10. // V8 ~ Chrome < 71 and Safari <= 15.4, FF < 23 throws InternalError
  11. var properErrorOnNonWritableLength = function () {
  12. try {
  13. // eslint-disable-next-line es/no-object-defineproperty -- safe
  14. Object.defineProperty([], 'length', { writable: false }).unshift();
  15. } catch (error) {
  16. return error instanceof TypeError;
  17. }
  18. };
  19. var FORCED = INCORRECT_RESULT || !properErrorOnNonWritableLength();
  20. // `Array.prototype.unshift` method
  21. // https://tc39.es/ecma262/#sec-array.prototype.unshift
  22. $({ target: 'Array', proto: true, arity: 1, forced: FORCED }, {
  23. // eslint-disable-next-line no-unused-vars -- required for `.length`
  24. unshift: function unshift(item) {
  25. var O = toObject(this);
  26. var len = lengthOfArrayLike(O);
  27. var argCount = arguments.length;
  28. if (argCount) {
  29. doesNotExceedSafeInteger(len + argCount);
  30. var k = len;
  31. while (k--) {
  32. var to = k + argCount;
  33. if (k in O) O[to] = O[k];
  34. else deletePropertyOrThrow(O, to);
  35. }
  36. for (var j = 0; j < argCount; j++) {
  37. O[j] = arguments[j];
  38. }
  39. } return setArrayLength(O, len + argCount);
  40. }
  41. });