Author: Stephan <[email protected]>
Branch: 
Changeset: r113:9e4d9c3ae29c
Date: 2011-07-20 17:47 +0200
http://bitbucket.org/pypy/lang-js/changeset/9e4d9c3ae29c/

Log:    added declare_variable method to execution context

diff --git a/js/jsexecution_context.py b/js/jsexecution_context.py
--- a/js/jsexecution_context.py
+++ b/js/jsexecution_context.py
@@ -28,6 +28,12 @@
             p = Property(identifier, value)
             self._identifier_set(identifier, p)
 
+    def declare_variable(self, identifier):
+        from js.jsobj import w_Undefined, DD
+        self.values.addname(identifier)
+        p = Property(identifier, w_Undefined, flags = DD)
+        self._identifier_set_local(identifier, p)
+
     def _identifier_set_local(self, identifier, value):
         self.values.set(identifier, value)
 
diff --git a/js/test/test_execution_context.py 
b/js/test/test_execution_context.py
--- a/js/test/test_execution_context.py
+++ b/js/test/test_execution_context.py
@@ -2,7 +2,7 @@
 
 from js.jsexecution_context import ExecutionContext
 from js.execution import ThrowException
-from js.jsobj import Property
+from js.jsobj import Property, w_Undefined
 
 class TestExecutionContext(object):
     def test_identifier_set_local(self):
@@ -140,3 +140,22 @@
 
         assert p_foo_0.value == 0
         assert p_foo_1.value == 42
+
+    def test_declare_variable(self):
+        ctx = None
+        parent = ExecutionContext()
+        context = ExecutionContext(parent)
+
+        p_foo = Property('foo', 0)
+        parent._identifier_set_local('foo', p_foo)
+
+        assert context.resolve_identifier(ctx, 'foo') == 0
+
+        context.declare_variable('foo')
+        assert context.resolve_identifier(ctx, 'foo') == w_Undefined
+
+        context.assign('foo', 42)
+
+        assert p_foo.value == 0
+        assert context._identifier_get_local('foo').value == 42
+        assert context.resolve_identifier(ctx, 'foo') == 42
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to