Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM] stack[0].getFileName() missing #728

Closed
stefanpenner opened this issue Dec 15, 2015 · 5 comments
Closed

[SM] stack[0].getFileName() missing #728

stefanpenner opened this issue Dec 15, 2015 · 5 comments

Comments

@stefanpenner
Copy link

The V8 specific (I believe) stack[0].getFileName() method is missing in SM (and likely vms), some node code depends on this, to discover the location (on-disk) of a caller.

If there is an alternative for SM, I could just implement it that way. Although it would be nice if some standard was eventually derived.

@stefanpenner stefanpenner changed the title stack[0].getFileName() missing [SM] stack[0].getFileName() missing Dec 15, 2015
@obastemur
Copy link
Member

JXcore SM build has a patch for V8's Error.captureStackTrace and it should behave similarly.

try {
  throw new Error("AAA");
} catch(e) {
  Error.captureStackTrace(e);
  console.log(e.stack[0].getFileName());
}

I've just tested the code above and it behaves as expected with SM build.

@stefanpenner
Copy link
Author

Although I get get it to work in isolation, i appear to not be able to get it to work in my specific (more complex example). I'm going to try and isolate it further

@stefanpenner
Copy link
Author

Actually, I believe my example is more similar to this SO response: http://stackoverflow.com/a/13227808

module.exports = getCallerFile;
function getCallerFile() {
  var oldPrepareStackTrace = Error.prepareStackTrace;
  Error.prepareStackTrace = function(err, stack) { return stack; };
  var stack = new Error().stack;
  Error.prepareStackTrace = oldPrepareStackTrace;

  // stack[0] holds this file
  // stack[1] holds where this function was called
  // stack[2] holds the file we're interested in
  return stack[2] ? stack[2].getFileName() : undefined;
}

which, when run in node results in:

> getCallerFile()
'repl.js'

The example provided in #728 (comment) does not appear to work in v8@4.6.85.28

@obastemur
Copy link
Member

@stefanpenner Thanks for all the details. Fix will be part of 0.3.1.0 (ee19070)

obastemur added a commit that referenced this issue Dec 16, 2015
See #728
With this commit, SM Error tooling should be fairly compatible with v8
@stefanpenner
Copy link
Author

@obastemur very nice, will give 0.3.1.0 a go sometime.

Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants