mixin.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. module.exports = function (t, a) {
  3. var o, o1, o2, x, y = {}, z = {};
  4. o = { inherited: true };
  5. o1 = Object.create(o);
  6. o1.visible = z;
  7. o1.nonremovable = 'raz';
  8. Object.defineProperty(o1, 'hidden', { value: 'hidden' });
  9. o2 = Object.defineProperties({}, { nonremovable: { value: y } });
  10. o2.other = 'other';
  11. try { t(o2, o1); } catch (ignore) {}
  12. a(o2.visible, z, "Enumerable");
  13. a(o1.hidden, 'hidden', "Not Enumerable");
  14. a(o2.propertyIsEnumerable('visible'), true, "Enumerable is enumerable");
  15. a(o2.propertyIsEnumerable('hidden'), false,
  16. "Not enumerable is not enumerable");
  17. a(o2.hasOwnProperty('inherited'), false, "Extend only own");
  18. a(o2.inherited, undefined, "Extend ony own: value");
  19. a(o2.nonremovable, y, "Do not overwrite non configurable");
  20. a(o2.other, 'other', "Own kept");
  21. x = {};
  22. t(x, o2);
  23. try { t(x, o1); } catch (ignore) {}
  24. a(x.visible, z, "Enumerable");
  25. a(x.hidden, 'hidden', "Not Enumerable");
  26. a(x.propertyIsEnumerable('visible'), true, "Enumerable is enumerable");
  27. a(x.propertyIsEnumerable('hidden'), false,
  28. "Not enumerable is not enumerable");
  29. a(x.hasOwnProperty('inherited'), false, "Extend only own");
  30. a(x.inherited, undefined, "Extend ony own: value");
  31. a(x.nonremovable, y, "Ignored non configurable");
  32. a(x.other, 'other', "Other");
  33. x.visible = 3;
  34. a(x.visible, 3, "Writable is writable");
  35. x = {};
  36. t(x, o1);
  37. a.throws(function () {
  38. x.hidden = 3;
  39. }, "Not writable is not writable");
  40. x = {};
  41. t(x, o1);
  42. delete x.visible;
  43. a.ok(!x.hasOwnProperty('visible'), "Configurable is configurable");
  44. x = {};
  45. t(x, o1);
  46. a.throws(function () {
  47. delete x.hidden;
  48. }, "Not configurable is not configurable");
  49. x = Object.defineProperty({}, 'foo',
  50. { configurable: false, writable: true, enumerable: false, value: 'bar' });
  51. try { t(x, { foo: 'lorem' }); } catch (ignore) {}
  52. a(x.foo, 'bar', "Writable, not enumerable");
  53. };