How to use the stacktrace-js.getSync function in stacktrace-js

To help you get started, we’ve selected a few stacktrace-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KnicKnic / WASM-ImageMagick / src / magickApi.ts View on Github external
// // instead of doing the sane code of being able to just use import.meta.url 
// // (Edge doesn't work) (safari mobile, chrome, opera, firefox all do)
// // 
// // I will use stacktrace-js library to get the current file name
// //
// try {
//   // @ts-ignore
//   let packageUrl = import.meta.url;
//   currentJavascriptURL = packageUrl;
// } catch (error) {
//   // eat
// }
//
//
{
  let stacktrace = StackTrace.getSync();
  currentJavascriptURL = stacktrace[0].fileName;
}

const magickWorkerUrl = GetCurrentUrlDifferentFilename('magick.js')

function GenerateMagickWorkerText(magickUrl){
  // generates code for the following
  // var magickJsCurrentPath = 'magickUrl';
  // importScripts(magickJsCurrentPath);

  return "var magickJsCurrentPath = '" + magickUrl +"';\n" +
         'importScripts(magickJsCurrentPath);'
}
let magickWorker;
if(currentJavascriptURL.startsWith('http'))
{
github KnicKnic / WASM-ImageMagick / src / magickApi.ts View on Github external
// // instead of doing the sane code of being able to just use import.meta.url 
// // (Edge doesn't work) (safari mobile, chrome, opera, firefox all do)
// // 
// // I will use stacktrace-js library to get the current file name
// //
// try {
//   // @ts-ignore
//   let packageUrl = import.meta.url;
//   currentJavascriptURL = packageUrl;
// } catch (error) {
//   // eat
// }
//
//
{
  let stacktrace = StackTrace.getSync();
  currentJavascriptURL = stacktrace[0].fileName;
}

const magickWorkerUrl = GetCurrentUrlDifferentFilename('magick.js')

function GenerateMagickWorkerText(magickUrl){
  // generates code for the following
  // var magickJsCurrentPath = 'magickUrl';
  // importScripts(magickJsCurrentPath);

  return "var magickJsCurrentPath = '" + magickUrl +"';\n" +
         'importScripts(magickJsCurrentPath);'
}
let magickWorker;
if(currentJavascriptURL.startsWith('http'))
{
github cucumber / cucumber-js / src / support_code_library_builder / build_helpers.js View on Github external
function getDefinitionLineAndUri(cwd) {
  let line = 'unknown'
  let uri = 'unknown'
  const stackframes = StackTrace.getSync()
  const stackframe = _.find(stackframes, frame => {
    return !isFileNameInCucumber(frame.getFileName())
  })
  if (stackframe) {
    line = stackframe.getLineNumber()
    uri = stackframe.getFileName()
    if (uri) {
      uri = path.relative(cwd, uri)
    }
  }
  return { line, uri }
}
github cucumber / cucumber-js / lib / cucumber / support_code / library.js View on Github external
function getStackframe() {
    var stackframes = StackTrace.getSync();
    if (stackframes.length > 2) {
      return stackframes[2];
    } else {
      return stackframes[0];
    }
  }
github ZhiXiao-Lin / nestify / server / src / common / lib / logger.ts View on Github external
static getStackTrace(deep: number = 2): ContextTrace {
        const stackList: StackTrace.StackFrame[] = StackTrace.getSync();
        const stackInfo: StackTrace.StackFrame = stackList[deep];

        const lineNumber: number = stackInfo.lineNumber;
        const columnNumber: number = stackInfo.columnNumber;
        const fileName: string = stackInfo.fileName;

        const extnameLength: number = Path.extname(fileName).length;
        let basename: string = Path.basename(fileName);
        basename = basename.substr(0, basename.length - extnameLength);
        const context: string = _.upperFirst(_.camelCase(basename));

        return new ContextTrace(context, fileName, lineNumber, columnNumber);
    }
github aholachek / redux-usage-report / src / generateReduxReport.js View on Github external
const shouldSkipProxy = () => {
  if (global.reduxReport.__inProgress || global.reduxReport.__reducerInProgress) return true

  if (!global.reduxReport.__skipAccessOriginCheck) {
    const stackFrames = StackTrace.getSync()
    const initiatingFunc =
      stackFrames[stackFrames.findIndex(s => s.functionName === "Object.get") + 1]

    const initiatingFuncNotLocal =
      !!initiatingFunc &&
      initiatingFunc.fileName &&
      (initiatingFunc.fileName.match(/\.\/~\/|\/node_modules\//) ||
        initiatingFunc.fileName.match(/extension:\/\//))

    if (!!initiatingFuncNotLocal) return true
  }
  return false
}
github GeneZharov / introversion / src / errors / util.js View on Github external
export function _warning(
  {
    warn,
    errorHandling,
    formatErrors
  }: {
    warn: Print,
    errorHandling: "warn" | "throw",
    formatErrors: boolean
  },
  msg: string[]
): void {
  if (errorHandling === "throw") error(msg);
  const trace = Stacktrace.getSync()
    .map(f => formatStackFrame(["file", "func", "line", "col"], f))
    .slice(1);
  formatErrors ? warn(formatWarnFmt(msg, trace)) : warn(formatWarn(msg));
}

stacktrace-js

Framework-agnostic, micro-library for getting stack traces in all environments

MIT
Latest version published 5 years ago

Package Health Score

79 / 100
Full package analysis