diff docs/rendered/_sources/pymonkey.txt @ 139:d08cb5a06c66

Added docs for Script, compile_script() and execute_script().
author Atul Varma <varmaa@toolness.com>
date Mon, 24 Aug 2009 11:39:58 -0700
parents 0c81cb18c935
children 96dc1beefc00
line wrap: on
line diff
--- a/docs/rendered/_sources/pymonkey.txt	Sun Aug 23 22:26:58 2009 -0700
+++ b/docs/rendered/_sources/pymonkey.txt	Mon Aug 24 11:39:58 2009 -0700
@@ -54,6 +54,16 @@
    This is the type of JavaScript functions, which is a subtype of
    :class:`Object`.
 
+.. class:: Script
+
+   This is the type of compiled JavaScript scripts; it's actually a
+   subtype of :class:`Object`, though when exposed to JS code it
+   doesn't provide access to any special data or functionality.
+
+   Script instances have a read-only buffer interface that exposes
+   their bytecode. This can be accessed by passing an instance to
+   Python's built-in ``buffer()`` function.
+
 .. class:: Context
 
    This is the type of JavaScript context objects. Contexts can only
@@ -174,6 +184,33 @@
         >>> cx.evaluate_script(obj, '5 * Math', '<string>', 1)
         nan
 
+   .. method:: compile_script(obj, code, filename, lineno)
+
+      Compiles the given string of code and returns a :class:`Script`
+      instance that can be executed via :meth:`execute_script()`.
+
+      `filename` and `lineno` are used just as in
+      :meth:`evaluate_script()`.
+
+      `obj` is defined in the SpiderMonkey documentation to be
+      the "object with which the script is associated", though it's
+      unclear what its actual role is.
+
+   .. method:: execute_script(globalobj, script)
+
+      Executes the code in the given :class:`Script` object, using
+      `globalobj` as the global object/scope, and returns the result.
+
+      For example:
+
+        >>> cx = pymonkey.Runtime().new_context()
+        >>> obj = cx.new_object()
+        >>> cx.init_standard_classes(obj)
+        >>> script = cx.compile_script(cx.new_object(), '5 * Math',
+        ...                            '<string>', 1)
+        >>> cx.execute_script(obj, script)
+        nan
+
    .. method:: call_function(thisobj, func, args)
 
       Calls a JavaScript function.