with.js 839 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* eslint no-restricted-syntax: 0, no-with: 0, strict: 0 */
  2. var test = require('tape');
  3. var shimUnscopables = require('../');
  4. test('`with` statement', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (t) {
  5. var entries;
  6. var concat;
  7. with ([]) {
  8. t.equal(concat, Array.prototype.concat, 'concat is dynamically bound');
  9. t.notEqual(entries, Array.prototype.entries, 'entries is not dynamically bound');
  10. }
  11. var obj = {
  12. foo: 1,
  13. bar: 2
  14. };
  15. var foo;
  16. var bar;
  17. obj[Symbol.unscopables] = { foo: true };
  18. with (obj) {
  19. t.equal(foo, undefined);
  20. t.equal(bar, obj.bar);
  21. }
  22. shimUnscopables('concat');
  23. with ([]) {
  24. t.notEqual(concat, Array.prototype.concat, 'concat is no longer dynamically bound');
  25. t.notEqual(entries, Array.prototype.entries, 'entries is still not dynamically bound');
  26. }
  27. t.end();
  28. });