es.array.reverse.js 672 B

12345678910111213141516171819
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var uncurryThis = require('../internals/function-uncurry-this');
  4. var isArray = require('../internals/is-array');
  5. var nativeReverse = uncurryThis([].reverse);
  6. var test = [1, 2];
  7. // `Array.prototype.reverse` method
  8. // https://tc39.es/ecma262/#sec-array.prototype.reverse
  9. // fix for Safari 12.0 bug
  10. // https://bugs.webkit.org/show_bug.cgi?id=188794
  11. $({ target: 'Array', proto: true, forced: String(test) === String(test.reverse()) }, {
  12. reverse: function reverse() {
  13. // eslint-disable-next-line no-self-assign -- dirty hack
  14. if (isArray(this)) this.length = this.length;
  15. return nativeReverse(this);
  16. }
  17. });