On Mon, Nov 17, 2014 at 6:10 AM, Francisco Tolmasky <tolma...@gmail.com> wrote: > I am writing an application that wants to examine the state of an > application without mutating it. > If the application throws an error, I'd like to be able to grab the string > stack trace located in error.stack. > In JSCore for example, this isn't a problem because I can do > Object.getOwnPropertyDescriptor(error, "stack").value. > However, in v8, stack is a getter/setter, not a value. This would maybe not > be a problem if I could do something like > Error.prototype.stack.apply(myError). But, as it turns out it is a *unique* > getter for every error: > Object.getOwnPropertyDescriptor(new Error, "stack").get !== > Object.getOwnPropertyDescriptor(new Error, "stack").get. > As such, I would at the very least like to be able to make sure that its the > normal stack getter (in which case I can feel > safe that its not doing any funny business for example if the user has > overwritten it with their own custom stack getter > that mutates the state of the program, or possibly throws an exception > itself!). So far the best I can come up with is to check > whether the source of the getter is "function() { [native code] }" which is > obviously not ideal since this doesn't preclude the user > havign set the stack getter to a *different* native function. Is there any > way to achieve what I want that I'm missing? > > Thanks, > > Francisco
I don't think it's possible to do directly but you can probably abuse the debug API for this. Start V8 with --expose_debug_as=Debug or evaluate the string 'Debug' in the debug context (see v8::Debug::GetDebugContext() in include/v8-debug.h), then execute the following: var err = /* ... */; var des = Object.getOwnPropertyDescriptor(err, 'stack'); if (des == null || des.get == null) return; var debug = Debug.Debug || Debug; var script = debug.findScript(des.get); if (script == null || script.name !== 'native messages.js') return; // err.stack should be safe. -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.