-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,56 @@ | ||
/* eslint-disable no-unused-vars -- required for functions `.length` */ | ||
var $ = require('../internals/export'); | ||
var global = require('../internals/global'); | ||
var apply = require('../internals/function-apply'); | ||
var wrapErrorConstructorWithCause = require('../internals/wrap-error-constructor-with-cause'); | ||
|
||
var WEB_ASSEMBLY = 'WebAssembly'; | ||
var WebAssembly = global[WEB_ASSEMBLY]; | ||
|
||
var FORCED = Error('e', { cause: 7 }).cause !== 7; | ||
|
||
var exportGlobalErrorCauseWrapper = function (ERROR_NAME, wrapper) { | ||
var O = {}; | ||
O[ERROR_NAME] = wrapErrorConstructorWithCause(ERROR_NAME, wrapper, FORCED); | ||
$({ global: true, forced: FORCED }, O); | ||
}; | ||
|
||
var exportWebAssemblyErrorCauseWrapper = function (ERROR_NAME, wrapper) { | ||
if (WebAssembly && WebAssembly[ERROR_NAME]) { | ||
var O = {}; | ||
O[ERROR_NAME] = wrapErrorConstructorWithCause(WEB_ASSEMBLY + '.' + ERROR_NAME, wrapper, FORCED); | ||
$({ target: WEB_ASSEMBLY, stat: true, forced: FORCED }, O); | ||
} | ||
}; | ||
|
||
// https://github.com/tc39/proposal-error-cause | ||
$({ global: true, forced: FORCED }, { | ||
Error: wrapErrorConstructorWithCause('Error', function (init) { | ||
return function Error(message) { return apply(init, this, arguments); }; | ||
}, FORCED) | ||
exportGlobalErrorCauseWrapper('Error', function (init) { | ||
return function Error(message) { return apply(init, this, arguments); }; | ||
}); | ||
|
||
$({ global: true, forced: FORCED }, { | ||
EvalError: wrapErrorConstructorWithCause('EvalError', function (init) { | ||
return function EvalError(message) { return apply(init, this, arguments); }; | ||
}, FORCED), | ||
RangeError: wrapErrorConstructorWithCause('RangeError', function (init) { | ||
return function RangeError(message) { return apply(init, this, arguments); }; | ||
}, FORCED), | ||
ReferenceError: wrapErrorConstructorWithCause('ReferenceError', function (init) { | ||
return function ReferenceError(message) { return apply(init, this, arguments); }; | ||
}, FORCED), | ||
SyntaxError: wrapErrorConstructorWithCause('SyntaxError', function (init) { | ||
return function SyntaxError(message) { return apply(init, this, arguments); }; | ||
}, FORCED), | ||
TypeError: wrapErrorConstructorWithCause('TypeError', function (init) { | ||
return function TypeError(message) { return apply(init, this, arguments); }; | ||
}, FORCED), | ||
URIError: wrapErrorConstructorWithCause('URIError', function (init) { | ||
return function URIError(message) { return apply(init, this, arguments); }; | ||
}, FORCED) | ||
exportGlobalErrorCauseWrapper('EvalError', function (init) { | ||
return function EvalError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportGlobalErrorCauseWrapper('RangeError', function (init) { | ||
return function RangeError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportGlobalErrorCauseWrapper('ReferenceError', function (init) { | ||
return function ReferenceError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportGlobalErrorCauseWrapper('SyntaxError', function (init) { | ||
return function SyntaxError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportGlobalErrorCauseWrapper('TypeError', function (init) { | ||
return function TypeError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportGlobalErrorCauseWrapper('URIError', function (init) { | ||
return function URIError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportWebAssemblyErrorCauseWrapper('CompileError', function (init) { | ||
return function CompileError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportWebAssemblyErrorCauseWrapper('LinkError', function (init) { | ||
return function LinkError(message) { return apply(init, this, arguments); }; | ||
}); | ||
exportWebAssemblyErrorCauseWrapper('RuntimeError', function (init) { | ||
return function RuntimeError(message) { return apply(init, this, arguments); }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters