See Error.captureStackTrace().
Error.captureStackTrace()
external static void captureStackTrace( JSError error, [ JSFunction constructor, ]);