LCOV - app.info - js/src/jsxml.h

LCOV - code coverage report
| Current view: | directory - js/src - jsxml.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 31 | 28 | 90.3 %
| Date: | 2012-04-07 | Functions: | 17 | 16 | 94.1 %

           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 "jspubtd.h"
          43                 : #include "jsobj.h"
          44                 : #include "jscell.h"
          45                 :
          46                 : #include "gc/Barrier.h"
          47                 :
          48                 : extern const char js_AnyName_str[];
          49                 : extern const char js_AttributeName_str[];
          50                 : extern const char js_isXMLName_str[];
          51                 : extern const char js_XMLList_str[];
          52                 :
          53                 : extern const char js_amp_entity_str[];
          54                 : extern const char js_gt_entity_str[];
          55                 : extern const char js_lt_entity_str[];
          56                 : extern const char js_quot_entity_str[];
          57                 :
          58                 : template<class T>
          59                 : struct JSXMLArrayCursor;
          60                 :
          61                 : template<class T>
          62                 : struct JSXMLArray
          63                 : {
          64                 :     uint32_t            length;
          65                 :     uint32_t            capacity;
          66                 :     js::HeapPtr<T>      *vector;
          67                 :     JSXMLArrayCursor<T> *cursors;
          68                 :
          69         7092858 :     void init() {
          70         7092858 :         length = capacity = 0;
          71         7092858 :         vector = NULL;
          72         7092858 :         cursors = NULL;
          73         7092858 :     }
          74                 :
          75         7092858 :     void finish(js::FreeOp *fop);
          76                 :
          77         7083383 :     bool setCapacity(JSContext *cx, uint32_t capacity);
          78            2027 :     void trim();
          79                 : };
          80                 :
          81                 : template<class T>
          82                 : struct JSXMLArrayCursor
          83                 : {
          84                 :     typedef js::HeapPtr<T> HeapPtrT;
          85                 :
          86                 :     JSXMLArray<T>       *array;
          87                 :     uint32_t            index;
          88                 :     JSXMLArrayCursor<T> *next;
          89                 :     JSXMLArrayCursor<T> **prevp;
          90                 :     HeapPtrT            root;
          91                 :
          92         4725464 :     JSXMLArrayCursor(JSXMLArray<T> *array)
          93                 :       : array(array), index(0), next(array->cursors), prevp(&array->cursors),
          94         4725464 :         root(NULL)
          95                 :     {
          96         4725464 :         if (next)
          97               0 :             next->prevp = &next;
          98         4725464 :         array->cursors = this;
          99         4725464 :     }
         100                 :
         101         4725464 :     ~JSXMLArrayCursor() { disconnect(); }
         102                 :
         103         4725518 :     void disconnect() {
         104         4725518 :         if (!array)
         105              54 :             return;
         106         4725464 :         if (next)
         107               0 :             next->prevp = prevp;
         108         4725464 :         *prevp = next;
         109         4725464 :         array = NULL;
         110         4725464 :         root.~HeapPtrT();
         111                 :     }
         112                 :
         113         9444056 :     T *getNext() {
         114         9444056 :         if (!array || index >= array->length)
         115         4725356 :             return NULL;
         116         4718700 :         return root = array->vector[index++];
         117                 :     }
         118                 :
         119              36 :     T *getCurrent() {
         120              36 :         if (!array || index >= array->length)
         121               0 :             return NULL;
         122              36 :         return root = array->vector[index];
         123                 :     }
         124                 : };
         125                 :
         126                 : void js_XMLArrayCursorTrace(JSTracer *trc, JSXMLArrayCursor<JSXML> *cursor);
         127                 : void js_XMLArrayCursorTrace(JSTracer *trc, JSXMLArrayCursor<JSObject> *cursor);
         128                 :
         129                 : #define JSXML_PRESET_CAPACITY   JS_BIT(31)
         130                 : #define JSXML_CAPACITY_MASK     JS_BITMASK(31)
         131                 : #define JSXML_CAPACITY(array)   ((array)->capacity & JSXML_CAPACITY_MASK)
         132                 :
         133                 : /*
         134                 :  * NB: don't reorder this enum without changing all array initializers that
         135                 :  * depend on it in jsxml.c.
         136                 :  */
         137                 : typedef enum JSXMLClass {
         138                 :     JSXML_CLASS_LIST,
         139                 :     JSXML_CLASS_ELEMENT,
         140                 :     JSXML_CLASS_ATTRIBUTE,
         141                 :     JSXML_CLASS_PROCESSING_INSTRUCTION,
         142                 :     JSXML_CLASS_TEXT,
         143                 :     JSXML_CLASS_COMMENT,
         144                 :     JSXML_CLASS_LIMIT
         145                 : } JSXMLClass;
         146                 :
         147                 : #define JSXML_CLASS_HAS_KIDS(class_)    ((class_) < JSXML_CLASS_ATTRIBUTE)
         148                 : #define JSXML_CLASS_HAS_VALUE(class_)   ((class_) >= JSXML_CLASS_ATTRIBUTE)
         149                 : #define JSXML_CLASS_HAS_NAME(class_)                                          \
         150                 :     ((unsigned)((class_) - JSXML_CLASS_ELEMENT) <=                               \
         151                 :      (unsigned)(JSXML_CLASS_PROCESSING_INSTRUCTION - JSXML_CLASS_ELEMENT))
         152                 :
         153                 : #ifdef DEBUG_notme
         154                 : #include "jsclist.h"
         155                 : #endif
         156                 :
         157                 : typedef struct JSXMLListVar {
         158                 :     JSXMLArray<JSXML>   kids;           /* NB: must come first */
         159                 :     js::HeapPtrXML      target;
         160                 :     js::HeapPtrObject   targetprop;
         161                 : } JSXMLListVar;
         162                 :
         163                 : typedef struct JSXMLElemVar {
         164                 :     JSXMLArray<JSXML>    kids;          /* NB: must come first */
         165                 :     JSXMLArray<JSObject> namespaces;
         166                 :     JSXMLArray<JSXML>    attrs;
         167                 : } JSXMLElemVar;
         168                 :
         169                 : /* union member shorthands */
         170                 : #define xml_kids        list.kids
         171                 : #define xml_target      list.target
         172                 : #define xml_targetprop  list.targetprop
         173                 : #define xml_namespaces  elem.namespaces
         174                 : #define xml_attrs       elem.attrs
         175                 : #define xml_value       value
         176                 :
         177                 : /* xml_class-testing macros */
         178                 : #define JSXML_HAS_KIDS(xml)     JSXML_CLASS_HAS_KIDS((xml)->xml_class)
         179                 : #define JSXML_HAS_VALUE(xml)    JSXML_CLASS_HAS_VALUE((xml)->xml_class)
         180                 : #define JSXML_HAS_NAME(xml)     JSXML_CLASS_HAS_NAME((xml)->xml_class)
         181                 : #define JSXML_LENGTH(xml)       (JSXML_CLASS_HAS_KIDS((xml)->xml_class)       \
         182                 :                                  ? (xml)->xml_kids.length                     \
         183                 :                                  : 0)
         184                 :
         185                 : struct JSXML : js::gc::Cell {
         186                 : #ifdef DEBUG_notme
         187                 :     JSCList             links;
         188                 :     uint32_t            serial;
         189                 : #endif
         190                 :     js::HeapPtrObject   object;
         191                 :     void                *domnode;       /* DOM node if mapped info item */
         192                 :     js::HeapPtrXML      parent;
         193                 :     js::HeapPtrObject   name;
         194                 :     uint32_t            xml_class;      /* discriminates u, below */
         195                 :     uint32_t            xml_flags;      /* flags, see below */
         196                 :
         197                 :     JSXMLListVar        list;
         198                 :     JSXMLElemVar        elem;
         199                 :     js::HeapPtrString   value;
         200                 :
         201                 : #if JS_BITS_PER_WORD == 32
         202                 :     /* The size of every GC thing must be divisible by the FreeCell size. */
         203                 :     void *pad;
         204                 : #endif
         205                 :
         206                 :     void finalize(js::FreeOp *fop);
         207                 :
         208                 :     static void writeBarrierPre(JSXML *xml);
         209                 :     static void writeBarrierPost(JSXML *xml, void *addr);
         210                 : };
         211                 :
         212                 : /* xml_flags values */
         213                 : #define XMLF_WHITESPACE_TEXT    0x1
         214                 :
         215                 : extern JSXML *
         216                 : js_NewXML(JSContext *cx, JSXMLClass xml_class);
         217                 :
         218                 : extern void
         219                 : js_TraceXML(JSTracer *trc, JSXML *xml);
         220                 :
         221                 : extern JSObject *
         222                 : js_NewXMLObject(JSContext *cx, JSXMLClass xml_class);
         223                 :
         224                 : extern JSObject *
         225                 : js_GetXMLObject(JSContext *cx, JSXML *xml);
         226                 :
         227                 : extern JSObject *
         228                 : js_InitNamespaceClass(JSContext *cx, JSObject *obj);
         229                 :
         230                 : extern JSObject *
         231                 : js_InitQNameClass(JSContext *cx, JSObject *obj);
         232                 :
         233                 : extern JSObject *
         234                 : js_InitXMLClass(JSContext *cx, JSObject *obj);
         235                 :
         236                 : extern JSObject *
         237                 : js_InitXMLClasses(JSContext *cx, JSObject *obj);
         238                 :
         239                 : /*
         240                 :  * If obj is a QName corresponding to function::name, set *funidp to name's id
         241                 :  * and return true, else return false.
         242                 :  */
         243                 : extern bool
         244                 : js_GetLocalNameFromFunctionQName(JSObject *obj, jsid *funidp, JSContext *cx);
         245                 :
         246                 : extern JSBool
         247                 : js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
         248                 :
         249                 : extern JSBool
         250                 : js_SetDefaultXMLNamespace(JSContext *cx, const js::Value &v);
         251                 :
         252                 : /*
         253                 :  * Return true if v is a XML QName object, or if it converts to a string that
         254                 :  * contains a valid XML qualified name (one containing no :), false otherwise.
         255                 :  * NB: This function is an infallible predicate, it hides exceptions.
         256                 :  */
         257                 : extern JSBool
         258                 : js_IsXMLName(JSContext *cx, jsval v);
         259                 :
         260                 : extern JSBool
         261                 : js_ToAttributeName(JSContext *cx, js::Value *vp);
         262                 :
         263                 : extern JSFlatString *
         264                 : js_EscapeAttributeValue(JSContext *cx, JSString *str, JSBool quote);
         265                 :
         266                 : extern JSString *
         267                 : js_AddAttributePart(JSContext *cx, JSBool isName, JSString *str,
         268                 :                     JSString *str2);
         269                 :
         270                 : extern JSFlatString *
         271                 : js_EscapeElementValue(JSContext *cx, JSString *str);
         272                 :
         273                 : extern JSString *
         274                 : js_ValueToXMLString(JSContext *cx, const js::Value &v);
         275                 :
         276                 : extern JSObject *
         277                 : js_ConstructXMLQNameObject(JSContext *cx, const js::Value & nsval,
         278                 :                            const js::Value & lnval);
         279                 :
         280                 : extern JSBool
         281                 : js_GetAnyName(JSContext *cx, jsid *idp);
         282                 :
         283                 : /*
         284                 :  * Note: nameval must be either QName, AttributeName, or AnyName.
         285                 :  */
         286                 : extern JSBool
         287                 : js_FindXMLProperty(JSContext *cx, const js::Value &nameval, JSObject **objp, jsid *idp);
         288                 :
         289                 : extern JSBool
         290                 : js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, js::Value *vp);
         291                 :
         292                 : extern JSBool
         293                 : js_GetXMLDescendants(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
         294                 :
         295                 : extern JSBool
         296                 : js_DeleteXMLListElements(JSContext *cx, JSObject *listobj);
         297                 :
         298                 : extern JSBool
         299                 : js_StepXMLListFilter(JSContext *cx, JSBool initialized);
         300                 :
         301                 : extern JSObject *
         302                 : js_ValueToXMLObject(JSContext *cx, const js::Value &v);
         303                 :
         304                 : extern JSObject *
         305                 : js_ValueToXMLListObject(JSContext *cx, const js::Value &v);
         306                 :
         307                 : extern JSObject *
         308                 : js_NewXMLSpecialObject(JSContext *cx, JSXMLClass xml_class, JSString *name,
         309                 :                        JSString *value);
         310                 :
         311                 : extern JSString *
         312                 : js_MakeXMLCDATAString(JSContext *cx, JSString *str);
         313                 :
         314                 : extern JSString *
         315                 : js_MakeXMLCommentString(JSContext *cx, JSString *str);
         316                 :
         317                 : extern JSString *
         318                 : js_MakeXMLPIString(JSContext *cx, JSString *name, JSString *str);
         319                 :
         320                 : /* The caller must ensure that either v1 or v2 is an object. */
         321                 : extern JSBool
         322                 : js_TestXMLEquality(JSContext *cx, const js::Value &v1, const js::Value &v2,
         323                 :                    JSBool *bp);
         324                 :
         325                 : extern JSBool
         326                 : js_ConcatenateXML(JSContext *cx, JSObject *obj1, JSObject *obj2, js::Value *vp);
         327                 :
         328                 : namespace js {
         329                 :
         330                 : extern bool
         331                 : GetLocalNameFromFunctionQName(JSObject *qn, JSAtom **namep, JSContext *cx);
         332                 :
         333                 : } /* namespace js */
         334                 :
         335                 : #endif /* jsxml_h___ */

Generated by: LCOV version 1.7