Code

change API: separate functions creating a blur filter, one for a given item, another...
[inkscape.git] / src / dom / jsengine.h
index 8b775c98bffd5ef61dbb71caa8349456f34d0b12..abcbb23e91457bd29d36b3db6d00d1ac672b9731 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 
+#include "dom.h"
 #include "js/jsapi.h"
 
 
@@ -52,25 +53,46 @@ public:
      *  Constructor
      */
     JavascriptEngine()
-        { init(); }
+        { startup(); }
+
 
     /**
-     *  Copy constructor
+     *  Destructor
      */
-    JavascriptEngine(const JavascriptEngine &other)
-        { assign(other); }
+    virtual ~JavascriptEngine()
+        { shutdown(); }
 
     /**
-     *  Assignment operator
+     *  Evaluate a script
      */
-    JavascriptEngine &operator=(const JavascriptEngine &other)
-        { assign(other); return *this; }
+    bool evaluate(const DOMString &script);
 
     /**
-     *  Destructor
+     *  Evaluate a script from a file
      */
-    virtual ~JavascriptEngine()
-        {}
+    bool evaluateFile(const DOMString &script);
+
+
+    /**
+     *  Return the runtime of the wrapped JS engine
+     */
+    JSRuntime *getRuntime()
+           { return rt; }
+               
+    /**
+     *  Return the current context of the wrapped JS engine
+     */
+       JSContext *getContext()
+           { return cx; }
+               
+    /**
+     *  Return the current global object of the wrapped JS engine
+     */
+       JSObject *getGlobalObject()
+           { return globalObj; } 
+    
+
+private:
 
     /**
      *  Startup the javascript engine
@@ -82,10 +104,6 @@ public:
      */
     bool shutdown();
 
-
-
-private:
-
     void init()
         {
         rt        = NULL;
@@ -93,6 +111,13 @@ private:
         globalObj = NULL;
         }
     
+    /**
+     *  Assignment operator.  Let's keep this private for now,
+     *  as we want one Spidermonkey runtime per c++ shell     
+     */
+    JavascriptEngine &operator=(const JavascriptEngine &other)
+        { assign(other); return *this; }
+
     void assign(const JavascriptEngine &other)
         {
         rt        = other.rt;
@@ -121,6 +146,17 @@ private:
 
     JSObject *globalObj;
 
+    static void errorReporter(JSContext *cx,
+        const char *message, JSErrorReport *report)
+        {
+        JavascriptEngine *engine = 
+               (JavascriptEngine *) JS_GetContextPrivate(cx);
+        engine->error((char *)message);
+        }
+
+    
+    
+
 };