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

Diff of /trunk/js/jsapi.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 506 by siliconforks, Sat Sep 26 23:15:22 2009 UTC revision 507 by siliconforks, Sun Jan 10 07:23:34 2010 UTC
# Line 54  Line 54 
54  /*  /*
55   * Type tags stored in the low bits of a jsval.   * Type tags stored in the low bits of a jsval.
56   */   */
57  #define JSVAL_OBJECT            0x0     /* untagged reference to object */  typedef enum jsvaltag {
58  #define JSVAL_INT               0x1     /* tagged 31-bit integer value */      JSVAL_OBJECT  =             0x0,     /* untagged reference to object */
59  #define JSVAL_DOUBLE            0x2     /* tagged reference to double */      JSVAL_INT     =             0x1,     /* tagged 31-bit integer value */
60  #define JSVAL_STRING            0x4     /* tagged reference to string */      JSVAL_DOUBLE  =             0x2,     /* tagged reference to double */
61  #define JSVAL_BOOLEAN           0x6     /* tagged boolean value */      JSVAL_STRING  =             0x4,     /* tagged reference to string */
62        JSVAL_SPECIAL =             0x6      /* tagged boolean or private value */
63    } jsvaltag;
64    
65  /* Type tag bitfield length and derived macros. */  /* Type tag bitfield length and derived macros. */
66  #define JSVAL_TAGBITS           3  #define JSVAL_TAGBITS           3
67  #define JSVAL_TAGMASK           JS_BITMASK(JSVAL_TAGBITS)  #define JSVAL_TAGMASK           ((jsval) JS_BITMASK(JSVAL_TAGBITS))
 #define JSVAL_TAG(v)            ((v) & JSVAL_TAGMASK)  
 #define JSVAL_SETTAG(v,t)       ((v) | (t))  
 #define JSVAL_CLRTAG(v)         ((v) & ~(jsval)JSVAL_TAGMASK)  
