Mercurial > pydertron
changeset 4:ae5869491e61
Added more to securablemodule impl.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Wed, 09 Sep 2009 22:18:35 -0700 |
parents | 14d8d73774d7 |
children | c11c84274192 |
files | modules/baz.js modules/foo.js pydertron.py |
diffstat | 3 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/baz.js Wed Sep 09 22:18:35 2009 -0700 @@ -0,0 +1,7 @@ +print("loading baz"); + +exports.blop = function blop() { + print("foo.hello is " + require('./foo').hello); +}; + +print("baz loaded");
--- a/modules/foo.js Wed Sep 09 22:01:43 2009 -0700 +++ b/modules/foo.js Wed Sep 09 22:18:35 2009 -0700 @@ -1,5 +1,11 @@ +print('loading foo'); + exports.bar = function bar() { print('hay!'); }; -print('loading foo'); +exports.hello = 1; + +require('baz').blop(); + +print('foo loaded.');
--- a/pydertron.py Wed Sep 09 22:01:43 2009 -0700 +++ b/pydertron.py Wed Sep 09 22:18:35 2009 -0700 @@ -504,19 +504,20 @@ cx.init_standard_classes(module) exports = cx.new_object() cx.define_property(module, 'exports', exports) - self._install_globals(sandbox.wrap_jsobject(module)) + self.modules[filename] = sandbox.wrap_jsobject(exports) contents = open(filename).read() cx.evaluate_script(module, contents, filename, 1) - return sandbox.wrap_jsobject(exports) @jsexposed def require(self, path): curr_script = self._get_calling_script() curr_dir = os.path.split(curr_script)[0] - filename = os.path.join(self.root_dir, curr_dir, "%s.js" % path) + if not curr_dir.startswith(self.root_dir): + curr_dir = self.root_dir + filename = os.path.join(curr_dir, "%s.js" % path) filename = os.path.normpath(filename) if (not filename.startswith(self.root_dir) or not (os.path.exists(filename) and @@ -524,7 +525,7 @@ raise pydermonkey.error('Module not found: %s' % path) if filename not in self.modules: - self.modules[filename] = self._load_module(filename) + self._load_module(filename) return self.modules[filename] if __name__ == '__main__':