| 1 | 'use strict';
|
|---|
| 2 | /* eslint-disable no-unused-vars -- required for functions `.length` */
|
|---|
| 3 | var $ = require('../internals/export');
|
|---|
| 4 | var globalThis = require('../internals/global-this');
|
|---|
| 5 | var apply = require('../internals/function-apply');
|
|---|
| 6 | var wrapErrorConstructorWithCause = require('../internals/wrap-error-constructor-with-cause');
|
|---|
| 7 |
|
|---|
| 8 | var WEB_ASSEMBLY = 'WebAssembly';
|
|---|
| 9 | var WebAssembly = globalThis[WEB_ASSEMBLY];
|
|---|
| 10 |
|
|---|
| 11 | // eslint-disable-next-line es/no-error-cause -- feature detection
|
|---|
| 12 | var FORCED = new Error('e', { cause: 7 }).cause !== 7;
|
|---|
| 13 |
|
|---|
| 14 | var exportGlobalErrorCauseWrapper = function (ERROR_NAME, wrapper) {
|
|---|
| 15 | var O = {};
|
|---|
| 16 | // eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
|---|
| 17 | O[ERROR_NAME] = wrapErrorConstructorWithCause(ERROR_NAME, wrapper, FORCED);
|
|---|
| 18 | $({ global: true, constructor: true, arity: 1, forced: FORCED }, O);
|
|---|
| 19 | };
|
|---|
| 20 |
|
|---|
| 21 | var exportWebAssemblyErrorCauseWrapper = function (ERROR_NAME, wrapper) {
|
|---|
| 22 | if (WebAssembly && WebAssembly[ERROR_NAME]) {
|
|---|
| 23 | var O = {};
|
|---|
| 24 | // eslint-disable-next-line unicorn/no-immediate-mutation -- ES3 syntax limitation
|
|---|
| 25 | O[ERROR_NAME] = wrapErrorConstructorWithCause(WEB_ASSEMBLY + '.' + ERROR_NAME, wrapper, FORCED);
|
|---|
| 26 | $({ target: WEB_ASSEMBLY, stat: true, constructor: true, arity: 1, forced: FORCED }, O);
|
|---|
| 27 | }
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | // https://tc39.es/ecma262/#sec-nativeerror
|
|---|
| 31 | exportGlobalErrorCauseWrapper('Error', function (init) {
|
|---|
| 32 | return function Error(message) { return apply(init, this, arguments); };
|
|---|
| 33 | });
|
|---|
| 34 | exportGlobalErrorCauseWrapper('EvalError', function (init) {
|
|---|
| 35 | return function EvalError(message) { return apply(init, this, arguments); };
|
|---|
| 36 | });
|
|---|
| 37 | exportGlobalErrorCauseWrapper('RangeError', function (init) {
|
|---|
| 38 | return function RangeError(message) { return apply(init, this, arguments); };
|
|---|
| 39 | });
|
|---|
| 40 | exportGlobalErrorCauseWrapper('ReferenceError', function (init) {
|
|---|
| 41 | return function ReferenceError(message) { return apply(init, this, arguments); };
|
|---|
| 42 | });
|
|---|
| 43 | exportGlobalErrorCauseWrapper('SyntaxError', function (init) {
|
|---|
| 44 | return function SyntaxError(message) { return apply(init, this, arguments); };
|
|---|
| 45 | });
|
|---|
| 46 | exportGlobalErrorCauseWrapper('TypeError', function (init) {
|
|---|
| 47 | return function TypeError(message) { return apply(init, this, arguments); };
|
|---|
| 48 | });
|
|---|
| 49 | exportGlobalErrorCauseWrapper('URIError', function (init) {
|
|---|
| 50 | return function URIError(message) { return apply(init, this, arguments); };
|
|---|
| 51 | });
|
|---|
| 52 | exportWebAssemblyErrorCauseWrapper('CompileError', function (init) {
|
|---|
| 53 | return function CompileError(message) { return apply(init, this, arguments); };
|
|---|
| 54 | });
|
|---|
| 55 | exportWebAssemblyErrorCauseWrapper('LinkError', function (init) {
|
|---|
| 56 | return function LinkError(message) { return apply(init, this, arguments); };
|
|---|
| 57 | });
|
|---|
| 58 | exportWebAssemblyErrorCauseWrapper('RuntimeError', function (init) {
|
|---|
| 59 | return function RuntimeError(message) { return apply(init, this, arguments); };
|
|---|
| 60 | });
|
|---|