68  #define JSVAL_ALIGN             JS_BIT(JSVAL_TAGBITS)  #define JSVAL_ALIGN             JS_BIT(JSVAL_TAGBITS)
69    
70    /* Not a function, because we have static asserts that use it */
71    #define JSVAL_TAG(v)            ((jsvaltag)((v) & JSVAL_TAGMASK))
72    
73    /* Not a function, because we have static asserts that use it */
74    #define JSVAL_SETTAG(v, t) ((v) | (t))
75    
76    static JS_ALWAYS_INLINE jsval
77    JSVAL_CLRTAG(jsval v)
78    {
79        return v & ~(jsval)JSVAL_TAGMASK;
80    }
81    
82    /*
83     * Well-known JS values.  The extern'd variables are initialized when the
84     * first JSContext is created by JS_NewContext (see below).
85     */
86    #define JSVAL_NULL              ((jsval) 0)
87    #define JSVAL_ZERO              INT_TO_JSVAL(0)
88    #define JSVAL_ONE               INT_TO_JSVAL(1)
89    #define JSVAL_FALSE             SPECIAL_TO_JSVAL(JS_FALSE)
90    #define JSVAL_TRUE              SPECIAL_TO_JSVAL(JS_TRUE)
91    #define JSVAL_VOID              SPECIAL_TO_JSVAL(2)
92    
93    /*
94     * A "special" value is a 29-bit (for 32-bit jsval) or 61-bit (for 64-bit jsval)
95     * value whose tag is JSVAL_SPECIAL.  These values include the booleans 0 and 1.
96     *
97     * JSVAL_VOID is a non-boolean special value, but embedders MUST NOT rely on
98     * this. All other possible special values are implementation-reserved
99     * and MUST NOT be constructed by any embedding of SpiderMonkey.
100     */
101    #define JSVAL_TO_SPECIAL(v) ((JSBool) ((v) >> JSVAL_TAGBITS))
102    #define SPECIAL_TO_JSVAL(b)                                                   \
103        JSVAL_SETTAG((jsval) (b) << JSVAL_TAGBITS, JSVAL_SPECIAL)
104    
105  /* Predicates for type testing. */  /* Predicates for type testing. */
106  #define JSVAL_IS_OBJECT(v)      (JSVAL_TAG(v) == JSVAL_OBJECT)  static JS_ALWAYS_INLINE JSBool
107  #define JSVAL_IS_NUMBER(v)      (JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v))  JSVAL_IS_OBJECT(jsval v)
108  #define JSVAL_IS_INT(v)         ((v) & JSVAL_INT)  {
109  #define JSVAL_IS_DOUBLE(v)      (JSVAL_TAG(v) == JSVAL_DOUBLE)      return JSVAL_TAG(v) == JSVAL_OBJECT;
110  #define JSVAL_IS_STRING(v)      (JSVAL_TAG(v) == JSVAL_STRING)  }
111  #define JSVAL_IS_BOOLEAN(v)     (((v) & ~((jsval)1 << JSVAL_TAGBITS)) ==      \  
112                                   JSVAL_BOOLEAN)  static JS_ALWAYS_INLINE JSBool
113  #define JSVAL_IS_NULL(v)        ((v) == JSVAL_NULL)  JSVAL_IS_INT(jsval v)
114  #define JSVAL_IS_VOID(v)        ((v) == JSVAL_VOID)  {
115  #define JSVAL_IS_PRIMITIVE(v)   (!JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v))      return v & JSVAL_INT;
116    }
117    
118    static JS_ALWAYS_INLINE JSBool
119    JSVAL_IS_DOUBLE(jsval v)
120    {
121        return JSVAL_TAG(v) == JSVAL_DOUBLE;
122    }
123    
124    static JS_ALWAYS_INLINE JSBool
125    JSVAL_IS_NUMBER(jsval v)
126    {
127        return JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v);
128    }
129    
130    static JS_ALWAYS_INLINE JSBool
131    JSVAL_IS_STRING(jsval v)
132    {
133        return JSVAL_TAG(v) == JSVAL_STRING;
134    }
135    
136    static JS_ALWAYS_INLINE JSBool
137    JSVAL_IS_SPECIAL(jsval v)
138    {
139        return JSVAL_TAG(v) == JSVAL_SPECIAL;
140    }
141    
142    static JS_ALWAYS_INLINE JSBool
143    JSVAL_IS_BOOLEAN(jsval v)
144    {
145        return (v & ~((jsval)1 << JSVAL_TAGBITS)) == JSVAL_SPECIAL;
146    }
147    
148    static JS_ALWAYS_INLINE JSBool
149    JSVAL_IS_NULL(jsval v)
150    {
151        return v == JSVAL_NULL;
152    }
153    
154    static JS_ALWAYS_INLINE JSBool
155    JSVAL_IS_VOID(jsval v)
156    {
157        return v == JSVAL_VOID;
158    }
159    
160    static JS_ALWAYS_INLINE JSBool
161    JSVAL_IS_PRIMITIVE(jsval v)
162    {
163        return !JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v);
164    }
165    
166  /* Objects, strings, and doubles are GC'ed. */  /* Objects, strings, and doubles are GC'ed. */
167  #define JSVAL_IS_GCTHING(v)     (!((v) & JSVAL_INT) &&                        \  static JS_ALWAYS_INLINE JSBool
168                                   JSVAL_TAG(v) != JSVAL_BOOLEAN)  JSVAL_IS_GCTHING(jsval v)
169    {
170        return !(v & JSVAL_INT) && JSVAL_TAG(v) != JSVAL_SPECIAL;
171    }
172    
173  static JS_ALWAYS_INLINE void *  static JS_ALWAYS_INLINE void *
174  JSVAL_TO_GCTHING(jsval v)  JSVAL_TO_GCTHING(jsval v)
# Line 145  Line 231 
231  #define JSVAL_INT_POW2(n)       ((jsval)1 << (n))  #define JSVAL_INT_POW2(n)       ((jsval)1 << (n))
232  #define JSVAL_INT_MIN           (-JSVAL_INT_POW2(30))  #define JSVAL_INT_MIN           (-JSVAL_INT_POW2(30))
233  #define JSVAL_INT_MAX           (JSVAL_INT_POW2(30) - 1)  #define JSVAL_INT_MAX           (JSVAL_INT_POW2(30) - 1)
234  #define INT_FITS_IN_JSVAL(i)    ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <=      \  
235    /* Not a function, because we have static asserts that use it */
236    #define INT_FITS_IN_JSVAL(i)    ((jsuint)(i) - (jsuint)JSVAL_INT_MIN <=       \
237                                   (jsuint)(JSVAL_INT_MAX - JSVAL_INT_MIN))                                   (jsuint)(JSVAL_INT_MAX - JSVAL_INT_MIN))
 #define JSVAL_TO_INT(v)         ((jsint)(v) >> 1)  
 #define INT_TO_JSVAL(i)         (((jsval)(i) << 1) | JSVAL_INT)  
