Author: Stephan <[email protected]>
Branch:
Changeset: r310:360e0e58f321
Date: 2012-12-11 16:18 +0100
http://bitbucket.org/pypy/lang-js/changeset/360e0e58f321/
Log: fix try/catch stack handling
diff --git a/js/execution_context.py b/js/execution_context.py
--- a/js/execution_context.py
+++ b/js/execution_context.py
@@ -269,11 +269,16 @@
self.declaration_binding_initialization()
-class CatchExecutionContext(SubExecutionContext):
+class CatchExecutionContext(ExecutionContext):
def __init__(self, code, catchparam, exception_value, parent_context):
- SubExecutionContext.__init__(self, parent_context)
self._code_ = code
self._strict_ = code.strict
+ self._parent_context_ = parent_context
+
+ stack_size = code.estimated_stack_size()
+ env_size = code.env_size() + 1 # neet do add one for the arguments
object
+
+ ExecutionContext.__init__(self, stack_size, env_size)
parent_env = parent_context.lexical_environment()
@@ -287,3 +292,6 @@
self._variable_environment_ = local_env
self.declaration_binding_initialization()
+
+ def this_binding(self):
+ return self._parent_context_.this_binding()
diff --git a/js/opcodes.py b/js/opcodes.py
--- a/js/opcodes.py
+++ b/js/opcodes.py
@@ -727,14 +727,26 @@
class TRYCATCHBLOCK(Opcode):
- _stack_change = 0
-
def __init__(self, tryfunc, catchparam, catchfunc, finallyfunc):
self.tryexec = tryfunc
self.catchexec = catchfunc
self.catchparam = catchparam
self.finallyexec = finallyfunc
+ def stack_change(self):
+ trystack = 0
+ catchstack = 0
+ finallystack = 0
+
+ if self.tryexec is not None:
+ trystack = self.tryexec.estimated_stack_size()
+ #if self.catchexec is not None:
+ #catchstack = self.catchexec.estimated_stack_size()
+ if self.finallyexec is not None:
+ finallystack = self.finallyexec.estimated_stack_size()
+
+ return trystack + catchstack + finallystack
+
def eval(self, ctx):
from js.completion import is_return_completion, is_completion,
NormalCompletion
from js.execution import JsException
@@ -744,10 +756,14 @@
finallyexec = self.finallyexec
catchparam = self.catchparam
+ stack_p = ctx._stack_pointer()
+
try:
b = tryexec.run(ctx)
assert is_completion(b)
+ ctx.stack_pop()
except JsException, e:
+ ctx._set_stack_pointer(stack_p)
if catchexec is not None:
from js.execution_context import CatchExecutionContext
msg = e.msg()
diff --git a/js/utils.py b/js/utils.py
--- a/js/utils.py
+++ b/js/utils.py
@@ -33,13 +33,20 @@
def _stack_append(self, element):
i = self._stack_pointer()
+ len_stack = len(self._stack_)
+
assert i >= 0
- if len(self._stack_) <= i and self._stack_resize_ is True:
+ if len_stack <= i and self._stack_resize_ is True:
self._stack_ += [None]
+ else:
+ assert len_stack > i
self._stack_[i] = element
self._stack_pointer_ = i + 1
+ def _set_stack_pointer(self, p):
+ self._stack_pointer_ = p
+
#@jit.unroll_safe
def _stack_pop_n(self, n):
l = [None] * n
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit