Skip to content
Permalink
Browse files

Merge pull request #683 from krekoten/exception_set_backtrace

Exception#set_backtrace
  • Loading branch information
alex committed May 6, 2013
2 parents f02639c + cf707be commit 2ce73502c9bfa3e502017c8778cfd8d37ca73496
Showing with 20 additions and 3 deletions.
  1. +0 −2 spec/tags/core/exception/set_backtrace_tags.txt
  2. +20 −1 topaz/objects/exceptionobject.py

This file was deleted.

@@ -9,14 +9,15 @@ def method_allocate(self, space, args_w):


class W_ExceptionObject(W_Object):
_attrs_ = ["msg", "frame", "last_instructions"]
_attrs_ = ["msg", "frame", "last_instructions", "w_backtrace"]

classdef = ClassDef("Exception", W_Object.classdef, filepath=__file__)

def __init__(self, space, klass=None):
W_Object.__init__(self, space, klass)
self.msg = ""
self.frame = None
self.w_backtrace = None

def __str__(self):
return "%s(%s)" % (self.__class__.__name__, self.msg)
@@ -52,6 +53,8 @@ def method_message(self, space):

@classdef.method("backtrace")
def method_backtrace(self, space):
if self.w_backtrace is not None:
return self.w_backtrace
frame = self.frame
results_w = []
prev_frame = None
@@ -65,6 +68,22 @@ def method_backtrace(self, space):
frame = frame.backref()
return space.newarray(results_w)

@classdef.method("set_backtrace")
def method_set_backtrace(self, space, w_backtrace):
if w_backtrace is space.w_nil:
self.w_backtrace = w_backtrace
return w_backtrace
if space.is_kind_of(w_backtrace, space.w_array):
for w_obj in space.listview(w_backtrace):
if not space.is_kind_of(w_obj, space.w_string):
raise space.error(space.w_TypeError, "backtrace must be Array of String")
self.w_backtrace = w_backtrace
return w_backtrace
if space.is_kind_of(w_backtrace, space.w_string):
self.w_backtrace = space.newarray([w_backtrace])
return self.w_backtrace
raise space.error(space.w_TypeError, "backtrace must be Array of String")


class W_ScriptError(W_ExceptionObject):
classdef = ClassDef("ScriptError", W_ExceptionObject.classdef, filepath=__file__)

0 comments on commit 2ce7350

Please sign in to comment.
You can’t perform that action at this time.