238    
239  /*  static JS_ALWAYS_INLINE jsint
240   * A pseudo-boolean is a 29-bit (for 32-bit jsval) or 61-bit (for 64-bit jsval)  JSVAL_TO_INT(jsval v)
241   * value other than 0 or 1 encoded as a jsval whose tag is JSVAL_BOOLEAN.  {
242   *      JS_ASSERT(JSVAL_IS_INT(v));
243   * JSVAL_VOID happens to be defined as a jsval encoding a pseudo-boolean, but      return (jsint) v >> 1;
244   * embedders MUST NOT rely on this. All other possible pseudo-boolean values  }
  * are implementation-reserved and MUST NOT be constructed by any embedding of  
  * SpiderMonkey.  
  */  
 #define JSVAL_TO_PSEUDO_BOOLEAN(v) ((JSBool) ((v) >> JSVAL_TAGBITS))  
 #define PSEUDO_BOOLEAN_TO_JSVAL(b)                                            \  
     JSVAL_SETTAG((jsval) (b) << JSVAL_TAGBITS, JSVAL_BOOLEAN)  
245    
246  /*  /* Not a function, because we have static asserts that use it */
247   * Well-known JS values.  The extern'd variables are initialized when the  #define INT_TO_JSVAL_CONSTEXPR(i)  (((jsval)(i) << 1) | JSVAL_INT)
  * first JSContext is created by JS_NewContext (see below).  
  */  
 #define JSVAL_NULL              ((jsval) 0)  
 #define JSVAL_ZERO              INT_TO_JSVAL(0)  
 #define JSVAL_ONE               INT_TO_JSVAL(1)  
 #define JSVAL_FALSE             PSEUDO_BOOLEAN_TO_JSVAL(JS_FALSE)  
 #define JSVAL_TRUE              PSEUDO_BOOLEAN_TO_JSVAL(JS_TRUE)  
 #define JSVAL_VOID              PSEUDO_BOOLEAN_TO_JSVAL(2)  
