You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

callBound.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. var test = require('tape');
  3. var callBound = require('../callBound');
  4. test('callBound', function (t) {
  5. // static primitive
  6. t.equal(callBound('Array.length'), Array.length, 'Array.length yields itself');
  7. t.equal(callBound('%Array.length%'), Array.length, '%Array.length% yields itself');
  8. // static non-function object
  9. t.equal(callBound('Array.prototype'), Array.prototype, 'Array.prototype yields itself');
  10. t.equal(callBound('%Array.prototype%'), Array.prototype, '%Array.prototype% yields itself');
  11. t.equal(callBound('Array.constructor'), Array.constructor, 'Array.constructor yields itself');
  12. t.equal(callBound('%Array.constructor%'), Array.constructor, '%Array.constructor% yields itself');
  13. // static function
  14. t.equal(callBound('Date.parse'), Date.parse, 'Date.parse yields itself');
  15. t.equal(callBound('%Date.parse%'), Date.parse, '%Date.parse% yields itself');
  16. // prototype primitive
  17. t.equal(callBound('Error.prototype.message'), Error.prototype.message, 'Error.prototype.message yields itself');
  18. t.equal(callBound('%Error.prototype.message%'), Error.prototype.message, '%Error.prototype.message% yields itself');
  19. // prototype function
  20. t.notEqual(callBound('Object.prototype.toString'), Object.prototype.toString, 'Object.prototype.toString does not yield itself');
  21. t.notEqual(callBound('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% does not yield itself');
  22. t.equal(callBound('Object.prototype.toString')(true), Object.prototype.toString.call(true), 'call-bound Object.prototype.toString calls into the original');
  23. t.equal(callBound('%Object.prototype.toString%')(true), Object.prototype.toString.call(true), 'call-bound %Object.prototype.toString% calls into the original');
  24. t['throws'](
  25. function () { callBound('does not exist'); },
  26. SyntaxError,
  27. 'nonexistent intrinsic throws'
  28. );
  29. t['throws'](
  30. function () { callBound('does not exist', true); },
  31. SyntaxError,
  32. 'allowMissing arg still throws for unknown intrinsic'
  33. );
  34. /* globals WeakRef: false */
  35. t.test('real but absent intrinsic', { skip: typeof WeakRef !== 'undefined' }, function (st) {
  36. st['throws'](
  37. function () { callBound('WeakRef'); },
  38. TypeError,
  39. 'real but absent intrinsic throws'
  40. );
  41. st.equal(callBound('WeakRef', true), undefined, 'allowMissing arg avoids exception');
  42. st.end();
  43. });
  44. t.end();
  45. });