Mercurial > scratch
comparison pydershell/pydershell.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 | 1950b0b5bcd8 |
children | 35ab0ad3c294 |
comparison
equal
deleted
inserted
replaced
21:1950b0b5bcd8 | 22:9413bebf2ee6 |
---|---|
1 #! /usr/bin/env python | |
2 | |
3 import sys | 1 import sys |
4 import time | 2 import time |
5 import threading | 3 import threading |
6 import traceback | 4 import traceback |
7 import weakref | 5 import weakref |
366 except InternalError, e: | 364 except InternalError, e: |
367 print "An internal error occurred." | 365 print "An internal error occurred." |
368 traceback.print_tb(e.exc_info[2]) | 366 traceback.print_tb(e.exc_info[2]) |
369 print e.exc_info[1] | 367 print e.exc_info[1] |
370 return retval | 368 return retval |
371 | |
372 if __name__ == '__main__': | |
373 sandbox = JsSandbox() | |
374 | |
375 class Baz(JsExposedObject): | |
376 def woozle(self, blap): | |
377 return blap + 5 | |
378 woozle.__jsexposed__ = True | |
379 | |
380 def baz(): | |
381 return Baz() | |
382 sandbox.root.baz = baz | |
383 | |
384 def bar(obj): | |
385 print obj.bar() | |
386 sandbox.root.bar = bar | |
387 | |
388 def foo(callback): | |
389 return callback() | |
390 sandbox.root.foo = foo | |
391 | |
392 def ensureBaz(baz): | |
393 if not isinstance(baz, Baz): | |
394 print "Uhoh" | |
395 else: | |
396 print "ok" | |
397 sandbox.root.ensureBaz = ensureBaz | |
398 | |
399 def jsprint(string): | |
400 print string | |
401 sandbox.root['print'] = jsprint | |
402 | |
403 retval = sandbox.run_script('test.js') | |
404 | |
405 sandbox.finish() | |
406 del sandbox | |
407 | |
408 import gc | |
409 gc.collect() | |
410 if pydermonkey.get_debug_info()['runtime_count']: | |
411 print "WARNING: JS runtime was not destroyed." | |
412 | |
413 sys.exit(retval) |