248    
249    static JS_ALWAYS_INLINE jsval
250    INT_TO_JSVAL(jsint i)
251    {
252        JS_ASSERT(INT_FITS_IN_JSVAL(i));
253        return INT_TO_JSVAL_CONSTEXPR(i);
254    }
255    
256  /* Convert between boolean and jsval, asserting that inputs are valid. */  /* Convert between boolean and jsval, asserting that inputs are valid. */
257  static JS_ALWAYS_INLINE JSBool  static JS_ALWAYS_INLINE JSBool
258  JSVAL_TO_BOOLEAN(jsval v)  JSVAL_TO_BOOLEAN(jsval v)
259  {  {
260      JS_ASSERT(v == JSVAL_TRUE || v == JSVAL_FALSE);      JS_ASSERT(v == JSVAL_TRUE || v == JSVAL_FALSE);
261      return JSVAL_TO_PSEUDO_BOOLEAN(v);      return JSVAL_TO_SPECIAL(v);
262  }  }
263    
264  static JS_ALWAYS_INLINE jsval  static JS_ALWAYS_INLINE jsval
265  BOOLEAN_TO_JSVAL(JSBool b)  BOOLEAN_TO_JSVAL(JSBool b)
266  {  {
267      JS_ASSERT(b == JS_TRUE || b == JS_FALSE);      JS_ASSERT(b == JS_TRUE || b == JS_FALSE);
268      return PSEUDO_BOOLEAN_TO_JSVAL(b);      return SPECIAL_TO_JSVAL(b);
269  }  }
270    
271  /* A private data pointer (2-byte-aligned) can be stored as an int jsval. */  /* A private data pointer (2-byte-aligned) can be stored as an int jsval. */
# Line 447  Line 525 
525  extern JS_PUBLIC_API(const char *)  extern JS_PUBLIC_API(const char *)
526  JS_GetTypeName(JSContext *cx, JSType type);  JS_GetTypeName(JSContext *cx, JSType type);
527    
528    extern JS_PUBLIC_API(JSBool)
529    JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2);
530    
531    extern JS_PUBLIC_API(JSBool)
532    JS_SameValue(JSContext *cx, jsval v1, jsval v2);
533    
534  /************************************************************************/  /************************************************************************/
535    
536  /*  /*
# Line 465  Line 549 
549  JS_NewRuntime(uint32 maxbytes);  JS_NewRuntime(uint32 maxbytes);
550    
551  extern JS_PUBLIC_API(void)  extern JS_PUBLIC_API(void)
552    JS_CommenceRuntimeShutDown(JSRuntime *rt);
553    
554    extern JS_PUBLIC_API(void)
555  JS_DestroyRuntime(JSRuntime *rt);  JS_DestroyRuntime(JSRuntime *rt);
556    
557  extern JS_PUBLIC_API(void)  extern JS_PUBLIC_API(void)
# Line 497  Line 584 
584    
585  class JSAutoRequest {  class JSAutoRequest {
586    public:    public:
587      JSAutoRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {      JSAutoRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
588            : mContext(cx), mSaveDepth(0) {
589            JS_GUARD_OBJECT_NOTIFIER_INIT;
590          JS_BeginRequest(mContext);          JS_BeginRequest(mContext);
591      }      }
592      ~JSAutoRequest() {      ~JSAutoRequest() {
# Line 514  Line 603 
603    protected:    protected:
604      JSContext *mContext;      JSContext *mContext;
605      jsrefcount mSaveDepth;      jsrefcount mSaveDepth;
606        JS_DECL_USE_GUARD_OBJECT_NOTIFIER
607    
608  #if 0  #if 0
609    private:    private:
# Line 524  Line 614 
614    
615  class JSAutoSuspendRequest {  class JSAutoSuspendRequest {
616    public:    public:
617      JSAutoSuspendRequest(JSContext *cx) : mContext(cx), mSaveDepth(0) {      JSAutoSuspendRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
618            : mContext(cx), mSaveDepth(0) {
619            JS_GUARD_OBJECT_NOTIFIER_INIT;
620          if (mContext) {          if (mContext) {
621              mSaveDepth = JS_SuspendRequest(mContext);              mSaveDepth = JS_SuspendRequest(mContext);
622          }          }
# Line 543  Line 635 
635    protected:    protected:
636      JSContext *mContext;      JSContext *mContext;
637      jsrefcount mSaveDepth;      jsrefcount mSaveDepth;
638        JS_DECL_USE_GUARD_OBJECT_NOTIFIER
639    
640  #if 0  #if 0
641    private:    private:
# Line 902  Line 995 
995    
996  class JSAutoLocalRootScope {  class JSAutoLocalRootScope {
997    public:    public:
998      JSAutoLocalRootScope(JSContext *cx) : mContext(cx) {      JSAutoLocalRootScope(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
999            : mContext(cx) {
1000            JS_GUARD_OBJECT_NOTIFIER_INIT;
1001          JS_EnterLocalRootScope(mContext);          JS_EnterLocalRootScope(mContext);
1002      }      }
1003      ~JSAutoLocalRootScope() {      ~JSAutoLocalRootScope() {
# Line 915  Line 1010 
1010    
1011    protected:    protected:
1012      JSContext *mContext;      JSContext *mContext;
1013        JS_DECL_USE_GUARD_OBJECT_NOTIFIER
1014    
1015  #if 0  #if 0
1016    private:    private:
# Line 1018  Line 1114 
1114  struct JSTracer {  struct JSTracer {
1115      JSContext           *context;      JSContext           *context;
1116      JSTraceCallback     callback;      JSTraceCallback     callback;
 #ifdef DEBUG  
1117      JSTraceNamePrinter  debugPrinter;      JSTraceNamePrinter  debugPrinter;
1118      const void          *debugPrintArg;      const void          *debugPrintArg;
1119      size_t              debugPrintIndex;      size_t              debugPrintIndex;
 #endif  
1120  };  };
1121    
1122  /*  /*
# Line 1126  Line 1220 
1220      JS_BEGIN_MACRO                                                            \      JS_BEGIN_MACRO                                                            \
1221          (trc)->context = (cx_);                                               \          (trc)->context = (cx_);                                               \
1222          (trc)->callback = (callback_);                                        \          (trc)->callback = (callback_);                                        \
1223          JS_SET_TRACING_DETAILS(trc, NULL, NULL, (size_t)-1);                  \          (trc)->debugPrinter = NULL;                                           \
1224            (trc)->debugPrintArg = NULL;                                          \
1225            (trc)->debugPrintIndex = (size_t)-1;                                  \
1226      JS_END_MACRO      JS_END_MACRO
1227    
1228  extern JS_PUBLIC_API(void)  extern JS_PUBLIC_API(void)
# Line 1226  Line 1322 
1322  JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);  JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);
1323    
1324  /*  /*
1325     * Flush the code cache for the current thread. The operation might be
1326     * delayed if the cache cannot be flushed currently because native
1327     * code is currently executing.
1328     */
1329    
1330    extern JS_PUBLIC_API(void)
1331    JS_FlushCaches(JSContext *cx);
1332    
1333    /*
1334   * Add a finalizer for external strings created by JS_NewExternalString (see   * Add a finalizer for external strings created by JS_NewExternalString (see
1335   * below) using a type-code returned from this function, and that understands   * below) using a type-code returned from this function, and that understands
1336   * how to free or release the memory pointed at by JS_GetStringChars(str).   * how to free or release the memory pointed at by JS_GetStringChars(str).
# Line 2226  Line 2331 
2331   * These functions allow setting an operation callback that will be called   * These functions allow setting an operation callback that will be called
2332   * from the thread the context is associated with some time after any thread   * from the thread the context is associated with some time after any thread
2333   * triggered the callback using JS_TriggerOperationCallback(cx).   * triggered the callback using JS_TriggerOperationCallback(cx).
2334   *   *
2335   * In a threadsafe build the engine internally triggers operation callbacks   * In a threadsafe build the engine internally triggers operation callbacks
2336   * under certain circumstances (i.e. GC and title transfer) to force the   * under certain circumstances (i.e. GC and title transfer) to force the
2337   * context to yield its current request, which the engine always   * context to yield its current request, which the engine always
2338   * automatically does immediately prior to calling the callback function.   * automatically does immediately prior to calling the callback function.
2339   * The embedding should thus not rely on callbacks being triggered through   * The embedding should thus not rely on callbacks being triggered through
2340   * the external API only.   * the external API only.
2341   *   *
2342   * Important note: Additional callbacks can occur inside the callback handler   * Important note: Additional callbacks can occur inside the callback handler
2343   * if it re-enters the JS engine. The embedding must ensure that the callback   * if it re-enters the JS engine. The embedding must ensure that the callback
2344   * is disconnected before attempting such re-entry.   * is disconnected before attempting such re-entry.
# Line 2614  Line 2719 
2719  #define JSREG_MULTILINE 0x04    /* treat ^ and $ as begin and end of line */  #define JSREG_MULTILINE 0x04    /* treat ^ and $ as begin and end of line */
2720  #define JSREG_STICKY    0x08    /* only match starting at lastIndex */  #define JSREG_STICKY    0x08    /* only match starting at lastIndex */
2721  #define JSREG_FLAT      0x10    /* parse as a flat regexp */  #define JSREG_FLAT      0x10    /* parse as a flat regexp */
2722    #define JSREG_NOCOMPILE 0x20    /* do not try to compile to native code */
2723    
2724  extern JS_PUBLIC_API(JSObject *)  extern JS_PUBLIC_API(JSObject *)
2725  JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags);  JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags);

Legend:
Removed from v.506  
changed lines
  Added in v.507

  ViewVC Help
Powered by ViewVC 1.1.24