[pypy-svn] r53315 - in pypy/branch/js-refactoring/pypy/lang/js: . test test/ecma
fijal at codespeak.net
fijal at codespeak.net
Fri Apr 4 06:01:01 CEST 2008
Author: fijal
Date: Fri Apr 4 06:00:59 2008
New Revision: 53315
Modified:
pypy/branch/js-refactoring/pypy/lang/js/jscode.py
pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
pypy/branch/js-refactoring/pypy/lang/js/operations.py
pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
Log:
* fix ecma conftest
* obscure hack for typeof
Modified: pypy/branch/js-refactoring/pypy/lang/js/jscode.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jscode.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jscode.py Fri Apr 4 06:00:59 2008
@@ -382,6 +382,17 @@
one = stack.pop()
stack.append(W_String(one.type()))
+class TYPEOF_VARIABLE(Opcode):
+ def __init__(self, name):
+ self.name = name
+
+ def eval(self, ctx, stack):
+ try:
+ var = ctx.resolve_identifier(self.name)
+ stack.append(var.type())
+ except ThrowException:
+ stack.append(w_Undefined)
+
#class Typeof(UnaryOp):
# def eval(self, ctx):
# val = self.expr.eval(ctx)
Modified: pypy/branch/js-refactoring/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/jsobj.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/jsobj.py Fri Apr 4 06:00:59 2008
@@ -375,8 +375,8 @@
def __init__(self, strval):
self.strval = strval
- def __str__(self):
- return self.strval+"W"
+ def __repr__(self):
+ return 'W_String(%s)' % (self.strval,)
def ToObject(self, ctx):
return create_object(ctx, 'String', Value=self)
Modified: pypy/branch/js-refactoring/pypy/lang/js/operations.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/operations.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/operations.py Fri Apr 4 06:00:59 2008
@@ -470,19 +470,19 @@
StrictNe = create_binary_op('ISNOT')
In = create_binary_op('IN')
-Typeof = create_unary_op('TYPEOF')
-# class Delete(UnaryOp):
-# """
-# the delete op, erases properties from objects
-# """
-# def eval(self, ctx):
-# r1 = self.expr.eval(ctx)
-# if not isinstance(r1, W_Reference):
-# return W_Boolean(True)
-# r3 = r1.GetBase()
-# r4 = r1.GetPropertyName()
-# return W_Boolean(r3.Delete(r4))
+class Typeof(Expression):
+ def __init__(self, pos, left):
+ self.pos = pos
+ self.left = left
+
+ def emit(self, bytecode):
+ # obscure hack to be compatible
+ if isinstance(self.left, Identifier):
+ bytecode.emit('TYPEOF_VARIABLE', self.left.name)
+ else:
+ self.left.emit(bytecode)
+ bytecode.emit('TYPEOF')
class Delete(Expression):
def __init__(self, pos, what):
Modified: pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/ecma/conftest.py Fri Apr 4 06:00:59 2008
@@ -57,7 +57,7 @@
#actually run the file :)
t = load_file(str(self.fspath))
try:
- t.execute(self.interp.global_context)
+ self.interp.run(t)
except ParseError, e:
raise Failed(msg=e.nice_error_message(filename=str(self.fspath)), excinfo=None)
except JsBaseExcept:
Modified: pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/test/test_interp.py Fri Apr 4 06:00:59 2008
@@ -350,6 +350,9 @@
var x = 3;
typeof x == 'number';
""", True)
+ assertv("""
+ typeof x
+ """, 'undefined')
def test_semicolon():
assertp(';', [])
More information about the pypy-svn
mailing list