[pypy-svn] r31021 - in pypy/dist/pypy/translator/js: . demo/jsdemo jssrc modules test

fijal at codespeak.net fijal at codespeak.net
Sat Aug 5 14:23:58 CEST 2006


Author: fijal
Date: Sat Aug  5 14:23:55 2006
New Revision: 31021

Modified:
   pypy/dist/pypy/translator/js/_class.py
   pypy/dist/pypy/translator/js/database.py
   pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py
   pypy/dist/pypy/translator/js/jssrc/misc.js
   pypy/dist/pypy/translator/js/modules/_dom.py
   pypy/dist/pypy/translator/js/opcodes.py
   pypy/dist/pypy/translator/js/test/test_exception.py
Log:
Added some test.
Mostly finished DOM interface. It's mostly working right now, I don't think more tweaks are needed now. Maybe later if someone needs it really, really hard.
Fixed several opcode issues. Removed dead code.


Modified: pypy/dist/pypy/translator/js/_class.py
==============================================================================
--- pypy/dist/pypy/translator/js/_class.py	(original)
+++ pypy/dist/pypy/translator/js/_class.py	Sat Aug  5 14:23:55 2006
@@ -71,10 +71,3 @@
     
     def basename(self, name):
         return name.replace('.', '_')#[-1]
-
-    #def _ctor(self):
-    #    self.ilasm.begin_function('.ctor', [], 'void', False, 'specialname', 'rtspecialname', 'instance')
-    #    self.ilasm.opcode('ldarg.0')
-    #    self.ilasm.call('instance void %s::.ctor()' % self.get_base_class())
-    #    self.ilasm.opcode('ret')
-    #    self.ilasm.end_function()

Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py	(original)
+++ pypy/dist/pypy/translator/js/database.py	Sat Aug  5 14:23:55 2006
@@ -465,6 +465,8 @@
         self.db = db
         self.const = const
         self.name = self.get_name()
+        self.depends = set()
+        self.depends_on = set()
     
     def __eq__(self, other):
         return self.name == other.name

Modified: pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py
==============================================================================
--- pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py	(original)
+++ pypy/dist/pypy/translator/js/demo/jsdemo/consserv.py	Sat Aug  5 14:23:55 2006
@@ -19,10 +19,6 @@
 from pypy.translator.js.modules.bltns import date
 
 class ConsoleRoot(BasicExternal, Root):
-    _methods = {
-        'run_command' : MethodDesc([('str_to_eval', 'ss'), ('callback', lambda : None)], {'aa':'aa'})
-    }
-    
     @turbogears.expose(format="json")
     def str_to_eval(self, str_to_eval = "some_string"):
         return dict()
@@ -37,7 +33,7 @@
 
     @turbogears.expose(format="json")
     @described(retval={'aa':'aa'})
-    def run_command(self, str_to_eval):
+    def run_command(self, str_to_eval = "aa"):
         # we need what has changed
         # we try to run it...
         

Modified: pypy/dist/pypy/translator/js/jssrc/misc.js
==============================================================================
--- pypy/dist/pypy/translator/js/jssrc/misc.js	(original)
+++ pypy/dist/pypy/translator/js/jssrc/misc.js	Sat Aug  5 14:23:55 2006
@@ -1,6 +1,12 @@
 // starts hand written code
 MALLOC_ZERO_FILLED = 0
 
+try {
+    log;
+    print = log;
+} catch(e) {
+}
+
 Function.prototype.method = function (name, func) {
     this.prototype[name] = func;
     return this;
@@ -26,28 +32,12 @@
     return (false);
 }
 
