es.error.cause.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-disable no-unused-vars -- required for functions `.length` */
  2. var $ = require('../internals/export');
  3. var global = require('../internals/global');
  4. var apply = require('../internals/function-apply');
  5. var wrapErrorConstructorWithCause = require('../internals/wrap-error-constructor-with-cause');
  6. var WEB_ASSEMBLY = 'WebAssembly';
  7. var WebAssembly = global[WEB_ASSEMBLY];
  8. var FORCED = Error('e', { cause: 7 }).cause !== 7;
  9. var exportGlobalErrorCauseWrapper = function (ERROR_NAME, wrapper) {
  10. var O = {};
  11. O[ERROR_NAME] = wrapErrorConstructorWithCause(ERROR_NAME, wrapper, FORCED);
  12. $({ global: true, forced: FORCED }, O);
  13. };
  14. var exportWebAssemblyErrorCauseWrapper = function (ERROR_NAME, wrapper) {
  15. if (WebAssembly && WebAssembly[ERROR_NAME]) {
  16. var O = {};
  17. O[ERROR_NAME] = wrapErrorConstructorWithCause(WEB_ASSEMBLY + '.' + ERROR_NAME, wrapper, FORCED);
  18. $({ target: WEB_ASSEMBLY, stat: true, forced: FORCED }, O);
  19. }
  20. };
  21. // https://github.com/tc39/proposal-error-cause
  22. exportGlobalErrorCauseWrapper('Error', function (init) {
  23. return function Error(message) { return apply(init, this, arguments); };
  24. });
  25. exportGlobalErrorCauseWrapper('EvalError', function (init) {
  26. return function EvalError(message) { return apply(init, this, arguments); };
  27. });
  28. exportGlobalErrorCauseWrapper('RangeError', function (init) {
  29. return function RangeError(message) { return apply(init, this, arguments); };
  30. });
  31. exportGlobalErrorCauseWrapper('ReferenceError', function (init) {
  32. return function ReferenceError(message) { return apply(init, this, arguments); };
  33. });
  34. exportGlobalErrorCauseWrapper('SyntaxError', function (init) {
  35. return function SyntaxError(message) { return apply(init, this, arguments); };
  36. });
  37. exportGlobalErrorCauseWrapper('TypeError', function (init) {
  38. return function TypeError(message) { return apply(init, this, arguments); };
  39. });
  40. exportGlobalErrorCauseWrapper('URIError', function (init) {
  41. return function URIError(message) { return apply(init, this, arguments); };
  42. });
  43. exportWebAssemblyErrorCauseWrapper('CompileError', function (init) {
  44. return function CompileError(message) { return apply(init, this, arguments); };
  45. });
  46. exportWebAssemblyErrorCauseWrapper('LinkError', function (init) {
  47. return function LinkError(message) { return apply(init, this, arguments); };
  48. });
  49. exportWebAssemblyErrorCauseWrapper('RuntimeError', function (init) {
  50. return function RuntimeError(message) { return apply(init, this, arguments); };
  51. });