Mercurial > pymonkey
view docs/src/pymonkey.txt @ 54:234fca1c4b86
Added docs for pymonkey.undefined.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 10 Jul 2009 17:22:42 -0700 |
parents | 2055d853b995 |
children | 40a404b9c467 |
line wrap: on
line source
:mod:`pymonkey` --- Access SpiderMonkey from Python =================================================== .. module:: pymonkey :synopsis: Access SpiderMonkey from Python .. testsetup:: * import pymonkey This module offers a low-level interface to the `Mozilla SpiderMonkey <https://developer.mozilla.org/en/SpiderMonkey>`_ JavaScript engine. .. exception:: error This is the type of any SpiderMonkey-related errors thrown by this module. .. data:: undefined This is the singleton that represents the JavaScript value ``undefined``, as Python has no equivalent representation (JavaScript's ``null`` is mapped to Python's ``None`` object). For instance: >>> cx = pymonkey.Runtime().new_context() >>> obj = cx.new_object() >>> cx.evaluate_script(obj, '', '<string>', 1) <type 'pymonkey.undefined'> Unfortunately, this object currently does not have a "falsy" value, e.g.: >>> if (pymonkey.undefined): ... print 'Huh, this is kind of unintuitive.' Huh, this is kind of unintuitive. The reason for this is simply that we don't currently know how to make this object have a falsy value, if it's even possible. .. class:: Object This is the type of JavaScript objects. Such objects can only be created via Pymonkey calls like :meth:`Context.new_object()` or through the execution of JS code, but this type object can be used with Python's built-in :func:`isinstance()` to verify that an object is a JS object, like so: >>> obj = pymonkey.Runtime().new_context().new_object() >>> isinstance(obj, pymonkey.Object) True .. class:: Context This is the type of JavaScript context objects. Contexts can only be created via a call to :meth:`Runtime.new_context()`, but this type object can be used with Python's built-in :func:`isinstance()` to verify that an object is a context, like so: >>> cx = pymonkey.Runtime().new_context() >>> isinstance(cx, pymonkey.Context) True .. class:: Runtime() Creates a new JavaScript runtime. JS objects created by the runtime may only interact with other JS objects of the same runtime. .. method:: new_context() Creates a new Context object and returns it. Contexts are best conceptualized as threads of execution in a JS runtme; each one has a program counter, a current exception state, and so forth. JS objects may be freely accessed and changed by contexts that are associated with the same JS runtime as the objects.