[pypy-svn] r43768 - in pypy/dist/pypy/lang/js: . test test/ecma/Array test/ecma/Boolean
santagada at codespeak.net
santagada at codespeak.net
Mon May 28 06:22:57 CEST 2007
Author: santagada
Date: Mon May 28 06:22:55 2007
New Revision: 43768
Modified:
pypy/dist/pypy/lang/js/interpreter.py
pypy/dist/pypy/lang/js/jsgrammar.txt
pypy/dist/pypy/lang/js/jsobj.py
pypy/dist/pypy/lang/js/jsparser.py
pypy/dist/pypy/lang/js/test/ecma/Array/15.4.1.2.js
pypy/dist/pypy/lang/js/test/ecma/Array/15.4.4.3-1.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-2.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-3.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-4.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-5.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-1.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-2.js
pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-3.js
pypy/dist/pypy/lang/js/test/test_interp.py
pypy/dist/pypy/lang/js/test/test_parser.py
Log:
fixed some semicolon problems on tests, implemented optional semicolons after a block and made Array behave more or less to the spec.
Modified: pypy/dist/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/js/interpreter.py (original)
+++ pypy/dist/pypy/lang/js/interpreter.py Mon May 28 06:22:55 2007
@@ -106,7 +106,10 @@
return W_String('')
def arrayjs(ctx, args, this):
- return W_Array()
+ arr = W_Array()
+ for i in range(len(args)):
+ arr.Put(str(i), args[i])
+ return arr
def numberjs(ctx, args, this):
@@ -151,6 +154,7 @@
w_math = W_Object(Class='Math')
w_Global.Put('Math', w_math)
w_math.Put('__proto__', w_ObjPrototype)
+ w_math.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True)
w_math.Put('abs', W_Builtin(absjs, Class='function'))
w_math.Put('floor', W_Builtin(floorjs, Class='function'))
w_math.Put('pow', W_Builtin(powjs, Class='function'))
@@ -158,11 +162,15 @@
w_math.Put('PI', W_Number(math.pi))
w_Global.Put('String', W_Builtin(stringjs, Class='String'))
+
+ w_Array = W_Builtin(arrayjs, Class='Array')
+ w_Array.Put('__proto__', w_ObjPrototype)
+ w_Array.Put('prototype', w_ObjPrototype, dd=True, de=True, ro=True)
#Global Properties
w_Global.Put('Object', w_Object)
w_Global.Put('Function', w_Function)
- w_Global.Put('Array', W_Builtin(arrayjs, Class='Array'))
+ w_Global.Put('Array', w_Array)
w_Global.Put('version', W_Builtin(versionjs))
#Number
Modified: pypy/dist/pypy/lang/js/jsgrammar.txt
==============================================================================
--- pypy/dist/pypy/lang/js/jsgrammar.txt (original)
+++ pypy/dist/pypy/lang/js/jsgrammar.txt Mon May 28 06:22:55 2007
@@ -29,11 +29,28 @@
| <trystatement>
;
+statementsemiopt : <block>
+ | <variablestatement> [";"]?
+ | <emptystatement>
+ | <expressionstatement> [";"]?
+ | <ifstatement>
+ | <iterationstatement>
+ | <continuestatement> [";"]?
+ | <breakstatement> [";"]?
+ | <returnstatement> [";"]?
+ | <withstatement>
+ | <labelledstatement>
+ | <switchstatement> [";"]?
+ | <throwstatement> [";"]?
+ | <trystatement>
+ ;
+
+
block : "{" >statementlist<? ["}"]
;
statementlist : statement >statementlist<
- | statement
+ | statementsemiopt
;
variablestatement : ["var"] variabledeclarationlist
Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py (original)
+++ pypy/dist/pypy/lang/js/jsobj.py Mon May 28 06:22:55 2007
@@ -503,7 +503,7 @@
return W_Reference(identifier)
-def global_context(w_global=W_Object()):
+def global_context(w_global):
ctx = ExecutionContext([w_global],
this = w_global,
variable = w_global,
@@ -525,6 +525,13 @@
jsproperty = Property('', w_Undefined))
return ctx
+def empty_context():
+ obj = W_Object()
+ ctx = ExecutionContext([obj],
+ this = obj,
+ variable = obj,
+ jsproperty = Property('', w_Undefined))
+ return ctx
class W_Reference(W_Root):
"""Reference Type"""
Modified: pypy/dist/pypy/lang/js/jsparser.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsparser.py (original)
+++ pypy/dist/pypy/lang/js/jsparser.py Mon May 28 06:22:55 2007
@@ -18,6 +18,7 @@
t = parsef(code)
except ParseError:
code += ';'
+ print code
t = parsef(code)
return ToAST().transform(t)
Modified: pypy/dist/pypy/lang/js/test/ecma/Array/15.4.1.2.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Array/15.4.1.2.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Array/15.4.1.2.js Mon May 28 06:22:55 2007
@@ -148,9 +148,9 @@
if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
return 0;
}
- n = sign * Math.floor( Math.abs(n) )
+ n = sign * Math.floor( Math.abs(n) );
- n = n % Math.pow(2,32);
+ n = n % Math.pow(2,32);
if ( n < 0 ){
n += Math.pow(2,32);
Modified: pypy/dist/pypy/lang/js/test/ecma/Array/15.4.4.3-1.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Array/15.4.4.3-1.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Array/15.4.4.3-1.js Mon May 28 06:22:55 2007
@@ -116,7 +116,7 @@
eval("var TEST_ARRAY = new Array(true); TEST_ARRAY.join('\v')") );
-SEPARATOR = "\t"
+SEPARATOR = "\t";
TEST_LENGTH = 100;
TEST_STRING = "";
ARGUMENTS = "";
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-2.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-2.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-2.js Mon May 28 06:22:55 2007
@@ -55,7 +55,7 @@
var SECTION = "15.6.3.1-2";
var VERSION = "ECMA_1";
startTest();
-var TITLE = "Boolean.prototype"
+var TITLE = "Boolean.prototype";
writeHeaderToLog( SECTION + TITLE );
var array = new Array();
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-3.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-3.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-3.js Mon May 28 06:22:55 2007
@@ -55,7 +55,7 @@
var SECTION = "15.6.3.1-3";
var VERSION = "ECMA_1";
startTest();
-var TITLE = "Boolean.prototype"
+var TITLE = "Boolean.prototype";
writeHeaderToLog( SECTION + TITLE );
var array = new Array();
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-4.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-4.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-4.js Mon May 28 06:22:55 2007
@@ -55,7 +55,7 @@
var SECTION = "15.6.3.1-4";
var VERSION = "ECMA_1";
startTest();
-var TITLE = "Boolean.prototype"
+var TITLE = "Boolean.prototype";
writeHeaderToLog( SECTION + TITLE );
var BOOL_PROTO = Boolean.prototype;
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-5.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-5.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.1-5.js Mon May 28 06:22:55 2007
@@ -47,7 +47,7 @@
var VERSION = "ECMA_2";
startTest();
var SECTION = "15.6.3.1-5";
-var TITLE = "Boolean.prototype"
+var TITLE = "Boolean.prototype";
writeHeaderToLog( SECTION + " " + TITLE );
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.3.js Mon May 28 06:22:55 2007
@@ -53,7 +53,7 @@
var SECTION = "15.6.3";
var VERSION = "ECMA_2";
startTest();
-var TITLE = "Properties of the Boolean Constructor"
+var TITLE = "Properties of the Boolean Constructor";
writeHeaderToLog( SECTION + TITLE );
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-1.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-1.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-1.js Mon May 28 06:22:55 2007
@@ -55,7 +55,7 @@
var SECTION = "15.6.4.2-1";
var VERSION = "ECMA_1";
startTest();
-var TITLE = "Boolean.prototype.toString()"
+var TITLE = "Boolean.prototype.toString()";
writeHeaderToLog( SECTION + TITLE );
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-2.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-2.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-2.js Mon May 28 06:22:55 2007
@@ -53,7 +53,7 @@
var SECTION = "15.6.4.2-2";
var VERSION = "ECMA_1";
startTest();
-var TITLE = "Boolean.prototype.toString()"
+var TITLE = "Boolean.prototype.toString()";
writeHeaderToLog( SECTION + TITLE );
new TestCase( SECTION,
Modified: pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-3.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-3.js (original)
+++ pypy/dist/pypy/lang/js/test/ecma/Boolean/15.6.4.2-3.js Mon May 28 06:22:55 2007
@@ -54,7 +54,7 @@
var SECTION = "15.6.4.2-3";
var VERSION = "ECMA_1";
startTest();
-var TITLE = "Boolean.prototype.toString()"
+var TITLE = "Boolean.prototype.toString()";
writeHeaderToLog( SECTION + TITLE );
new TestCase( SECTION, "tostr=Boolean.prototype.toString; x=true; x.toString=tostr;x.toString()", "true", eval("tostr=Boolean.prototype.toString; x=true; x.toString=tostr;x.toString()") );
Modified: pypy/dist/pypy/lang/js/test/test_interp.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_interp.py (original)
+++ pypy/dist/pypy/lang/js/test/test_interp.py Mon May 28 06:22:55 2007
@@ -1,9 +1,5 @@
-import sys
-from StringIO import StringIO
-
import py
-
from pypy.lang.js import interpreter
from pypy.lang.js.operations import AEC, Number, Position, Plus
from pypy.lang.js.jsobj import W_Number, W_Object, \
Modified: pypy/dist/pypy/lang/js/test/test_parser.py
==============================================================================
--- pypy/dist/pypy/lang/js/test/test_parser.py (original)
+++ pypy/dist/pypy/lang/js/test/test_parser.py Mon May 28 06:22:55 2007
@@ -4,7 +4,7 @@
from pypy.rlib.parsing.ebnfparse import parse_ebnf, make_parse_function
from pypy.rlib.parsing.parsing import ParseError, Rule
from pypy.rlib.parsing.tree import RPythonVisitor
-from pypy.lang.js.jsobj import global_context, ThrowException
+from pypy.lang.js.jsobj import empty_context, ThrowException
from pypy.lang.js.astbuilder import ASTBuilder
from pypy import conftest
import sys
@@ -18,7 +18,7 @@
print e.nice_error_message(filename=str(GFILE),source=t)
raise
-parse = make_parse_function(regexs, rules, eof=True)
+parse_function = make_parse_function(regexs, rules, eof=True)
def setstartrule(rules, start):
"takes the rule start and put it on the beginning of the rules"
@@ -27,20 +27,17 @@
return newrules
def get_defaultparse():
- global parse
- if parse is None:
- parse = make_parse_function(regexs, rules, eof=True)
- return parse
+ return parse_function
def parse_func(start=None):
if start is not None:
- parse = make_parse_function(regexs, setstartrule(rules, start),
+ parse_function = make_parse_function(regexs, setstartrule(rules, start),
eof=True)
else:
- parse = get_defaultparse()
+ parse_function = get_defaultparse()
def methodparse(self, text):
- tree = parse(text)
+ tree = parse_function(text)
if start is not None:
assert tree.symbol == "hacked_first_symbol"
tree = tree.children[0]
@@ -288,7 +285,7 @@
def eval_expr(self, s):
ast = self.to_ast(s)
- return ast.eval(global_context())
+ return ast.eval(empty_context())
def test_get_pos(self):
from pypy.lang.js import operations
@@ -327,4 +324,11 @@
assert w_num.ToNumber() == 4
w_str = self.eval_expr('"hello "+\'world\'')
assert w_str.ToString() == 'hello world'
+
+from pypy.lang.js.jsparser import parse
+def test_simplesemicolon():
+ yield parse, 'x'
+ yield parse, 'if(1){x}'
+ yield parse, 'function x () {}'
+ yield parse,'if(1) {}'
\ No newline at end of file
More information about the Pypy-commit
mailing list