Mercurial > pydertron
comparison pydertron.py @ 27:0b00162939ae
Fixed to work w/ latest Pydermonkey tip.
| author | Atul Varma <avarma@mozilla.com> |
|---|---|
| date | Mon, 10 May 2010 00:56:56 -0700 |
| parents | c4181cc0771d |
| children |
comparison
equal
deleted
inserted
replaced
| 26:c4181cc0771d | 27:0b00162939ae |
|---|---|
| 362 arglist = [] | 362 arglist = [] |
| 363 for arg in args: | 363 for arg in args: |
| 364 arglist.append(self.wrap_jsobject(arg)) | 364 arglist.append(self.wrap_jsobject(arg)) |
| 365 instance = func_cx.get_object_private(this) | 365 instance = func_cx.get_object_private(this) |
| 366 if instance is None or not isinstance(instance, pyproto): | 366 if instance is None or not isinstance(instance, pyproto): |
| 367 raise pydermonkey.error("Method type mismatch") | 367 raise pydermonkey.ScriptError("Method type mismatch") |
| 368 | 368 |
| 369 # TODO: Fill in extra required params with | 369 # TODO: Fill in extra required params with |
| 370 # pymonkey.undefined? or automatically throw an | 370 # pymonkey.undefined? or automatically throw an |
| 371 # exception to calling js code? | 371 # exception to calling js code? |
| 372 return self.wrap_pyobject(func(instance, *arglist)) | 372 return self.wrap_pyobject(func(instance, *arglist)) |
| 373 except pydermonkey.error: | 373 except pydermonkey.ScriptError: |
| 374 raise | 374 raise |
| 375 except Exception: | 375 except Exception: |
| 376 raise InternalError() | 376 raise InternalError() |
| 377 else: | 377 else: |
| 378 def wrapper(func_cx, this, args): | 378 def wrapper(func_cx, this, args): |
| 383 | 383 |
| 384 # TODO: Fill in extra required params with | 384 # TODO: Fill in extra required params with |
| 385 # pymonkey.undefined? or automatically throw an | 385 # pymonkey.undefined? or automatically throw an |
| 386 # exception to calling js code? | 386 # exception to calling js code? |
| 387 return self.wrap_pyobject(func(*arglist)) | 387 return self.wrap_pyobject(func(*arglist)) |
| 388 except pydermonkey.error: | 388 except pydermonkey.ScriptError: |
| 389 raise | 389 raise |
| 390 except Exception: | 390 except Exception: |
| 391 raise InternalError() | 391 raise InternalError() |
| 392 wrapper.wrapped_pyobject = func | 392 wrapper.wrapped_pyobject = func |
| 393 wrapper.__name__ = name | 393 wrapper.__name__ = name |
| 548 http://wiki.commonjs.org/wiki/CommonJS/Modules/SecurableModules | 548 http://wiki.commonjs.org/wiki/CommonJS/Modules/SecurableModules |
| 549 """ | 549 """ |
| 550 | 550 |
| 551 filename = self.fs.find_module(self.get_calling_script(), path) | 551 filename = self.fs.find_module(self.get_calling_script(), path) |
| 552 if not filename: | 552 if not filename: |
| 553 raise pydermonkey.error('Module not found: %s' % path) | 553 raise pydermonkey.ScriptError('Module not found: %s' % path) |
| 554 if not filename in self.__modules: | 554 if not filename in self.__modules: |
| 555 cx = self.cx | 555 cx = self.cx |
| 556 module = cx.new_object(None, self.__root_proto) | 556 module = cx.new_object(None, self.__root_proto) |
| 557 cx.init_standard_classes(module) | |
| 558 exports = cx.new_object() | 557 exports = cx.new_object() |
| 559 cx.define_property(module, 'exports', exports) | 558 cx.define_property(module, 'exports', exports) |
| 560 self._install_globals(self.wrap_jsobject(module)) | 559 self._install_globals(self.wrap_jsobject(module)) |
| 561 self.__modules[filename] = self.wrap_jsobject(exports) | 560 self.__modules[filename] = self.wrap_jsobject(exports) |
| 562 contents = self.fs.open(filename).read() | 561 contents = self.fs.open(filename).read() |
| 578 result = cx.evaluate_script(self.root.wrapped_jsobject, | 577 result = cx.evaluate_script(self.root.wrapped_jsobject, |
| 579 contents, filename, lineno) | 578 contents, filename, lineno) |
| 580 if callback: | 579 if callback: |
| 581 callback(self.wrap_jsobject(result)) | 580 callback(self.wrap_jsobject(result)) |
| 582 retval = 0 | 581 retval = 0 |
| 583 except pydermonkey.error, e: | 582 except pydermonkey.ScriptError, e: |
| 584 params = dict( | 583 params = dict( |
| 585 stack_trace = format_stack(self.js_stack, self.fs.open), | 584 stack_trace = format_stack(self.js_stack, self.fs.open), |
| 586 error = e.args[1] | 585 error = e.args[1] |
| 587 ) | 586 ) |
| 588 stderr.write("%(stack_trace)s\n%(error)s\n" % params) | 587 stderr.write("%(stack_trace)s\n%(error)s\n" % params) |
