es.error.cause.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, constructor: true, arity: 1, 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, constructor: true, arity: 1, forced: FORCED }, O);
  19. }
  20. };
  21. // https://tc39.es/ecma262/#sec-nativeerror
  22. // https://github.com/tc39/proposal-error-cause
  23. exportGlobalErrorCauseWrapper('Error', function (init) {
  24. return function Error(message) { return apply(init, this, arguments); };
  25. });
  26. exportGlobalErrorCauseWrapper('EvalError', function (init) {
  27. return function EvalError(message) { return apply(init, this, arguments); };
  28. });
  29. exportGlobalErrorCauseWrapper('RangeError', function (init) {
  30. return function RangeError(message) { return apply(init, this, arguments); };
  31. });
  32. exportGlobalErrorCauseWrapper('ReferenceError', function (init) {
  33. return function ReferenceError(message) { return apply(init, this, arguments); };
  34. });
  35. exportGlobalErrorCauseWrapper('SyntaxError', function (init) {
  36. return function SyntaxError(message) { return apply(init, this, arguments); };
  37. });
  38. exportGlobalErrorCauseWrapper('TypeError', function (init) {
  39. return function TypeError(message) { return apply(init, this, arguments); };
  40. });
  41. exportGlobalErrorCauseWrapper('URIError', function (init) {
  42. return function URIError(message) { return apply(init, this, arguments); };
  43. });
  44. exportWebAssemblyErrorCauseWrapper('CompileError', function (init) {
  45. return function CompileError(message) { return apply(init, this, arguments); };
  46. });
  47. exportWebAssemblyErrorCauseWrapper('LinkError', function (init) {
  48. return function LinkError(message) { return apply(init, this, arguments); };
  49. });
  50. exportWebAssemblyErrorCauseWrapper('RuntimeError', function (init) {
  51. return function RuntimeError(message) { return apply(init, this, arguments); };
  52. });