-/*function alloc_and_set(L0, len, elem) {
-    l = [];
-    for(i = 0; i < len; ++i){
-        l[i] = elem;
-    }
-    return(l);
-}*/
-
-function strconcat(s1, s2) {
-    return(s1+s2);
-}
-
-function stritem(cl, s, it) {
-    return(s[it]);
-}
-
-function delitem(fn, l, i) {
+/*function delitem(fn, l, i) {
     for(j = i; j < l.length-1; ++j) {
         l[j] = l[j+1];
     }
     l.length--;
-}
+}*/
 
 function strcmp(s1, s2) {
     if ( s1 < s2 ) {

Modified: pypy/dist/pypy/translator/js/modules/_dom.py
==============================================================================
--- pypy/dist/pypy/translator/js/modules/_dom.py	(original)
+++ pypy/dist/pypy/translator/js/modules/_dom.py	Sat Aug  5 14:23:55 2006
@@ -36,6 +36,9 @@
 class Window(Node):
     pass
 
+class Form(Node):
+    pass
+
 class Style(BasicExternal):
     _fields = {
         'azimuth' : 'aa',
@@ -256,15 +259,132 @@
         'supports' : MethodDesc(["aa", 1.0]),
     }
 
-Document._methods = Element._methods
+Document._methods = Element._methods.copy()
 Document._methods.update({
-    'getElementById' : MethodDesc(["aa"], Element()),
+    'clear' : MethodDesc([]),
+    'close' : MethodDesc([]),
+    'createAttribute' : MethodDesc(["aa"], Element()),
+    'createDocumentFragment' : MethodDesc([], Element()),
     'createElement' : MethodDesc(["aa"], Element()),
+    'createElementNS' : MethodDesc(["aa", "aa"], Element()),
+    'createTextNode' : MethodDesc(["aa"], Element()),
+    'createEvent' : MethodDesc(["aa"], Event()),
+    #'createRange' : MethodDesc(["aa"], Range()) - don't know what to do here
+    'getElementById' : MethodDesc(["aa"], Element()),
+    'getElementsByName' : MethodDesc(["aa"], [Element(), Element()]),
+    'getElementsByTagName' : MethodDesc(["aa"], [Element(), Element()]),
+    'importNode' : MethodDesc([Element(), True], Element()),
+    'open' : MethodDesc([]),
+    'write' : MethodDesc(["aa"]),
+    'writeln' : MethodDesc(["aa"]),
 })
 
-Document._fields = Element._fields
+Document._fields = Element._fields.copy()
 Document._fields.update({
+    'alinkColor' : "aa",
+    'bgColor' : "aa",
     'body' : Element(),
+    'characterSet' : "aa",
+    'cookie' : "aa",
+    'contentWindow' : Window(),
+    'defaultView' : Window(),
+    'doctype' : "aa",
+    'documentElement' : Element(),
+    'domain' : "aa",
+    'embeds' : [Element(), Element()],
+    'fgColor' : "aa",
+    'firstChild' : Element(),
+    'forms' : [Form(), Form()],
+    'height' : 123,
+    'images' : [Element(), Element()],
+    'lastModified' : "aa",
+    'linkColor' : "aa",
+    'links' : [Element(), Element()],
+    'location' : "aa",
+    'namespaceURI' : "aa",
+    'referrer' : "aa",
+    'styleSheets' : [Style(), Style()],
+    'title' : "aa",
+    'URL' : "aa",
+    'vlinkColor' : "aa",
+    'width' : 123,
+})
+
+Window._fields = Element._fields.copy()
+Window._fields.update({
+    'content' : Window(),
+    'closed' : True,
+    #'crypto' : Crypto() - not implemented in Gecko, leave alone
+    'defaultStatus' : "aa",
+    'document' : Document(),
+    # 'frameElement' :  - leave alone
+    'frames' : [Window(), Window()],
+    'history' : ["aa", "aa"],
+    'innerHeight' : 123,
+    'innerWidth' : 123,
+    'length' : 12,
+    'location' : "aa",
+    'name' : "aa",
+    # 'preference' : # denied in gecko
+    'opener' : Window(),
+    'outerHeight' : 123,
+    'outerWidth' : 123,
+    'pageXOffset' : 12,
+    'pageYOffset' : 12,
+    'parent' : Window(),
+    # 'personalbar' :  - disallowed
+    # 'screen' : Screen() - not part of the standard, allow it if you want
+    'screenX' : 12,
+    'screenY' : 12,
+    'scrollMaxX' : 12,
+    'scrollMaxY' : 12,
+    'scrollX' : 12,
+    'scrollY' : 12,
+    'self' : Window(),
+    'status' : "asd",
+    'top' : Window(),
+    'window' : Window(),
+})
+
+Window._methods = Element._methods.copy()
+Window._methods.update({
+    'alert' : MethodDesc(["aa"]),
+    'atob' : MethodDesc(["aa"], "aa"),
+    'back' : MethodDesc([]),
+    'blur' : MethodDesc([]),
+    'btoa' : MethodDesc(["aa"], "aa"),
+    'close' : MethodDesc([]),
+    'confirm' : MethodDesc(["aa"], True),
+    'dump' : MethodDesc(["aa"]),
+    'escape' : MethodDesc(["aa"], "aa"),
+    #'find' : MethodDesc(["aa"],  - gecko only
+    'focus' : MethodDesc([]),
+    'forward' : MethodDesc([]),
+    'getComputedStyle' : MethodDesc([Element(), "aa"], Style()),
+    'home' : MethodDesc([]),
+    'open' : MethodDesc(["aa", "aa"]),
+    'onabort' : MethodDesc([Event()]),
+    'onblur' : MethodDesc([Event()]),
+    'onchange' : MethodDesc([Event()]),
+    'onclick' : MethodDesc([MouseEvent()]),
+    'onclose' : MethodDesc([MouseEvent()]),
+    'ondragdrop' : MethodDesc([MouseEvent()]),
+    'onerror' : MethodDesc([MouseEvent()]),
+    'onfocus' : MethodDesc([Event()]),
+    'onkeydown' : MethodDesc([KeyEvent()]),
+    'onkeypress' : MethodDesc([KeyEvent()]),
+    'onkeyup' : MethodDesc([KeyEvent()]),
+    'onload' : MethodDesc([KeyEvent()]),
+    'onmousedown' : MethodDesc([MouseEvent()]),
+    'onmousemove' : MethodDesc([MouseEvent()]),
+    'onmouseup' : MethodDesc([MouseEvent()]),
+    'onmouseover' : MethodDesc([MouseEvent()]),
+    'onmouseup' : MethodDesc([MouseEvent()]),
+    'onresize' : MethodDesc([MouseEvent()]),
+    'onscroll' : MethodDesc([MouseEvent()]),
+    'onselect' : MethodDesc([MouseEvent()]),
+    'onsubmit' : MethodDesc([MouseEvent()]),
+    'onunload' : MethodDesc([Event()]),
 })
 
 def get_document():

Modified: pypy/dist/pypy/translator/js/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/js/opcodes.py	(original)
+++ pypy/dist/pypy/translator/js/opcodes.py	Sat Aug  5 14:23:55 2006
@@ -104,6 +104,7 @@
     'int_is_true': [PushAllArgs,_Prefix('!!')],
     'uint_is_true': [PushAllArgs,_Prefix('!!')],
     'float_is_true': [PushAllArgs,_Prefix('!!')],
+    'is_true': [PushAllArgs,_Prefix('!!')],
     
     'direct_call' : [_CallDispatcher(Builtins, class_map)],
     'indirect_call' : [IndirectCall],

Modified: pypy/dist/pypy/translator/js/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_exception.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_exception.py	Sat Aug  5 14:23:55 2006
@@ -278,7 +278,10 @@
             pass
     
     def function_raise1(i):
-        function_raise2(i)
+        try:
+            function_raise2(i)
+        except Exception, e:
+            return str(e)
     
     fn = compile_function(function_raise1, [int])
-    fn()
+    fn(3)



More information about the Pypy-commit mailing list