es.array.with.js 770 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var arrayWith = require('../internals/array-with');
  4. var toIndexedObject = require('../internals/to-indexed-object');
  5. var $Array = Array;
  6. // Firefox bug
  7. var INCORRECT_EXCEPTION_ON_COERCION_FAIL = (function () {
  8. try {
  9. // eslint-disable-next-line es/no-array-prototype-with, no-throw-literal -- needed for testing
  10. []['with']({ valueOf: function () { throw 4; } }, null);
  11. } catch (error) {
  12. return error !== 4;
  13. }
  14. })();
  15. // `Array.prototype.with` method
  16. // https://tc39.es/ecma262/#sec-array.prototype.with
  17. $({ target: 'Array', proto: true, forced: INCORRECT_EXCEPTION_ON_COERCION_FAIL }, {
  18. 'with': function (index, value) {
  19. return arrayWith(toIndexedObject(this), $Array, index, value);
  20. }
  21. });