1 /*
2  * The contents of this file are subject to the Mozilla Public
3  * License Version 1.1 (the "License"); you may not use this file
4  * except in compliance with the License. You may obtain a copy of
5  * the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS
8  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9  * implied. See the License for the specific language governing
10  * rights and limitations under the License.
11  *
12  * The Original Code is the Sablotron XSLT Processor.
13  *
14  * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15  * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16  * Ginger Alliance Ltd. All Rights Reserved.
17  *
18  * Contributor(s):
19  *
20  * Alternatively, the contents of this file may be used under the
21  * terms of the GNU General Public License Version 2 or later (the
22  * "GPL"), in which case the provisions of the GPL are applicable
23  * instead of those above.  If you wish to allow use of your
24  * version of this file only under the terms of the GPL and not to
25  * allow others to use your version of this file under the MPL,
26  * indicate your decision by deleting the provisions above and
27  * replace them with the notice and other provisions required by
28  * the GPL.  If you do not delete the provisions above, a recipient
29  * may use your version of this file under either the MPL or the
30  * GPL.
31  */
32 
33 #ifndef JSExtHIncl
34 #define JSExtHIncl
35 
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39 
40 #ifdef ENABLE_JS
41 
42 #include "datastr.h"
43 #include "base.h"
44 
45 //hardcoded value - fix on Win etc.
46 #define XP_UNIX
47 #include <jsapi.h>
48 
49 #define JSRuntime_Sab JSRuntime
50 #define JSContext_Sab JSContext
51 #define JSClass_Sab JSClass
52 #define JSObject_Sab JSObject
53 
54 //macros for method/property declarations
55 #define JS_METHOD(name) JSBool name(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
56 #define JS_PROP(name) JSBool name(JSContext *cx, JSObject *obj, jsval id, jsval *rval)
57 #define PROP_OPT  JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT
58 
59 #define JS_RUNTIME_SIZE 0x100000
60 #define JS_CONTEXT_SIZE 0x20000
61 
62 //forwards
63 class Context;
64 class Processor;
65 
66 class JSManager
67 {
68 public:
69   static JSRuntime_Sab* getRuntime();
70   static JSContext_Sab* createContext(int size = JS_CONTEXT_SIZE);
71   static void finalize();
72 private:
73 };
74 
75 /*******************************************************
76 JS contexts
77 *******************************************************/
78 extern const char* theArrayProtoRoot;
79 
80 class JSContextItem
81 {
82 public:
83   JSContextItem(JSContext_Sab *cx_, Str &uri_, Processor* proc);
84   ~JSContextItem();
85   JSContext_Sab *cx;
86   //JSClass_Sab *cls;
87   Str uri;
88   PList<Str*> names;
89   Processor *proc     ;
90   struct {
91     char *message;
92     char *token;
93     int line;
94     int errNumber;
95   } errInfo;
96   //prototypes
97   JSObject_Sab *node;
98   JSObject_Sab *domex;
99   JSObject_Sab *domimpl;
100   JSObject_Sab *nlclass;
101   JSObject_Sab *nnmclass;
102   JSObject_Sab *array_proto;
103 };
104 
105 class JSContextList: public PList<JSContextItem*>
106 {
107  public:
JSContextList(Processor * proc_)108   JSContextList(Processor* proc_) : proc(proc_) {};
109   JSContextItem* find(Str uri, Bool canCreate = FALSE);
110  private:
111   Processor* proc;
112 };
113 
114 class External;
115 
116 class JSExternalPrivate
117 {
118   friend class External;
119 public:
120   JSExternalPrivate(void *p_, void *v_);
121   ~JSExternalPrivate();
122 private:
123   void *priv;
124   void *value;
125   int refcnt;
126 };
127 
128 /************** ordinary functions ****************/
129 JSClass_Sab* SJSGetGlobalClass();
130 Bool SJSEvaluate(JSContextItem &item, DStr &script);
131 Bool SJSCallFunction(Sit S, Context *c, JSContextItem &item, Str &name,
132 		      ExprList &atoms, Expression &retxpr);
133 
134 #endif //ENABLE_JS
135 
136 #endif //JSExtHIncl
137