MCPcopy Create free account
hub / github.com/ICBNetwork/web3-Wallet / tameErrorConstructor

Function tameErrorConstructor

ses.cjs:7552–7770  ·  view source on GitHub ↗
(
  errorTaming=  'safe',
  stackFiltering=  'concise')

Source from the content-addressed store, hash-verified

7550
7551
7552function tameErrorConstructor(
7553 errorTaming= 'safe',
7554 stackFiltering= 'concise')
7555 {
7556 if( errorTaming!== 'safe'&& errorTaming!== 'unsafe') {
7557 throw TypeError( `unrecognized errorTaming ${errorTaming}`);
7558 }
7559 if( stackFiltering!== 'concise'&& stackFiltering!== 'verbose') {
7560 throw TypeError( `unrecognized stackFiltering ${stackFiltering}`);
7561 }
7562 const ErrorPrototype= FERAL_ERROR.prototype;
7563
7564 const platform=
7565 typeof FERAL_ERROR.captureStackTrace=== 'function'? 'v8': 'unknown';
7566 const { captureStackTrace: originalCaptureStackTrace}= FERAL_ERROR;
7567
7568 const makeErrorConstructor= (_= {})=> {
7569 // eslint-disable-next-line no-shadow
7570 const ResultError= function Error(...rest) {
7571 let error;
7572 if( new.target=== undefined) {
7573 error= apply(FERAL_ERROR, this, rest);
7574 }else {
7575 error= construct(FERAL_ERROR, rest, new.target);
7576 }
7577 if( platform=== 'v8') {
7578 // TODO Likely expensive!
7579 apply(originalCaptureStackTrace, FERAL_ERROR, [error, ResultError]);
7580 }
7581 return error;
7582 };
7583 defineProperties(ResultError, {
7584 length: { value: 1},
7585 prototype: {
7586 value: ErrorPrototype,
7587 writable: false,
7588 enumerable: false,
7589 configurable: false}});
7590
7591
7592 return ResultError;
7593 };
7594 const InitialError= makeErrorConstructor({ powers: 'original'});
7595 const SharedError= makeErrorConstructor({ powers: 'none'});
7596 defineProperties(ErrorPrototype, {
7597 constructor: { value: SharedError}});
7598
7599
7600 for( const NativeError of NativeErrors) {
7601 setPrototypeOf(NativeError, SharedError);
7602 }
7603
7604 // https://v8.dev/docs/stack-trace-api#compatibility advises that
7605 // programmers can "always" set `Error.stackTraceLimit`
7606 // even on non-v8 platforms. On non-v8
7607 // it will have no effect, but this advice only makes sense
7608 // if the assignment itself does not fail, which it would
7609 // if `Error` were naively frozen. Hence, we add setters that

Callers 1

repairIntrinsicsFunction · 0.85

Calls 4

makeErrorConstructorFunction · 0.85
setPrototypeOfFunction · 0.85
definePropertyFunction · 0.85
tameV8ErrorConstructorFunction · 0.85

Tested by

no test coverage detected