/[jscoverage]/trunk/js/jsxml.h
ViewVC logotype

Contents of /trunk/js/jsxml.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 460 - (show annotations)
Sat Sep 26 23:15:22 2009 UTC (9 years, 11 months ago) by siliconforks
File MIME type: text/plain
File size: 9572 byte(s)
Upgrade to SpiderMonkey from Firefox 3.5.3.

1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is SpiderMonkey E4X code, released August, 2004.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 #ifndef jsxml_h___
40 #define jsxml_h___
41
42 #include "jsstddef.h"
43 #include "jspubtd.h"
44
45 JS_BEGIN_EXTERN_C
46
47 extern const char js_AnyName_str[];
48 extern const char js_AttributeName_str[];
49 extern const char js_isXMLName_str[];
50 extern const char js_XMLList_str[];
51
52 extern const char js_amp_entity_str[];
53 extern const char js_gt_entity_str[];
54 extern const char js_lt_entity_str[];
55 extern const char js_quot_entity_str[];
56
57 typedef JSBool
58 (* JSIdentityOp)(const void *a, const void *b);
59
60 struct JSXMLArray {
61 uint32 length;
62 uint32 capacity;
63 void **vector;
64 JSXMLArrayCursor *cursors;
65 };
66
67 #define JSXML_PRESET_CAPACITY JS_BIT(31)
68 #define JSXML_CAPACITY_MASK JS_BITMASK(31)
69 #define JSXML_CAPACITY(array) ((array)->capacity & JSXML_CAPACITY_MASK)
70
71 struct JSXMLArrayCursor {
72 JSXMLArray *array;
73 uint32 index;
74 JSXMLArrayCursor *next;
75 JSXMLArrayCursor **prevp;
76 void *root;
77 };
78
79 /*
80 * NB: don't reorder this enum without changing all array initializers that
81 * depend on it in jsxml.c.
82 */
83 typedef enum JSXMLClass {
84 JSXML_CLASS_LIST,
85 JSXML_CLASS_ELEMENT,
86 JSXML_CLASS_ATTRIBUTE,
87 JSXML_CLASS_PROCESSING_INSTRUCTION,
88 JSXML_CLASS_TEXT,
89 JSXML_CLASS_COMMENT,
90 JSXML_CLASS_LIMIT
91 } JSXMLClass;
92
93 #define JSXML_CLASS_HAS_KIDS(class_) ((class_) < JSXML_CLASS_ATTRIBUTE)
94 #define JSXML_CLASS_HAS_VALUE(class_) ((class_) >= JSXML_CLASS_ATTRIBUTE)
95 #define JSXML_CLASS_HAS_NAME(class_) \
96 ((uintN)((class_) - JSXML_CLASS_ELEMENT) <= \
97 (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
98
99 #ifdef DEBUG_notme
100 #include "jsclist.h"
101 #endif
102
103 typedef struct JSXMLListVar {
104 JSXMLArray kids; /* NB: must come first */
105 JSXML *target;
106 JSObject *targetprop;
107 } JSXMLListVar;
108
109 typedef struct JSXMLElemVar {
110 JSXMLArray kids; /* NB: must come first */
111 JSXMLArray namespaces;
112 JSXMLArray attrs;
113 } JSXMLElemVar;
114
115 struct JSXML {
116 #ifdef DEBUG_notme
117 JSCList links;
118 uint32 serial;
119 #endif
120 JSObject *object;
121 void *domnode; /* DOM node if mapped info item */
122 JSXML *parent;
123 JSObject *name;
124 uint16 xml_class; /* discriminates u, below */
125 uint16 xml_flags; /* flags, see below */
126 union {
127 JSXMLListVar list;
128 JSXMLElemVar elem;
129 JSString *value;
130 } u;
131
132 /* Don't add anything after u -- see js_NewXML for why. */
133 };
134
135 /* union member shorthands */
136 #define xml_kids u.list.kids
137 #define xml_target u.list.target
138 #define xml_targetprop u.list.targetprop
139 #define xml_namespaces u.elem.namespaces
140 #define xml_attrs u.elem.attrs
141 #define xml_value u.value
142
143 /* xml_flags values */
144 #define XMLF_WHITESPACE_TEXT 0x1
145
146 /* xml_class-testing macros */
147 #define JSXML_HAS_KIDS(xml) JSXML_CLASS_HAS_KIDS((xml)->xml_class)
148 #define JSXML_HAS_VALUE(xml) JSXML_CLASS_HAS_VALUE((xml)->xml_class)
149 #define JSXML_HAS_NAME(xml) JSXML_CLASS_HAS_NAME((xml)->xml_class)
150 #define JSXML_LENGTH(xml) (JSXML_CLASS_HAS_KIDS((xml)->xml_class) \
151 ? (xml)->xml_kids.length \
152 : 0)
153
154 extern JSXML *
155 js_NewXML(JSContext *cx, JSXMLClass xml_class);
156
157 extern void
158 js_TraceXML(JSTracer *trc, JSXML *xml);
159
160 extern void
161 js_FinalizeXML(JSContext *cx, JSXML *xml);
162
163 extern JSObject *
164 js_ParseNodeToXMLObject(JSCompiler *jsc, JSParseNode *pn);
165
166 extern JSObject *
167 js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
168
169 extern JSObject *
170 js_GetXMLObject(JSContext *cx, JSXML *xml);
171
172 extern JS_FRIEND_DATA(JSObjectOps) js_XMLObjectOps;
173 extern JS_FRIEND_DATA(JSClass) js_XMLClass;
174 extern JS_FRIEND_DATA(JSExtendedClass) js_NamespaceClass;
175 extern JS_FRIEND_DATA(JSExtendedClass) js_QNameClass;
176 extern JS_FRIEND_DATA(JSClass) js_AttributeNameClass;
177 extern JS_FRIEND_DATA(JSClass) js_AnyNameClass;
178 extern JSClass js_XMLFilterClass;
179
180 /*
181 * Macros to test whether an object or a value is of type "xml" (per typeof).
182 * NB: jsobj.h must be included before any call to OBJECT_IS_XML, and jsapi.h
183 * and jsobj.h must be included before any call to VALUE_IS_XML.
184 */
185 #define OBJECT_IS_XML(cx,obj) ((obj)->map->ops == &js_XMLObjectOps)
186 #define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \
187 OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v)))
188
189 extern JSObject *
190 js_InitNamespaceClass(JSContext *cx, JSObject *obj);
191
192 extern JSObject *
193 js_InitQNameClass(JSContext *cx, JSObject *obj);
194
195 extern JSObject *
196 js_InitAttributeNameClass(JSContext *cx, JSObject *obj);
197
198 extern JSObject *
199 js_InitAnyNameClass(JSContext *cx, JSObject *obj);
200
201 extern JSObject *
202 js_InitXMLClass(JSContext *cx, JSObject *obj);
203
204 extern JSObject *
205 js_InitXMLClasses(JSContext *cx, JSObject *obj);
206
207 extern JSBool
208 js_GetFunctionNamespace(JSContext *cx, jsval *vp);
209
210 /*
211 * If obj is QName corresponding to function::name, set *funidp to name's id,
212 * otherwise set *funidp to 0.
213 */
214 JSBool
215 js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp);
216
217 extern JSBool
218 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
219
220 extern JSBool
221 js_SetDefaultXMLNamespace(JSContext *cx, jsval v);
222
223 /*
224 * Return true if v is a XML QName object, or if it converts to a string that
225 * contains a valid XML qualified name (one containing no :), false otherwise.
226 * NB: This function is an infallible predicate, it hides exceptions.
227 */
228 extern JSBool
229 js_IsXMLName(JSContext *cx, jsval v);
230
231 extern JSBool
232 js_ToAttributeName(JSContext *cx, jsval *vp);
233
234 extern JSString *
235 js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote);
236
237 extern JSString *
238 js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
239 JSString *str2);
240
241 extern JSString *
242 js_EscapeElementValue(JSContext *cx, JSString *str);
243
244 extern JSString *
245 js_ValueToXMLString(JSContext *cx, jsval v);
246
247 extern JSObject *
248 js_ConstructXMLQNameObject(JSContext *cx, jsval nsval, jsval lnval);
249
250 extern JSBool
251 js_GetAnyName(JSContext *cx, jsval *vp);
252
253 /*
254 * Note: nameval must be either QName, AttributeName, or AnyName.
255 */
256 extern JSBool
257 js_FindXMLProperty(JSContext *cx, jsval nameval, JSObject **objp, jsid *idp);
258
259 extern JSBool
260 js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
261
262 extern JSBool
263 js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
264
265 extern JSBool
266 js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
267
268 extern JSBool
269 js_StepXMLListFilter(JSContext *cx, JSBool initialized);
270
271 extern JSObject *
272 js_ValueToXMLObject(JSContext *cx, jsval v);
273
274 extern JSObject *
275 js_ValueToXMLListObject(JSContext *cx, jsval v);
276
277 extern JSObject *
278 js_CloneXMLObject(JSContext *cx, JSObject *obj);
279
280 extern JSObject *
281 js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
282 JSString *value);
283
284 extern JSString *
285 js_MakeXMLCDATAString(JSContext *cx, JSString *str);
286
287 extern JSString *
288 js_MakeXMLCommentString(JSContext *cx, JSString *str);
289
290 extern JSString *
291 js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str);
292
293 extern JSBool
294 js_EnumerateXMLValues(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
295 jsval *statep, jsid *idp, jsval *vp);
296
297 extern JSBool
298 js_TestXMLEquality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
299
300 extern JSBool
301 js_ConcatenateXML(JSContext *cx, JSObject *obj, jsval v, jsval *vp);
302
303 JS_END_EXTERN_C
304
305 #endif /* jsxml_h___ */

  ViewVC Help
Powered by ViewVC 1.1.24