Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

es2016.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. var ES2015 = require('./es2015');
  3. var GetIntrinsic = require('./GetIntrinsic');
  4. var assign = require('./helpers/assign');
  5. var $setProto = require('./helpers/setProto');
  6. var callBound = require('./helpers/callBound');
  7. var getIteratorMethod = require('./helpers/getIteratorMethod');
  8. var $TypeError = GetIntrinsic('%TypeError%');
  9. var $arrayPush = callBound('Array.prototype.push');
  10. var $getProto = require('./helpers/getProto');
  11. var ES2016 = assign(assign({}, ES2015), {
  12. // https://www.ecma-international.org/ecma-262/7.0/#sec-samevaluenonnumber
  13. SameValueNonNumber: function SameValueNonNumber(x, y) {
  14. if (typeof x === 'number' || typeof x !== typeof y) {
  15. throw new TypeError('SameValueNonNumber requires two non-number values of the same type.');
  16. }
  17. return this.SameValue(x, y);
  18. },
  19. // https://www.ecma-international.org/ecma-262/7.0/#sec-iterabletoarraylike
  20. IterableToArrayLike: function IterableToArrayLike(items) {
  21. var usingIterator = getIteratorMethod(this, items);
  22. if (typeof usingIterator !== 'undefined') {
  23. var iterator = this.GetIterator(items, usingIterator);
  24. var values = [];
  25. var next = true;
  26. while (next) {
  27. next = this.IteratorStep(iterator);
  28. if (next) {
  29. var nextValue = this.IteratorValue(next);
  30. $arrayPush(values, nextValue);
  31. }
  32. }
  33. return values;
  34. }
  35. return this.ToObject(items);
  36. },
  37. // https://ecma-international.org/ecma-262/7.0/#sec-ordinarygetprototypeof
  38. OrdinaryGetPrototypeOf: function (O) {
  39. if (this.Type(O) !== 'Object') {
  40. throw new $TypeError('Assertion failed: O must be an Object');
  41. }
  42. if (!$getProto) {
  43. throw new $TypeError('This environment does not support fetching prototypes.');
  44. }
  45. return $getProto(O);
  46. },
  47. // https://ecma-international.org/ecma-262/7.0/#sec-ordinarysetprototypeof
  48. OrdinarySetPrototypeOf: function (O, V) {
  49. if (this.Type(V) !== 'Object' && this.Type(V) !== 'Null') {
  50. throw new $TypeError('Assertion failed: V must be Object or Null');
  51. }
  52. /*
  53. var extensible = this.IsExtensible(O);
  54. var current = this.OrdinaryGetPrototypeOf(O);
  55. if (this.SameValue(V, current)) {
  56. return true;
  57. }
  58. if (!extensible) {
  59. return false;
  60. }
  61. */
  62. try {
  63. $setProto(O, V);
  64. } catch (e) {
  65. return false;
  66. }
  67. return this.OrdinaryGetPrototypeOf(O) === V;
  68. /*
  69. var p = V;
  70. var done = false;
  71. while (!done) {
  72. if (p === null) {
  73. done = true;
  74. } else if (this.SameValue(p, O)) {
  75. return false;
  76. } else {
  77. if (wat) {
  78. done = true;
  79. } else {
  80. p = p.[[Prototype]];
  81. }
  82. }
  83. }
  84. O.[[Prototype]] = V;
  85. return true;
  86. */
  87. }
  88. });
  89. module.exports = ES2016;