function callAndWrapError(target, ...args) {
      try {
        return target(...args);
      } catch (err) {
        if (Object(err) !== err) {
          // err is a primitive value, which is safe to rethrow
          throw err;
        }
        let eName, eMessage, eStack;
        try {
          // The child environment might seek to use 'err' to reach the
          // parent's intrinsics and corrupt them. `${err.name}` will cause
          // string coercion of 'err.name'. If err.name is an object (probably
          // a String of the parent Realm), the coercion uses
          // err.name.toString(), which is under the control of the parent. If
          // err.name were a primitive (e.g. a number), it would use
          // Number.toString(err.name), using the child's version of Number
          // (which the child could modify to capture its argument for later
          // use), however primitives don't have properties like .prototype so
          // they aren't useful for an attack.
          eName = `${err.name}`;
          eMessage = `${err.message}`;
          eStack = `${err.stack || eMessage}`;
          // eName/eMessage/eStack are now child-realm primitive strings, and
          // safe to expose
        } catch (ignored) {
          // if err.name.toString() throws, keep the (parent realm) Error away
          // from the child
          throw new Error('unknown error');
        }
        const ErrorConstructor = errorConstructors.get(eName) || Error;
        try {
          throw new ErrorConstructor(eMessage);
        } catch (err2) {
          err2.stack = eStack; // replace with the captured inner stack
          throw err2;
        }
      }
    }
// as an Error from this realm
as an Error from this realm
as an Error from this realm
function callAndWrapError(target, ...args) {
      try {
        return target(...args);
      } catch (err) {
        if (Object(err) !== err) {
          throw err;
        }
        let eName, eMessage, eStack;
        try {
          eName = `${err.name}`;
          eMessage = `${err.message}`;
          eStack = `${err.stack || eMessage}`;
        } catch (ignored) {
          throw new Error('unknown error');
        }
        const ErrorConstructor = errorConstructors.get(eName) || Error;
        try {
          throw new ErrorConstructor(eMessage);
        } catch (err2) {
          err2.stack = eStack; 
          throw err2;
        }
      }
    }
function callAndWrapError ( target , ... args ) { try { return target ( ... args ) ; } catch ( err ) { if ( Object ( err ) !== err ) { throw err ; } let eName , eMessage , eStack ; try { eName = ` ${ err . name } ` ; eMessage = ` ${ err . message } ` ; eStack = ` ${ err . stack || eMessage } ` ; } catch ( ignored ) { throw new Error ( 'unknown error' ) ; } const ErrorConstructor = errorConstructors . get ( eName ) || Error ; try { throw new ErrorConstructor ( eMessage ) ; } catch ( err2 ) { err2 . stack = eStack ; throw err2 ; } } }
as an Error from this realm
as an Error from this realm
// err is a primitive value, which is safe to rethrow // The child environment might seek to use 'err' to reach the // parent's intrinsics and corrupt them. `${err.name}` will cause // string coercion of 'err.name'. If err.name is an object (probably // a String of the parent Realm), the coercion uses // err.name.toString(), which is under the control of the parent. If // err.name were a primitive (e.g. a number), it would use // Number.toString(err.name), using the child's version of Number // (which the child could modify to capture its argument for later // use), however primitives don't have properties like .prototype so // they aren't useful for an attack. // eName/eMessage/eStack are now child-realm primitive strings, and // safe to expose // if err.name.toString() throws, keep the (parent realm) Error away // from the child // replace with the captured inner stack