this.window = this; // wrapper around Python objects, this exists both to allow changing or // reducing functionality and APIs compared to the Python counterpart (DOM) // and to allow creating references to the functions/methods (which is not // possible with objects exposed by python-spidermonkey) function _importobject(pyobj, properties) { /* 'import' a python object this wraps the python object in a JavaScript layer, exposing only the methods named in methods methods is a mapping from name to the method to call */ var ret = {}; for (var i=0; i < properties.length; i++) { var prop = properties[i]; if (typeof pyobj[prop] == 'function') { ret[prop] = function() { var retval = pyobj[prop].apply(pyobj, arguments); if (retval instanceof JSPyError) { throw(new JSPyError(retval.name, retval.message, retval.exception)); }; return retval; }; } else { ret[prop] = pyobj[prop]; }; }; return ret; }; this.document = _importobject(__document, [ 'getElementsByTagName', 'getElementById', 'getElementByClassName', 'documentElement', 'addEventListener', ]); this.window = _importobject(__window, [ 'navigator', 'title', 'printline', ]); function print() { window.printline.apply(window, arguments); };