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 extern const char js_AnyName_str[]; 46 extern const char js_AttributeName_str[]; 47 extern const char js_isXMLName_str[]; 48 extern const char js_XMLList_str[]; 49 50 extern const char js_amp_entity_str[]; 51 extern const char js_gt_entity_str[]; 52 extern const char js_lt_entity_str[]; 53 extern const char js_quot_entity_str[]; 54 55 struct JSXMLNamespace { 56 JSObject *object; 57 JSString *prefix; 58 JSString *uri; 59 JSBool declared; /* true if declared in its XML tag */ 60 }; 61 62 extern JSXMLNamespace * 63 js_NewXMLNamespace(JSContext *cx, JSString *prefix, JSString *uri, 64 JSBool declared); 65 66 extern void 67 js_MarkXMLNamespace(JSContext *cx, JSXMLNamespace *ns); 68 69 extern void 70 js_FinalizeXMLNamespace(JSContext *cx, JSXMLNamespace *ns); 71 72 extern JSObject * 73 js_NewXMLNamespaceObject(JSContext *cx, JSString *prefix, JSString *uri, 74 JSBool declared); 75 76 extern JSObject * 77 js_GetXMLNamespaceObject(JSContext *cx, JSXMLNamespace *ns); 78 79 struct JSXMLQName { 80 JSObject *object; 81 JSString *uri; 82 JSString *prefix; 83 JSString *localName; 84 }; 85 86 extern JSXMLQName * 87 js_NewXMLQName(JSContext *cx, JSString *uri, JSString *prefix, 88 JSString *localName); 89 90 extern void 91 js_MarkXMLQName(JSContext *cx, JSXMLQName *qn); 92 93 extern void 94 js_FinalizeXMLQName(JSContext *cx, JSXMLQName *qn); 95 96 extern JSObject * 97 js_NewXMLQNameObject(JSContext *cx, JSString *uri, JSString *prefix, 98 JSString *localName); 99 100 extern JSObject * 101 js_GetXMLQNameObject(JSContext *cx, JSXMLQName *qn); 102 103 extern JSObject * 104 js_GetAttributeNameObject(JSContext *cx, JSXMLQName *qn); 105 106 extern JSObject * 107 js_ConstructXMLQNameObject(JSContext *cx, jsval nsval, jsval lnval); 108 109 typedef JSBool 110 (* JS_DLL_CALLBACK JSIdentityOp)(const void *a, const void *b); 111 112 struct JSXMLArray { 113 uint32 length; 114 uint32 capacity; 115 void **vector; 116 JSXMLArrayCursor *cursors; 117 }; 118 119 #define JSXML_PRESET_CAPACITY JS_BIT(31) 120 #define JSXML_CAPACITY_MASK JS_BITMASK(31) 121 #define JSXML_CAPACITY(array) ((array)->capacity & JSXML_CAPACITY_MASK) 122 123 struct JSXMLArrayCursor { 124 JSXMLArray *array; 125 uint32 index; 126 JSXMLArrayCursor *next; 127 JSXMLArrayCursor **prevp; 128 void *root; 129 }; 130 131 /* 132 * NB: don't reorder this enum without changing all array initializers that 133 * depend on it in jsxml.c. 134 */ 135 typedef enum JSXMLClass { 136 JSXML_CLASS_LIST, 137 JSXML_CLASS_ELEMENT, 138 JSXML_CLASS_ATTRIBUTE, 139 JSXML_CLASS_PROCESSING_INSTRUCTION, 140 JSXML_CLASS_TEXT, 141 JSXML_CLASS_COMMENT, 142 JSXML_CLASS_LIMIT 143 } JSXMLClass; 144 145 #define JSXML_CLASS_HAS_KIDS(class_) ((class_) < JSXML_CLASS_ATTRIBUTE) 146 #define JSXML_CLASS_HAS_VALUE(class_) ((class_) >= JSXML_CLASS_ATTRIBUTE) 147 #define JSXML_CLASS_HAS_NAME(class_) \ 148 ((uintN)((class_) - JSXML_CLASS_ELEMENT) <= \ 149 (uintN)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT)) 150 151 #ifdef DEBUG_notme 152 #include "jsclist.h" 153 #endif 154 155 struct JSXML { 156 #ifdef DEBUG_notme 157 JSCList links; 158 uint32 serial; 159 #endif 160 JSObject *object; 161 void *domnode; /* DOM node if mapped info item */ 162 JSXML *parent; 163 JSXMLQName *name; 164 uint16 xml_class; /* discriminates u, below */ 165 uint16 xml_flags; /* flags, see below */ 166 union { 167 struct JSXMLListVar { 168 JSXMLArray kids; /* NB: must come first */ 169 JSXML *target; 170 JSXMLQName *targetprop; 171 } list; 172 struct JSXMLVar { 173 JSXMLArray kids; /* NB: must come first */ 174 JSXMLArray namespaces; 175 JSXMLArray attrs; 176 } elem; 177 JSString *value; 178 } u; 179 180 /* Don't add anything after u -- see js_NewXML for why. */ 181 }; 182 183 /* union member shorthands */ 184 #define xml_kids u.list.kids 185 #define xml_target u.list.target 186 #define xml_targetprop u.list.targetprop 187 #define xml_namespaces u.elem.namespaces 188 #define xml_attrs u.elem.attrs 189 #define xml_value u.value 190 191 /* xml_flags values */ 192 #define XMLF_WHITESPACE_TEXT 0x1 193 194 /* xml_class-testing macros */ 195 #define JSXML_HAS_KIDS(xml) JSXML_CLASS_HAS_KIDS((xml)->xml_class) 196 #define JSXML_HAS_VALUE(xml) JSXML_CLASS_HAS_VALUE((xml)->xml_class) 197 #define JSXML_HAS_NAME(xml) JSXML_CLASS_HAS_NAME((xml)->xml_class) 198 #define JSXML_LENGTH(xml) (JSXML_CLASS_HAS_KIDS((xml)->xml_class) \ 199 ? (xml)->xml_kids.length \ 200 : 0) 201 202 extern JSXML * 203 js_NewXML(JSContext *cx, JSXMLClass xml_class); 204 205 extern void 206 js_MarkXML(JSContext *cx, JSXML *xml); 207 208 extern void 209 js_FinalizeXML(JSContext *cx, JSXML *xml); 210 211 extern JSObject * 212 js_ParseNodeToXMLObject(JSContext *cx, JSParseNode *pn); 213 214 extern JSObject * 215 js_NewXMLObject(JSContext *cx, JSXMLClass xml_class); 216 217 extern JSObject * 218 js_GetXMLObject(JSContext *cx, JSXML *xml); 219 220 extern JS_FRIEND_DATA(JSXMLObjectOps) js_XMLObjectOps; 221 extern JS_FRIEND_DATA(JSClass) js_XMLClass; 222 extern JS_FRIEND_DATA(JSExtendedClass) js_NamespaceClass; 223 extern JS_FRIEND_DATA(JSExtendedClass) js_QNameClass; 224 extern JS_FRIEND_DATA(JSClass) js_AttributeNameClass; 225 extern JS_FRIEND_DATA(JSClass) js_AnyNameClass; 226 227 /* 228 * Macros to test whether an object or a value is of type "xml" (per typeof). 229 * NB: jsapi.h must be included before any call to VALUE_IS_XML. 230 */ 231 #define OBJECT_IS_XML(cx,obj) ((obj)->map->ops == &js_XMLObjectOps.base) 232 #define VALUE_IS_XML(cx,v) (!JSVAL_IS_PRIMITIVE(v) && \ 233 OBJECT_IS_XML(cx, JSVAL_TO_OBJECT(v))) 234 235 extern JSObject * 236 js_InitNamespaceClass(JSContext *cx, JSObject *obj); 237 238 extern JSObject * 239 js_InitQNameClass(JSContext *cx, JSObject *obj); 240 241 extern JSObject * 242 js_InitAttributeNameClass(JSContext *cx, JSObject *obj); 243 244 extern JSObject * 245 js_InitAnyNameClass(JSContext *cx, JSObject *obj); 246 247 extern JSObject * 248 js_InitXMLClass(JSContext *cx, JSObject *obj); 249 250 extern JSObject * 251 js_InitXMLClasses(JSContext *cx, JSObject *obj); 252 253 extern JSBool 254 js_GetFunctionNamespace(JSContext *cx, jsval *vp); 255 256 extern JSBool 257 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp); 258 259 extern JSBool 260 js_SetDefaultXMLNamespace(JSContext *cx, jsval v); 261 262 /* 263 * Return true if v is a XML QName object, or if it converts to a string that 264 * contains a valid XML qualified name (one containing no :), false otherwise. 265 * NB: This function is an infallible predicate, it hides exceptions. 266 */ 267 extern JSBool 268 js_IsXMLName(JSContext *cx, jsval v); 269 270 extern JSBool 271 js_ToAttributeName(JSContext *cx, jsval *vp); 272 273 extern JSString * 274 js_EscapeAttributeValue(JSContext *cx, JSString *str); 275 276 extern JSString * 277 js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str, 278 JSString *str2); 279 280 extern JSString * 281 js_EscapeElementValue(JSContext *cx, JSString *str); 282 283 extern JSString * 284 js_ValueToXMLString(JSContext *cx, jsval v); 285 286 extern JSBool 287 js_GetAnyName(JSContext *cx, jsval *vp); 288 289 extern JSBool 290 js_FindXMLProperty(JSContext *cx, jsval name, JSObject **objp, jsval *namep); 291 292 extern JSBool 293 js_GetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp); 294 295 extern JSBool 296 js_GetXMLFunction(JSContext *cx, JSObject *obj, jsid id, jsval *vp); 297 298 extern JSBool 299 js_SetXMLProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp); 300 301 extern JSBool 302 js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp); 303 304 extern JSBool 305 js_DeleteXMLListElements(JSContext *cx, JSObject *listobj); 306 307 extern JSBool 308 js_FilterXMLList(JSContext *cx, JSObject *obj, jsbytecode *pc, jsval *vp); 309 310 extern JSObject * 311 js_ValueToXMLObject(JSContext *cx, jsval v); 312 313 extern JSObject * 314 js_ValueToXMLListObject(JSContext *cx, jsval v); 315 316 extern JSObject * 317 js_CloneXMLObject(JSContext *cx, JSObject *obj); 318 319 extern JSObject * 320 js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name, 321 JSString *value); 322 323 extern JSString * 324 js_MakeXMLCDATAString(JSContext *cx, JSString *str); 325 326 extern JSString * 327 js_MakeXMLCommentString(JSContext *cx, JSString *str); 328 329 extern JSString * 330 js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str); 331 332 #endif /* jsxml_h___ */ 333