Mercurial > scratch
comparison pydershell/test.py @ 22:9413bebf2ee6
Separated the test functionality out into a separate file.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 07 Sep 2009 16:18:34 -0700 |
parents | |
children | dace90a7f5e3 |
comparison
equal
deleted
inserted
replaced
21:1950b0b5bcd8 | 22:9413bebf2ee6 |
---|---|
1 #! /usr/bin/env python | |
2 | |
3 # Trivial embedding of pydershell. | |
4 | |
5 import sys | |
6 | |
7 import pydermonkey | |
8 from pydershell import JsSandbox, JsExposedObject | |
9 | |
10 if __name__ == '__main__': | |
11 sandbox = JsSandbox() | |
12 | |
13 class Baz(JsExposedObject): | |
14 def woozle(self, blap): | |
15 return blap + 5 | |
16 woozle.__jsexposed__ = True | |
17 | |
18 def baz(): | |
19 return Baz() | |
20 sandbox.root.baz = baz | |
21 | |
22 def bar(obj): | |
23 print obj.bar() | |
24 sandbox.root.bar = bar | |
25 | |
26 def foo(callback): | |
27 return callback() | |
28 sandbox.root.foo = foo | |
29 | |
30 def ensureBaz(baz): | |
31 if not isinstance(baz, Baz): | |
32 print "Uhoh" | |
33 else: | |
34 print "ok" | |
35 sandbox.root.ensureBaz = ensureBaz | |
36 | |
37 def jsprint(string): | |
38 print string | |
39 sandbox.root['print'] = jsprint | |
40 | |
41 retval = sandbox.run_script('test.js') | |
42 | |
43 sandbox.finish() | |
44 del sandbox | |
45 | |
46 import gc | |
47 gc.collect() | |
48 if pydermonkey.get_debug_info()['runtime_count']: | |
49 print "WARNING: JS runtime was not destroyed." | |
50 | |
51 sys.exit(retval) |