LCOV - code coverage report
Current view: directory - objdir/dist/include - jsapi.h (source / functions) Found Hit Coverage
Test: app.info Lines: 394 331 84.0 %
Date: 2012-06-02 Functions: 156 130 83.3 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: set ts=8 sw=4 et tw=78:
       3                 :  *
       4                 :  * ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is Mozilla Communicator client code, released
      18                 :  * March 31, 1998.
      19                 :  *
      20                 :  * The Initial Developer of the Original Code is
      21                 :  * Netscape Communications Corporation.
      22                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      23                 :  * the Initial Developer. All Rights Reserved.
      24                 :  *
      25                 :  * Contributor(s):
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #ifndef jsapi_h___
      42                 : #define jsapi_h___
      43                 : /*
      44                 :  * JavaScript API.
      45                 :  */
      46                 : 
      47                 : #include "mozilla/StandardInteger.h"
      48                 : 
      49                 : #include <stddef.h>
      50                 : #include <stdio.h>
      51                 : #include "js-config.h"
      52                 : #include "jspubtd.h"
      53                 : #include "jsutil.h"
      54                 : #include "jsval.h"
      55                 : 
      56                 : #include "js/Utility.h"
      57                 : 
      58                 : #ifdef __cplusplus
      59                 : #include "jsalloc.h"
      60                 : #include "js/Vector.h"
      61                 : #include "mozilla/Attributes.h"
      62                 : #endif
      63                 : 
      64                 : /************************************************************************/
      65                 : 
      66                 : /* JS::Value can store a full int32_t. */
      67                 : #define JSVAL_INT_BITS          32
      68                 : #define JSVAL_INT_MIN           ((int32_t)0x80000000)
      69                 : #define JSVAL_INT_MAX           ((int32_t)0x7fffffff)
      70                 : 
      71                 : /************************************************************************/
      72                 : 
      73                 : #define JS_Assert MOZ_Assert
      74                 : 
      75                 : #ifdef __cplusplus
      76                 : namespace JS {
      77                 : 
      78                 : /*
      79                 :  * Protecting non-jsval, non-JSObject *, non-JSString * values from collection
      80                 :  *
      81                 :  * Most of the time, the garbage collector's conservative stack scanner works
      82                 :  * behind the scenes, finding all live values and protecting them from being
      83                 :  * collected. However, when JSAPI client code obtains a pointer to data the
      84                 :  * scanner does not know about, owned by an object the scanner does know about,
      85                 :  * Care Must Be Taken.
      86                 :  *
      87                 :  * The scanner recognizes only a select set of types: pointers to JSObjects and
      88                 :  * similar things (JSFunctions, and so on), pointers to JSStrings, and jsvals.
      89                 :  * So while the scanner finds all live |JSString| pointers, it does not notice
      90                 :  * |jschar| pointers.
      91                 :  *
      92                 :  * So suppose we have:
      93                 :  *
      94                 :  *   void f(JSString *str) {
      95                 :  *     const jschar *ch = JS_GetStringCharsZ(str);
      96                 :  *     ... do stuff with ch, but no uses of str ...;
      97                 :  *   }
      98                 :  *
      99                 :  * After the call to |JS_GetStringCharsZ|, there are no further uses of
     100                 :  * |str|, which means that the compiler is within its rights to not store
     101                 :  * it anywhere. But because the stack scanner will not notice |ch|, there
     102                 :  * is no longer any live value in this frame that would keep the string
     103                 :  * alive. If |str| is the last reference to that |JSString|, and the
     104                 :  * collector runs while we are using |ch|, the string's array of |jschar|s
     105                 :  * may be freed out from under us.
     106                 :  *
     107                 :  * Note that there is only an issue when 1) we extract a thing X the scanner
     108                 :  * doesn't recognize from 2) a thing Y the scanner does recognize, and 3) if Y
     109                 :  * gets garbage-collected, then X gets freed. If we have code like this:
     110                 :  *
     111                 :  *   void g(JSObject *obj) {
     112                 :  *     jsval x;
     113                 :  *     JS_GetProperty(obj, "x", &x);
     114                 :  *     ... do stuff with x ...
     115                 :  *   }
     116                 :  *
     117                 :  * there's no problem, because the value we've extracted, x, is a jsval, a
     118                 :  * type that the conservative scanner recognizes.
     119                 :  *
     120                 :  * Conservative GC frees us from the obligation to explicitly root the types it
     121                 :  * knows about, but when we work with derived values like |ch|, we must root
     122                 :  * their owners, as the derived value alone won't keep them alive.
     123                 :  *
     124                 :  * A JS::Anchor is a kind of GC root that allows us to keep the owners of
     125                 :  * derived values like |ch| alive throughout the Anchor's lifetime. We could
     126                 :  * fix the above code as follows:
     127                 :  *
     128                 :  *   void f(JSString *str) {
     129                 :  *     JS::Anchor<JSString *> a_str(str);
     130                 :  *     const jschar *ch = JS_GetStringCharsZ(str);
     131                 :  *     ... do stuff with ch, but no uses of str ...;
     132                 :  *   }
     133                 :  *
     134                 :  * This simply ensures that |str| will be live until |a_str| goes out of scope.
     135                 :  * As long as we don't retain a pointer to the string's characters for longer
     136                 :  * than that, we have avoided all garbage collection hazards.
     137                 :  */
     138                 : template<typename T> class AnchorPermitted;
     139                 : template<> class AnchorPermitted<JSObject *> { };
     140                 : template<> class AnchorPermitted<const JSObject *> { };
     141                 : template<> class AnchorPermitted<JSFunction *> { };
     142                 : template<> class AnchorPermitted<const JSFunction *> { };
     143         4137023 : template<> class AnchorPermitted<JSString *> { };
     144                 : template<> class AnchorPermitted<const JSString *> { };
     145            9767 : template<> class AnchorPermitted<Value> { };
     146                 : 
     147                 : template<typename T>
     148                 : class Anchor: AnchorPermitted<T>
     149                 : {
     150                 :   public:
     151                 :     Anchor() { }
     152         4146790 :     explicit Anchor(T t) { hold = t; }
     153                 :     inline ~Anchor();
     154            9780 :     T &get() { return hold; }
     155                 :     const T &get() const { return hold; }
     156               0 :     void set(const T &t) { hold = t; }
     157               0 :     void clear() { hold = 0; }
     158                 :   private:
     159                 :     T hold;
     160                 :     /* Anchors should not be assigned or passed to functions. */
     161                 :     Anchor(const Anchor &);
     162                 :     const Anchor &operator=(const Anchor &);
     163                 : };
     164                 : 
     165                 : #ifdef __GNUC__
     166                 : template<typename T>
     167         4146790 : inline Anchor<T>::~Anchor()
     168                 : {
     169                 :     /*
     170                 :      * No code is generated for this. But because this is marked 'volatile', G++ will
     171                 :      * assume it has important side-effects, and won't delete it. (G++ never looks at
     172                 :      * the actual text and notices it's empty.) And because we have passed |hold| to
     173                 :      * it, GCC will keep |hold| alive until this point.
     174                 :      *
     175                 :      * The "memory" clobber operand ensures that G++ will not move prior memory
     176                 :      * accesses after the asm --- it's a barrier. Unfortunately, it also means that
     177                 :      * G++ will assume that all memory has changed after the asm, as it would for a
     178                 :      * call to an unknown function. I don't know of a way to avoid that consequence.
     179                 :      */
     180         4146790 :     asm volatile("":: "g" (hold) : "memory");
     181         4146790 : }
     182                 : #else
     183                 : template<typename T>
     184                 : inline Anchor<T>::~Anchor()
     185                 : {
     186                 :     /*
     187                 :      * An adequate portable substitute, for non-structure types.
     188                 :      *
     189                 :      * The compiler promises that, by the end of an expression statement, the
     190                 :      * last-stored value to a volatile object is the same as it would be in an
     191                 :      * unoptimized, direct implementation (the "abstract machine" whose behavior the
     192                 :      * language spec describes). However, the compiler is still free to reorder
     193                 :      * non-volatile accesses across this store --- which is what we must prevent. So
     194                 :      * assigning the held value to a volatile variable, as we do here, is not enough.
     195                 :      *
     196                 :      * In our case, however, garbage collection only occurs at function calls, so it
     197                 :      * is sufficient to ensure that the destructor's store isn't moved earlier across
     198                 :      * any function calls that could collect. It is hard to imagine the compiler
     199                 :      * analyzing the program so thoroughly that it could prove that such motion was
     200                 :      * safe. In practice, compilers treat calls to the collector as opaque operations
     201                 :      * --- in particular, as operations which could access volatile variables, across
     202                 :      * which this destructor must not be moved.
     203                 :      *
     204                 :      * ("Objection, your honor!  *Alleged* killer whale!")
     205                 :      *
     206                 :      * The disadvantage of this approach is that it does generate code for the store.
     207                 :      * We do need to use Anchors in some cases where cycles are tight.
     208                 :      *
     209                 :      * NB: there is a Anchor<Value>::~Anchor() specialization below.
     210                 :      */
     211                 :     volatile T sink;
     212                 :     sink = hold;
     213                 : }
     214                 : #endif  /* defined(__GNUC__) */
     215                 : 
     216                 : /*
     217                 :  * Methods for poisoning GC heap pointer words and checking for poisoned words.
     218                 :  * These are in this file for use in Value methods and so forth.
     219                 :  *
     220                 :  * If the moving GC hazard analysis is in use and detects a non-rooted stack
     221                 :  * pointer to a GC thing, one byte of that pointer is poisoned to refer to an
     222                 :  * invalid location. For both 32 bit and 64 bit systems, the fourth byte of the
     223                 :  * pointer is overwritten, to reduce the likelihood of accidentally changing
     224                 :  * a live integer value.
     225                 :  */
     226                 : 
     227                 : inline void PoisonPtr(uintptr_t *v)
     228                 : {
     229                 : #if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG)
     230                 :     uint8_t *ptr = (uint8_t *) v + 3;
     231                 :     *ptr = JS_FREE_PATTERN;
     232                 : #endif
     233                 : }
     234                 : 
     235                 : template <typename T>
     236       350855096 : inline bool IsPoisonedPtr(T *v)
     237                 : {
     238                 : #if defined(JSGC_ROOT_ANALYSIS) && defined(DEBUG)
     239                 :     uint32_t mask = uintptr_t(v) & 0xff000000;
     240                 :     return mask == uint32_t(JS_FREE_PATTERN << 24);
     241                 : #else
     242       350855096 :     return false;
     243                 : #endif
     244                 : }
     245                 : 
     246                 : /*
     247                 :  * JS::Value is the C++ interface for a single JavaScript Engine value.
     248                 :  * A few general notes on JS::Value:
     249                 :  *
     250                 :  * - JS::Value has setX() and isX() members for X in
     251                 :  *
     252                 :  *     { Int32, Double, String, Boolean, Undefined, Null, Object, Magic }
     253                 :  *
     254                 :  *   JS::Value also contains toX() for each of the non-singleton types.
     255                 :  *
     256                 :  * - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for
     257                 :  *   the magic value. By providing JSWhyMagic values when creating and checking
     258                 :  *   for magic values, it is possible to assert, at runtime, that only magic
     259                 :  *   values with the expected reason flow through a particular value. For
     260                 :  *   example, if cx->exception has a magic value, the reason must be
     261                 :  *   JS_GENERATOR_CLOSING.
     262                 :  *
     263                 :  * - A key difference between JSVAL_* and JS::Value operations is that
     264                 :  *   JS::Value gives null a separate type. Thus
     265                 :  *
     266                 :  *           JSVAL_IS_OBJECT(v) === v.isObjectOrNull()
     267                 :  *       !JSVAL_IS_PRIMITIVE(v) === v.isObject()
     268                 :  *
     269                 :  *   To help prevent mistakenly boxing a nullable JSObject* as an object,
     270                 :  *   Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a
     271                 :  *   JSObject&. A convenience member Value::setObjectOrNull is provided.
     272                 :  *
     273                 :  * - JSVAL_VOID is the same as the singleton value of the Undefined type.
     274                 :  *
     275                 :  * - Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on
     276                 :  *   32-bit user code should avoid copying jsval/JS::Value as much as possible,
     277                 :  *   preferring to pass by const Value &.
     278                 :  */
     279                 : class Value
     280         3838566 : {
     281                 :   public:
     282                 :     /*
     283                 :      * N.B. the default constructor leaves Value unitialized. Adding a default
     284                 :      * constructor prevents Value from being stored in a union.
     285                 :      */
     286                 : 
     287                 :     /*** Mutators ***/
     288                 : 
     289                 :     JS_ALWAYS_INLINE
     290         4156664 :     void setNull() {
     291         4156664 :         data.asBits = BUILD_JSVAL(JSVAL_TAG_NULL, 0).asBits;
     292         4156664 :     }
     293                 : 
     294                 :     JS_ALWAYS_INLINE
     295        52662033 :     void setUndefined() {
     296        52662033 :         data.asBits = BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0).asBits;
     297        52662033 :     }
     298                 : 
     299                 :     JS_ALWAYS_INLINE
     300        52923038 :     void setInt32(int32_t i) {
     301        52923038 :         data = INT32_TO_JSVAL_IMPL(i);
     302        52923038 :     }
     303                 : 
     304                 :     JS_ALWAYS_INLINE
     305                 :     int32_t &getInt32Ref() {
     306                 :         JS_ASSERT(isInt32());
     307                 :         return data.s.payload.i32;
     308                 :     }
     309                 : 
     310                 :     JS_ALWAYS_INLINE
     311          168683 :     void setDouble(double d) {
     312          168683 :         data = DOUBLE_TO_JSVAL_IMPL(d);
     313          168683 :     }
     314                 : 
     315                 :     JS_ALWAYS_INLINE
     316                 :     double &getDoubleRef() {
     317                 :         JS_ASSERT(isDouble());
     318                 :         return data.asDouble;
     319                 :     }
     320                 : 
     321                 :     JS_ALWAYS_INLINE
     322        25572240 :     void setString(JSString *str) {
     323        25572240 :         JS_ASSERT(!IsPoisonedPtr(str));
     324        25572240 :         data = STRING_TO_JSVAL_IMPL(str);
     325        25572240 :     }
     326                 : 
     327                 :     JS_ALWAYS_INLINE
     328                 :     void setString(const JS::Anchor<JSString *> &str) {
     329                 :         setString(str.get());
     330                 :     }
     331                 : 
     332                 :     JS_ALWAYS_INLINE
     333        80467741 :     void setObject(JSObject &obj) {
     334        80467741 :         JS_ASSERT(!IsPoisonedPtr(&obj));
     335        80467741 :         data = OBJECT_TO_JSVAL_IMPL(&obj);
     336        80467741 :     }
     337                 : 
     338                 :     JS_ALWAYS_INLINE
     339        10338724 :     void setBoolean(bool b) {
     340        10338724 :         data = BOOLEAN_TO_JSVAL_IMPL(b);
     341        10338724 :     }
     342                 : 
     343                 :     JS_ALWAYS_INLINE
     344                 :     void setMagic(JSWhyMagic why) {
     345                 :         data = MAGIC_TO_JSVAL_IMPL(why);
     346                 :     }
     347                 : 
     348                 :     JS_ALWAYS_INLINE
     349                 :     bool setNumber(uint32_t ui) {
     350                 :         if (ui > JSVAL_INT_MAX) {
     351                 :             setDouble((double)ui);
     352                 :             return false;
     353                 :         } else {
     354                 :             setInt32((int32_t)ui);
     355                 :             return true;
     356                 :         }
     357                 :     }
     358                 : 
     359                 :     JS_ALWAYS_INLINE
     360         6734396 :     bool setNumber(double d) {
     361                 :         int32_t i;
     362         6734396 :         if (JSDOUBLE_IS_INT32(d, &i)) {
     363         6653084 :             setInt32(i);
     364         6653084 :             return true;
     365                 :         } else {
     366           81312 :             setDouble(d);
     367           81312 :             return false;
     368                 :         }
     369                 :     }
     370                 : 
     371                 :     JS_ALWAYS_INLINE
     372         1740336 :     void setObjectOrNull(JSObject *arg) {
     373         1740336 :         if (arg)
     374         1138027 :             setObject(*arg);
     375                 :         else
     376          602309 :             setNull();
     377         1740336 :     }
     378                 : 
     379                 :     JS_ALWAYS_INLINE
     380                 :     void swap(Value &rhs) {
     381                 :         uint64_t tmp = rhs.data.asBits;
     382                 :         rhs.data.asBits = data.asBits;
     383                 :         data.asBits = tmp;
     384                 :     }
     385                 : 
     386                 :     /*** Value type queries ***/
     387                 : 
     388                 :     JS_ALWAYS_INLINE
     389        72702772 :     bool isUndefined() const {
     390        72702772 :         return JSVAL_IS_UNDEFINED_IMPL(data);
     391                 :     }
     392                 : 
     393                 :     JS_ALWAYS_INLINE
     394                 :     bool isNull() const {
     395                 :         return JSVAL_IS_NULL_IMPL(data);
     396                 :     }
     397                 : 
     398                 :     JS_ALWAYS_INLINE
     399                 :     bool isNullOrUndefined() const {
     400                 :         return isNull() || isUndefined();
     401                 :     }
     402                 : 
     403                 :     JS_ALWAYS_INLINE
     404       214828606 :     bool isInt32() const {
     405       214828606 :         return JSVAL_IS_INT32_IMPL(data);
     406                 :     }
     407                 : 
     408                 :     JS_ALWAYS_INLINE
     409                 :     bool isInt32(int32_t i32) const {
     410                 :         return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32);
     411                 :     }
     412                 : 
     413                 :     JS_ALWAYS_INLINE
     414        15631810 :     bool isDouble() const {
     415        15631810 :         return JSVAL_IS_DOUBLE_IMPL(data);
     416                 :     }
     417                 : 
     418                 :     JS_ALWAYS_INLINE
     419        16056872 :     bool isNumber() const {
     420        16056872 :         return JSVAL_IS_NUMBER_IMPL(data);
     421                 :     }
     422                 : 
     423                 :     JS_ALWAYS_INLINE
     424       593843044 :     bool isString() const {
     425       593843044 :         return JSVAL_IS_STRING_IMPL(data);
     426                 :     }
     427                 : 
     428                 :     JS_ALWAYS_INLINE
     429       804192469 :     bool isObject() const {
     430       804192469 :         return JSVAL_IS_OBJECT_IMPL(data);
     431                 :     }
     432                 : 
     433                 :     JS_ALWAYS_INLINE
     434                 :     bool isPrimitive() const {
     435                 :         return JSVAL_IS_PRIMITIVE_IMPL(data);
     436                 :     }
     437                 : 
     438                 :     JS_ALWAYS_INLINE
     439         9143494 :     bool isObjectOrNull() const {
     440         9143494 :         return JSVAL_IS_OBJECT_OR_NULL_IMPL(data);
     441                 :     }
     442                 : 
     443                 :     JS_ALWAYS_INLINE
     444                 :     bool isGCThing() const {
     445                 :         return JSVAL_IS_GCTHING_IMPL(data);
     446                 :     }
     447                 : 
     448                 :     JS_ALWAYS_INLINE
     449                 :     bool isBoolean() const {
     450                 :         return JSVAL_IS_BOOLEAN_IMPL(data);
     451                 :     }
     452                 : 
     453                 :     JS_ALWAYS_INLINE
     454                 :     bool isTrue() const {
     455                 :         return JSVAL_IS_SPECIFIC_BOOLEAN(data, true);
     456                 :     }
     457                 : 
     458                 :     JS_ALWAYS_INLINE
     459                 :     bool isFalse() const {
     460                 :         return JSVAL_IS_SPECIFIC_BOOLEAN(data, false);
     461                 :     }
     462                 : 
     463                 :     JS_ALWAYS_INLINE
     464                 :     bool isMagic() const {
     465                 :         return JSVAL_IS_MAGIC_IMPL(data);
     466                 :     }
     467                 : 
     468                 :     JS_ALWAYS_INLINE
     469                 :     bool isMagic(JSWhyMagic why) const {
     470                 :         JS_ASSERT_IF(isMagic(), data.s.payload.why == why);
     471                 :         return JSVAL_IS_MAGIC_IMPL(data);
     472                 :     }
     473                 : 
     474                 :     /*
     475                 :      * Although the Value class comment says 'magic' is a singleton type, it is
     476                 :      * technically possible to use the payload. This should be avoided to
     477                 :      * preserve the ability for the strong assertions in isMagic().
     478                 :      */
     479                 :     JS_ALWAYS_INLINE
     480                 :     bool isParticularMagic(JSWhyMagic why) const {
     481                 :         return isMagic() && data.s.payload.why == why;
     482                 :     }
     483                 : 
     484                 :     JS_ALWAYS_INLINE
     485       101747996 :     bool isMarkable() const {
     486       101747996 :         return JSVAL_IS_TRACEABLE_IMPL(data);
     487                 :     }
     488                 : 
     489                 :     JS_ALWAYS_INLINE
     490                 :     JSGCTraceKind gcKind() const {
     491                 :         JS_ASSERT(isMarkable());
     492                 :         return JSGCTraceKind(JSVAL_TRACE_KIND_IMPL(data));
     493                 :     }
     494                 : 
     495                 :     JS_ALWAYS_INLINE
     496                 :     JSWhyMagic whyMagic() const {
     497                 :         JS_ASSERT(isMagic());
     498                 :         return data.s.payload.why;
     499                 :     }
     500                 : 
     501                 :     /*** Comparison ***/
     502                 : 
     503                 :     JS_ALWAYS_INLINE
     504           35914 :     bool operator==(const Value &rhs) const {
     505           35914 :         return data.asBits == rhs.data.asBits;
     506                 :     }
     507                 : 
     508                 :     JS_ALWAYS_INLINE
     509         3233638 :     bool operator!=(const Value &rhs) const {
     510         3233638 :         return data.asBits != rhs.data.asBits;
     511                 :     }
     512                 : 
     513                 :     friend inline bool SameType(const Value &lhs, const Value &rhs);
     514                 : 
     515                 :     /*** Extract the value's typed payload ***/
     516                 : 
     517                 :     JS_ALWAYS_INLINE
     518       104610410 :     int32_t toInt32() const {
     519       104610410 :         JS_ASSERT(isInt32());
     520       104610410 :         return JSVAL_TO_INT32_IMPL(data);
     521                 :     }
     522                 : 
     523                 :     JS_ALWAYS_INLINE
     524          256528 :     double toDouble() const {
     525          256528 :         JS_ASSERT(isDouble());
     526          256528 :         return data.asDouble;
     527                 :     }
     528                 : 
     529                 :     JS_ALWAYS_INLINE
     530          658498 :     double toNumber() const {
     531          658498 :         JS_ASSERT(isNumber());
     532          658498 :         return isDouble() ? toDouble() : double(toInt32());
     533                 :     }
     534                 : 
     535                 :     JS_ALWAYS_INLINE
     536       147294019 :     JSString *toString() const {
     537       147294019 :         JS_ASSERT(isString());
     538       147294019 :         return JSVAL_TO_STRING_IMPL(data);
     539                 :     }
     540                 : 
     541                 :     JS_ALWAYS_INLINE
     542       286597709 :     JSObject &toObject() const {
     543       286597709 :         JS_ASSERT(isObject());
     544       286597709 :         return *JSVAL_TO_OBJECT_IMPL(data);
     545                 :     }
     546                 : 
     547                 :     JS_ALWAYS_INLINE
     548         4210559 :     JSObject *toObjectOrNull() const {
     549         4210559 :         JS_ASSERT(isObjectOrNull());
     550         4210559 :         return JSVAL_TO_OBJECT_IMPL(data);
     551                 :     }
     552                 : 
     553                 :     JS_ALWAYS_INLINE
     554                 :     void *toGCThing() const {
     555                 :         JS_ASSERT(isGCThing());
     556                 :         return JSVAL_TO_GCTHING_IMPL(data);
     557                 :     }
     558                 : 
     559                 :     JS_ALWAYS_INLINE
     560                 :     bool toBoolean() const {
     561                 :         JS_ASSERT(isBoolean());
     562                 :         return JSVAL_TO_BOOLEAN_IMPL(data);
     563                 :     }
     564                 : 
     565                 :     JS_ALWAYS_INLINE
     566                 :     uint32_t payloadAsRawUint32() const {
     567                 :         JS_ASSERT(!isDouble());
     568                 :         return data.s.payload.u32;
     569                 :     }
     570                 : 
     571                 :     JS_ALWAYS_INLINE
     572                 :     uint64_t asRawBits() const {
     573                 :         return data.asBits;
     574                 :     }
     575                 : 
     576                 :     JS_ALWAYS_INLINE
     577                 :     JSValueType extractNonDoubleType() const {
     578                 :         return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data);
     579                 :     }
     580                 : 
     581                 :     /*
     582                 :      * Private API
     583                 :      *
     584                 :      * Private setters/getters allow the caller to read/write arbitrary types
     585                 :      * that fit in the 64-bit payload. It is the caller's responsibility, after
     586                 :      * storing to a value with setPrivateX to read only using getPrivateX.
     587                 :      * Privates values are given a type type which ensures they are not marked.
     588                 :      */
     589                 : 
     590                 :     JS_ALWAYS_INLINE
     591         1603593 :     void setPrivate(void *ptr) {
     592         1603593 :         data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr);
     593         1603593 :     }
     594                 : 
     595                 :     JS_ALWAYS_INLINE
     596         3935303 :     void *toPrivate() const {
     597         3935303 :         JS_ASSERT(JSVAL_IS_DOUBLE_IMPL(data));
     598         3935303 :         return JSVAL_TO_PRIVATE_PTR_IMPL(data);
     599                 :     }
     600                 : 
     601                 :     JS_ALWAYS_INLINE
     602          871399 :     void setPrivateUint32(uint32_t ui) {
     603          871399 :         data = PRIVATE_UINT32_TO_JSVAL_IMPL(ui);
     604          871399 :     }
     605                 : 
     606                 :     JS_ALWAYS_INLINE
     607         2680456 :     uint32_t toPrivateUint32() const {
     608         2680456 :         JS_ASSERT(JSVAL_IS_DOUBLE_IMPL(data));
     609         2680456 :         return JSVAL_TO_PRIVATE_UINT32_IMPL(data);
     610                 :     }
     611                 : 
     612                 :     JS_ALWAYS_INLINE
     613                 :     uint32_t &getPrivateUint32Ref() {
     614                 :         JS_ASSERT(isDouble());
     615                 :         return data.s.payload.u32;
     616                 :     }
     617                 : 
     618                 :     /*
     619                 :      * An unmarked value is just a void* cast as a Value. Thus, the Value is
     620                 :      * not safe for GC and must not be marked. This API avoids raw casts
     621                 :      * and the ensuing strict-aliasing warnings.
     622                 :      */
     623                 : 
     624                 :     JS_ALWAYS_INLINE
     625                 :     void setUnmarkedPtr(void *ptr) {
     626                 :         data.asPtr = ptr;
     627                 :     }
     628                 : 
     629                 :     JS_ALWAYS_INLINE
     630                 :     void *toUnmarkedPtr() const {
     631                 :         return data.asPtr;
     632                 :     }
     633                 : 
     634                 :     const size_t *payloadWord() const {
     635                 : #if JS_BITS_PER_WORD == 32
     636                 :         return &data.s.payload.word;
     637                 : #elif JS_BITS_PER_WORD == 64
     638                 :         return &data.asWord;
     639                 : #endif
     640                 :     }
     641                 : 
     642                 : #ifndef _MSC_VER
     643                 :   /* To make jsval binary compatible when linking across C and C++ with MSVC,
     644                 :    * JS::Value needs to be POD. Otherwise, jsval will be passed in memory
     645                 :    * in C++ but by value in C (bug 645111).
     646                 :    */
     647                 :   private:
     648                 : #endif
     649                 : 
     650                 :     jsval_layout data;
     651                 : 
     652                 :   private:
     653                 :     void staticAssertions() {
     654                 :         JS_STATIC_ASSERT(sizeof(JSValueType) == 1);
     655                 :         JS_STATIC_ASSERT(sizeof(JSValueTag) == 4);
     656                 :         JS_STATIC_ASSERT(sizeof(JSBool) == 4);
     657                 :         JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4);
     658                 :         JS_STATIC_ASSERT(sizeof(Value) == 8);
     659                 :     }
     660                 : 
     661                 :     friend jsval_layout (::JSVAL_TO_IMPL)(Value);
     662                 :     friend Value (::IMPL_TO_JSVAL)(jsval_layout l);
     663                 : };
     664                 : 
     665                 : inline bool
     666                 : IsPoisonedValue(const Value &v)
     667                 : {
     668                 :     if (v.isString())
     669                 :         return IsPoisonedPtr(v.toString());
     670                 :     if (v.isObject())
     671                 :         return IsPoisonedPtr(&v.toObject());
     672                 :     return false;
     673                 : }
     674                 : 
     675                 : /************************************************************************/
     676                 : 
     677                 : static JS_ALWAYS_INLINE Value
     678           42706 : NullValue()
     679                 : {
     680                 :     Value v;
     681           42706 :     v.setNull();
     682                 :     return v;
     683                 : }
     684                 : 
     685                 : static JS_ALWAYS_INLINE Value
     686               0 : UndefinedValue()
     687                 : {
     688                 :     Value v;
     689               0 :     v.setUndefined();
     690                 :     return v;
     691                 : }
     692                 : 
     693                 : static JS_ALWAYS_INLINE Value
     694               0 : Int32Value(int32_t i32)
     695                 : {
     696                 :     Value v;
     697               0 :     v.setInt32(i32);
     698                 :     return v;
     699                 : }
     700                 : 
     701                 : static JS_ALWAYS_INLINE Value
     702                 : DoubleValue(double dbl)
     703                 : {
     704                 :     Value v;
     705                 :     v.setDouble(dbl);
     706                 :     return v;
     707                 : }
     708                 : 
     709                 : static JS_ALWAYS_INLINE Value
     710               0 : StringValue(JSString *str)
     711                 : {
     712                 :     Value v;
     713               0 :     v.setString(str);
     714                 :     return v;
     715                 : }
     716                 : 
     717                 : static JS_ALWAYS_INLINE Value
     718                 : BooleanValue(bool boo)
     719                 : {
     720                 :     Value v;
     721                 :     v.setBoolean(boo);
     722                 :     return v;
     723                 : }
     724                 : 
     725                 : static JS_ALWAYS_INLINE Value
     726               0 : ObjectValue(JSObject &obj)
     727                 : {
     728                 :     Value v;
     729               0 :     v.setObject(obj);
     730                 :     return v;
     731                 : }
     732                 : 
     733                 : static JS_ALWAYS_INLINE Value
     734                 : MagicValue(JSWhyMagic why)
     735                 : {
     736                 :     Value v;
     737                 :     v.setMagic(why);
     738                 :     return v;
     739                 : }
     740                 : 
     741                 : static JS_ALWAYS_INLINE Value
     742               0 : NumberValue(double dbl)
     743                 : {
     744                 :     Value v;
     745               0 :     v.setNumber(dbl);
     746                 :     return v;
     747                 : }
     748                 : 
     749                 : static JS_ALWAYS_INLINE Value
     750               0 : ObjectOrNullValue(JSObject *obj)
     751                 : {
     752                 :     Value v;
     753               0 :     v.setObjectOrNull(obj);
     754                 :     return v;
     755                 : }
     756                 : 
     757                 : static JS_ALWAYS_INLINE Value
     758           12957 : PrivateValue(void *ptr)
     759                 : {
     760                 :     Value v;
     761           12957 :     v.setPrivate(ptr);
     762                 :     return v;
     763                 : }
     764                 : 
     765                 : static JS_ALWAYS_INLINE Value
     766            5441 : PrivateUint32Value(uint32_t ui)
     767                 : {
     768                 :     Value v;
     769            5441 :     v.setPrivateUint32(ui);
     770                 :     return v;
     771                 : }
     772                 : 
     773                 : JS_ALWAYS_INLINE bool
     774                 : SameType(const Value &lhs, const Value &rhs)
     775                 : {
     776                 :     return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data);
     777                 : }
     778                 : 
     779                 : /************************************************************************/
     780                 : 
     781                 : #ifndef __GNUC__
     782                 : 
     783                 : /*
     784                 :  * The default assignment operator for |struct C| has the signature:
     785                 :  *
     786                 :  *   C& C::operator=(const C&)
     787                 :  *
     788                 :  * And in particular requires implicit conversion of |this| to type |C| for the
     789                 :  * return value. But |volatile C| cannot thus be converted to |C|, so just
     790                 :  * doing |sink = hold| as in the non-specialized version would fail to compile.
     791                 :  * Do the assignment on asBits instead, since I don't think we want to give
     792                 :  * jsval_layout an assignment operator returning |volatile jsval_layout|.
     793                 :  */
     794                 : template<>
     795                 : inline Anchor<Value>::~Anchor()
     796                 : {
     797                 :     volatile uint64_t bits;
     798                 :     bits = JSVAL_TO_IMPL(hold).asBits;
     799                 : }
     800                 : 
     801                 : #endif
     802                 : 
     803                 : #if defined JS_THREADSAFE && defined DEBUG
     804                 : 
     805                 : class JS_PUBLIC_API(AutoCheckRequestDepth)
     806                 : {
     807                 :     JSContext *cx;
     808                 :   public:
     809                 :     AutoCheckRequestDepth(JSContext *cx);
     810                 :     ~AutoCheckRequestDepth();
     811                 : };
     812                 : 
     813                 : # define CHECK_REQUEST(cx) \
     814                 :     JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx)
     815                 : 
     816                 : #else
     817                 : 
     818                 : # define CHECK_REQUEST(cx) \
     819                 :     ((void) 0)
     820                 : 
     821                 : #endif
     822                 : 
     823                 : class JS_PUBLIC_API(AutoGCRooter) {
     824                 :   public:
     825                 :     AutoGCRooter(JSContext *cx, ptrdiff_t tag);
     826                 : 
     827        12917324 :     ~AutoGCRooter() {
     828        12917324 :         JS_ASSERT(this == *stackTop);
     829        12917324 :         *stackTop = down;
     830        12917324 :     }
     831                 : 
     832                 :     /* Implemented in jsgc.cpp. */
     833                 :     inline void trace(JSTracer *trc);
     834                 :     static void traceAll(JSTracer *trc);
     835                 : 
     836                 :   protected:
     837                 :     AutoGCRooter * const down;
     838                 : 
     839                 :     /*
     840                 :      * Discriminates actual subclass of this being used.  If non-negative, the
     841                 :      * subclass roots an array of values of the length stored in this field.
     842                 :      * If negative, meaning is indicated by the corresponding value in the enum
     843                 :      * below.  Any other negative value indicates some deeper problem such as
     844                 :      * memory corruption.
     845                 :      */
     846                 :     ptrdiff_t tag;
     847                 : 
     848                 :     enum {
     849                 :         JSVAL =        -1, /* js::AutoValueRooter */
     850                 :         VALARRAY =     -2, /* js::AutoValueArrayRooter */
     851                 :         PARSER =       -3, /* js::Parser */
     852                 :         SHAPEVECTOR =  -4, /* js::AutoShapeVector */
     853                 :         ENUMERATOR =   -5, /* js::AutoEnumStateRooter */
     854                 :         IDARRAY =      -6, /* js::AutoIdArray */
     855                 :         DESCRIPTORS =  -7, /* js::AutoPropDescArrayRooter */
     856                 :         NAMESPACES =   -8, /* js::AutoNamespaceArray */
     857                 :         XML =          -9, /* js::AutoXMLRooter */
     858                 :         OBJECT =      -10, /* js::AutoObjectRooter */
     859                 :         ID =          -11, /* js::AutoIdRooter */
     860                 :         VALVECTOR =   -12, /* js::AutoValueVector */
     861                 :         DESCRIPTOR =  -13, /* js::AutoPropertyDescriptorRooter */
     862                 :         STRING =      -14, /* js::AutoStringRooter */
     863                 :         IDVECTOR =    -15, /* js::AutoIdVector */
     864                 :         OBJVECTOR =   -16, /* js::AutoObjectVector */
     865                 :         SCRIPTVECTOR =-17  /* js::AutoScriptVector */
     866                 :     };
     867                 : 
     868                 :   private:
     869                 :     AutoGCRooter ** const stackTop;
     870                 : 
     871                 :     /* No copy or assignment semantics. */
     872                 :     AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE;
     873                 :     void operator=(AutoGCRooter &ida) MOZ_DELETE;
     874                 : };
     875                 : 
     876                 : class AutoValueRooter : private AutoGCRooter
     877         6807851 : {
     878                 :   public:
     879           42403 :     explicit AutoValueRooter(JSContext *cx
     880                 :                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
     881           42403 :       : AutoGCRooter(cx, JSVAL), val(NullValue())
     882                 :     {
     883           42403 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
     884           42403 :     }
     885                 : 
     886         6765448 :     AutoValueRooter(JSContext *cx, const Value &v
     887                 :                     JS_GUARD_OBJECT_NOTIFIER_PARAM)
     888         6765448 :       : AutoGCRooter(cx, JSVAL), val(v)
     889                 :     {
     890         6765448 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
     891         6765448 :     }
     892                 : 
     893                 :     /*
     894                 :      * If you are looking for Object* overloads, use AutoObjectRooter instead;
     895                 :      * rooting Object*s as a js::Value requires discerning whether or not it is
     896                 :      * a function object. Also, AutoObjectRooter is smaller.
     897                 :      */
     898                 : 
     899               4 :     void set(Value v) {
     900               4 :         JS_ASSERT(tag == JSVAL);
     901               4 :         val = v;
     902               4 :     }
     903                 : 
     904              10 :     const Value &value() const {
     905              10 :         JS_ASSERT(tag == JSVAL);
     906              10 :         return val;
     907                 :     }
     908                 : 
     909               8 :     Value *addr() {
     910               8 :         JS_ASSERT(tag == JSVAL);
     911               8 :         return &val;
     912                 :     }
     913                 : 
     914            8548 :     const Value &jsval_value() const {
     915            8548 :         JS_ASSERT(tag == JSVAL);
     916            8548 :         return val;
     917                 :     }
     918                 : 
     919            4809 :     Value *jsval_addr() {
     920            4809 :         JS_ASSERT(tag == JSVAL);
     921            4809 :         return &val;
     922                 :     }
     923                 : 
     924                 :     friend void AutoGCRooter::trace(JSTracer *trc);
     925                 : 
     926                 :   private:
     927                 :     Value val;
     928                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
     929                 : };
     930                 : 
     931          413895 : class AutoObjectRooter : private AutoGCRooter {
     932                 :   public:
     933          413895 :     AutoObjectRooter(JSContext *cx, JSObject *obj = NULL
     934                 :                      JS_GUARD_OBJECT_NOTIFIER_PARAM)
     935          413895 :       : AutoGCRooter(cx, OBJECT), obj(obj)
     936                 :     {
     937          413895 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
     938          413895 :     }
     939                 : 
     940                 :     void setObject(JSObject *obj) {
     941                 :         this->obj = obj;
     942                 :     }
     943                 : 
     944                 :     JSObject * object() const {
     945                 :         return obj;
     946                 :     }
     947                 : 
     948                 :     JSObject ** addr() {
     949                 :         return &obj;
     950                 :     }
     951                 : 
     952                 :     friend void AutoGCRooter::trace(JSTracer *trc);
     953                 : 
     954                 :   private:
     955                 :     JSObject *obj;
     956                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
     957                 : };
     958                 : 
     959                 : class AutoStringRooter : private AutoGCRooter {
     960                 :   public:
     961                 :     AutoStringRooter(JSContext *cx, JSString *str = NULL
     962                 :                      JS_GUARD_OBJECT_NOTIFIER_PARAM)
     963                 :       : AutoGCRooter(cx, STRING), str(str)
     964                 :     {
     965                 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
     966                 :     }
     967                 : 
     968                 :     void setString(JSString *str) {
     969                 :         this->str = str;
     970                 :     }
     971                 : 
     972                 :     JSString * string() const {
     973                 :         return str;
     974                 :     }
     975                 : 
     976                 :     JSString ** addr() {
     977                 :         return &str;
     978                 :     }
     979                 : 
     980                 :     friend void AutoGCRooter::trace(JSTracer *trc);
     981                 : 
     982                 :   private:
     983                 :     JSString *str;
     984                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
     985                 : };
     986                 : 
     987           75876 : class AutoArrayRooter : private AutoGCRooter {
     988                 :   public:
     989           75876 :     AutoArrayRooter(JSContext *cx, size_t len, Value *vec
     990                 :                     JS_GUARD_OBJECT_NOTIFIER_PARAM)
     991           75876 :       : AutoGCRooter(cx, len), array(vec)
     992                 :     {
     993           75876 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
     994           75876 :         JS_ASSERT(tag >= 0);
     995           75876 :     }
     996                 : 
     997               0 :     void changeLength(size_t newLength) {
     998               0 :         tag = ptrdiff_t(newLength);
     999               0 :         JS_ASSERT(tag >= 0);
    1000               0 :     }
    1001                 : 
    1002               0 :     void changeArray(Value *newArray, size_t newLength) {
    1003               0 :         changeLength(newLength);
    1004               0 :         array = newArray;
    1005               0 :     }
    1006                 : 
    1007                 :     Value *array;
    1008                 : 
    1009                 :     friend void AutoGCRooter::trace(JSTracer *trc);
    1010                 : 
    1011                 :   private:
    1012                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    1013                 : };
    1014                 : 
    1015                 : /* The auto-root for enumeration object and its state. */
    1016                 : class AutoEnumStateRooter : private AutoGCRooter
    1017                 : {
    1018                 :   public:
    1019                 :     AutoEnumStateRooter(JSContext *cx, JSObject *obj
    1020                 :                         JS_GUARD_OBJECT_NOTIFIER_PARAM)
    1021                 :       : AutoGCRooter(cx, ENUMERATOR), obj(obj), stateValue(), context(cx)
    1022                 :     {
    1023                 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    1024                 :         JS_ASSERT(obj);
    1025                 :     }
    1026                 : 
    1027                 :     ~AutoEnumStateRooter();
    1028                 : 
    1029                 :     friend void AutoGCRooter::trace(JSTracer *trc);
    1030                 : 
    1031                 :     const Value &state() const { return stateValue; }
    1032                 :     Value *addr() { return &stateValue; }
    1033                 : 
    1034                 :   protected:
    1035                 :     void trace(JSTracer *trc);
    1036                 : 
    1037                 :     JSObject *obj;
    1038                 : 
    1039                 :   private:
    1040                 :     Value stateValue;
    1041                 :     JSContext *context;
    1042                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    1043                 : };
    1044                 : 
    1045                 : template<class T>
    1046                 : class AutoVectorRooter : protected AutoGCRooter
    1047         1696858 : {
    1048                 :   public:
    1049         1696858 :     explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
    1050                 :                               JS_GUARD_OBJECT_NOTIFIER_PARAM)
    1051         1696858 :         : AutoGCRooter(cx, tag), vector(cx)
    1052                 :     {
    1053         1696858 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    1054         1696858 :     }
    1055                 : 
    1056          655880 :     size_t length() const { return vector.length(); }
    1057                 : 
    1058         1619616 :     bool append(const T &v) { return vector.append(v); }
    1059                 : 
    1060                 :     /* For use when space has already been reserved. */
    1061                 :     void infallibleAppend(const T &v) { vector.infallibleAppend(v); }
    1062                 : 
    1063                 :     void popBack() { vector.popBack(); }
    1064                 :     T popCopy() { return vector.popCopy(); }
    1065                 : 
    1066                 :     bool growBy(size_t inc) {
    1067                 :         size_t oldLength = vector.length();
    1068                 :         if (!vector.growByUninitialized(inc))
    1069                 :             return false;
    1070                 :         makeRangeGCSafe(oldLength);
    1071                 :         return true;
    1072                 :     }
    1073                 : 
    1074         1227699 :     bool resize(size_t newLength) {
    1075         1227699 :         size_t oldLength = vector.length();
    1076         1227699 :         if (newLength <= oldLength) {
    1077          776239 :             vector.shrinkBy(oldLength - newLength);
    1078          776239 :             return true;
    1079                 :         }
    1080          451460 :         if (!vector.growByUninitialized(newLength - oldLength))
    1081               0 :             return false;
    1082          451460 :         makeRangeGCSafe(oldLength);
    1083          451460 :         return true;
    1084                 :     }
    1085                 : 
    1086                 :     void clear() { vector.clear(); }
    1087                 : 
    1088                 :     bool reserve(size_t newLength) {
    1089                 :         return vector.reserve(newLength);
    1090                 :     }
    1091                 : 
    1092           25786 :     T &operator[](size_t i) { return vector[i]; }
    1093                 :     const T &operator[](size_t i) const { return vector[i]; }
    1094                 : 
    1095                 :     const T *begin() const { return vector.begin(); }
    1096         1253007 :     T *begin() { return vector.begin(); }
    1097                 : 
    1098                 :     const T *end() const { return vector.end(); }
    1099                 :     T *end() { return vector.end(); }
    1100                 : 
    1101                 :     const T &back() const { return vector.back(); }
    1102                 : 
    1103                 :     friend void AutoGCRooter::trace(JSTracer *trc);
    1104                 : 
    1105                 :   private:
    1106          451460 :     void makeRangeGCSafe(size_t oldLength) {
    1107          451460 :         T *t = vector.begin() + oldLength;
    1108         1149644 :         for (size_t i = oldLength; i < vector.length(); ++i, ++t)
    1109          698184 :             memset(t, 0, sizeof(T));
    1110          451460 :     }
    1111                 : 
    1112                 :     typedef js::Vector<T, 8> VectorImpl;
    1113                 :     VectorImpl vector;
    1114                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    1115                 : };
    1116                 : 
    1117                 : class AutoValueVector : public AutoVectorRooter<Value>
    1118         1431959 : {
    1119                 :   public:
    1120         1431959 :     explicit AutoValueVector(JSContext *cx
    1121                 :                              JS_GUARD_OBJECT_NOTIFIER_PARAM)
    1122         1431959 :         : AutoVectorRooter<Value>(cx, VALVECTOR)
    1123                 :     {
    1124         1431959 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    1125         1431959 :     }
    1126                 : 
    1127                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    1128                 : };
    1129                 : 
    1130                 : class AutoIdVector : public AutoVectorRooter<jsid>
    1131          264899 : {
    1132                 :   public:
    1133          264899 :     explicit AutoIdVector(JSContext *cx
    1134                 :                           JS_GUARD_OBJECT_NOTIFIER_PARAM)
    1135          264899 :         : AutoVectorRooter<jsid>(cx, IDVECTOR)
    1136                 :     {
    1137          264899 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    1138          264899 :     }
    1139                 : 
    1140                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    1141                 : };
    1142                 : 
    1143                 : class AutoScriptVector : public AutoVectorRooter<JSScript *>
    1144                 : {
    1145                 :   public:
    1146                 :     explicit AutoScriptVector(JSContext *cx
    1147                 :                               JS_GUARD_OBJECT_NOTIFIER_PARAM)
    1148                 :         : AutoVectorRooter<JSScript *>(cx, SCRIPTVECTOR)
    1149                 :     {
    1150                 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    1151                 :     }
    1152                 : 
    1153                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    1154                 : };
    1155                 : 
    1156                 : }  /* namespace JS */
    1157                 : 
    1158                 : /************************************************************************/
    1159                 : 
    1160                 : /*
    1161                 :  * JS::Value and jsval are the same type; jsval is the old name, kept around
    1162                 :  * for backwards compatibility along with all the JSVAL_* operations below.
    1163                 :  * jsval_layout is an implementation detail and should not be used externally.
    1164                 :  */
    1165                 : typedef JS::Value jsval;
    1166                 : 
    1167                 : static JS_ALWAYS_INLINE jsval_layout
    1168        85417379 : JSVAL_TO_IMPL(jsval v)
    1169                 : {
    1170        85417379 :     return v.data;
    1171                 : }
    1172                 : 
    1173                 : static JS_ALWAYS_INLINE jsval
    1174        29564070 : IMPL_TO_JSVAL(jsval_layout l)
    1175                 : {
    1176                 :     JS::Value v;
    1177        29564070 :     v.data = l;
    1178                 :     return v;
    1179                 : }
    1180                 : 
    1181                 : #ifdef DEBUG
    1182                 : struct JSValueAlignmentTester { char c; JS::Value v; };
    1183                 : JS_STATIC_ASSERT(sizeof(JSValueAlignmentTester) == 16);
    1184                 : #endif /* DEBUG */
    1185                 : 
    1186                 : #else  /* defined(__cplusplus) */
    1187                 : 
    1188                 : /*
    1189                 :  * For SpiderMonkey C clients, there is no JS::Value class, only the
    1190                 :  * traditional jsval with the traditional JSVAL_* operations. Since
    1191                 :  * SpiderMonkey itself is always compiled as C++, this relies on the binary
    1192                 :  * compatibility of jsval_layout and JS::Value (statically asserted below).
    1193                 :  */
    1194                 : typedef union jsval_layout jsval;
    1195                 : 
    1196                 : static JS_ALWAYS_INLINE jsval_layout
    1197              22 : JSVAL_TO_IMPL(jsval v)
    1198                 : {
    1199              22 :     return v;
    1200                 : }
    1201                 : 
    1202                 : static JS_ALWAYS_INLINE jsval
    1203               9 : IMPL_TO_JSVAL(jsval_layout l)
    1204                 : {
    1205               9 :     return l;
    1206                 : }
    1207                 : 
    1208                 : #endif  /* defined(__cplusplus) */
    1209                 : 
    1210                 : #ifdef DEBUG
    1211                 : typedef struct { char c; jsval_layout l; } JSLayoutAlignmentTester;
    1212                 : JS_STATIC_ASSERT(sizeof(JSLayoutAlignmentTester) == 16);
    1213                 : #endif /* DEBUG */
    1214                 : 
    1215                 : JS_STATIC_ASSERT(sizeof(jsval_layout) == sizeof(jsval));
    1216                 : 
    1217                 : /************************************************************************/
    1218                 : 
    1219                 : /* JSClass operation signatures. */
    1220                 : 
    1221                 : /*
    1222                 :  * Add, delete, or get a property named by id in obj.  Note the jsid id
    1223                 :  * type -- id may be a string (Unicode property identifier) or an int (element
    1224                 :  * index).  The *vp out parameter, on success, is the new property value after
    1225                 :  * an add or get.  After a successful delete, *vp is JSVAL_FALSE iff
    1226                 :  * obj[id] can't be deleted (because it's permanent).
    1227                 :  */
    1228                 : typedef JSBool
    1229                 : (* JSPropertyOp)(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
    1230                 : 
    1231                 : /*
    1232                 :  * Set a property named by id in obj, treating the assignment as strict
    1233                 :  * mode code if strict is true. Note the jsid id type -- id may be a string
    1234                 :  * (Unicode property identifier) or an int (element index). The *vp out
    1235                 :  * parameter, on success, is the new property value after the
    1236                 :  * set.
    1237                 :  */
    1238                 : typedef JSBool
    1239                 : (* JSStrictPropertyOp)(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
    1240                 : 
    1241                 : /*
    1242                 :  * This function type is used for callbacks that enumerate the properties of
    1243                 :  * a JSObject.  The behavior depends on the value of enum_op:
    1244                 :  *
    1245                 :  *  JSENUMERATE_INIT
    1246                 :  *    A new, opaque iterator state should be allocated and stored in *statep.
    1247                 :  *    (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored).
    1248                 :  *
    1249                 :  *    The number of properties that will be enumerated should be returned as
    1250                 :  *    an integer jsval in *idp, if idp is non-null, and provided the number of
    1251                 :  *    enumerable properties is known.  If idp is non-null and the number of
    1252                 :  *    enumerable properties can't be computed in advance, *idp should be set
    1253                 :  *    to JSVAL_ZERO.
    1254                 :  *
    1255                 :  *  JSENUMERATE_INIT_ALL
    1256                 :  *    Used identically to JSENUMERATE_INIT, but exposes all properties of the
    1257                 :  *    object regardless of enumerability.
    1258                 :  *
    1259                 :  *  JSENUMERATE_NEXT
    1260                 :  *    A previously allocated opaque iterator state is passed in via statep.
    1261                 :  *    Return the next jsid in the iteration using *idp.  The opaque iterator
    1262                 :  *    state pointed at by statep is destroyed and *statep is set to JSVAL_NULL
    1263                 :  *    if there are no properties left to enumerate.
    1264                 :  *
    1265                 :  *  JSENUMERATE_DESTROY
    1266                 :  *    Destroy the opaque iterator state previously allocated in *statep by a
    1267                 :  *    call to this function when enum_op was JSENUMERATE_INIT or
    1268                 :  *    JSENUMERATE_INIT_ALL.
    1269                 :  *
    1270                 :  * The return value is used to indicate success, with a value of JS_FALSE
    1271                 :  * indicating failure.
    1272                 :  */
    1273                 : typedef JSBool
    1274                 : (* JSNewEnumerateOp)(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
    1275                 :                      jsval *statep, jsid *idp);
    1276                 : 
    1277                 : /*
    1278                 :  * The old-style JSClass.enumerate op should define all lazy properties not
    1279                 :  * yet reflected in obj.
    1280                 :  */
    1281                 : typedef JSBool
    1282                 : (* JSEnumerateOp)(JSContext *cx, JSObject *obj);
    1283                 : 
    1284                 : /*
    1285                 :  * Resolve a lazy property named by id in obj by defining it directly in obj.
    1286                 :  * Lazy properties are those reflected from some peer native property space
    1287                 :  * (e.g., the DOM attributes for a given node reflected as obj) on demand.
    1288                 :  *
    1289                 :  * JS looks for a property in an object, and if not found, tries to resolve
    1290                 :  * the given id.  If resolve succeeds, the engine looks again in case resolve
    1291                 :  * defined obj[id].  If no such property exists directly in obj, the process
    1292                 :  * is repeated with obj's prototype, etc.
    1293                 :  *
    1294                 :  * NB: JSNewResolveOp provides a cheaper way to resolve lazy properties.
    1295                 :  */
    1296                 : typedef JSBool
    1297                 : (* JSResolveOp)(JSContext *cx, JSObject *obj, jsid id);
    1298                 : 
    1299                 : /*
    1300                 :  * Like JSResolveOp, but flags provide contextual information as follows:
    1301                 :  *
    1302                 :  *  JSRESOLVE_QUALIFIED   a qualified property id: obj.id or obj[id], not id
    1303                 :  *  JSRESOLVE_ASSIGNING   obj[id] is on the left-hand side of an assignment
    1304                 :  *  JSRESOLVE_DETECTING   'if (o.p)...' or similar detection opcode sequence
    1305                 :  *  JSRESOLVE_DECLARING   var, const, or function prolog declaration opcode
    1306                 :  *  JSRESOLVE_CLASSNAME   class name used when constructing
    1307                 :  *
    1308                 :  * The *objp out parameter, on success, should be null to indicate that id
    1309                 :  * was not resolved; and non-null, referring to obj or one of its prototypes,
    1310                 :  * if id was resolved.
    1311                 :  *
    1312                 :  * This hook instead of JSResolveOp is called via the JSClass.resolve member
    1313                 :  * if JSCLASS_NEW_RESOLVE is set in JSClass.flags.
    1314                 :  *
    1315                 :  * Setting JSCLASS_NEW_RESOLVE and JSCLASS_NEW_RESOLVE_GETS_START further
    1316                 :  * extends this hook by passing in the starting object on the prototype chain
    1317                 :  * via *objp.  Thus a resolve hook implementation may define the property id
    1318                 :  * being resolved in the object in which the id was first sought, rather than
    1319                 :  * in a prototype object whose class led to the resolve hook being called.
    1320                 :  *
    1321                 :  * When using JSCLASS_NEW_RESOLVE_GETS_START, the resolve hook must therefore
    1322                 :  * null *objp to signify "not resolved".  With only JSCLASS_NEW_RESOLVE and no
    1323                 :  * JSCLASS_NEW_RESOLVE_GETS_START, the hook can assume *objp is null on entry.
    1324                 :  * This is not good practice, but enough existing hook implementations count
    1325                 :  * on it that we can't break compatibility by passing the starting object in
    1326                 :  * *objp without a new JSClass flag.
    1327                 :  */
    1328                 : typedef JSBool
    1329                 : (* JSNewResolveOp)(JSContext *cx, JSObject *obj, jsid id, unsigned flags,
    1330                 :                    JSObject **objp);
    1331                 : 
    1332                 : /*
    1333                 :  * Convert obj to the given type, returning true with the resulting value in
    1334                 :  * *vp on success, and returning false on error or exception.
    1335                 :  */
    1336                 : typedef JSBool
    1337                 : (* JSConvertOp)(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
    1338                 : 
    1339                 : /*
    1340                 :  * Delegate typeof to an object so it can cloak a primitive or another object.
    1341                 :  */
    1342                 : typedef JSType
    1343                 : (* JSTypeOfOp)(JSContext *cx, JSObject *obj);
    1344                 : 
    1345                 : /*
    1346                 :  * Finalize obj, which the garbage collector has determined to be unreachable
    1347                 :  * from other live objects or from GC roots.  Obviously, finalizers must never
    1348                 :  * store a reference to obj.
    1349                 :  */
    1350                 : typedef void
    1351                 : (* JSFinalizeOp)(JSContext *cx, JSObject *obj);
    1352                 : 
    1353                 : /*
    1354                 :  * Finalizes external strings created by JS_NewExternalString.
    1355                 :  */
    1356                 : typedef struct JSStringFinalizer JSStringFinalizer;
    1357                 : 
    1358                 : struct JSStringFinalizer {
    1359                 :     void (*finalize)(const JSStringFinalizer *fin, jschar *chars);
    1360                 : };
    1361                 : 
    1362                 : /*
    1363                 :  * JSClass.checkAccess type: check whether obj[id] may be accessed per mode,
    1364                 :  * returning false on error/exception, true on success with obj[id]'s last-got
    1365                 :  * value in *vp, and its attributes in *attrsp.  As for JSPropertyOp above, id
    1366                 :  * is either a string or an int jsval.
    1367                 :  */
    1368                 : typedef JSBool
    1369                 : (* JSCheckAccessOp)(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
    1370                 :                     jsval *vp);
    1371                 : 
    1372                 : /*
    1373                 :  * Check whether v is an instance of obj.  Return false on error or exception,
    1374                 :  * true on success with JS_TRUE in *bp if v is an instance of obj, JS_FALSE in
    1375                 :  * *bp otherwise.
    1376                 :  */
    1377                 : typedef JSBool
    1378                 : (* JSHasInstanceOp)(JSContext *cx, JSObject *obj, const jsval *v, JSBool *bp);
    1379                 : 
    1380                 : /*
    1381                 :  * Function type for trace operation of the class called to enumerate all
    1382                 :  * traceable things reachable from obj's private data structure. For each such
    1383                 :  * thing, a trace implementation must call
    1384                 :  *
    1385                 :  *    JS_CallTracer(trc, thing, kind);
    1386                 :  *
    1387                 :  * or one of its convenience macros as described in jsapi.h.
    1388                 :  *
    1389                 :  * JSTraceOp implementation can assume that no other threads mutates object
    1390                 :  * state. It must not change state of the object or corresponding native
    1391                 :  * structures. The only exception for this rule is the case when the embedding
    1392                 :  * needs a tight integration with GC. In that case the embedding can check if
    1393                 :  * the traversal is a part of the marking phase through calling
    1394                 :  * JS_IsGCMarkingTracer and apply a special code like emptying caches or
    1395                 :  * marking its native structures.
    1396                 :  */
    1397                 : typedef void
    1398                 : (* JSTraceOp)(JSTracer *trc, JSObject *obj);
    1399                 : 
    1400                 : /*
    1401                 :  * DEBUG only callback that JSTraceOp implementation can provide to return
    1402                 :  * a string describing the reference traced with JS_CallTracer.
    1403                 :  */
    1404                 : typedef void
    1405                 : (* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize);
    1406                 : 
    1407                 : typedef JSBool
    1408                 : (* JSEqualityOp)(JSContext *cx, JSObject *obj, const jsval *v, JSBool *bp);
    1409                 : 
    1410                 : /*
    1411                 :  * Typedef for native functions called by the JS VM.
    1412                 :  *
    1413                 :  * See jsapi.h, the JS_CALLEE, JS_THIS, etc. macros.
    1414                 :  */
    1415                 : 
    1416                 : typedef JSBool
    1417                 : (* JSNative)(JSContext *cx, unsigned argc, jsval *vp);
    1418                 : 
    1419                 : /* Callbacks and their arguments. */
    1420                 : 
    1421                 : typedef enum JSContextOp {
    1422                 :     JSCONTEXT_NEW,
    1423                 :     JSCONTEXT_DESTROY
    1424                 : } JSContextOp;
    1425                 : 
    1426                 : /*
    1427                 :  * The possible values for contextOp when the runtime calls the callback are:
    1428                 :  *   JSCONTEXT_NEW      JS_NewContext successfully created a new JSContext
    1429                 :  *                      instance. The callback can initialize the instance as
    1430                 :  *                      required. If the callback returns false, the instance
    1431                 :  *                      will be destroyed and JS_NewContext returns null. In
    1432                 :  *                      this case the callback is not called again.
    1433                 :  *   JSCONTEXT_DESTROY  One of JS_DestroyContext* methods is called. The
    1434                 :  *                      callback may perform its own cleanup and must always
    1435                 :  *                      return true.
    1436                 :  *   Any other value    For future compatibility the callback must do nothing
    1437                 :  *                      and return true in this case.
    1438                 :  */
    1439                 : typedef JSBool
    1440                 : (* JSContextCallback)(JSContext *cx, unsigned contextOp);
    1441                 : 
    1442                 : typedef enum JSGCStatus {
    1443                 :     JSGC_BEGIN,
    1444                 :     JSGC_END
    1445                 : } JSGCStatus;
    1446                 : 
    1447                 : typedef void
    1448                 : (* JSGCCallback)(JSRuntime *rt, JSGCStatus status);
    1449                 : 
    1450                 : typedef enum JSFinalizeStatus {
    1451                 :     JSFINALIZE_START,
    1452                 :     JSFINALIZE_END
    1453                 : } JSFinalizeStatus;
    1454                 : 
    1455                 : typedef void
    1456                 : (* JSFinalizeCallback)(JSContext *cx, JSFinalizeStatus status);
    1457                 : 
    1458                 : /*
    1459                 :  * Generic trace operation that calls JS_CallTracer on each traceable thing
    1460                 :  * stored in data.
    1461                 :  */
    1462                 : typedef void
    1463                 : (* JSTraceDataOp)(JSTracer *trc, void *data);
    1464                 : 
    1465                 : typedef JSBool
    1466                 : (* JSOperationCallback)(JSContext *cx);
    1467                 : 
    1468                 : typedef void
    1469                 : (* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report);
    1470                 : 
    1471                 : #ifdef MOZ_TRACE_JSCALLS
    1472                 : typedef void
    1473                 : (* JSFunctionCallback)(const JSFunction *fun,
    1474                 :                        const JSScript *scr,
    1475                 :                        const JSContext *cx,
    1476                 :                        int entering);
    1477                 : #endif
    1478                 : 
    1479                 : /*
    1480                 :  * Possible exception types. These types are part of a JSErrorFormatString
    1481                 :  * structure. They define which error to throw in case of a runtime error.
    1482                 :  * JSEXN_NONE marks an unthrowable error.
    1483                 :  */
    1484                 : typedef enum JSExnType {
    1485                 :     JSEXN_NONE = -1,
    1486                 :       JSEXN_ERR,
    1487                 :         JSEXN_INTERNALERR,
    1488                 :         JSEXN_EVALERR,
    1489                 :         JSEXN_RANGEERR,
    1490                 :         JSEXN_REFERENCEERR,
    1491                 :         JSEXN_SYNTAXERR,
    1492                 :         JSEXN_TYPEERR,
    1493                 :         JSEXN_URIERR,
    1494                 :         JSEXN_LIMIT
    1495                 : } JSExnType;
    1496                 : 
    1497                 : typedef struct JSErrorFormatString {
    1498                 :     /* The error format string (UTF-8 if js_CStringsAreUTF8). */
    1499                 :     const char *format;
    1500                 : 
    1501                 :     /* The number of arguments to expand in the formatted error message. */
    1502                 :     uint16_t argCount;
    1503                 : 
    1504                 :     /* One of the JSExnType constants above. */
    1505                 :     int16_t exnType;
    1506                 : } JSErrorFormatString;
    1507                 : 
    1508                 : typedef const JSErrorFormatString *
    1509                 : (* JSErrorCallback)(void *userRef, const char *locale,
    1510                 :                     const unsigned errorNumber);
    1511                 : 
    1512                 : #ifdef va_start
    1513                 : #define JS_ARGUMENT_FORMATTER_DEFINED 1
    1514                 : 
    1515                 : typedef JSBool
    1516                 : (* JSArgumentFormatter)(JSContext *cx, const char *format, JSBool fromJS,
    1517                 :                         jsval **vpp, va_list *app);
    1518                 : #endif
    1519                 : 
    1520                 : typedef JSBool
    1521                 : (* JSLocaleToUpperCase)(JSContext *cx, JSString *src, jsval *rval);
    1522                 : 
    1523                 : typedef JSBool
    1524                 : (* JSLocaleToLowerCase)(JSContext *cx, JSString *src, jsval *rval);
    1525                 : 
    1526                 : typedef JSBool
    1527                 : (* JSLocaleCompare)(JSContext *cx, JSString *src1, JSString *src2,
    1528                 :                     jsval *rval);
    1529                 : 
    1530                 : typedef JSBool
    1531                 : (* JSLocaleToUnicode)(JSContext *cx, const char *src, jsval *rval);
    1532                 : 
    1533                 : /*
    1534                 :  * Security protocol types.
    1535                 :  */
    1536                 : 
    1537                 : typedef void
    1538                 : (* JSDestroyPrincipalsOp)(JSPrincipals *principals);
    1539                 : 
    1540                 : typedef JSBool
    1541                 : (* JSSubsumePrincipalsOp)(JSPrincipals *principals1, JSPrincipals *principals2);
    1542                 : 
    1543                 : /*
    1544                 :  * XDR-encode or -decode a principals instance, based on whether xdr->mode is
    1545                 :  * JSXDR_ENCODE, in which case *principalsp should be encoded; or JSXDR_DECODE,
    1546                 :  * in which case implementations must return a held (via JSPRINCIPALS_HOLD),
    1547                 :  * non-null *principalsp out parameter.  Return true on success, false on any
    1548                 :  * error, which the implementation must have reported.
    1549                 :  */
    1550                 : typedef JSBool
    1551                 : (* JSPrincipalsTranscoder)(JSXDRState *xdr, JSPrincipals **principalsp);
    1552                 : 
    1553                 : /*
    1554                 :  * Return a weak reference to the principals associated with obj, possibly via
    1555                 :  * the immutable parent chain leading from obj to a top-level container (e.g.,
    1556                 :  * a window object in the DOM level 0).  If there are no principals associated
    1557                 :  * with obj, return null.  Therefore null does not mean an error was reported;
    1558                 :  * in no event should an error be reported or an exception be thrown by this
    1559                 :  * callback's implementation.
    1560                 :  */
    1561                 : typedef JSPrincipals *
    1562                 : (* JSObjectPrincipalsFinder)(JSObject *obj);
    1563                 : 
    1564                 : /*
    1565                 :  * Used to check if a CSP instance wants to disable eval() and friends.
    1566                 :  * See js_CheckCSPPermitsJSAction() in jsobj.
    1567                 :  */
    1568                 : typedef JSBool
    1569                 : (* JSCSPEvalChecker)(JSContext *cx);
    1570                 : 
    1571                 : /*
    1572                 :  * Callback used to ask the embedding for the cross compartment wrapper handler
    1573                 :  * that implements the desired prolicy for this kind of object in the
    1574                 :  * destination compartment.
    1575                 :  */
    1576                 : typedef JSObject *
    1577                 : (* JSWrapObjectCallback)(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent,
    1578                 :                          unsigned flags);
    1579                 : 
    1580                 : /*
    1581                 :  * Callback used by the wrap hook to ask the embedding to prepare an object
    1582                 :  * for wrapping in a context. This might include unwrapping other wrappers
    1583                 :  * or even finding a more suitable object for the new compartment.
    1584                 :  */
    1585                 : typedef JSObject *
    1586                 : (* JSPreWrapCallback)(JSContext *cx, JSObject *scope, JSObject *obj, unsigned flags);
    1587                 : 
    1588                 : typedef enum {
    1589                 :     JSCOMPARTMENT_DESTROY
    1590                 : } JSCompartmentOp;
    1591                 : 
    1592                 : typedef JSBool
    1593                 : (* JSCompartmentCallback)(JSContext *cx, JSCompartment *compartment, unsigned compartmentOp);
    1594                 : 
    1595                 : /*
    1596                 :  * Read structured data from the reader r. This hook is used to read a value
    1597                 :  * previously serialized by a call to the WriteStructuredCloneOp hook.
    1598                 :  *
    1599                 :  * tag and data are the pair of uint32_t values from the header. The callback
    1600                 :  * may use the JS_Read* APIs to read any other relevant parts of the object
    1601                 :  * from the reader r. closure is any value passed to the JS_ReadStructuredClone
    1602                 :  * function. Return the new object on success, NULL on error/exception.
    1603                 :  */
    1604                 : typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r,
    1605                 :                                            uint32_t tag, uint32_t data, void *closure);
    1606                 : 
    1607                 : /*
    1608                 :  * Structured data serialization hook. The engine can write primitive values,
    1609                 :  * Objects, Arrays, Dates, RegExps, TypedArrays, and ArrayBuffers. Any other
    1610                 :  * type of object requires application support. This callback must first use
    1611                 :  * the JS_WriteUint32Pair API to write an object header, passing a value
    1612                 :  * greater than JS_SCTAG_USER to the tag parameter. Then it can use the
    1613                 :  * JS_Write* APIs to write any other relevant parts of the value v to the
    1614                 :  * writer w. closure is any value passed to the JS_WriteStructuredCLone function.
    1615                 :  *
    1616                 :  * Return true on success, false on error/exception.
    1617                 :  */
    1618                 : typedef JSBool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w,
    1619                 :                                          JSObject *obj, void *closure);
    1620                 : 
    1621                 : /*
    1622                 :  * This is called when JS_WriteStructuredClone finds that the object to be
    1623                 :  * written is recursive. To follow HTML5, the application must throw a
    1624                 :  * DATA_CLONE_ERR DOMException. errorid is always JS_SCERR_RECURSION.
    1625                 :  */
    1626                 : typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid);
    1627                 : 
    1628                 : /************************************************************************/
    1629                 : 
    1630                 : JS_BEGIN_EXTERN_C
    1631                 : 
    1632                 : /*
    1633                 :  * Silence warning about returning JS::Value (aka jsval) from functions with C
    1634                 :  * linkage. For C JSAPI clients, jsval will be jsval_layout, which should be
    1635                 :  * ABI compatible.
    1636                 :  */
    1637                 : #ifdef _MSC_VER
    1638                 : # pragma warning(disable:4190)
    1639                 : #endif
    1640                 : 
    1641                 : /************************************************************************/
    1642                 : 
    1643                 : /*
    1644                 :  * JS constants. For efficiency, prefer predicates (e.g., JSVAL_IS_NULL).
    1645                 :  * N.B. These constants are initialized at startup.
    1646                 :  */
    1647                 : extern JS_PUBLIC_DATA(const jsval) JSVAL_NULL;
    1648                 : extern JS_PUBLIC_DATA(const jsval) JSVAL_ZERO;
    1649                 : extern JS_PUBLIC_DATA(const jsval) JSVAL_ONE;
    1650                 : extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE;
    1651                 : extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE;
    1652                 : extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID;
    1653                 : 
    1654                 : /************************************************************************/
    1655                 : 
    1656                 : static JS_ALWAYS_INLINE JSBool
    1657         6183871 : JSVAL_IS_NULL(jsval v)
    1658                 : {
    1659         6183871 :     return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v));
    1660                 : }
    1661                 : 
    1662                 : static JS_ALWAYS_INLINE JSBool
    1663         4747842 : JSVAL_IS_VOID(jsval v)
    1664                 : {
    1665         4747842 :     return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v));
    1666                 : }
    1667                 : 
    1668                 : static JS_ALWAYS_INLINE JSBool
    1669          217766 : JSVAL_IS_INT(jsval v)
    1670                 : {
    1671          217766 :     return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v));
    1672                 : }
    1673                 : 
    1674                 : static JS_ALWAYS_INLINE int32_t
    1675           52546 : JSVAL_TO_INT(jsval v)
    1676                 : {
    1677           52546 :     JS_ASSERT(JSVAL_IS_INT(v));
    1678           52546 :     return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v));
    1679                 : }
    1680                 : 
    1681                 : static JS_ALWAYS_INLINE jsval
    1682        14810185 : INT_TO_JSVAL(int32_t i)
    1683                 : {
    1684        14810185 :     return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i));
    1685                 : }
    1686                 : 
    1687                 : static JS_ALWAYS_INLINE JSBool
    1688        13642993 : JSVAL_IS_DOUBLE(jsval v)
    1689                 : {
    1690        13642993 :     return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v));
    1691                 : }
    1692                 : 
    1693                 : static JS_ALWAYS_INLINE double
    1694           70116 : JSVAL_TO_DOUBLE(jsval v)
    1695                 : {
    1696                 :     jsval_layout l;
    1697           70116 :     JS_ASSERT(JSVAL_IS_DOUBLE(v));
    1698           70116 :     l = JSVAL_TO_IMPL(v);
    1699           70116 :     return l.asDouble;
    1700                 : }
    1701                 : 
    1702                 : static JS_ALWAYS_INLINE jsval
    1703          159074 : DOUBLE_TO_JSVAL(double d)
    1704                 : {
    1705                 :     /* This is a manually inlined version of:
    1706                 :      *    d = JS_CANONICALIZE_NAN(d);
    1707                 :      *    return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d));
    1708                 :      * because GCC from XCode 3.1.4 miscompiles the above code. */
    1709                 :     jsval_layout l;
    1710          159074 :     if (JS_UNLIKELY(d != d)) {
    1711               0 :         l.asBits = 0x7FF8000000000000LL;
    1712                 :     } else {
    1713          159074 :         l.asDouble = d;
    1714                 :     }
    1715          159074 :     return IMPL_TO_JSVAL(l);
    1716                 : }
    1717                 : 
    1718                 : static JS_ALWAYS_INLINE jsval
    1719          571750 : UINT_TO_JSVAL(uint32_t i)
    1720                 : {
    1721          571750 :     if (i <= JSVAL_INT_MAX)
    1722          562274 :         return INT_TO_JSVAL((int32_t)i);
    1723            9476 :     return DOUBLE_TO_JSVAL((double)i);
    1724                 : }
    1725                 : 
    1726                 : static JS_ALWAYS_INLINE JSBool
    1727           57731 : JSVAL_IS_NUMBER(jsval v)
    1728                 : {
    1729           57731 :     return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v));
    1730                 : }
    1731                 : 
    1732                 : static JS_ALWAYS_INLINE JSBool
    1733          381020 : JSVAL_IS_STRING(jsval v)
    1734                 : {
    1735          381020 :     return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v));
    1736                 : }
    1737                 : 
    1738                 : static JS_ALWAYS_INLINE JSString *
    1739           68241 : JSVAL_TO_STRING(jsval v)
    1740                 : {
    1741           68241 :     JS_ASSERT(JSVAL_IS_STRING(v));
    1742           68241 :     return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v));
    1743                 : }
    1744                 : 
    1745                 : static JS_ALWAYS_INLINE jsval
    1746         3618563 : STRING_TO_JSVAL(JSString *str)
    1747                 : {
    1748         3618563 :     return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str));
    1749                 : }
    1750                 : 
    1751                 : static JS_ALWAYS_INLINE JSBool
    1752        19706215 : JSVAL_IS_OBJECT(jsval v)
    1753                 : {
    1754        19706215 :     return JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v));
    1755                 : }
    1756                 : 
    1757                 : static JS_ALWAYS_INLINE JSObject *
    1758        18261834 : JSVAL_TO_OBJECT(jsval v)
    1759                 : {
    1760        18261834 :     JS_ASSERT(JSVAL_IS_OBJECT(v));
    1761        18261834 :     return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v));
    1762                 : }
    1763                 : 
    1764                 : static JS_ALWAYS_INLINE jsval
    1765         6213007 : OBJECT_TO_JSVAL(JSObject *obj)
    1766                 : {
    1767         6213007 :     if (obj)
    1768         6213001 :         return IMPL_TO_JSVAL(OBJECT_TO_JSVAL_IMPL(obj));
    1769               6 :     return JSVAL_NULL;
    1770                 : }
    1771                 : 
    1772                 : static JS_ALWAYS_INLINE JSBool
    1773           24802 : JSVAL_IS_BOOLEAN(jsval v)
    1774                 : {
    1775           24802 :     return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v));
    1776                 : }
    1777                 : 
    1778                 : static JS_ALWAYS_INLINE JSBool
    1779             404 : JSVAL_TO_BOOLEAN(jsval v)
    1780                 : {
    1781             404 :     JS_ASSERT(JSVAL_IS_BOOLEAN(v));
    1782             404 :     return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v));
    1783                 : }
    1784                 : 
    1785                 : static JS_ALWAYS_INLINE jsval
    1786         1311062 : BOOLEAN_TO_JSVAL(JSBool b)
    1787                 : {
    1788         1311062 :     return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b));
    1789                 : }
    1790                 : 
    1791                 : static JS_ALWAYS_INLINE JSBool
    1792         8534633 : JSVAL_IS_PRIMITIVE(jsval v)
    1793                 : {
    1794         8534633 :     return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v));
    1795                 : }
    1796                 : 
    1797                 : static JS_ALWAYS_INLINE JSBool
    1798           14996 : JSVAL_IS_GCTHING(jsval v)
    1799                 : {
    1800           14996 :     return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v));
    1801                 : }
    1802                 : 
    1803                 : static JS_ALWAYS_INLINE void *
    1804            1216 : JSVAL_TO_GCTHING(jsval v)
    1805                 : {
    1806            1216 :     JS_ASSERT(JSVAL_IS_GCTHING(v));
    1807            1216 :     return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v));
    1808                 : }
    1809                 : 
    1810                 : /* To be GC-safe, privates are tagged as doubles. */
    1811                 : 
    1812                 : static JS_ALWAYS_INLINE jsval
    1813         3452194 : PRIVATE_TO_JSVAL(void *ptr)
    1814                 : {
    1815         3452194 :     return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr));
    1816                 : }
    1817                 : 
    1818                 : static JS_ALWAYS_INLINE void *
    1819        13443545 : JSVAL_TO_PRIVATE(jsval v)
    1820                 : {
    1821        13443545 :     JS_ASSERT(JSVAL_IS_DOUBLE(v));
    1822        13443545 :     return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v));
    1823                 : }
    1824                 : 
    1825                 : /************************************************************************/
    1826                 : 
    1827                 : /*
    1828                 :  * A jsid is an identifier for a property or method of an object which is
    1829                 :  * either a 31-bit signed integer, interned string or object. If XML is
    1830                 :  * enabled, there is an additional singleton jsid value; see
    1831                 :  * JS_DEFAULT_XML_NAMESPACE_ID below. Finally, there is an additional jsid
    1832                 :  * value, JSID_VOID, which does not occur in JS scripts but may be used to
    1833                 :  * indicate the absence of a valid jsid.
    1834                 :  *
    1835                 :  * A jsid is not implicitly convertible to or from a jsval; JS_ValueToId or
    1836                 :  * JS_IdToValue must be used instead.
    1837                 :  */
    1838                 : 
    1839                 : #define JSID_TYPE_STRING                 0x0
    1840                 : #define JSID_TYPE_INT                    0x1
    1841                 : #define JSID_TYPE_VOID                   0x2
    1842                 : #define JSID_TYPE_OBJECT                 0x4
    1843                 : #define JSID_TYPE_DEFAULT_XML_NAMESPACE  0x6
    1844                 : #define JSID_TYPE_MASK                   0x7
    1845                 : 
    1846                 : /*
    1847                 :  * Avoid using canonical 'id' for jsid parameters since this is a magic word in
    1848                 :  * Objective-C++ which, apparently, wants to be able to #include jsapi.h.
    1849                 :  */
    1850                 : #define id iden
    1851                 : 
    1852                 : static JS_ALWAYS_INLINE JSBool
    1853         1457283 : JSID_IS_STRING(jsid id)
    1854                 : {
    1855         1457283 :     return (JSID_BITS(id) & JSID_TYPE_MASK) == 0;
    1856                 : }
    1857                 : 
    1858                 : static JS_ALWAYS_INLINE JSString *
    1859          634128 : JSID_TO_STRING(jsid id)
    1860                 : {
    1861          634128 :     JS_ASSERT(JSID_IS_STRING(id));
    1862          634128 :     return (JSString *)JSID_BITS(id);
    1863                 : }
    1864                 : 
    1865                 : static JS_ALWAYS_INLINE JSBool
    1866                 : JSID_IS_ZERO(jsid id)
    1867                 : {
    1868                 :     return JSID_BITS(id) == 0;
    1869                 : }
    1870                 : 
    1871                 : JS_PUBLIC_API(JSBool)
    1872                 : JS_StringHasBeenInterned(JSContext *cx, JSString *str);
    1873                 : 
    1874                 : /*
    1875                 :  * Only JSStrings that have been interned via the JSAPI can be turned into
    1876                 :  * jsids by API clients.
    1877                 :  *
    1878                 :  * N.B. if a jsid is backed by a string which has not been interned, that
    1879                 :  * string must be appropriately rooted to avoid being collected by the GC.
    1880                 :  */
    1881                 : static JS_ALWAYS_INLINE jsid
    1882         2103261 : INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str)
    1883                 : {
    1884                 :     jsid id;
    1885         2103261 :     JS_ASSERT(str);
    1886         2103261 :     JS_ASSERT(((size_t)str & JSID_TYPE_MASK) == 0);
    1887                 : #ifdef DEBUG
    1888         2103261 :     JS_ASSERT(JS_StringHasBeenInterned(cx, str));
    1889                 : #else
    1890                 :     (void)cx;
    1891                 : #endif
    1892         2103261 :     JSID_BITS(id) = (size_t)str;
    1893                 :     return id;
    1894                 : }
    1895                 : 
    1896                 : static JS_ALWAYS_INLINE JSBool
    1897          170735 : JSID_IS_INT(jsid id)
    1898                 : {
    1899          170735 :     return !!(JSID_BITS(id) & JSID_TYPE_INT);
    1900                 : }
    1901                 : 
    1902                 : static JS_ALWAYS_INLINE int32_t
    1903            2819 : JSID_TO_INT(jsid id)
    1904                 : {
    1905            2819 :     JS_ASSERT(JSID_IS_INT(id));
    1906            2819 :     return ((int32_t)JSID_BITS(id)) >> 1;
    1907                 : }
    1908                 : 
    1909                 : /*
    1910                 :  * Note: when changing these values, verify that their use in
    1911                 :  * js_CheckForStringIndex is still valid.
    1912                 :  */
    1913                 : #define JSID_INT_MIN  (-(1 << 30))
    1914                 : #define JSID_INT_MAX  ((1 << 30) - 1)
    1915                 : 
    1916                 : static JS_ALWAYS_INLINE JSBool
    1917               0 : INT_FITS_IN_JSID(int32_t i)
    1918                 : {
    1919                 :     return ((uint32_t)(i) - (uint32_t)JSID_INT_MIN <=
    1920               0 :             (uint32_t)(JSID_INT_MAX - JSID_INT_MIN));
    1921                 : }
    1922                 : 
    1923                 : static JS_ALWAYS_INLINE jsid
    1924               0 : INT_TO_JSID(int32_t i)
    1925                 : {
    1926                 :     jsid id;
    1927               0 :     JS_ASSERT(INT_FITS_IN_JSID(i));
    1928               0 :     JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT);
    1929                 :     return id;
    1930                 : }
    1931                 : 
    1932                 : static JS_ALWAYS_INLINE JSBool
    1933               1 : JSID_IS_OBJECT(jsid id)
    1934                 : {
    1935                 :     return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT &&
    1936               1 :            (size_t)JSID_BITS(id) != JSID_TYPE_OBJECT;
    1937                 : }
    1938                 : 
    1939                 : static JS_ALWAYS_INLINE JSObject *
    1940               0 : JSID_TO_OBJECT(jsid id)
    1941                 : {
    1942               0 :     JS_ASSERT(JSID_IS_OBJECT(id));
    1943               0 :     return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK);
    1944                 : }
    1945                 : 
    1946                 : static JS_ALWAYS_INLINE jsid
    1947                 : OBJECT_TO_JSID(JSObject *obj)
    1948                 : {
    1949                 :     jsid id;
    1950                 :     JS_ASSERT(obj != NULL);
    1951                 :     JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0);
    1952                 :     JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT);
    1953                 :     return id;
    1954                 : }
    1955                 : 
    1956                 : static JS_ALWAYS_INLINE JSBool
    1957                 : JSID_IS_GCTHING(jsid id)
    1958                 : {
    1959                 :     return JSID_IS_STRING(id) || JSID_IS_OBJECT(id);
    1960                 : }
    1961                 : 
    1962                 : static JS_ALWAYS_INLINE void *
    1963                 : JSID_TO_GCTHING(jsid id)
    1964                 : {
    1965                 :     return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK);
    1966                 : }
    1967                 : 
    1968                 : /*
    1969                 :  * The magic XML namespace id is not a valid jsid. Global object classes in
    1970                 :  * embeddings that enable JS_HAS_XML_SUPPORT (E4X) should handle this id.
    1971                 :  */
    1972                 : 
    1973                 : static JS_ALWAYS_INLINE JSBool
    1974               0 : JSID_IS_DEFAULT_XML_NAMESPACE(jsid id)
    1975                 : {
    1976               0 :     JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_DEFAULT_XML_NAMESPACE,
    1977               0 :                  JSID_BITS(id) == JSID_TYPE_DEFAULT_XML_NAMESPACE);
    1978               0 :     return ((size_t)JSID_BITS(id) == JSID_TYPE_DEFAULT_XML_NAMESPACE);
    1979                 : }
    1980                 : 
    1981                 : #ifdef JS_USE_JSID_STRUCT_TYPES
    1982                 : extern JS_PUBLIC_DATA(jsid) JS_DEFAULT_XML_NAMESPACE_ID;
    1983                 : #else
    1984                 : # define JS_DEFAULT_XML_NAMESPACE_ID ((jsid)JSID_TYPE_DEFAULT_XML_NAMESPACE)
    1985                 : #endif
    1986                 : 
    1987                 : /*
    1988                 :  * A void jsid is not a valid id and only arises as an exceptional API return
    1989                 :  * value, such as in JS_NextProperty. Embeddings must not pass JSID_VOID into
    1990                 :  * JSAPI entry points expecting a jsid and do not need to handle JSID_VOID in
    1991                 :  * hooks receiving a jsid except when explicitly noted in the API contract.
    1992                 :  */
    1993                 : 
    1994                 : static JS_ALWAYS_INLINE JSBool
    1995        12226294 : JSID_IS_VOID(jsid id)
    1996                 : {
    1997               0 :     JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID,
    1998        12226294 :                  JSID_BITS(id) == JSID_TYPE_VOID);
    1999        12226294 :     return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID);
    2000                 : }
    2001                 : 
    2002                 : static JS_ALWAYS_INLINE JSBool
    2003                 : JSID_IS_EMPTY(jsid id)
    2004                 : {
    2005                 :     return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT);
    2006                 : }
    2007                 : 
    2008                 : #undef id
    2009                 : 
    2010                 : #ifdef JS_USE_JSID_STRUCT_TYPES
    2011                 : extern JS_PUBLIC_DATA(jsid) JSID_VOID;
    2012                 : extern JS_PUBLIC_DATA(jsid) JSID_EMPTY;
    2013                 : #else
    2014                 : # define JSID_VOID ((jsid)JSID_TYPE_VOID)
    2015                 : # define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT)
    2016                 : #endif
    2017                 : 
    2018                 : /*
    2019                 :  * Returns true iff the given jsval is immune to GC and can be used across
    2020                 :  * multiple JSRuntimes without requiring any conversion API.
    2021                 :  */
    2022                 : static JS_ALWAYS_INLINE JSBool
    2023               0 : JSVAL_IS_UNIVERSAL(jsval v)
    2024                 : {
    2025               0 :     return !JSVAL_IS_GCTHING(v);
    2026                 : }
    2027                 : 
    2028                 : #ifdef __cplusplus
    2029                 : 
    2030                 : namespace JS {
    2031                 : 
    2032                 : class AutoIdRooter : private AutoGCRooter
    2033                 : {
    2034                 :   public:
    2035                 :     explicit AutoIdRooter(JSContext *cx, jsid id = INT_TO_JSID(0)
    2036                 :                           JS_GUARD_OBJECT_NOTIFIER_PARAM)
    2037                 :       : AutoGCRooter(cx, ID), id_(id)
    2038                 :     {
    2039                 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    2040                 :     }
    2041                 : 
    2042                 :     jsid id() {
    2043                 :         return id_;
    2044                 :     }
    2045                 : 
    2046                 :     jsid * addr() {
    2047                 :         return &id_;
    2048                 :     }
    2049                 : 
    2050                 :     friend void AutoGCRooter::trace(JSTracer *trc);
    2051                 : 
    2052                 :   private:
    2053                 :     jsid id_;
    2054                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    2055                 : };
    2056                 : 
    2057                 : } /* namespace JS */
    2058                 : 
    2059                 : #endif /* __cplusplus */
    2060                 : 
    2061                 : /************************************************************************/
    2062                 : 
    2063                 : /* Lock and unlock the GC thing held by a jsval. */
    2064                 : #define JSVAL_LOCK(cx,v)        (JSVAL_IS_GCTHING(v)                          \
    2065                 :                                  ? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v))    \
    2066                 :                                  : JS_TRUE)
    2067                 : #define JSVAL_UNLOCK(cx,v)      (JSVAL_IS_GCTHING(v)                          \
    2068                 :                                  ? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v))  \
    2069                 :                                  : JS_TRUE)
    2070                 : 
    2071                 : /* Property attributes, set in JSPropertySpec and passed to API functions. */
    2072                 : #define JSPROP_ENUMERATE        0x01    /* property is visible to for/in loop */
    2073                 : #define JSPROP_READONLY         0x02    /* not settable: assignment is no-op.
    2074                 :                                            This flag is only valid when neither
    2075                 :                                            JSPROP_GETTER nor JSPROP_SETTER is
    2076                 :                                            set. */
    2077                 : #define JSPROP_PERMANENT        0x04    /* property cannot be deleted */
    2078                 : #define JSPROP_GETTER           0x10    /* property holds getter function */
    2079                 : #define JSPROP_SETTER           0x20    /* property holds setter function */
    2080                 : #define JSPROP_SHARED           0x40    /* don't allocate a value slot for this
    2081                 :                                            property; don't copy the property on
    2082                 :                                            set of the same-named property in an
    2083                 :                                            object that delegates to a prototype
    2084                 :                                            containing this property */
    2085                 : #define JSPROP_INDEX            0x80    /* name is actually (int) index */
    2086                 : #define JSPROP_SHORTID          0x100   /* set in JS_DefineProperty attrs
    2087                 :                                            if getters/setters use a shortid */
    2088                 : #define JSPROP_NATIVE_ACCESSORS 0x08    /* set in JSPropertyDescriptor.flags
    2089                 :                                            if getters/setters are JSNatives */
    2090                 : 
    2091                 : /* Function flags, internal use only, returned by JS_GetFunctionFlags. */
    2092                 : #define JSFUN_LAMBDA            0x08    /* expressed, not declared, function */
    2093                 : #define JSFUN_HEAVYWEIGHT       0x80    /* activation requires a Call object */
    2094                 : 
    2095                 : #define JSFUN_HEAVYWEIGHT_TEST(f)  ((f) & JSFUN_HEAVYWEIGHT)
    2096                 : 
    2097                 : /* 0x0100 is unused */
    2098                 : #define JSFUN_CONSTRUCTOR     0x0200    /* native that can be called as a ctor
    2099                 :                                            without creating a this object */
    2100                 : 
    2101                 : #define JSFUN_FLAGS_MASK      0x07f8    /* overlay JSFUN_* attributes --
    2102                 :                                            bits 12-15 are used internally to
    2103                 :                                            flag interpreted functions */
    2104                 : 
    2105                 : #define JSFUN_STUB_GSOPS      0x1000    /* use JS_PropertyStub getter/setter
    2106                 :                                            instead of defaulting to class gsops
    2107                 :                                            for property holding function */
    2108                 : 
    2109                 : /*
    2110                 :  * Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
    2111                 :  * JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
    2112                 :  * methods of a class prototype that are exposed as static methods taking an
    2113                 :  * extra leading argument: the generic |this| parameter.
    2114                 :  *
    2115                 :  * If you set this flag in a JSFunctionSpec struct's flags initializer, then
    2116                 :  * that struct must live at least as long as the native static method object
    2117                 :  * created due to this flag by JS_DefineFunctions or JS_InitClass.  Typically
    2118                 :  * JSFunctionSpec structs are allocated in static arrays.
    2119                 :  */
    2120                 : #define JSFUN_GENERIC_NATIVE    JSFUN_LAMBDA
    2121                 : 
    2122                 : /*
    2123                 :  * The first call to JS_CallOnce by any thread in a process will call 'func'.
    2124                 :  * Later calls to JS_CallOnce with the same JSCallOnceType object will be
    2125                 :  * suppressed.
    2126                 :  *
    2127                 :  * Equivalently: each distinct JSCallOnceType object will allow one JS_CallOnce
    2128                 :  * to invoke its JSInitCallback.
    2129                 :  */
    2130                 : extern JS_PUBLIC_API(JSBool)
    2131                 : JS_CallOnce(JSCallOnceType *once, JSInitCallback func);
    2132                 : 
    2133                 : /* Microseconds since the epoch, midnight, January 1, 1970 UTC. */
    2134                 : extern JS_PUBLIC_API(int64_t)
    2135                 : JS_Now(void);
    2136                 : 
    2137                 : /* Don't want to export data, so provide accessors for non-inline jsvals. */
    2138                 : extern JS_PUBLIC_API(jsval)
    2139                 : JS_GetNaNValue(JSContext *cx);
    2140                 : 
    2141                 : extern JS_PUBLIC_API(jsval)
    2142                 : JS_GetNegativeInfinityValue(JSContext *cx);
    2143                 : 
    2144                 : extern JS_PUBLIC_API(jsval)
    2145                 : JS_GetPositiveInfinityValue(JSContext *cx);
    2146                 : 
    2147                 : extern JS_PUBLIC_API(jsval)
    2148                 : JS_GetEmptyStringValue(JSContext *cx);
    2149                 : 
    2150                 : extern JS_PUBLIC_API(JSString *)
    2151                 : JS_GetEmptyString(JSRuntime *rt);
    2152                 : 
    2153                 : /*
    2154                 :  * Format is a string of the following characters (spaces are insignificant),
    2155                 :  * specifying the tabulated type conversions:
    2156                 :  *
    2157                 :  *   b      JSBool          Boolean
    2158                 :  *   c      uint16_t/jschar ECMA uint16_t, Unicode char
    2159                 :  *   i      int32_t         ECMA int32_t
    2160                 :  *   u      uint32_t        ECMA uint32_t
    2161                 :  *   j      int32_t         Rounded int32_t (coordinate)
    2162                 :  *   d      double          IEEE double
    2163                 :  *   I      double          Integral IEEE double
    2164                 :  *   S      JSString *      Unicode string, accessed by a JSString pointer
    2165                 :  *   W      jschar *        Unicode character vector, 0-terminated (W for wide)
    2166                 :  *   o      JSObject *      Object reference
    2167                 :  *   f      JSFunction *    Function private
    2168                 :  *   v      jsval           Argument value (no conversion)
    2169                 :  *   *      N/A             Skip this argument (no vararg)
    2170                 :  *   /      N/A             End of required arguments
    2171                 :  *
    2172                 :  * The variable argument list after format must consist of &b, &c, &s, e.g.,
    2173                 :  * where those variables have the types given above.  For the pointer types
    2174                 :  * char *, JSString *, and JSObject *, the pointed-at memory returned belongs
    2175                 :  * to the JS runtime, not to the calling native code.  The runtime promises
    2176                 :  * to keep this memory valid so long as argv refers to allocated stack space
    2177                 :  * (so long as the native function is active).
    2178                 :  *
    2179                 :  * Fewer arguments than format specifies may be passed only if there is a /
    2180                 :  * in format after the last required argument specifier and argc is at least
    2181                 :  * the number of required arguments.  More arguments than format specifies
    2182                 :  * may be passed without error; it is up to the caller to deal with trailing
    2183                 :  * unconverted arguments.
    2184                 :  */
    2185                 : extern JS_PUBLIC_API(JSBool)
    2186                 : JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format,
    2187                 :                     ...);
    2188                 : 
    2189                 : #ifdef va_start
    2190                 : extern JS_PUBLIC_API(JSBool)
    2191                 : JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv,
    2192                 :                       const char *format, va_list ap);
    2193                 : #endif
    2194                 : 
    2195                 : #ifdef JS_ARGUMENT_FORMATTER_DEFINED
    2196                 : 
    2197                 : /*
    2198                 :  * Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
    2199                 :  * The handler function has this signature:
    2200                 :  *
    2201                 :  *   JSBool MyArgumentFormatter(JSContext *cx, const char *format,
    2202                 :  *                              JSBool fromJS, jsval **vpp, va_list *app);
    2203                 :  *
    2204                 :  * It should return true on success, and return false after reporting an error
    2205                 :  * or detecting an already-reported error.
    2206                 :  *
    2207                 :  * For a given format string, for example "AA", the formatter is called from
    2208                 :  * JS_ConvertArgumentsVA like so:
    2209                 :  *
    2210                 :  *   formatter(cx, "AA...", JS_TRUE, &sp, &ap);
    2211                 :  *
    2212                 :  * sp points into the arguments array on the JS stack, while ap points into
    2213                 :  * the stdarg.h va_list on the C stack.  The JS_TRUE passed for fromJS tells
    2214                 :  * the formatter to convert zero or more jsvals at sp to zero or more C values
    2215                 :  * accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
    2216                 :  * (via *app) to point past the converted arguments and their result pointers
    2217                 :  * on the C stack.
    2218                 :  *
    2219                 :  * When called from JS_PushArgumentsVA, the formatter is invoked thus:
    2220                 :  *
    2221                 :  *   formatter(cx, "AA...", JS_FALSE, &sp, &ap);
    2222                 :  *
    2223                 :  * where JS_FALSE for fromJS means to wrap the C values at ap according to the
    2224                 :  * format specifier and store them at sp, updating ap and sp appropriately.
    2225                 :  *
    2226                 :  * The "..." after "AA" is the rest of the format string that was passed into
    2227                 :  * JS_{Convert,Push}Arguments{,VA}.  The actual format trailing substring used
    2228                 :  * in each Convert or PushArguments call is passed to the formatter, so that
    2229                 :  * one such function may implement several formats, in order to share code.
    2230                 :  *
    2231                 :  * Remove just forgets about any handler associated with format.  Add does not
    2232                 :  * copy format, it points at the string storage allocated by the caller, which
    2233                 :  * is typically a string constant.  If format is in dynamic storage, it is up
    2234                 :  * to the caller to keep the string alive until Remove is called.
    2235                 :  */
    2236                 : extern JS_PUBLIC_API(JSBool)
    2237                 : JS_AddArgumentFormatter(JSContext *cx, const char *format,
    2238                 :                         JSArgumentFormatter formatter);
    2239                 : 
    2240                 : extern JS_PUBLIC_API(void)
    2241                 : JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
    2242                 : 
    2243                 : #endif /* JS_ARGUMENT_FORMATTER_DEFINED */
    2244                 : 
    2245                 : extern JS_PUBLIC_API(JSBool)
    2246                 : JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
    2247                 : 
    2248                 : extern JS_PUBLIC_API(JSBool)
    2249                 : JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
    2250                 : 
    2251                 : extern JS_PUBLIC_API(JSFunction *)
    2252                 : JS_ValueToFunction(JSContext *cx, jsval v);
    2253                 : 
    2254                 : extern JS_PUBLIC_API(JSFunction *)
    2255                 : JS_ValueToConstructor(JSContext *cx, jsval v);
    2256                 : 
    2257                 : extern JS_PUBLIC_API(JSString *)
    2258                 : JS_ValueToString(JSContext *cx, jsval v);
    2259                 : 
    2260                 : extern JS_PUBLIC_API(JSString *)
    2261                 : JS_ValueToSource(JSContext *cx, jsval v);
    2262                 : 
    2263                 : extern JS_PUBLIC_API(JSBool)
    2264                 : JS_ValueToNumber(JSContext *cx, jsval v, double *dp);
    2265                 : 
    2266                 : extern JS_PUBLIC_API(JSBool)
    2267                 : JS_DoubleIsInt32(double d, int32_t *ip);
    2268                 : 
    2269                 : extern JS_PUBLIC_API(int32_t)
    2270                 : JS_DoubleToInt32(double d);
    2271                 : 
    2272                 : extern JS_PUBLIC_API(uint32_t)
    2273                 : JS_DoubleToUint32(double d);
    2274                 : 
    2275                 : /*
    2276                 :  * Convert a value to a number, then to an int32_t, according to the ECMA rules
    2277                 :  * for ToInt32.
    2278                 :  */
    2279                 : extern JS_PUBLIC_API(JSBool)
    2280                 : JS_ValueToECMAInt32(JSContext *cx, jsval v, int32_t *ip);
    2281                 : 
    2282                 : /*
    2283                 :  * Convert a value to a number, then to a uint32_t, according to the ECMA rules
    2284                 :  * for ToUint32.
    2285                 :  */
    2286                 : extern JS_PUBLIC_API(JSBool)
    2287                 : JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32_t *ip);
    2288                 : 
    2289                 : /*
    2290                 :  * Convert a value to a number, then to an int32_t if it fits by rounding to
    2291                 :  * nearest; but failing with an error report if the double is out of range
    2292                 :  * or unordered.
    2293                 :  */
    2294                 : extern JS_PUBLIC_API(JSBool)
    2295                 : JS_ValueToInt32(JSContext *cx, jsval v, int32_t *ip);
    2296                 : 
    2297                 : /*
    2298                 :  * ECMA ToUint16, for mapping a jsval to a Unicode point.
    2299                 :  */
    2300                 : extern JS_PUBLIC_API(JSBool)
    2301                 : JS_ValueToUint16(JSContext *cx, jsval v, uint16_t *ip);
    2302                 : 
    2303                 : extern JS_PUBLIC_API(JSBool)
    2304                 : JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
    2305                 : 
    2306                 : extern JS_PUBLIC_API(JSType)
    2307                 : JS_TypeOfValue(JSContext *cx, jsval v);
    2308                 : 
    2309                 : extern JS_PUBLIC_API(const char *)
    2310                 : JS_GetTypeName(JSContext *cx, JSType type);
    2311                 : 
    2312                 : extern JS_PUBLIC_API(JSBool)
    2313                 : JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal);
    2314                 : 
    2315                 : extern JS_PUBLIC_API(JSBool)
    2316                 : JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal);
    2317                 : 
    2318                 : extern JS_PUBLIC_API(JSBool)
    2319                 : JS_SameValue(JSContext *cx, jsval v1, jsval v2, JSBool *same);
    2320                 : 
    2321                 : /* True iff fun is the global eval function. */
    2322                 : extern JS_PUBLIC_API(JSBool)
    2323                 : JS_IsBuiltinEvalFunction(JSFunction *fun);
    2324                 : 
    2325                 : /* True iff fun is the Function constructor. */
    2326                 : extern JS_PUBLIC_API(JSBool)
    2327                 : JS_IsBuiltinFunctionConstructor(JSFunction *fun);
    2328                 : 
    2329                 : /************************************************************************/
    2330                 : 
    2331                 : /*
    2332                 :  * Initialization, locking, contexts, and memory allocation.
    2333                 :  *
    2334                 :  * It is important that the first runtime and first context be created in a
    2335                 :  * single-threaded fashion, otherwise the behavior of the library is undefined.
    2336                 :  * See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
    2337                 :  */
    2338                 : #define JS_NewRuntime       JS_Init
    2339                 : #define JS_DestroyRuntime   JS_Finish
    2340                 : #define JS_LockRuntime      JS_Lock
    2341                 : #define JS_UnlockRuntime    JS_Unlock
    2342                 : 
    2343                 : extern JS_PUBLIC_API(JSRuntime *)
    2344                 : JS_NewRuntime(uint32_t maxbytes);
    2345                 : 
    2346                 : /* Deprecated. */
    2347                 : #define JS_CommenceRuntimeShutDown(rt) ((void) 0)
    2348                 : 
    2349                 : extern JS_PUBLIC_API(void)
    2350                 : JS_DestroyRuntime(JSRuntime *rt);
    2351                 : 
    2352                 : extern JS_PUBLIC_API(void)
    2353                 : JS_ShutDown(void);
    2354                 : 
    2355                 : JS_PUBLIC_API(void *)
    2356                 : JS_GetRuntimePrivate(JSRuntime *rt);
    2357                 : 
    2358                 : extern JS_PUBLIC_API(JSRuntime *)
    2359                 : JS_GetRuntime(JSContext *cx);
    2360                 : 
    2361                 : JS_PUBLIC_API(void)
    2362                 : JS_SetRuntimePrivate(JSRuntime *rt, void *data);
    2363                 : 
    2364                 : extern JS_PUBLIC_API(void)
    2365                 : JS_BeginRequest(JSContext *cx);
    2366                 : 
    2367                 : extern JS_PUBLIC_API(void)
    2368                 : JS_EndRequest(JSContext *cx);
    2369                 : 
    2370                 : /* Yield to pending GC operations, regardless of request depth */
    2371                 : extern JS_PUBLIC_API(void)
    2372                 : JS_YieldRequest(JSContext *cx);
    2373                 : 
    2374                 : extern JS_PUBLIC_API(unsigned)
    2375                 : JS_SuspendRequest(JSContext *cx);
    2376                 : 
    2377                 : extern JS_PUBLIC_API(void)
    2378                 : JS_ResumeRequest(JSContext *cx, unsigned saveDepth);
    2379                 : 
    2380                 : extern JS_PUBLIC_API(JSBool)
    2381                 : JS_IsInRequest(JSRuntime *rt);
    2382                 : 
    2383                 : extern JS_PUBLIC_API(JSBool)
    2384                 : JS_IsInSuspendedRequest(JSRuntime *rt);
    2385                 : 
    2386                 : #ifdef __cplusplus
    2387                 : JS_END_EXTERN_C
    2388                 : 
    2389                 : inline bool
    2390                 : IsPoisonedId(jsid iden)
    2391                 : {
    2392                 :     if (JSID_IS_STRING(iden))
    2393                 :         return JS::IsPoisonedPtr(JSID_TO_STRING(iden));
    2394                 :     if (JSID_IS_OBJECT(iden))
    2395                 :         return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden));
    2396                 :     return false;
    2397                 : }
    2398                 : 
    2399                 : class JSAutoRequest {
    2400                 :   public:
    2401          522992 :     JSAutoRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
    2402          522992 :         : mContext(cx), mSaveDepth(0) {
    2403          522992 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    2404          522992 :         JS_BeginRequest(mContext);
    2405          522992 :     }
    2406         1045984 :     ~JSAutoRequest() {
    2407          522992 :         JS_EndRequest(mContext);
    2408          522992 :     }
    2409                 : 
    2410                 :     void suspend() {
    2411                 :         mSaveDepth = JS_SuspendRequest(mContext);
    2412                 :     }
    2413                 :     void resume() {
    2414                 :         JS_ResumeRequest(mContext, mSaveDepth);
    2415                 :     }
    2416                 : 
    2417                 :   protected:
    2418                 :     JSContext *mContext;
    2419                 :     unsigned  mSaveDepth;
    2420                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    2421                 : 
    2422                 : #if 0
    2423                 :   private:
    2424                 :     static void *operator new(size_t) CPP_THROW_NEW { return 0; };
    2425                 :     static void operator delete(void *, size_t) { };
    2426                 : #endif
    2427                 : };
    2428                 : 
    2429                 : class JSAutoSuspendRequest {
    2430                 :   public:
    2431            5977 :     JSAutoSuspendRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
    2432            5977 :         : mContext(cx), mSaveDepth(0) {
    2433            5977 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    2434            5977 :         if (mContext) {
    2435            5977 :             mSaveDepth = JS_SuspendRequest(mContext);
    2436                 :         }
    2437            5977 :     }
    2438           11954 :     ~JSAutoSuspendRequest() {
    2439            5977 :         resume();
    2440            5977 :     }
    2441                 : 
    2442            5977 :     void resume() {
    2443            5977 :         if (mContext) {
    2444            5977 :             JS_ResumeRequest(mContext, mSaveDepth);
    2445            5977 :             mContext = 0;
    2446                 :         }
    2447            5977 :     }
    2448                 : 
    2449                 :   protected:
    2450                 :     JSContext *mContext;
    2451                 :     unsigned mSaveDepth;
    2452                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    2453                 : 
    2454                 : #if 0
    2455                 :   private:
    2456                 :     static void *operator new(size_t) CPP_THROW_NEW { return 0; };
    2457                 :     static void operator delete(void *, size_t) { };
    2458                 : #endif
    2459                 : };
    2460                 : 
    2461                 : class JSAutoCheckRequest {
    2462                 :   public:
    2463                 :     JSAutoCheckRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM) {
    2464                 : #if defined JS_THREADSAFE && defined DEBUG
    2465                 :         mContext = cx;
    2466                 :         JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx)));
    2467                 : #endif
    2468                 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    2469                 :     }
    2470                 : 
    2471                 :     ~JSAutoCheckRequest() {
    2472                 : #if defined JS_THREADSAFE && defined DEBUG
    2473                 :         JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext)));
    2474                 : #endif
    2475                 :     }
    2476                 : 
    2477                 : 
    2478                 :   private:
    2479                 : #if defined JS_THREADSAFE && defined DEBUG
    2480                 :     JSContext *mContext;
    2481                 : #endif
    2482                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    2483                 : };
    2484                 : 
    2485                 : JS_BEGIN_EXTERN_C
    2486                 : #endif
    2487                 : 
    2488                 : extern JS_PUBLIC_API(JSContextCallback)
    2489                 : JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
    2490                 : 
    2491                 : extern JS_PUBLIC_API(JSContext *)
    2492                 : JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
    2493                 : 
    2494                 : extern JS_PUBLIC_API(void)
    2495                 : JS_DestroyContext(JSContext *cx);
    2496                 : 
    2497                 : extern JS_PUBLIC_API(void)
    2498                 : JS_DestroyContextNoGC(JSContext *cx);
    2499                 : 
    2500                 : extern JS_PUBLIC_API(void)
    2501                 : JS_DestroyContextMaybeGC(JSContext *cx);
    2502                 : 
    2503                 : extern JS_PUBLIC_API(void *)
    2504                 : JS_GetContextPrivate(JSContext *cx);
    2505                 : 
    2506                 : extern JS_PUBLIC_API(void)
    2507                 : JS_SetContextPrivate(JSContext *cx, void *data);
    2508                 : 
    2509                 : extern JS_PUBLIC_API(void *)
    2510                 : JS_GetSecondContextPrivate(JSContext *cx);
    2511                 : 
    2512                 : extern JS_PUBLIC_API(void)
    2513                 : JS_SetSecondContextPrivate(JSContext *cx, void *data);
    2514                 : 
    2515                 : extern JS_PUBLIC_API(JSRuntime *)
    2516                 : JS_GetRuntime(JSContext *cx);
    2517                 : 
    2518                 : extern JS_PUBLIC_API(JSContext *)
    2519                 : JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
    2520                 : 
    2521                 : extern JS_PUBLIC_API(JSVersion)
    2522                 : JS_GetVersion(JSContext *cx);
    2523                 : 
    2524                 : extern JS_PUBLIC_API(JSVersion)
    2525                 : JS_SetVersion(JSContext *cx, JSVersion version);
    2526                 : 
    2527                 : extern JS_PUBLIC_API(const char *)
    2528                 : JS_VersionToString(JSVersion version);
    2529                 : 
    2530                 : extern JS_PUBLIC_API(JSVersion)
    2531                 : JS_StringToVersion(const char *string);
    2532                 : 
    2533                 : /*
    2534                 :  * JS options are orthogonal to version, and may be freely composed with one
    2535                 :  * another as well as with version.
    2536                 :  *
    2537                 :  * JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
    2538                 :  * prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
    2539                 :  */
    2540                 : #define JSOPTION_STRICT         JS_BIT(0)       /* warn on dubious practice */
    2541                 : #define JSOPTION_WERROR         JS_BIT(1)       /* convert warning to error */
    2542                 : #define JSOPTION_VAROBJFIX      JS_BIT(2)       /* make JS_EvaluateScript use
    2543                 :                                                    the last object on its 'obj'
    2544                 :                                                    param's scope chain as the
    2545                 :                                                    ECMA 'variables object' */
    2546                 : #define JSOPTION_PRIVATE_IS_NSISUPPORTS \
    2547                 :                                 JS_BIT(3)       /* context private data points
    2548                 :                                                    to an nsISupports subclass */
    2549                 : #define JSOPTION_COMPILE_N_GO   JS_BIT(4)       /* caller of JS_Compile*Script
    2550                 :                                                    promises to execute compiled
    2551                 :                                                    script once only; enables
    2552                 :                                                    compile-time scope chain
    2553                 :                                                    resolution of consts. */
    2554                 : #define JSOPTION_ATLINE         JS_BIT(5)       /* //@line number ["filename"]
    2555                 :                                                    option supported for the
    2556                 :                                                    XUL preprocessor and kindred
    2557                 :                                                    beasts. */
    2558                 : #define JSOPTION_XML            JS_BIT(6)       /* EMCAScript for XML support:
    2559                 :                                                    parse <!-- --> as a token,
    2560                 :                                                    not backward compatible with
    2561                 :                                                    the comment-hiding hack used
    2562                 :                                                    in HTML script tags. */
    2563                 : #define JSOPTION_DONT_REPORT_UNCAUGHT \
    2564                 :                                 JS_BIT(8)       /* When returning from the
    2565                 :                                                    outermost API call, prevent
    2566                 :                                                    uncaught exceptions from
    2567                 :                                                    being converted to error
    2568                 :                                                    reports */
    2569                 : 
    2570                 : #define JSOPTION_RELIMIT        JS_BIT(9)       /* Throw exception on any
    2571                 :                                                    regular expression which
    2572                 :                                                    backtracks more than n^3
    2573                 :                                                    times, where n is length
    2574                 :                                                    of the input string */
    2575                 : /* JS_BIT(10) is currently unused. */
    2576                 : 
    2577                 : /* JS_BIT(11) is currently unused. */
    2578                 : 
    2579                 : #define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12)      /* A promise to the compiler
    2580                 :                                                    that a null rval out-param
    2581                 :                                                    will be passed to each call
    2582                 :                                                    to JS_ExecuteScript. */
    2583                 : #define JSOPTION_UNROOTED_GLOBAL JS_BIT(13)     /* The GC will not root the
    2584                 :                                                    contexts' global objects
    2585                 :                                                    (see JS_GetGlobalObject),
    2586                 :                                                    leaving that up to the
    2587                 :                                                    embedding. */
    2588                 : 
    2589                 : #define JSOPTION_METHODJIT      JS_BIT(14)      /* Whole-method JIT. */
    2590                 : 
    2591                 : /* JS_BIT(15) is currently unused. */
    2592                 : 
    2593                 : #define JSOPTION_METHODJIT_ALWAYS \
    2594                 :                                 JS_BIT(16)      /* Always whole-method JIT,
    2595                 :                                                    don't tune at run-time. */
    2596                 : #define JSOPTION_PCCOUNT        JS_BIT(17)      /* Collect per-op execution counts */
    2597                 : 
    2598                 : #define JSOPTION_TYPE_INFERENCE JS_BIT(18)      /* Perform type inference. */
    2599                 : 
    2600                 : /* Options which reflect compile-time properties of scripts. */
    2601                 : #define JSCOMPILEOPTION_MASK    (JSOPTION_XML)
    2602                 : 
    2603                 : #define JSRUNOPTION_MASK        (JS_BITMASK(19) & ~JSCOMPILEOPTION_MASK)
    2604                 : #define JSALLOPTION_MASK        (JSCOMPILEOPTION_MASK | JSRUNOPTION_MASK)
    2605                 : 
    2606                 : extern JS_PUBLIC_API(uint32_t)
    2607                 : JS_GetOptions(JSContext *cx);
    2608                 : 
    2609                 : extern JS_PUBLIC_API(uint32_t)
    2610                 : JS_SetOptions(JSContext *cx, uint32_t options);
    2611                 : 
    2612                 : extern JS_PUBLIC_API(uint32_t)
    2613                 : JS_ToggleOptions(JSContext *cx, uint32_t options);
    2614                 : 
    2615                 : extern JS_PUBLIC_API(void)
    2616                 : JS_SetJitHardening(JSRuntime *rt, JSBool enabled);
    2617                 : 
    2618                 : extern JS_PUBLIC_API(const char *)
    2619                 : JS_GetImplementationVersion(void);
    2620                 : 
    2621                 : extern JS_PUBLIC_API(JSCompartmentCallback)
    2622                 : JS_SetCompartmentCallback(JSRuntime *rt, JSCompartmentCallback callback);
    2623                 : 
    2624                 : extern JS_PUBLIC_API(JSWrapObjectCallback)
    2625                 : JS_SetWrapObjectCallbacks(JSRuntime *rt,
    2626                 :                           JSWrapObjectCallback callback,
    2627                 :                           JSPreWrapCallback precallback);
    2628                 : 
    2629                 : extern JS_PUBLIC_API(JSCrossCompartmentCall *)
    2630                 : JS_EnterCrossCompartmentCall(JSContext *cx, JSObject *target);
    2631                 : 
    2632                 : extern JS_PUBLIC_API(void)
    2633                 : JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call);
    2634                 : 
    2635                 : extern JS_PUBLIC_API(void)
    2636                 : JS_SetCompartmentPrivate(JSCompartment *compartment, void *data);
    2637                 : 
    2638                 : extern JS_PUBLIC_API(void *)
    2639                 : JS_GetCompartmentPrivate(JSCompartment *compartment);
    2640                 : 
    2641                 : extern JS_PUBLIC_API(JSBool)
    2642                 : JS_WrapObject(JSContext *cx, JSObject **objp);
    2643                 : 
    2644                 : extern JS_PUBLIC_API(JSBool)
    2645                 : JS_WrapValue(JSContext *cx, jsval *vp);
    2646                 : 
    2647                 : extern JS_PUBLIC_API(JSObject *)
    2648                 : JS_TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target);
    2649                 : 
    2650                 : extern JS_FRIEND_API(JSObject *)
    2651                 : js_TransplantObjectWithWrapper(JSContext *cx,
    2652                 :                                JSObject *origobj,
    2653                 :                                JSObject *origwrapper,
    2654                 :                                JSObject *targetobj,
    2655                 :                                JSObject *targetwrapper);
    2656                 : 
    2657                 : extern JS_FRIEND_API(JSObject *)
    2658                 : js_TransplantObjectWithWrapper(JSContext *cx,
    2659                 :                                JSObject *origobj,
    2660                 :                                JSObject *origwrapper,
    2661                 :                                JSObject *targetobj,
    2662                 :                                JSObject *targetwrapper);
    2663                 : 
    2664                 : #ifdef __cplusplus
    2665                 : JS_END_EXTERN_C
    2666                 : 
    2667                 : class JS_PUBLIC_API(JSAutoEnterCompartment)
    2668                 : {
    2669                 :     /*
    2670                 :      * This is a poor man's Maybe<AutoCompartment>, because we don't have
    2671                 :      * access to the AutoCompartment definition here.  We statically assert in
    2672                 :      * jsapi.cpp that we have the right size here.
    2673                 :      *
    2674                 :      * In practice, 32-bit Windows and Android get 16-word |bytes|, while
    2675                 :      * other platforms get 13-word |bytes|.
    2676                 :      */
    2677                 :     void* bytes[sizeof(void*) == 4 && MOZ_ALIGNOF(uint64_t) == 8 ? 16 : 13];
    2678                 : 
    2679                 :     /*
    2680                 :      * This object may be in one of three states.  If enter() or
    2681                 :      * enterAndIgnoreErrors() hasn't been called, it's in STATE_UNENTERED.
    2682                 :      * Otherwise, if we were asked to enter into the current compartment, our
    2683                 :      * state is STATE_SAME_COMPARTMENT.  If we actually created an
    2684                 :      * AutoCompartment and entered another compartment, our state is
    2685                 :      * STATE_OTHER_COMPARTMENT.
    2686                 :      */
    2687                 :     enum State {
    2688                 :         STATE_UNENTERED,
    2689                 :         STATE_SAME_COMPARTMENT,
    2690                 :         STATE_OTHER_COMPARTMENT
    2691                 :     } state;
    2692                 : 
    2693                 :   public:
    2694         6895096 :     JSAutoEnterCompartment() : state(STATE_UNENTERED) {}
    2695                 : 
    2696                 :     bool enter(JSContext *cx, JSObject *target);
    2697                 : 
    2698                 :     void enterAndIgnoreErrors(JSContext *cx, JSObject *target);
    2699                 : 
    2700                 :     bool entered() const { return state != STATE_UNENTERED; }
    2701                 : 
    2702                 :     ~JSAutoEnterCompartment();
    2703                 : };
    2704                 : 
    2705                 : JS_BEGIN_EXTERN_C
    2706                 : #endif
    2707                 : 
    2708                 : typedef void (*JSIterateCompartmentCallback)(JSRuntime *rt, void *data, JSCompartment *compartment);
    2709                 : 
    2710                 : /*
    2711                 :  * This function calls |compartmentCallback| on every compartment.  Beware that
    2712                 :  * there is no guarantee that the compartment will survive after the callback
    2713                 :  * returns.
    2714                 :  */
    2715                 : extern JS_PUBLIC_API(void)
    2716                 : JS_IterateCompartments(JSRuntime *rt, void *data,
    2717                 :                        JSIterateCompartmentCallback compartmentCallback);
    2718                 : 
    2719                 : extern JS_PUBLIC_API(JSObject *)
    2720                 : JS_GetGlobalObject(JSContext *cx);
    2721                 : 
    2722                 : extern JS_PUBLIC_API(void)
    2723                 : JS_SetGlobalObject(JSContext *cx, JSObject *obj);
    2724                 : 
    2725                 : /*
    2726                 :  * Initialize standard JS class constructors, prototypes, and any top-level
    2727                 :  * functions and constants associated with the standard classes (e.g. isNaN
    2728                 :  * for Number).
    2729                 :  *
    2730                 :  * NB: This sets cx's global object to obj if it was null.
    2731                 :  */
    2732                 : extern JS_PUBLIC_API(JSBool)
    2733                 : JS_InitStandardClasses(JSContext *cx, JSObject *obj);
    2734                 : 
    2735                 : /*
    2736                 :  * Resolve id, which must contain either a string or an int, to a standard
    2737                 :  * class name in obj if possible, defining the class's constructor and/or
    2738                 :  * prototype and storing true in *resolved.  If id does not name a standard
    2739                 :  * class or a top-level property induced by initializing a standard class,
    2740                 :  * store false in *resolved and just return true.  Return false on error,
    2741                 :  * as usual for JSBool result-typed API entry points.
    2742                 :  *
    2743                 :  * This API can be called directly from a global object class's resolve op,
    2744                 :  * to define standard classes lazily.  The class's enumerate op should call
    2745                 :  * JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
    2746                 :  * loops any classes not yet resolved lazily.
    2747                 :  */
    2748                 : extern JS_PUBLIC_API(JSBool)
    2749                 : JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsid id,
    2750                 :                         JSBool *resolved);
    2751                 : 
    2752                 : extern JS_PUBLIC_API(JSBool)
    2753                 : JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
    2754                 : 
    2755                 : /*
    2756                 :  * Enumerate any already-resolved standard class ids into ida, or into a new
    2757                 :  * JSIdArray if ida is null.  Return the augmented array on success, null on
    2758                 :  * failure with ida (if it was non-null on entry) destroyed.
    2759                 :  */
    2760                 : extern JS_PUBLIC_API(JSIdArray *)
    2761                 : JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
    2762                 :                                     JSIdArray *ida);
    2763                 : 
    2764                 : extern JS_PUBLIC_API(JSBool)
    2765                 : JS_GetClassObject(JSContext *cx, JSObject *obj, JSProtoKey key,
    2766                 :                   JSObject **objp);
    2767                 : 
    2768                 : /*
    2769                 :  * Returns the original value of |Function.prototype| from the global object in
    2770                 :  * which |forObj| was created.
    2771                 :  */
    2772                 : extern JS_PUBLIC_API(JSObject *)
    2773                 : JS_GetFunctionPrototype(JSContext *cx, JSObject *forObj);
    2774                 : 
    2775                 : /*
    2776                 :  * Returns the original value of |Object.prototype| from the global object in
    2777                 :  * which |forObj| was created.
    2778                 :  */
    2779                 : extern JS_PUBLIC_API(JSObject *)
    2780                 : JS_GetObjectPrototype(JSContext *cx, JSObject *forObj);
    2781                 : 
    2782                 : extern JS_PUBLIC_API(JSObject *)
    2783                 : JS_GetGlobalForObject(JSContext *cx, JSObject *obj);
    2784                 : 
    2785                 : extern JS_PUBLIC_API(JSObject *)
    2786                 : JS_GetGlobalForScopeChain(JSContext *cx);
    2787                 : 
    2788                 : /*
    2789                 :  * Initialize the 'Reflect' object on a global object.
    2790                 :  */
    2791                 : extern JS_PUBLIC_API(JSObject *)
    2792                 : JS_InitReflect(JSContext *cx, JSObject *global);
    2793                 : 
    2794                 : #ifdef JS_HAS_CTYPES
    2795                 : /*
    2796                 :  * Initialize the 'ctypes' object on a global variable 'obj'. The 'ctypes'
    2797                 :  * object will be sealed.
    2798                 :  */
    2799                 : extern JS_PUBLIC_API(JSBool)
    2800                 : JS_InitCTypesClass(JSContext *cx, JSObject *global);
    2801                 : 
    2802                 : /*
    2803                 :  * Convert a unicode string 'source' of length 'slen' to the platform native
    2804                 :  * charset, returning a null-terminated string allocated with JS_malloc. On
    2805                 :  * failure, this function should report an error.
    2806                 :  */
    2807                 : typedef char *
    2808                 : (* JSCTypesUnicodeToNativeFun)(JSContext *cx, const jschar *source, size_t slen);
    2809                 : 
    2810                 : /*
    2811                 :  * Set of function pointers that ctypes can use for various internal functions.
    2812                 :  * See JS_SetCTypesCallbacks below. Providing NULL for a function is safe,
    2813                 :  * and will result in the applicable ctypes functionality not being available.
    2814                 :  */
    2815                 : struct JSCTypesCallbacks {
    2816                 :     JSCTypesUnicodeToNativeFun unicodeToNative;
    2817                 : };
    2818                 : 
    2819                 : typedef struct JSCTypesCallbacks JSCTypesCallbacks;
    2820                 : 
    2821                 : /*
    2822                 :  * Set the callbacks on the provided 'ctypesObj' object. 'callbacks' should be a
    2823                 :  * pointer to static data that exists for the lifetime of 'ctypesObj', but it
    2824                 :  * may safely be altered after calling this function and without having
    2825                 :  * to call this function again.
    2826                 :  */
    2827                 : extern JS_PUBLIC_API(void)
    2828                 : JS_SetCTypesCallbacks(JSObject *ctypesObj, JSCTypesCallbacks *callbacks);
    2829                 : #endif
    2830                 : 
    2831                 : typedef JSBool
    2832                 : (* JSEnumerateDiagnosticMemoryCallback)(void *ptr, size_t length);
    2833                 : 
    2834                 : /*
    2835                 :  * Enumerate memory regions that contain diagnostic information
    2836                 :  * intended to be included in crash report minidumps.
    2837                 :  */
    2838                 : extern JS_PUBLIC_API(void)
    2839                 : JS_EnumerateDiagnosticMemoryRegions(JSEnumerateDiagnosticMemoryCallback callback);
    2840                 : 
    2841                 : /*
    2842                 :  * Macros to hide interpreter stack layout details from a JSFastNative using
    2843                 :  * its jsval *vp parameter. The stack layout underlying invocation can't change
    2844                 :  * without breaking source and binary compatibility (argv[-2] is well-known to
    2845                 :  * be the callee jsval, and argv[-1] is as well known to be |this|).
    2846                 :  *
    2847                 :  * Note well: However, argv[-1] may be JSVAL_NULL where with slow natives it
    2848                 :  * is the global object, so embeddings implementing fast natives *must* call
    2849                 :  * JS_THIS or JS_THIS_OBJECT and test for failure indicated by a null return,
    2850                 :  * which should propagate as a false return from native functions and hooks.
    2851                 :  *
    2852                 :  * To reduce boilerplace checks, JS_InstanceOf and JS_GetInstancePrivate now
    2853                 :  * handle a null obj parameter by returning false (throwing a TypeError if
    2854                 :  * given non-null argv), so most native functions that type-check their |this|
    2855                 :  * parameter need not add null checking.
    2856                 :  *
    2857                 :  * NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
    2858                 :  * methods that may inspect their callee must defer setting their return value
    2859                 :  * until after any such possible inspection. Otherwise the return value will be
    2860                 :  * inspected instead of the callee function object.
    2861                 :  *
    2862                 :  * WARNING: These are not (yet) mandatory macros, but new code outside of the
    2863                 :  * engine should use them. In the Mozilla 2.0 milestone their definitions may
    2864                 :  * change incompatibly.
    2865                 :  *
    2866                 :  * N.B. constructors must not use JS_THIS, as no 'this' object has been created.
    2867                 :  */
    2868                 : 
    2869                 : #define JS_CALLEE(cx,vp)        ((vp)[0])
    2870                 : #define JS_THIS(cx,vp)          JS_ComputeThis(cx, vp)
    2871                 : #define JS_THIS_OBJECT(cx,vp)   (JSVAL_TO_OBJECT(JS_THIS(cx,vp)))
    2872                 : #define JS_ARGV(cx,vp)          ((vp) + 2)
    2873                 : #define JS_RVAL(cx,vp)          (*(vp))
    2874                 : #define JS_SET_RVAL(cx,vp,v)    (*(vp) = (v))
    2875                 : 
    2876                 : extern JS_PUBLIC_API(jsval)
    2877                 : JS_ComputeThis(JSContext *cx, jsval *vp);
    2878                 : 
    2879                 : #ifdef __cplusplus
    2880                 : #undef JS_THIS
    2881                 : static inline jsval
    2882         6766572 : JS_THIS(JSContext *cx, jsval *vp)
    2883                 : {
    2884         6766572 :     return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1];
    2885                 : }
    2886                 : #endif
    2887                 : 
    2888                 : /*
    2889                 :  * |this| is passed to functions in ES5 without change.  Functions themselves
    2890                 :  * do any post-processing they desire to box |this|, compute the global object,
    2891                 :  * &c.  Use this macro to retrieve a function's unboxed |this| value.
    2892                 :  *
    2893                 :  * This macro must not be used in conjunction with JS_THIS or JS_THIS_OBJECT,
    2894                 :  * or vice versa.  Either use the provided this value with this macro, or
    2895                 :  * compute the boxed this value using those.
    2896                 :  *
    2897                 :  * N.B. constructors must not use JS_THIS_VALUE, as no 'this' object has been
    2898                 :  * created.
    2899                 :  */
    2900                 : #define JS_THIS_VALUE(cx,vp)    ((vp)[1])
    2901                 : 
    2902                 : extern JS_PUBLIC_API(void)
    2903                 : JS_MallocInCompartment(JSCompartment *comp, size_t nbytes);
    2904                 : 
    2905                 : extern JS_PUBLIC_API(void)
    2906                 : JS_FreeInCompartment(JSCompartment *comp, size_t nbytes);
    2907                 : 
    2908                 : extern JS_PUBLIC_API(void *)
    2909                 : JS_malloc(JSContext *cx, size_t nbytes);
    2910                 : 
    2911                 : extern JS_PUBLIC_API(void *)
    2912                 : JS_realloc(JSContext *cx, void *p, size_t nbytes);
    2913                 : 
    2914                 : extern JS_PUBLIC_API(void)
    2915                 : JS_free(JSContext *cx, void *p);
    2916                 : 
    2917                 : extern JS_PUBLIC_API(void)
    2918                 : JS_updateMallocCounter(JSContext *cx, size_t nbytes);
    2919                 : 
    2920                 : extern JS_PUBLIC_API(char *)
    2921                 : JS_strdup(JSContext *cx, const char *s);
    2922                 : 
    2923                 : extern JS_PUBLIC_API(JSBool)
    2924                 : JS_NewNumberValue(JSContext *cx, double d, jsval *rval);
    2925                 : 
    2926                 : /*
    2927                 :  * A GC root is a pointer to a jsval, JSObject * or JSString * that itself
    2928                 :  * points into the GC heap. JS_AddValueRoot takes a pointer to a jsval and
    2929                 :  * JS_AddGCThingRoot takes a pointer to a JSObject * or JString *.
    2930                 :  *
    2931                 :  * Note that, since JS_Add*Root stores the address of a variable (of type
    2932                 :  * jsval, JSString *, or JSObject *), that variable must live until
    2933                 :  * JS_Remove*Root is called to remove that variable. For example, after:
    2934                 :  *
    2935                 :  *   void some_function() {
    2936                 :  *     jsval v;
    2937                 :  *     JS_AddNamedRootedValue(cx, &v, "name");
    2938                 :  *
    2939                 :  * the caller must perform
    2940                 :  *
    2941                 :  *     JS_RemoveRootedValue(cx, &v);
    2942                 :  *
    2943                 :  * before some_function() returns.
    2944                 :  *
    2945                 :  * Also, use JS_AddNamed*Root(cx, &structPtr->memberObj, "structPtr->memberObj")
    2946                 :  * in preference to JS_Add*Root(cx, &structPtr->memberObj), in order to identify
    2947                 :  * roots by their source callsites.  This way, you can find the callsite while
    2948                 :  * debugging if you should fail to do JS_Remove*Root(cx, &structPtr->memberObj)
    2949                 :  * before freeing structPtr's memory.
    2950                 :  */
    2951                 : extern JS_PUBLIC_API(JSBool)
    2952                 : JS_AddValueRoot(JSContext *cx, jsval *vp);
    2953                 : 
    2954                 : extern JS_PUBLIC_API(JSBool)
    2955                 : JS_AddStringRoot(JSContext *cx, JSString **rp);
    2956                 : 
    2957                 : extern JS_PUBLIC_API(JSBool)
    2958                 : JS_AddObjectRoot(JSContext *cx, JSObject **rp);
    2959                 : 
    2960                 : extern JS_PUBLIC_API(JSBool)
    2961                 : JS_AddGCThingRoot(JSContext *cx, void **rp);
    2962                 : 
    2963                 : #ifdef NAME_ALL_GC_ROOTS
    2964                 : #define JS_DEFINE_TO_TOKEN(def) #def
    2965                 : #define JS_DEFINE_TO_STRING(def) JS_DEFINE_TO_TOKEN(def)
    2966                 : #define JS_AddValueRoot(cx,vp) JS_AddNamedValueRoot((cx), (vp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
    2967                 : #define JS_AddStringRoot(cx,rp) JS_AddNamedStringRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
    2968                 : #define JS_AddObjectRoot(cx,rp) JS_AddNamedObjectRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
    2969                 : #define JS_AddGCThingRoot(cx,rp) JS_AddNamedGCThingRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
    2970                 : #endif
    2971                 : 
    2972                 : extern JS_PUBLIC_API(JSBool)
    2973                 : JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name);
    2974                 : 
    2975                 : extern JS_PUBLIC_API(JSBool)
    2976                 : JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name);
    2977                 : 
    2978                 : extern JS_PUBLIC_API(JSBool)
    2979                 : JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name);
    2980                 : 
    2981                 : extern JS_PUBLIC_API(JSBool)
    2982                 : JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name);
    2983                 : 
    2984                 : extern JS_PUBLIC_API(JSBool)
    2985                 : JS_AddNamedGCThingRoot(JSContext *cx, void **rp, const char *name);
    2986                 : 
    2987                 : extern JS_PUBLIC_API(JSBool)
    2988                 : JS_RemoveValueRoot(JSContext *cx, jsval *vp);
    2989                 : 
    2990                 : extern JS_PUBLIC_API(JSBool)
    2991                 : JS_RemoveStringRoot(JSContext *cx, JSString **rp);
    2992                 : 
    2993                 : extern JS_PUBLIC_API(JSBool)
    2994                 : JS_RemoveObjectRoot(JSContext *cx, JSObject **rp);
    2995                 : 
    2996                 : extern JS_PUBLIC_API(JSBool)
    2997                 : JS_RemoveScriptRoot(JSContext *cx, JSScript **rp);
    2998                 : 
    2999                 : extern JS_PUBLIC_API(JSBool)
    3000                 : JS_RemoveGCThingRoot(JSContext *cx, void **rp);
    3001                 : 
    3002                 : /* TODO: remove these APIs */
    3003                 : 
    3004                 : extern JS_FRIEND_API(JSBool)
    3005                 : js_AddRootRT(JSRuntime *rt, jsval *vp, const char *name);
    3006                 : 
    3007                 : extern JS_FRIEND_API(JSBool)
    3008                 : js_AddGCThingRootRT(JSRuntime *rt, void **rp, const char *name);
    3009                 : 
    3010                 : extern JS_FRIEND_API(JSBool)
    3011                 : js_RemoveRoot(JSRuntime *rt, void *rp);
    3012                 : 
    3013                 : /*
    3014                 :  * C-compatible version of the Anchor class. It should be called after the last
    3015                 :  * use of the variable it protects.
    3016                 :  */
    3017                 : extern JS_NEVER_INLINE JS_PUBLIC_API(void)
    3018                 : JS_AnchorPtr(void *p);
    3019                 : 
    3020                 : /*
    3021                 :  * This symbol may be used by embedders to detect the change from the old
    3022                 :  * JS_AddRoot(JSContext *, void *) APIs to the new ones above.
    3023                 :  */
    3024                 : #define JS_TYPED_ROOTING_API
    3025                 : 
    3026                 : /* Obsolete rooting APIs. */
    3027                 : #define JS_EnterLocalRootScope(cx) (JS_TRUE)
    3028                 : #define JS_LeaveLocalRootScope(cx) ((void) 0)
    3029                 : #define JS_LeaveLocalRootScopeWithResult(cx, rval) ((void) 0)
    3030                 : #define JS_ForgetLocalRoot(cx, thing) ((void) 0)
    3031                 : 
    3032                 : typedef enum JSGCRootType {
    3033                 :     JS_GC_ROOT_VALUE_PTR,
    3034                 :     JS_GC_ROOT_GCTHING_PTR
    3035                 : } JSGCRootType;
    3036                 : 
    3037                 : #ifdef DEBUG
    3038                 : extern JS_PUBLIC_API(void)
    3039                 : JS_DumpNamedRoots(JSRuntime *rt,
    3040                 :                   void (*dump)(const char *name, void *rp, JSGCRootType type, void *data),
    3041                 :                   void *data);
    3042                 : #endif
    3043                 : 
    3044                 : /*
    3045                 :  * Call JS_MapGCRoots to map the GC's roots table using map(rp, name, data).
    3046                 :  * The root is pointed at by rp; if the root is unnamed, name is null; data is
    3047                 :  * supplied from the third parameter to JS_MapGCRoots.
    3048                 :  *
    3049                 :  * The map function should return JS_MAP_GCROOT_REMOVE to cause the currently
    3050                 :  * enumerated root to be removed.  To stop enumeration, set JS_MAP_GCROOT_STOP
    3051                 :  * in the return value.  To keep on mapping, return JS_MAP_GCROOT_NEXT.  These
    3052                 :  * constants are flags; you can OR them together.
    3053                 :  *
    3054                 :  * This function acquires and releases rt's GC lock around the mapping of the
    3055                 :  * roots table, so the map function should run to completion in as few cycles
    3056                 :  * as possible.  Of course, map cannot call JS_GC, JS_MaybeGC, JS_BeginRequest,
    3057                 :  * or any JS API entry point that acquires locks, without double-tripping or
    3058                 :  * deadlocking on the GC lock.
    3059                 :  *
    3060                 :  * The JSGCRootType parameter indicates whether rp is a pointer to a Value
    3061                 :  * (which is obtained by '(Value *)rp') or a pointer to a GC-thing pointer
    3062                 :  * (which is obtained by '(void **)rp').
    3063                 :  *
    3064                 :  * JS_MapGCRoots returns the count of roots that were successfully mapped.
    3065                 :  */
    3066                 : #define JS_MAP_GCROOT_NEXT      0       /* continue mapping entries */
    3067                 : #define JS_MAP_GCROOT_STOP      1       /* stop mapping entries */
    3068                 : #define JS_MAP_GCROOT_REMOVE    2       /* remove and free the current entry */
    3069                 : 
    3070                 : typedef int
    3071                 : (* JSGCRootMapFun)(void *rp, JSGCRootType type, const char *name, void *data);
    3072                 : 
    3073                 : extern JS_PUBLIC_API(uint32_t)
    3074                 : JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
    3075                 : 
    3076                 : extern JS_PUBLIC_API(JSBool)
    3077                 : JS_LockGCThing(JSContext *cx, void *thing);
    3078                 : 
    3079                 : extern JS_PUBLIC_API(JSBool)
    3080                 : JS_LockGCThingRT(JSRuntime *rt, void *thing);
    3081                 : 
    3082                 : extern JS_PUBLIC_API(JSBool)
    3083                 : JS_UnlockGCThing(JSContext *cx, void *thing);
    3084                 : 
    3085                 : extern JS_PUBLIC_API(JSBool)
    3086                 : JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
    3087                 : 
    3088                 : /*
    3089                 :  * Register externally maintained GC roots.
    3090                 :  *
    3091                 :  * traceOp: the trace operation. For each root the implementation should call
    3092                 :  *          JS_CallTracer whenever the root contains a traceable thing.
    3093                 :  * data:    the data argument to pass to each invocation of traceOp.
    3094                 :  */
    3095                 : extern JS_PUBLIC_API(void)
    3096                 : JS_SetExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
    3097                 : 
    3098                 : /*
    3099                 :  * JS_CallTracer API and related macros for implementors of JSTraceOp, to
    3100                 :  * enumerate all references to traceable things reachable via a property or
    3101                 :  * other strong ref identified for debugging purposes by name or index or
    3102                 :  * a naming callback.
    3103                 :  *
    3104                 :  * See the JSTraceOp typedef.
    3105                 :  */
    3106                 : 
    3107                 : /*
    3108                 :  * Use the following macros to check if a particular jsval is a traceable
    3109                 :  * thing and to extract the thing and its kind to pass to JS_CallTracer.
    3110                 :  */
    3111                 : static JS_ALWAYS_INLINE JSBool
    3112            7073 : JSVAL_IS_TRACEABLE(jsval v)
    3113                 : {
    3114            7073 :     return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v));
    3115                 : }
    3116                 : 
    3117                 : static JS_ALWAYS_INLINE void *
    3118             551 : JSVAL_TO_TRACEABLE(jsval v)
    3119                 : {
    3120             551 :     return JSVAL_TO_GCTHING(v);
    3121                 : }
    3122                 : 
    3123                 : static JS_ALWAYS_INLINE JSGCTraceKind
    3124             557 : JSVAL_TRACE_KIND(jsval v)
    3125                 : {
    3126             557 :     JS_ASSERT(JSVAL_IS_GCTHING(v));
    3127             557 :     return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v));
    3128                 : }
    3129                 : 
    3130                 : /*
    3131                 :  * Tracer callback, called for each traceable thing directly referenced by a
    3132                 :  * particular object or runtime structure. It is the callback responsibility
    3133                 :  * to ensure the traversal of the full object graph via calling eventually
    3134                 :  * JS_TraceChildren on the passed thing. In this case the callback must be
    3135                 :  * prepared to deal with cycles in the traversal graph.
    3136                 :  *
    3137                 :  * kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting
    3138                 :  * internal implementation-specific traversal kind. In the latter case the only
    3139                 :  * operations on thing that the callback can do is to call JS_TraceChildren or
    3140                 :  * DEBUG-only JS_PrintTraceThingInfo.
    3141                 :  *
    3142                 :  * If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all
    3143                 :  * of its mappings.  This should be used in cases where the tracer
    3144                 :  * wants to use the existing liveness of entries.
    3145                 :  */
    3146                 : typedef void
    3147                 : (* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind);
    3148                 : 
    3149          669039 : struct JSTracer {
    3150                 :     JSRuntime           *runtime;
    3151                 :     JSTraceCallback     callback;
    3152                 :     JSTraceNamePrinter  debugPrinter;
    3153                 :     const void          *debugPrintArg;
    3154                 :     size_t              debugPrintIndex;
    3155                 :     JSBool              eagerlyTraceWeakMaps;
    3156                 : };
    3157                 : 
    3158                 : /*
    3159                 :  * The method to call on each reference to a traceable thing stored in a
    3160                 :  * particular JSObject or other runtime structure. With DEBUG defined the
    3161                 :  * caller before calling JS_CallTracer must initialize JSTracer fields
    3162                 :  * describing the reference using the macros below.
    3163                 :  */
    3164                 : extern JS_PUBLIC_API(void)
    3165                 : JS_CallTracer(JSTracer *trc, void *thing, JSGCTraceKind kind);
    3166                 : 
    3167                 : /*
    3168                 :  * Set debugging information about a reference to a traceable thing to prepare
    3169                 :  * for the following call to JS_CallTracer.
    3170                 :  *
    3171                 :  * When printer is null, arg must be const char * or char * C string naming
    3172                 :  * the reference and index must be either (size_t)-1 indicating that the name
    3173                 :  * alone describes the reference or it must be an index into some array vector
    3174                 :  * that stores the reference.
    3175                 :  *
    3176                 :  * When printer callback is not null, the arg and index arguments are
    3177                 :  * available to the callback as debugPrintArg and debugPrintIndex fields
    3178                 :  * of JSTracer.
    3179                 :  *
    3180                 :  * The storage for name or callback's arguments needs to live only until
    3181                 :  * the following call to JS_CallTracer returns.
    3182                 :  */
    3183                 : #ifdef DEBUG
    3184                 : # define JS_SET_TRACING_DETAILS(trc, printer, arg, index)                     \
    3185                 :     JS_BEGIN_MACRO                                                            \
    3186                 :         (trc)->debugPrinter = (printer);                                      \
    3187                 :         (trc)->debugPrintArg = (arg);                                         \
    3188                 :         (trc)->debugPrintIndex = (index);                                     \
    3189                 :     JS_END_MACRO
    3190                 : #else
    3191                 : # define JS_SET_TRACING_DETAILS(trc, printer, arg, index)                     \
    3192                 :     JS_BEGIN_MACRO                                                            \
    3193                 :     JS_END_MACRO
    3194                 : #endif
    3195                 : 
    3196                 : /*
    3197                 :  * Convenience macro to describe the argument of JS_CallTracer using C string
    3198                 :  * and index.
    3199                 :  */
    3200                 : # define JS_SET_TRACING_INDEX(trc, name, index)                               \
    3201                 :     JS_SET_TRACING_DETAILS(trc, NULL, name, index)
    3202                 : 
    3203                 : /*
    3204                 :  * Convenience macro to describe the argument of JS_CallTracer using C string.
    3205                 :  */
    3206                 : # define JS_SET_TRACING_NAME(trc, name)                                       \
    3207                 :     JS_SET_TRACING_DETAILS(trc, NULL, name, (size_t)-1)
    3208                 : 
    3209                 : /*
    3210                 :  * Convenience macro to invoke JS_CallTracer using C string as the name for
    3211                 :  * the reference to a traceable thing.
    3212                 :  */
    3213                 : # define JS_CALL_TRACER(trc, thing, kind, name)                               \
    3214                 :     JS_BEGIN_MACRO                                                            \
    3215                 :         JS_SET_TRACING_NAME(trc, name);                                       \
    3216                 :         JS_CallTracer((trc), (thing), (kind));                                \
    3217                 :     JS_END_MACRO
    3218                 : 
    3219                 : /*
    3220                 :  * Convenience macros to invoke JS_CallTracer when jsval represents a
    3221                 :  * reference to a traceable thing.
    3222                 :  */
    3223                 : #define JS_CALL_VALUE_TRACER(trc, val, name)                                  \
    3224                 :     JS_BEGIN_MACRO                                                            \
    3225                 :         if (JSVAL_IS_TRACEABLE(val)) {                                        \
    3226                 :             JS_CALL_TRACER((trc), JSVAL_TO_GCTHING(val),                      \
    3227                 :                            JSVAL_TRACE_KIND(val), name);                      \
    3228                 :         }                                                                     \
    3229                 :     JS_END_MACRO
    3230                 : 
    3231                 : #define JS_CALL_OBJECT_TRACER(trc, object, name)                              \
    3232                 :     JS_BEGIN_MACRO                                                            \
    3233                 :         JSObject *obj_ = (object);                                            \
    3234                 :         JS_ASSERT(obj_);                                                      \
    3235                 :         JS_CALL_TRACER((trc), obj_, JSTRACE_OBJECT, name);                    \
    3236                 :     JS_END_MACRO
    3237                 : 
    3238                 : #define JS_CALL_STRING_TRACER(trc, string, name)                              \
    3239                 :     JS_BEGIN_MACRO                                                            \
    3240                 :         JSString *str_ = (string);                                            \
    3241                 :         JS_ASSERT(str_);                                                      \
    3242                 :         JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name);                    \
    3243                 :     JS_END_MACRO
    3244                 : 
    3245                 : /*
    3246                 :  * API for JSTraceCallback implementations.
    3247                 :  */
    3248                 : extern JS_PUBLIC_API(void)
    3249                 : JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback);
    3250                 : 
    3251                 : extern JS_PUBLIC_API(void)
    3252                 : JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind);
    3253                 : 
    3254                 : extern JS_PUBLIC_API(void)
    3255                 : JS_TraceRuntime(JSTracer *trc);
    3256                 : 
    3257                 : #ifdef DEBUG
    3258                 : 
    3259                 : extern JS_PUBLIC_API(void)
    3260                 : JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
    3261                 :                        void *thing, JSGCTraceKind kind, JSBool includeDetails);
    3262                 : 
    3263                 : extern JS_PUBLIC_API(const char *)
    3264                 : JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize);
    3265                 : 
    3266                 : /*
    3267                 :  * DEBUG-only method to dump the object graph of heap-allocated things.
    3268                 :  *
    3269                 :  * fp:              file for the dump output.
    3270                 :  * start:           when non-null, dump only things reachable from start
    3271                 :  *                  thing. Otherwise dump all things reachable from the
    3272                 :  *                  runtime roots.
    3273                 :  * startKind:       trace kind of start if start is not null. Must be
    3274                 :  *                  JSTRACE_OBJECT when start is null.
    3275                 :  * thingToFind:     dump only paths in the object graph leading to thingToFind
    3276                 :  *                  when non-null.
    3277                 :  * maxDepth:        the upper bound on the number of edges to descend from the
    3278                 :  *                  graph roots.
    3279                 :  * thingToIgnore:   thing to ignore during the graph traversal when non-null.
    3280                 :  */
    3281                 : extern JS_PUBLIC_API(JSBool)
    3282                 : JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind kind,
    3283                 :             void *thingToFind, size_t maxDepth, void *thingToIgnore);
    3284                 : 
    3285                 : #endif
    3286                 : 
    3287                 : /*
    3288                 :  * Garbage collector API.
    3289                 :  */
    3290                 : extern JS_PUBLIC_API(void)
    3291                 : JS_GC(JSContext *cx);
    3292                 : 
    3293                 : extern JS_PUBLIC_API(void)
    3294                 : JS_CompartmentGC(JSContext *cx, JSCompartment *comp);
    3295                 : 
    3296                 : extern JS_PUBLIC_API(void)
    3297                 : JS_MaybeGC(JSContext *cx);
    3298                 : 
    3299                 : extern JS_PUBLIC_API(void)
    3300                 : JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb);
    3301                 : 
    3302                 : extern JS_PUBLIC_API(void)
    3303                 : JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb);
    3304                 : 
    3305                 : extern JS_PUBLIC_API(JSBool)
    3306                 : JS_IsGCMarkingTracer(JSTracer *trc);
    3307                 : 
    3308                 : extern JS_PUBLIC_API(JSBool)
    3309                 : JS_IsAboutToBeFinalized(void *thing);
    3310                 : 
    3311                 : typedef enum JSGCParamKey {
    3312                 :     /* Maximum nominal heap before last ditch GC. */
    3313                 :     JSGC_MAX_BYTES          = 0,
    3314                 : 
    3315                 :     /* Number of JS_malloc bytes before last ditch GC. */
    3316                 :     JSGC_MAX_MALLOC_BYTES   = 1,
    3317                 : 
    3318                 :     /* Amount of bytes allocated by the GC. */
    3319                 :     JSGC_BYTES = 3,
    3320                 : 
    3321                 :     /* Number of times when GC was invoked. */
    3322                 :     JSGC_NUMBER = 4,
    3323                 : 
    3324                 :     /* Max size of the code cache in bytes. */
    3325                 :     JSGC_MAX_CODE_CACHE_BYTES = 5,
    3326                 : 
    3327                 :     /* Select GC mode. */
    3328                 :     JSGC_MODE = 6,
    3329                 : 
    3330                 :     /* Number of cached empty GC chunks. */
    3331                 :     JSGC_UNUSED_CHUNKS = 7,
    3332                 : 
    3333                 :     /* Total number of allocated GC chunks. */
    3334                 :     JSGC_TOTAL_CHUNKS = 8,
    3335                 : 
    3336                 :     /* Max milliseconds to spend in an incremental GC slice. */
    3337                 :     JSGC_SLICE_TIME_BUDGET = 9,
    3338                 : 
    3339                 :     /* Maximum size the GC mark stack can grow to. */
    3340                 :     JSGC_MARK_STACK_LIMIT = 10
    3341                 : } JSGCParamKey;
    3342                 : 
    3343                 : typedef enum JSGCMode {
    3344                 :     /* Perform only global GCs. */
    3345                 :     JSGC_MODE_GLOBAL = 0,
    3346                 : 
    3347                 :     /* Perform per-compartment GCs until too much garbage has accumulated. */
    3348                 :     JSGC_MODE_COMPARTMENT = 1,
    3349                 : 
    3350                 :     /*
    3351                 :      * Collect in short time slices rather than all at once. Implies
    3352                 :      * JSGC_MODE_COMPARTMENT.
    3353                 :      */
    3354                 :     JSGC_MODE_INCREMENTAL = 2
    3355                 : } JSGCMode;
    3356                 : 
    3357                 : extern JS_PUBLIC_API(void)
    3358                 : JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value);
    3359                 : 
    3360                 : extern JS_PUBLIC_API(uint32_t)
    3361                 : JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key);
    3362                 : 
    3363                 : extern JS_PUBLIC_API(void)
    3364                 : JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value);
    3365                 : 
    3366                 : extern JS_PUBLIC_API(uint32_t)
    3367                 : JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);
    3368                 : 
    3369                 : /*
    3370                 :  * Flush the code cache for the current thread. The operation might be
    3371                 :  * delayed if the cache cannot be flushed currently because native
    3372                 :  * code is currently executing.
    3373                 :  */
    3374                 : 
    3375                 : extern JS_PUBLIC_API(void)
    3376                 : JS_FlushCaches(JSContext *cx);
    3377                 : 
    3378                 : /*
    3379                 :  * Create a new JSString whose chars member refers to external memory, i.e.,
    3380                 :  * memory requiring application-specific finalization.
    3381                 :  */
    3382                 : extern JS_PUBLIC_API(JSString *)
    3383                 : JS_NewExternalString(JSContext *cx, const jschar *chars, size_t length,
    3384                 :                      const JSStringFinalizer *fin);
    3385                 : 
    3386                 : /*
    3387                 :  * Return whether 'str' was created with JS_NewExternalString or
    3388                 :  * JS_NewExternalStringWithClosure.
    3389                 :  */
    3390                 : extern JS_PUBLIC_API(JSBool)
    3391                 : JS_IsExternalString(JSString *str);
    3392                 : 
    3393                 : /*
    3394                 :  * Return the 'closure' arg passed to JS_NewExternalStringWithClosure or NULL
    3395                 :  * if the external string was created via JS_NewExternalString.
    3396                 :  */
    3397                 : extern JS_PUBLIC_API(const JSStringFinalizer *)
    3398                 : JS_GetExternalStringFinalizer(JSString *str);
    3399                 : 
    3400                 : /*
    3401                 :  * Set the size of the native stack that should not be exceed. To disable
    3402                 :  * stack size checking pass 0.
    3403                 :  */
    3404                 : extern JS_PUBLIC_API(void)
    3405                 : JS_SetNativeStackQuota(JSRuntime *cx, size_t stackSize);
    3406                 : 
    3407                 : /************************************************************************/
    3408                 : 
    3409                 : /*
    3410                 :  * Classes, objects, and properties.
    3411                 :  */
    3412                 : typedef void (*JSClassInternal)();
    3413                 : 
    3414               0 : struct JSClass {
    3415                 :     const char          *name;
    3416                 :     uint32_t            flags;
    3417                 : 
    3418                 :     /* Mandatory non-null function pointer members. */
    3419                 :     JSPropertyOp        addProperty;
    3420                 :     JSPropertyOp        delProperty;
    3421                 :     JSPropertyOp        getProperty;
    3422                 :     JSStrictPropertyOp  setProperty;
    3423                 :     JSEnumerateOp       enumerate;
    3424                 :     JSResolveOp         resolve;
    3425                 :     JSConvertOp         convert;
    3426                 :     JSFinalizeOp        finalize;
    3427                 : 
    3428                 :     /* Optionally non-null members start here. */
    3429                 :     JSCheckAccessOp     checkAccess;
    3430                 :     JSNative            call;
    3431                 :     JSNative            construct;
    3432                 :     JSHasInstanceOp     hasInstance;
    3433                 :     JSTraceOp           trace;
    3434                 : 
    3435                 :     void                *reserved[40];
    3436                 : };
    3437                 : 
    3438                 : #define JSCLASS_HAS_PRIVATE             (1<<0)  /* objects have private slot */
    3439                 : #define JSCLASS_NEW_ENUMERATE           (1<<1)  /* has JSNewEnumerateOp hook */
    3440                 : #define JSCLASS_NEW_RESOLVE             (1<<2)  /* has JSNewResolveOp hook */
    3441                 : #define JSCLASS_PRIVATE_IS_NSISUPPORTS  (1<<3)  /* private is (nsISupports *) */
    3442                 : #define JSCLASS_NEW_RESOLVE_GETS_START  (1<<4)  /* JSNewResolveOp gets starting
    3443                 :                                                    object in prototype chain
    3444                 :                                                    passed in via *objp in/out
    3445                 :                                                    parameter */
    3446                 : #define JSCLASS_IMPLEMENTS_BARRIERS     (1<<5)  /* Correctly implements GC read
    3447                 :                                                    and write barriers */
    3448                 : #define JSCLASS_DOCUMENT_OBSERVER       (1<<6)  /* DOM document observer */
    3449                 : 
    3450                 : /*
    3451                 :  * To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
    3452                 :  * JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
    3453                 :  * n is a constant in [1, 255].  Reserved slots are indexed from 0 to n-1.
    3454                 :  */
    3455                 : #define JSCLASS_RESERVED_SLOTS_SHIFT    8       /* room for 8 flags below */
    3456                 : #define JSCLASS_RESERVED_SLOTS_WIDTH    8       /* and 16 above this field */
    3457                 : #define JSCLASS_RESERVED_SLOTS_MASK     JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
    3458                 : #define JSCLASS_HAS_RESERVED_SLOTS(n)   (((n) & JSCLASS_RESERVED_SLOTS_MASK)  \
    3459                 :                                          << JSCLASS_RESERVED_SLOTS_SHIFT)
    3460                 : #define JSCLASS_RESERVED_SLOTS(clasp)   (((clasp)->flags                      \
    3461                 :                                           >> JSCLASS_RESERVED_SLOTS_SHIFT)    \
    3462                 :                                          & JSCLASS_RESERVED_SLOTS_MASK)
    3463                 : 
    3464                 : #define JSCLASS_HIGH_FLAGS_SHIFT        (JSCLASS_RESERVED_SLOTS_SHIFT +       \
    3465                 :                                          JSCLASS_RESERVED_SLOTS_WIDTH)
    3466                 : 
    3467                 : /*
    3468                 :  * Call the iteratorObject hook only to iterate over contents (for-of), not to
    3469                 :  * enumerate properties (for-in, for-each, Object.keys, etc.)
    3470                 :  */
    3471                 : #define JSCLASS_FOR_OF_ITERATION        (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
    3472                 : 
    3473                 : #define JSCLASS_IS_ANONYMOUS            (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
    3474                 : #define JSCLASS_IS_GLOBAL               (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
    3475                 : #define JSCLASS_INTERNAL_FLAG2          (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
    3476                 : #define JSCLASS_INTERNAL_FLAG3          (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4))
    3477                 : 
    3478                 : /* Indicate whether the proto or ctor should be frozen. */
    3479                 : #define JSCLASS_FREEZE_PROTO            (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5))
    3480                 : #define JSCLASS_FREEZE_CTOR             (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6))
    3481                 : 
    3482                 : #define JSCLASS_XPCONNECT_GLOBAL        (1<<(JSCLASS_HIGH_FLAGS_SHIFT+7))
    3483                 : 
    3484                 : /* Global flags. */
    3485                 : #define JSGLOBAL_FLAGS_CLEARED          0x1
    3486                 : 
    3487                 : /*
    3488                 :  * ECMA-262 requires that most constructors used internally create objects
    3489                 :  * with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
    3490                 :  * member initial value.  The "original ... value" verbiage is there because
    3491                 :  * in ECMA-262, global properties naming class objects are read/write and
    3492                 :  * deleteable, for the most part.
    3493                 :  *
    3494                 :  * Implementing this efficiently requires that global objects have classes
    3495                 :  * with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was
    3496                 :  * prevously allowed, but is now an ES5 violation and thus unsupported.
    3497                 :  */
    3498                 : #define JSCLASS_GLOBAL_SLOT_COUNT      (JSProto_LIMIT * 3 + 8)
    3499                 : #define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n)                                    \
    3500                 :     (JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n)))
    3501                 : #define JSCLASS_GLOBAL_FLAGS                                                  \
    3502                 :     JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0)
    3503                 : #define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp)                              \
    3504                 :   (((clasp)->flags & JSCLASS_IS_GLOBAL)                                       \
    3505                 :    && JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT)
    3506                 : 
    3507                 : /* Fast access to the original value of each standard class's prototype. */
    3508                 : #define JSCLASS_CACHED_PROTO_SHIFT      (JSCLASS_HIGH_FLAGS_SHIFT + 8)
    3509                 : #define JSCLASS_CACHED_PROTO_WIDTH      8
    3510                 : #define JSCLASS_CACHED_PROTO_MASK       JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
    3511                 : #define JSCLASS_HAS_CACHED_PROTO(key)   ((key) << JSCLASS_CACHED_PROTO_SHIFT)
    3512                 : #define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey)                         \
    3513                 :                                          (((clasp)->flags                     \
    3514                 :                                            >> JSCLASS_CACHED_PROTO_SHIFT)     \
    3515                 :                                           & JSCLASS_CACHED_PROTO_MASK))
    3516                 : 
    3517                 : /* Initializer for unused members of statically initialized JSClass structs. */
    3518                 : #define JSCLASS_NO_INTERNAL_MEMBERS     {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
    3519                 : #define JSCLASS_NO_OPTIONAL_MEMBERS     0,0,0,0,0,JSCLASS_NO_INTERNAL_MEMBERS
    3520                 : 
    3521                 : extern JS_PUBLIC_API(int)
    3522                 : JS_IdArrayLength(JSContext *cx, JSIdArray *ida);
    3523                 : 
    3524                 : extern JS_PUBLIC_API(jsid)
    3525                 : JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index);
    3526                 : 
    3527                 : extern JS_PUBLIC_API(void)
    3528                 : JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
    3529                 : 
    3530                 : #ifdef __cplusplus
    3531                 : 
    3532                 : namespace JS {
    3533                 : 
    3534                 : class AutoIdArray : private AutoGCRooter {
    3535                 :   public:
    3536               0 :     AutoIdArray(JSContext *cx, JSIdArray *ida JS_GUARD_OBJECT_NOTIFIER_PARAM)
    3537               0 :       : AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida)
    3538                 :     {
    3539               0 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    3540               0 :     }
    3541               0 :     ~AutoIdArray() {
    3542               0 :         if (idArray)
    3543               0 :             JS_DestroyIdArray(context, idArray);
    3544               0 :     }
    3545               0 :     bool operator!() {
    3546               0 :         return !idArray;
    3547                 :     }
    3548               0 :     jsid operator[](size_t i) const {
    3549               0 :         JS_ASSERT(idArray);
    3550               0 :         JS_ASSERT(i < length());
    3551               0 :         return JS_IdArrayGet(context, idArray, i);
    3552                 :     }
    3553               0 :     size_t length() const {
    3554               0 :         return JS_IdArrayLength(context, idArray);
    3555                 :     }
    3556                 : 
    3557                 :     friend void AutoGCRooter::trace(JSTracer *trc);
    3558                 : 
    3559                 :     JSIdArray *steal() {
    3560                 :         JSIdArray *copy = idArray;
    3561                 :         idArray = NULL;
    3562                 :         return copy;
    3563                 :     }
    3564                 : 
    3565                 :   protected:
    3566                 :     inline void trace(JSTracer *trc);
    3567                 : 
    3568                 :   private:
    3569                 :     JSContext *context;
    3570                 :     JSIdArray *idArray;
    3571                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    3572                 : 
    3573                 :     /* No copy or assignment semantics. */
    3574                 :     AutoIdArray(AutoIdArray &ida) MOZ_DELETE;
    3575                 :     void operator=(AutoIdArray &ida) MOZ_DELETE;
    3576                 : };
    3577                 : 
    3578                 : } /* namespace JS */
    3579                 : 
    3580                 : #endif /* __cplusplus */
    3581                 : 
    3582                 : extern JS_PUBLIC_API(JSBool)
    3583                 : JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
    3584                 : 
    3585                 : extern JS_PUBLIC_API(JSBool)
    3586                 : JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
    3587                 : 
    3588                 : /*
    3589                 :  * JSNewResolveOp flag bits.
    3590                 :  */
    3591                 : #define JSRESOLVE_QUALIFIED     0x01    /* resolve a qualified property id */
    3592                 : #define JSRESOLVE_ASSIGNING     0x02    /* resolve on the left of assignment */
    3593                 : #define JSRESOLVE_DETECTING     0x04    /* 'if (o.p)...' or '(o.p) ?...:...' */
    3594                 : #define JSRESOLVE_DECLARING     0x08    /* var, const, or function prolog op */
    3595                 : #define JSRESOLVE_CLASSNAME     0x10    /* class name used when constructing */
    3596                 : #define JSRESOLVE_WITH          0x20    /* resolve inside a with statement */
    3597                 : 
    3598                 : /*
    3599                 :  * Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on
    3600                 :  * the specified object, computing a primitive default value for the object.
    3601                 :  * The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint).  On
    3602                 :  * success the resulting value is stored in *vp.
    3603                 :  */
    3604                 : extern JS_PUBLIC_API(JSBool)
    3605                 : JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
    3606                 : 
    3607                 : extern JS_PUBLIC_API(JSBool)
    3608                 : JS_PropertyStub(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
    3609                 : 
    3610                 : extern JS_PUBLIC_API(JSBool)
    3611                 : JS_StrictPropertyStub(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
    3612                 : 
    3613                 : extern JS_PUBLIC_API(JSBool)
    3614                 : JS_EnumerateStub(JSContext *cx, JSObject *obj);
    3615                 : 
    3616                 : extern JS_PUBLIC_API(JSBool)
    3617                 : JS_ResolveStub(JSContext *cx, JSObject *obj, jsid id);
    3618                 : 
    3619                 : extern JS_PUBLIC_API(JSBool)
    3620                 : JS_ConvertStub(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
    3621                 : 
    3622                 : extern JS_PUBLIC_API(void)
    3623                 : JS_FinalizeStub(JSContext *cx, JSObject *obj);
    3624                 : 
    3625                 : struct JSConstDoubleSpec {
    3626                 :     double          dval;
    3627                 :     const char      *name;
    3628                 :     uint8_t         flags;
    3629                 :     uint8_t         spare[3];
    3630                 : };
    3631                 : 
    3632                 : /*
    3633                 :  * To define an array element rather than a named property member, cast the
    3634                 :  * element's index to (const char *) and initialize name with it, and set the
    3635                 :  * JSPROP_INDEX bit in flags.
    3636                 :  */
    3637                 : struct JSPropertySpec {
    3638                 :     const char            *name;
    3639                 :     int8_t                tinyid;
    3640                 :     uint8_t               flags;
    3641                 :     JSPropertyOp          getter;
    3642                 :     JSStrictPropertyOp    setter;
    3643                 : };
    3644                 : 
    3645                 : struct JSFunctionSpec {
    3646                 :     const char      *name;
    3647                 :     JSNative        call;
    3648                 :     uint16_t        nargs;
    3649                 :     uint16_t        flags;
    3650                 : };
    3651                 : 
    3652                 : /*
    3653                 :  * Terminating sentinel initializer to put at the end of a JSFunctionSpec array
    3654                 :  * that's passed to JS_DefineFunctions or JS_InitClass.
    3655                 :  */
    3656                 : #define JS_FS_END JS_FS(NULL,NULL,0,0)
    3657                 : 
    3658                 : /*
    3659                 :  * Initializer macros for a JSFunctionSpec array element. JS_FN (whose name
    3660                 :  * pays homage to the old JSNative/JSFastNative split) simply adds the flag
    3661                 :  * JSFUN_STUB_GSOPS.
    3662                 :  */
    3663                 : #define JS_FS(name,call,nargs,flags)                                          \
    3664                 :     {name, call, nargs, flags}
    3665                 : #define JS_FN(name,call,nargs,flags)                                          \
    3666                 :     {name, call, nargs, (flags) | JSFUN_STUB_GSOPS}
    3667                 : 
    3668                 : extern JS_PUBLIC_API(JSObject *)
    3669                 : JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
    3670                 :              JSClass *clasp, JSNative constructor, unsigned nargs,
    3671                 :              JSPropertySpec *ps, JSFunctionSpec *fs,
    3672                 :              JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
    3673                 : 
    3674                 : /*
    3675                 :  * Set up ctor.prototype = proto and proto.constructor = ctor with the
    3676                 :  * right property flags.
    3677                 :  */
    3678                 : extern JS_PUBLIC_API(JSBool)
    3679                 : JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto);
    3680                 : 
    3681                 : extern JS_PUBLIC_API(JSClass *)
    3682                 : JS_GetClass(JSObject *obj);
    3683                 : 
    3684                 : extern JS_PUBLIC_API(JSBool)
    3685                 : JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
    3686                 : 
    3687                 : extern JS_PUBLIC_API(JSBool)
    3688                 : JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
    3689                 : 
    3690                 : extern JS_PUBLIC_API(void *)
    3691                 : JS_GetPrivate(JSObject *obj);
    3692                 : 
    3693                 : extern JS_PUBLIC_API(void)
    3694                 : JS_SetPrivate(JSObject *obj, void *data);
    3695                 : 
    3696                 : extern JS_PUBLIC_API(void *)
    3697                 : JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
    3698                 :                       jsval *argv);
    3699                 : 
    3700                 : extern JS_PUBLIC_API(JSObject *)
    3701                 : JS_GetPrototype(JSObject *obj);
    3702                 : 
    3703                 : extern JS_PUBLIC_API(JSBool)
    3704                 : JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
    3705                 : 
    3706                 : extern JS_PUBLIC_API(JSObject *)
    3707                 : JS_GetParent(JSObject *obj);
    3708                 : 
    3709                 : extern JS_PUBLIC_API(JSBool)
    3710                 : JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
    3711                 : 
    3712                 : extern JS_PUBLIC_API(JSObject *)
    3713                 : JS_GetConstructor(JSContext *cx, JSObject *proto);
    3714                 : 
    3715                 : /*
    3716                 :  * Get a unique identifier for obj, good for the lifetime of obj (even if it
    3717                 :  * is moved by a copying GC).  Return false on failure (likely out of memory),
    3718                 :  * and true with *idp containing the unique id on success.
    3719                 :  */
    3720                 : extern JS_PUBLIC_API(JSBool)
    3721                 : JS_GetObjectId(JSContext *cx, JSObject *obj, jsid *idp);
    3722                 : 
    3723                 : extern JS_PUBLIC_API(JSObject *)
    3724                 : JS_NewGlobalObject(JSContext *cx, JSClass *clasp);
    3725                 : 
    3726                 : extern JS_PUBLIC_API(JSObject *)
    3727                 : JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals);
    3728                 : 
    3729                 : extern JS_PUBLIC_API(JSObject *)
    3730                 : JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
    3731                 : 
    3732                 : /* Queries the [[Extensible]] property of the object. */
    3733                 : extern JS_PUBLIC_API(JSBool)
    3734                 : JS_IsExtensible(JSObject *obj);
    3735                 : 
    3736                 : extern JS_PUBLIC_API(JSBool)
    3737                 : JS_IsNative(JSObject *obj);
    3738                 : 
    3739                 : extern JS_PUBLIC_API(JSRuntime *)
    3740                 : JS_GetObjectRuntime(JSObject *obj);
    3741                 : 
    3742                 : /*
    3743                 :  * Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
    3744                 :  * proto if proto's actual parameter value is null.
    3745                 :  */
    3746                 : extern JS_PUBLIC_API(JSObject *)
    3747                 : JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
    3748                 :                            JSObject *parent);
    3749                 : 
    3750                 : /*
    3751                 :  * Freeze obj, and all objects it refers to, recursively. This will not recurse
    3752                 :  * through non-extensible objects, on the assumption that those are already
    3753                 :  * deep-frozen.
    3754                 :  */
    3755                 : extern JS_PUBLIC_API(JSBool)
    3756                 : JS_DeepFreezeObject(JSContext *cx, JSObject *obj);
    3757                 : 
    3758                 : /*
    3759                 :  * Freezes an object; see ES5's Object.freeze(obj) method.
    3760                 :  */
    3761                 : extern JS_PUBLIC_API(JSBool)
    3762                 : JS_FreezeObject(JSContext *cx, JSObject *obj);
    3763                 : 
    3764                 : extern JS_PUBLIC_API(JSObject *)
    3765                 : JS_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *parent);
    3766                 : 
    3767                 : extern JS_PUBLIC_API(JSObject *)
    3768                 : JS_ConstructObjectWithArguments(JSContext *cx, JSClass *clasp, JSObject *parent,
    3769                 :                                 unsigned argc, jsval *argv);
    3770                 : 
    3771                 : extern JS_PUBLIC_API(JSObject *)
    3772                 : JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv);
    3773                 : 
    3774                 : extern JS_PUBLIC_API(JSObject *)
    3775                 : JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
    3776                 :                 JSObject *proto, unsigned attrs);
    3777                 : 
    3778                 : extern JS_PUBLIC_API(JSBool)
    3779                 : JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
    3780                 : 
    3781                 : extern JS_PUBLIC_API(JSBool)
    3782                 : JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
    3783                 : 
    3784                 : extern JS_PUBLIC_API(JSBool)
    3785                 : JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
    3786                 :                   JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
    3787                 : 
    3788                 : extern JS_PUBLIC_API(JSBool)
    3789                 : JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
    3790                 :                       JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
    3791                 : 
    3792                 : extern JS_PUBLIC_API(JSBool)
    3793                 : JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, JSBool *bp);
    3794                 : 
    3795                 : /*
    3796                 :  * Determine the attributes (JSPROP_* flags) of a property on a given object.
    3797                 :  *
    3798                 :  * If the object does not have a property by that name, *foundp will be
    3799                 :  * JS_FALSE and the value of *attrsp is undefined.
    3800                 :  */
    3801                 : extern JS_PUBLIC_API(JSBool)
    3802                 : JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
    3803                 :                          unsigned *attrsp, JSBool *foundp);
    3804                 : 
    3805                 : /*
    3806                 :  * The same, but if the property is native, return its getter and setter via
    3807                 :  * *getterp and *setterp, respectively (and only if the out parameter pointer
    3808                 :  * is not null).
    3809                 :  */
    3810                 : extern JS_PUBLIC_API(JSBool)
    3811                 : JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
    3812                 :                                    const char *name,
    3813                 :                                    unsigned *attrsp, JSBool *foundp,
    3814                 :                                    JSPropertyOp *getterp,
    3815                 :                                    JSStrictPropertyOp *setterp);
    3816                 : 
    3817                 : extern JS_PUBLIC_API(JSBool)
    3818                 : JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj,
    3819                 :                                        jsid id,
    3820                 :                                        unsigned *attrsp, JSBool *foundp,
    3821                 :                                        JSPropertyOp *getterp,
    3822                 :                                        JSStrictPropertyOp *setterp);
    3823                 : 
    3824                 : /*
    3825                 :  * Set the attributes of a property on a given object.
    3826                 :  *
    3827                 :  * If the object does not have a property by that name, *foundp will be
    3828                 :  * JS_FALSE and nothing will be altered.
    3829                 :  */
    3830                 : extern JS_PUBLIC_API(JSBool)
    3831                 : JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
    3832                 :                          unsigned attrs, JSBool *foundp);
    3833                 : 
    3834                 : extern JS_PUBLIC_API(JSBool)
    3835                 : JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
    3836                 :                             int8_t tinyid, jsval value,
    3837                 :                             JSPropertyOp getter, JSStrictPropertyOp setter,
    3838                 :                             unsigned attrs);
    3839                 : 
    3840                 : extern JS_PUBLIC_API(JSBool)
    3841                 : JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
    3842                 :                          JSBool *foundp);
    3843                 : 
    3844                 : extern JS_PUBLIC_API(JSBool)
    3845                 : JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id,
    3846                 :                              JSBool *foundp);
    3847                 : 
    3848                 : extern JS_PUBLIC_API(JSBool)
    3849                 : JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
    3850                 : 
    3851                 : extern JS_PUBLIC_API(JSBool)
    3852                 : JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp);
    3853                 : 
    3854                 : extern JS_PUBLIC_API(JSBool)
    3855                 : JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
    3856                 : 
    3857                 : extern JS_PUBLIC_API(JSBool)
    3858                 : JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
    3859                 : 
    3860                 : extern JS_PUBLIC_API(JSBool)
    3861                 : JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
    3862                 :                            unsigned flags, jsval *vp);
    3863                 : 
    3864                 : extern JS_PUBLIC_API(JSBool)
    3865                 : JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id,
    3866                 :                                unsigned flags, JSObject **objp, jsval *vp);
    3867                 : 
    3868                 : struct JSPropertyDescriptor {
    3869                 :     JSObject           *obj;
    3870                 :     unsigned              attrs;
    3871                 :     JSPropertyOp       getter;
    3872                 :     JSStrictPropertyOp setter;
    3873                 :     jsval              value;
    3874                 :     unsigned              shortid;
    3875                 : };
    3876                 : 
    3877                 : /*
    3878                 :  * Like JS_GetPropertyAttrsGetterAndSetterById but will return a property on
    3879                 :  * an object on the prototype chain (returned in objp). If data->obj is null,
    3880                 :  * then this property was not found on the prototype chain.
    3881                 :  */
    3882                 : extern JS_PUBLIC_API(JSBool)
    3883                 : JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags,
    3884                 :                              JSPropertyDescriptor *desc);
    3885                 : 
    3886                 : extern JS_PUBLIC_API(JSBool)
    3887                 : JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
    3888                 : 
    3889                 : extern JS_PUBLIC_API(JSBool)
    3890                 : JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
    3891                 : 
    3892                 : extern JS_PUBLIC_API(JSBool)
    3893                 : JS_GetPropertyDefault(JSContext *cx, JSObject *obj, const char *name, jsval def, jsval *vp);
    3894                 : 
    3895                 : extern JS_PUBLIC_API(JSBool)
    3896                 : JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
    3897                 : 
    3898                 : extern JS_PUBLIC_API(JSBool)
    3899                 : JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsval *vp);
    3900                 : 
    3901                 : extern JS_PUBLIC_API(JSBool)
    3902                 : JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, jsval *vp);
    3903                 : 
    3904                 : extern JS_PUBLIC_API(JSBool)
    3905                 : JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
    3906                 :                  jsval *vp);
    3907                 : 
    3908                 : extern JS_PUBLIC_API(JSBool)
    3909                 : JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
    3910                 :              jsval *vp);
    3911                 : 
    3912                 : extern JS_PUBLIC_API(JSBool)
    3913                 : JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
    3914                 : 
    3915                 : extern JS_PUBLIC_API(JSBool)
    3916                 : JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
    3917                 : 
    3918                 : extern JS_PUBLIC_API(JSBool)
    3919                 : JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
    3920                 : 
    3921                 : extern JS_PUBLIC_API(JSBool)
    3922                 : JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
    3923                 :                    jsval *rval);
    3924                 : 
    3925                 : extern JS_PUBLIC_API(JSBool)
    3926                 : JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id);
    3927                 : 
    3928                 : extern JS_PUBLIC_API(JSBool)
    3929                 : JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
    3930                 : 
    3931                 : extern JS_PUBLIC_API(JSBool)
    3932                 : JS_DefineUCProperty(JSContext *cx, JSObject *obj,
    3933                 :                     const jschar *name, size_t namelen, jsval value,
    3934                 :                     JSPropertyOp getter, JSStrictPropertyOp setter,
    3935                 :                     unsigned attrs);
    3936                 : 
    3937                 : /*
    3938                 :  * Determine the attributes (JSPROP_* flags) of a property on a given object.
    3939                 :  *
    3940                 :  * If the object does not have a property by that name, *foundp will be
    3941                 :  * JS_FALSE and the value of *attrsp is undefined.
    3942                 :  */
    3943                 : extern JS_PUBLIC_API(JSBool)
    3944                 : JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
    3945                 :                            const jschar *name, size_t namelen,
    3946                 :                            unsigned *attrsp, JSBool *foundp);
    3947                 : 
    3948                 : /*
    3949                 :  * The same, but if the property is native, return its getter and setter via
    3950                 :  * *getterp and *setterp, respectively (and only if the out parameter pointer
    3951                 :  * is not null).
    3952                 :  */
    3953                 : extern JS_PUBLIC_API(JSBool)
    3954                 : JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
    3955                 :                                      const jschar *name, size_t namelen,
    3956                 :                                      unsigned *attrsp, JSBool *foundp,
    3957                 :                                      JSPropertyOp *getterp,
    3958                 :                                      JSStrictPropertyOp *setterp);
    3959                 : 
    3960                 : /*
    3961                 :  * Set the attributes of a property on a given object.
    3962                 :  *
    3963                 :  * If the object does not have a property by that name, *foundp will be
    3964                 :  * JS_FALSE and nothing will be altered.
    3965                 :  */
    3966                 : extern JS_PUBLIC_API(JSBool)
    3967                 : JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
    3968                 :                            const jschar *name, size_t namelen,
    3969                 :                            unsigned attrs, JSBool *foundp);
    3970                 : 
    3971                 : 
    3972                 : extern JS_PUBLIC_API(JSBool)
    3973                 : JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
    3974                 :                               const jschar *name, size_t namelen,
    3975                 :                               int8_t tinyid, jsval value,
    3976                 :                               JSPropertyOp getter, JSStrictPropertyOp setter,
    3977                 :                               unsigned attrs);
    3978                 : 
    3979                 : extern JS_PUBLIC_API(JSBool)
    3980                 : JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name,
    3981                 :                            size_t namelen, JSBool *foundp);
    3982                 : 
    3983                 : extern JS_PUBLIC_API(JSBool)
    3984                 : JS_HasUCProperty(JSContext *cx, JSObject *obj,
    3985                 :                  const jschar *name, size_t namelen,
    3986                 :                  JSBool *vp);
    3987                 : 
    3988                 : extern JS_PUBLIC_API(JSBool)
    3989                 : JS_LookupUCProperty(JSContext *cx, JSObject *obj,
    3990                 :                     const jschar *name, size_t namelen,
    3991                 :                     jsval *vp);
    3992                 : 
    3993                 : extern JS_PUBLIC_API(JSBool)
    3994                 : JS_GetUCProperty(JSContext *cx, JSObject *obj,
    3995                 :                  const jschar *name, size_t namelen,
    3996                 :                  jsval *vp);
    3997                 : 
    3998                 : extern JS_PUBLIC_API(JSBool)
    3999                 : JS_SetUCProperty(JSContext *cx, JSObject *obj,
    4000                 :                  const jschar *name, size_t namelen,
    4001                 :                  jsval *vp);
    4002                 : 
    4003                 : extern JS_PUBLIC_API(JSBool)
    4004                 : JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
    4005                 :                      const jschar *name, size_t namelen,
    4006                 :                      jsval *rval);
    4007                 : 
    4008                 : extern JS_PUBLIC_API(JSObject *)
    4009                 : JS_NewArrayObject(JSContext *cx, int length, jsval *vector);
    4010                 : 
    4011                 : extern JS_PUBLIC_API(JSBool)
    4012                 : JS_IsArrayObject(JSContext *cx, JSObject *obj);
    4013                 : 
    4014                 : extern JS_PUBLIC_API(JSBool)
    4015                 : JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp);
    4016                 : 
    4017                 : extern JS_PUBLIC_API(JSBool)
    4018                 : JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length);
    4019                 : 
    4020                 : extern JS_PUBLIC_API(JSBool)
    4021                 : JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value,
    4022                 :                  JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
    4023                 : 
    4024                 : extern JS_PUBLIC_API(JSBool)
    4025                 : JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, JSBool *foundp);
    4026                 : 
    4027                 : extern JS_PUBLIC_API(JSBool)
    4028                 : JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, JSBool *foundp);
    4029                 : 
    4030                 : extern JS_PUBLIC_API(JSBool)
    4031                 : JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
    4032                 : 
    4033                 : extern JS_PUBLIC_API(JSBool)
    4034                 : JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
    4035                 : 
    4036                 : extern JS_PUBLIC_API(JSBool)
    4037                 : JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
    4038                 :                        jsval *vp);
    4039                 : 
    4040                 : /*
    4041                 :  * Get the property with name given by |index|, if it has one.  If
    4042                 :  * not, |*present| will be set to false and the value of |vp| must not
    4043                 :  * be relied on.
    4044                 :  */
    4045                 : extern JS_PUBLIC_API(JSBool)
    4046                 : JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
    4047                 :                        jsval *vp, JSBool* present);
    4048                 : 
    4049                 : extern JS_PUBLIC_API(JSBool)
    4050                 : JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
    4051                 : 
    4052                 : extern JS_PUBLIC_API(JSBool)
    4053                 : JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index);
    4054                 : 
    4055                 : extern JS_PUBLIC_API(JSBool)
    4056                 : JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, jsval *rval);
    4057                 : 
    4058                 : extern JS_PUBLIC_API(void)
    4059                 : JS_ClearScope(JSContext *cx, JSObject *obj);
    4060                 : 
    4061                 : extern JS_PUBLIC_API(JSIdArray *)
    4062                 : JS_Enumerate(JSContext *cx, JSObject *obj);
    4063                 : 
    4064                 : /*
    4065                 :  * Create an object to iterate over enumerable properties of obj, in arbitrary
    4066                 :  * property definition order.  NB: This differs from longstanding for..in loop
    4067                 :  * order, which uses order of property definition in obj.
    4068                 :  */
    4069                 : extern JS_PUBLIC_API(JSObject *)
    4070                 : JS_NewPropertyIterator(JSContext *cx, JSObject *obj);
    4071                 : 
    4072                 : /*
    4073                 :  * Return true on success with *idp containing the id of the next enumerable
    4074                 :  * property to visit using iterobj, or JSID_IS_VOID if there is no such property
    4075                 :  * left to visit.  Return false on error.
    4076                 :  */
    4077                 : extern JS_PUBLIC_API(JSBool)
    4078                 : JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp);
    4079                 : 
    4080                 : /*
    4081                 :  * Create an object to iterate over the elements of obj in for-of order. This
    4082                 :  * can be used to implement the iteratorObject hook for an array-like Class.
    4083                 :  */
    4084                 : extern JS_PUBLIC_API(JSObject *)
    4085                 : JS_NewElementIterator(JSContext *cx, JSObject *obj);
    4086                 : 
    4087                 : /*
    4088                 :  * To make your array-like class iterable using the for-of loop, set the
    4089                 :  * JSCLASS_FOR_OF_ITERATION bit in the class's flags field and set its
    4090                 :  * .ext.iteratorObject hook to this function.
    4091                 :  */
    4092                 : extern JS_PUBLIC_API(JSObject *)
    4093                 : JS_ElementIteratorStub(JSContext *cx, JSObject *obj, JSBool keysonly);
    4094                 : 
    4095                 : extern JS_PUBLIC_API(JSBool)
    4096                 : JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
    4097                 :                jsval *vp, unsigned *attrsp);
    4098                 : 
    4099                 : extern JS_PUBLIC_API(jsval)
    4100                 : JS_GetReservedSlot(JSObject *obj, uint32_t index);
    4101                 : 
    4102                 : extern JS_PUBLIC_API(void)
    4103                 : JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v);
    4104                 : 
    4105                 : /************************************************************************/
    4106                 : 
    4107                 : /*
    4108                 :  * Security protocol.
    4109                 :  */
    4110            5687 : struct JSPrincipals {
    4111                 :     /* Don't call "destroy"; use reference counting macros below. */
    4112                 :     int refcount;
    4113                 : 
    4114                 : #ifdef DEBUG
    4115                 :     /* A helper to facilitate principals debugging. */
    4116                 :     uint32_t    debugToken;
    4117                 : #endif
    4118                 : 
    4119                 : #ifdef __cplusplus
    4120           11352 :     void setDebugToken(uint32_t token) {
    4121                 : # ifdef DEBUG
    4122           11352 :         debugToken = token;
    4123                 : # endif
    4124           11352 :     }
    4125                 : 
    4126                 :     /*
    4127                 :      * This is not defined by the JS engine but should be provided by the
    4128                 :      * embedding.
    4129                 :      */
    4130                 :     JS_PUBLIC_API(void) dump();
    4131                 : #endif
    4132                 : };
    4133                 : 
    4134                 : extern JS_PUBLIC_API(void)
    4135                 : JS_HoldPrincipals(JSPrincipals *principals);
    4136                 : 
    4137                 : extern JS_PUBLIC_API(void)
    4138                 : JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals);
    4139                 : 
    4140                 : struct JSSecurityCallbacks {
    4141                 :     JSCheckAccessOp            checkObjectAccess;
    4142                 :     JSSubsumePrincipalsOp      subsumePrincipals;
    4143                 :     JSPrincipalsTranscoder     principalsTranscoder;
    4144                 :     JSObjectPrincipalsFinder   findObjectPrincipals;
    4145                 :     JSCSPEvalChecker           contentSecurityPolicyAllows;
    4146                 : };
    4147                 : 
    4148                 : extern JS_PUBLIC_API(void)
    4149                 : JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks);
    4150                 : 
    4151                 : extern JS_PUBLIC_API(const JSSecurityCallbacks *)
    4152                 : JS_GetSecurityCallbacks(JSRuntime *rt);
    4153                 : 
    4154                 : /*
    4155                 :  * Code running with "trusted" principals will be given a deeper stack
    4156                 :  * allocation than ordinary scripts. This allows trusted script to run after
    4157                 :  * untrusted script has exhausted the stack. This function sets the
    4158                 :  * runtime-wide trusted principal.
    4159                 :  *
    4160                 :  * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since
    4161                 :  * there is no available JSContext. Instead, the caller must ensure that the
    4162                 :  * given principals stays valid for as long as 'rt' may point to it. If the
    4163                 :  * principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be
    4164                 :  * called again, passing NULL for 'prin'.
    4165                 :  */
    4166                 : extern JS_PUBLIC_API(void)
    4167                 : JS_SetTrustedPrincipals(JSRuntime *rt, JSPrincipals *prin);
    4168                 : 
    4169                 : /*
    4170                 :  * Initialize the callback that is called to destroy JSPrincipals instance
    4171                 :  * when its reference counter drops to zero. The initialization can be done
    4172                 :  * only once per JS runtime.
    4173                 :  */
    4174                 : extern JS_PUBLIC_API(void)
    4175                 : JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals);
    4176                 : 
    4177                 : /************************************************************************/
    4178                 : 
    4179                 : /*
    4180                 :  * Functions and scripts.
    4181                 :  */
    4182                 : extern JS_PUBLIC_API(JSFunction *)
    4183                 : JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
    4184                 :                JSObject *parent, const char *name);
    4185                 : 
    4186                 : /*
    4187                 :  * Create the function with the name given by the id. JSID_IS_STRING(id) must
    4188                 :  * be true.
    4189                 :  */
    4190                 : extern JS_PUBLIC_API(JSFunction *)
    4191                 : JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
    4192                 :                    JSObject *parent, jsid id);
    4193                 : 
    4194                 : extern JS_PUBLIC_API(JSObject *)
    4195                 : JS_GetFunctionObject(JSFunction *fun);
    4196                 : 
    4197                 : /*
    4198                 :  * Return the function's identifier as a JSString, or null if fun is unnamed.
    4199                 :  * The returned string lives as long as fun, so you don't need to root a saved
    4200                 :  * reference to it if fun is well-connected or rooted, and provided you bound
    4201                 :  * the use of the saved reference by fun's lifetime.
    4202                 :  */
    4203                 : extern JS_PUBLIC_API(JSString *)
    4204                 : JS_GetFunctionId(JSFunction *fun);
    4205                 : 
    4206                 : /*
    4207                 :  * Return JSFUN_* flags for fun.
    4208                 :  */
    4209                 : extern JS_PUBLIC_API(unsigned)
    4210                 : JS_GetFunctionFlags(JSFunction *fun);
    4211                 : 
    4212                 : /*
    4213                 :  * Return the arity (length) of fun.
    4214                 :  */
    4215                 : extern JS_PUBLIC_API(uint16_t)
    4216                 : JS_GetFunctionArity(JSFunction *fun);
    4217                 : 
    4218                 : /*
    4219                 :  * Infallible predicate to test whether obj is a function object (faster than
    4220                 :  * comparing obj's class name to "Function", but equivalent unless someone has
    4221                 :  * overwritten the "Function" identifier with a different constructor and then
    4222                 :  * created instances using that constructor that might be passed in as obj).
    4223                 :  */
    4224                 : extern JS_PUBLIC_API(JSBool)
    4225                 : JS_ObjectIsFunction(JSContext *cx, JSObject *obj);
    4226                 : 
    4227                 : extern JS_PUBLIC_API(JSBool)
    4228                 : JS_ObjectIsCallable(JSContext *cx, JSObject *obj);
    4229                 : 
    4230                 : extern JS_PUBLIC_API(JSBool)
    4231                 : JS_IsNativeFunction(JSObject *funobj, JSNative call);
    4232                 : 
    4233                 : extern JS_PUBLIC_API(JSBool)
    4234                 : JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
    4235                 : 
    4236                 : extern JS_PUBLIC_API(JSFunction *)
    4237                 : JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
    4238                 :                   unsigned nargs, unsigned attrs);
    4239                 : 
    4240                 : extern JS_PUBLIC_API(JSFunction *)
    4241                 : JS_DefineUCFunction(JSContext *cx, JSObject *obj,
    4242                 :                     const jschar *name, size_t namelen, JSNative call,
    4243                 :                     unsigned nargs, unsigned attrs);
    4244                 : 
    4245                 : extern JS_PUBLIC_API(JSFunction *)
    4246                 : JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call,
    4247                 :                       unsigned nargs, unsigned attrs);
    4248                 : 
    4249                 : extern JS_PUBLIC_API(JSObject *)
    4250                 : JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSObject *parent);
    4251                 : 
    4252                 : /*
    4253                 :  * Given a buffer, return JS_FALSE if the buffer might become a valid
    4254                 :  * javascript statement with the addition of more lines.  Otherwise return
    4255                 :  * JS_TRUE.  The intent is to support interactive compilation - accumulate
    4256                 :  * lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
    4257                 :  * the compiler.
    4258                 :  */
    4259                 : extern JS_PUBLIC_API(JSBool)
    4260                 : JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8,
    4261                 :                           JSObject *obj, const char *bytes, size_t length);
    4262                 : 
    4263                 : extern JS_PUBLIC_API(JSScript *)
    4264                 : JS_CompileScript(JSContext *cx, JSObject *obj,
    4265                 :                  const char *bytes, size_t length,
    4266                 :                  const char *filename, unsigned lineno);
    4267                 : 
    4268                 : extern JS_PUBLIC_API(JSScript *)
    4269                 : JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
    4270                 :                               JSPrincipals *principals,
    4271                 :                               const char *bytes, size_t length,
    4272                 :                               const char *filename, unsigned lineno);
    4273                 : 
    4274                 : extern JS_PUBLIC_API(JSScript *)
    4275                 : JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
    4276                 :                                      JSPrincipals *principals,
    4277                 :                                      const char *bytes, size_t length,
    4278                 :                                      const char *filename, unsigned lineno,
    4279                 :                                      JSVersion version);
    4280                 : 
    4281                 : extern JS_PUBLIC_API(JSScript *)
    4282                 : JS_CompileUCScript(JSContext *cx, JSObject *obj,
    4283                 :                    const jschar *chars, size_t length,
    4284                 :                    const char *filename, unsigned lineno);
    4285                 : 
    4286                 : extern JS_PUBLIC_API(JSScript *)
    4287                 : JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
    4288                 :                                 JSPrincipals *principals,
    4289                 :                                 const jschar *chars, size_t length,
    4290                 :                                 const char *filename, unsigned lineno);
    4291                 : 
    4292                 : extern JS_PUBLIC_API(JSScript *)
    4293                 : JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
    4294                 :                                        JSPrincipals *principals,
    4295                 :                                        const jschar *chars, size_t length,
    4296                 :                                        const char *filename, unsigned lineno,
    4297                 :                                        JSVersion version);
    4298                 : /*
    4299                 :  * If originPrincipals is null, then the value of principals is used as origin
    4300                 :  * principals for the compiled script.
    4301                 :  */
    4302                 : extern JS_PUBLIC_API(JSScript *)
    4303                 : JS_CompileUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj,
    4304                 :                                              JSPrincipals *principals,
    4305                 :                                              JSPrincipals *originPrincipals,
    4306                 :                                              const jschar *chars, size_t length,
    4307                 :                                              const char *filename, unsigned lineno,
    4308                 :                                              JSVersion version);
    4309                 : 
    4310                 : extern JS_PUBLIC_API(JSScript *)
    4311                 : JS_CompileUTF8File(JSContext *cx, JSObject *obj, const char *filename);
    4312                 : 
    4313                 : extern JS_PUBLIC_API(JSScript *)
    4314                 : JS_CompileUTF8FileHandle(JSContext *cx, JSObject *obj, const char *filename,
    4315                 :                          FILE *fh);
    4316                 : 
    4317                 : extern JS_PUBLIC_API(JSScript *)
    4318                 : JS_CompileUTF8FileHandleForPrincipals(JSContext *cx, JSObject *obj,
    4319                 :                                       const char *filename, FILE *fh,
    4320                 :                                       JSPrincipals *principals);
    4321                 : 
    4322                 : extern JS_PUBLIC_API(JSScript *)
    4323                 : JS_CompileUTF8FileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj,
    4324                 :                                              const char *filename, FILE *fh,
    4325                 :                                              JSPrincipals *principals,
    4326                 :                                              JSVersion version);
    4327                 : 
    4328                 : extern JS_PUBLIC_API(JSObject *)
    4329                 : JS_GetGlobalFromScript(JSScript *script);
    4330                 : 
    4331                 : extern JS_PUBLIC_API(JSFunction *)
    4332                 : JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
    4333                 :                    unsigned nargs, const char **argnames,
    4334                 :                    const char *bytes, size_t length,
    4335                 :                    const char *filename, unsigned lineno);
    4336                 : 
    4337                 : extern JS_PUBLIC_API(JSFunction *)
    4338                 : JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
    4339                 :                                 JSPrincipals *principals, const char *name,
    4340                 :                                 unsigned nargs, const char **argnames,
    4341                 :                                 const char *bytes, size_t length,
    4342                 :                                 const char *filename, unsigned lineno);
    4343                 : 
    4344                 : extern JS_PUBLIC_API(JSFunction *)
    4345                 : JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
    4346                 :                      unsigned nargs, const char **argnames,
    4347                 :                      const jschar *chars, size_t length,
    4348                 :                      const char *filename, unsigned lineno);
    4349                 : 
    4350                 : extern JS_PUBLIC_API(JSFunction *)
    4351                 : JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
    4352                 :                                   JSPrincipals *principals, const char *name,
    4353                 :                                   unsigned nargs, const char **argnames,
    4354                 :                                   const jschar *chars, size_t length,
    4355                 :                                   const char *filename, unsigned lineno);
    4356                 : 
    4357                 : extern JS_PUBLIC_API(JSFunction *)
    4358                 : JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj,
    4359                 :                                          JSPrincipals *principals, const char *name,
    4360                 :                                          unsigned nargs, const char **argnames,
    4361                 :                                          const jschar *chars, size_t length,
    4362                 :                                          const char *filename, unsigned lineno,
    4363                 :                                          JSVersion version);
    4364                 : 
    4365                 : extern JS_PUBLIC_API(JSString *)
    4366                 : JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent);
    4367                 : 
    4368                 : /*
    4369                 :  * API extension: OR this into indent to avoid pretty-printing the decompiled
    4370                 :  * source resulting from JS_DecompileFunction{,Body}.
    4371                 :  */
    4372                 : #define JS_DONT_PRETTY_PRINT    ((unsigned)0x8000)
    4373                 : 
    4374                 : extern JS_PUBLIC_API(JSString *)
    4375                 : JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent);
    4376                 : 
    4377                 : extern JS_PUBLIC_API(JSString *)
    4378                 : JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent);
    4379                 : 
    4380                 : /*
    4381                 :  * NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj
    4382                 :  * parameter as the initial scope chain header, the 'this' keyword value, and
    4383                 :  * the variables object (ECMA parlance for where 'var' and 'function' bind
    4384                 :  * names) of the execution context for script.
    4385                 :  *
    4386                 :  * Using obj as the variables object is problematic if obj's parent (which is
    4387                 :  * the scope chain link; see JS_SetParent and JS_NewObject) is not null: in
    4388                 :  * this case, variables created by 'var x = 0', e.g., go in obj, but variables
    4389                 :  * created by assignment to an unbound id, 'x = 0', go in the last object on
    4390                 :  * the scope chain linked by parent.
    4391                 :  *
    4392                 :  * ECMA calls that last scoping object the "global object", but note that many
    4393                 :  * embeddings have several such objects.  ECMA requires that "global code" be
    4394                 :  * executed with the variables object equal to this global object.  But these
    4395                 :  * JS API entry points provide freedom to execute code against a "sub-global",
    4396                 :  * i.e., a parented or scoped object, in which case the variables object will
    4397                 :  * differ from the last object on the scope chain, resulting in confusing and
    4398                 :  * non-ECMA explicit vs. implicit variable creation.
    4399                 :  *
    4400                 :  * Caveat embedders: unless you already depend on this buggy variables object
    4401                 :  * binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or
    4402                 :  * JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if
    4403                 :  * someone may have set other options on cx already -- for each context in the
    4404                 :  * application, if you pass parented objects as the obj parameter, or may ever
    4405                 :  * pass such objects in the future.
    4406                 :  *
    4407                 :  * Why a runtime option?  The alternative is to add six or so new API entry
    4408                 :  * points with signatures matching the following six, and that doesn't seem
    4409                 :  * worth the code bloat cost.  Such new entry points would probably have less
    4410                 :  * obvious names, too, so would not tend to be used.  The JS_SetOption call,
    4411                 :  * OTOH, can be more easily hacked into existing code that does not depend on
    4412                 :  * the bug; such code can continue to use the familiar JS_EvaluateScript,
    4413                 :  * etc., entry points.
    4414                 :  */
    4415                 : extern JS_PUBLIC_API(JSBool)
    4416                 : JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
    4417                 : 
    4418                 : extern JS_PUBLIC_API(JSBool)
    4419                 : JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
    4420                 :                         JSVersion version);
    4421                 : 
    4422                 : /*
    4423                 :  * Execute either the function-defining prolog of a script, or the script's
    4424                 :  * main body, but not both.
    4425                 :  */
    4426                 : typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;
    4427                 : 
    4428                 : extern JS_PUBLIC_API(JSBool)
    4429                 : JS_EvaluateScript(JSContext *cx, JSObject *obj,
    4430                 :                   const char *bytes, unsigned length,
    4431                 :                   const char *filename, unsigned lineno,
    4432                 :                   jsval *rval);
    4433                 : 
    4434                 : extern JS_PUBLIC_API(JSBool)
    4435                 : JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
    4436                 :                                JSPrincipals *principals,
    4437                 :                                const char *bytes, unsigned length,
    4438                 :                                const char *filename, unsigned lineno,
    4439                 :                                jsval *rval);
    4440                 : 
    4441                 : extern JS_PUBLIC_API(JSBool)
    4442                 : JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
    4443                 :                                       JSPrincipals *principals,
    4444                 :                                       const char *bytes, unsigned length,
    4445                 :                                       const char *filename, unsigned lineno,
    4446                 :                                       jsval *rval, JSVersion version);
    4447                 : 
    4448                 : extern JS_PUBLIC_API(JSBool)
    4449                 : JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
    4450                 :                     const jschar *chars, unsigned length,
    4451                 :                     const char *filename, unsigned lineno,
    4452                 :                     jsval *rval);
    4453                 : 
    4454                 : extern JS_PUBLIC_API(JSBool)
    4455                 : JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
    4456                 :                                  JSPrincipals *principals,
    4457                 :                                  const jschar *chars, unsigned length,
    4458                 :                                  const char *filename, unsigned lineno,
    4459                 :                                  jsval *rval);
    4460                 : 
    4461                 : extern JS_PUBLIC_API(JSBool)
    4462                 : JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
    4463                 :                                         JSPrincipals *principals,
    4464                 :                                         const jschar *chars, unsigned length,
    4465                 :                                         const char *filename, unsigned lineno,
    4466                 :                                         jsval *rval, JSVersion version);
    4467                 : 
    4468                 : /*
    4469                 :  * JSAPI clients may optionally specify the 'originPrincipals' of a script.
    4470                 :  * A script's originPrincipals may be retrieved through the debug API (via
    4471                 :  * JS_GetScriptOriginPrincipals) and the originPrincipals are transitively
    4472                 :  * assigned to any nested scripts (including scripts dynamically created via
    4473                 :  * eval and the Function constructor). If originPrincipals is null, then the
    4474                 :  * value of principals is used as origin principals for the script.
    4475                 :  */
    4476                 : extern JS_PUBLIC_API(JSBool)
    4477                 : JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj,
    4478                 :                                               JSPrincipals *principals,
    4479                 :                                               JSPrincipals *originPrincipals,
    4480                 :                                               const jschar *chars, unsigned length,
    4481                 :                                               const char *filename, unsigned lineno,
    4482                 :                                               jsval *rval, JSVersion version);
    4483                 : 
    4484                 : extern JS_PUBLIC_API(JSBool)
    4485                 : JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc,
    4486                 :                 jsval *argv, jsval *rval);
    4487                 : 
    4488                 : extern JS_PUBLIC_API(JSBool)
    4489                 : JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc,
    4490                 :                     jsval *argv, jsval *rval);
    4491                 : 
    4492                 : extern JS_PUBLIC_API(JSBool)
    4493                 : JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc,
    4494                 :                      jsval *argv, jsval *rval);
    4495                 : 
    4496                 : #ifdef __cplusplus
    4497                 : JS_END_EXTERN_C
    4498                 : 
    4499                 : namespace JS {
    4500                 : 
    4501                 : static inline bool
    4502               2 : Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, jsval *rval) {
    4503               2 :     return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval);
    4504                 : }
    4505                 : 
    4506                 : static inline bool
    4507                 : Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, jsval *rval) {
    4508                 :     return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval);
    4509                 : }
    4510                 : 
    4511                 : static inline bool
    4512                 : Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, jsval *rval) {
    4513                 :     return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval);
    4514                 : }
    4515                 : 
    4516                 : extern JS_PUBLIC_API(bool)
    4517                 : Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, jsval *rval);
    4518                 : 
    4519                 : static inline bool
    4520               0 : Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, jsval *rval) {
    4521               0 :     return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval);
    4522                 : }
    4523                 : 
    4524                 : } /* namespace JS */
    4525                 : 
    4526                 : JS_BEGIN_EXTERN_C
    4527                 : #endif /* __cplusplus */
    4528                 : 
    4529                 : /*
    4530                 :  * These functions allow setting an operation callback that will be called
    4531                 :  * from the JS thread some time after any thread triggered the callback using
    4532                 :  * JS_TriggerOperationCallback(rt).
    4533                 :  *
    4534                 :  * To schedule the GC and for other activities the engine internally triggers
    4535                 :  * operation callbacks. The embedding should thus not rely on callbacks being
    4536                 :  * triggered through the external API only.
    4537                 :  *
    4538                 :  * Important note: Additional callbacks can occur inside the callback handler
    4539                 :  * if it re-enters the JS engine. The embedding must ensure that the callback
    4540                 :  * is disconnected before attempting such re-entry.
    4541                 :  */
    4542                 : extern JS_PUBLIC_API(JSOperationCallback)
    4543                 : JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback);
    4544                 : 
    4545                 : extern JS_PUBLIC_API(JSOperationCallback)
    4546                 : JS_GetOperationCallback(JSContext *cx);
    4547                 : 
    4548                 : extern JS_PUBLIC_API(void)
    4549                 : JS_TriggerOperationCallback(JSRuntime *rt);
    4550                 : 
    4551                 : extern JS_PUBLIC_API(JSBool)
    4552                 : JS_IsRunning(JSContext *cx);
    4553                 : 
    4554                 : /*
    4555                 :  * Saving and restoring frame chains.
    4556                 :  *
    4557                 :  * These two functions are used to set aside cx's call stack while that stack
    4558                 :  * is inactive. After a call to JS_SaveFrameChain, it looks as if there is no
    4559                 :  * code running on cx. Before calling JS_RestoreFrameChain, cx's call stack
    4560                 :  * must be balanced and all nested calls to JS_SaveFrameChain must have had
    4561                 :  * matching JS_RestoreFrameChain calls.
    4562                 :  *
    4563                 :  * JS_SaveFrameChain deals with cx not having any code running on it.
    4564                 :  */
    4565                 : extern JS_PUBLIC_API(JSBool)
    4566                 : JS_SaveFrameChain(JSContext *cx);
    4567                 : 
    4568                 : extern JS_PUBLIC_API(void)
    4569                 : JS_RestoreFrameChain(JSContext *cx);
    4570                 : 
    4571                 : #ifdef MOZ_TRACE_JSCALLS
    4572                 : /*
    4573                 :  * The callback is expected to be quick and noninvasive. It should not
    4574                 :  * trigger interrupts, turn on debugging, or produce uncaught JS
    4575                 :  * exceptions. The state of the stack and registers in the context
    4576                 :  * cannot be relied upon, since this callback may be invoked directly
    4577                 :  * from either JIT. The 'entering' field means we are entering a
    4578                 :  * function if it is positive, leaving a function if it is zero or
    4579                 :  * negative.
    4580                 :  */
    4581                 : extern JS_PUBLIC_API(void)
    4582                 : JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb);
    4583                 : 
    4584                 : extern JS_PUBLIC_API(JSFunctionCallback)
    4585                 : JS_GetFunctionCallback(JSContext *cx);
    4586                 : #endif /* MOZ_TRACE_JSCALLS */
    4587                 : 
    4588                 : /************************************************************************/
    4589                 : 
    4590                 : /*
    4591                 :  * Strings.
    4592                 :  *
    4593                 :  * NB: JS_NewUCString takes ownership of bytes on success, avoiding a copy;
    4594                 :  * but on error (signified by null return), it leaves chars owned by the
    4595                 :  * caller. So the caller must free bytes in the error case, if it has no use
    4596                 :  * for them. In contrast, all the JS_New*StringCopy* functions do not take
    4597                 :  * ownership of the character memory passed to them -- they copy it.
    4598                 :  */
    4599                 : extern JS_PUBLIC_API(JSString *)
    4600                 : JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
    4601                 : 
    4602                 : extern JS_PUBLIC_API(JSString *)
    4603                 : JS_NewStringCopyZ(JSContext *cx, const char *s);
    4604                 : 
    4605                 : extern JS_PUBLIC_API(JSString *)
    4606                 : JS_InternJSString(JSContext *cx, JSString *str);
    4607                 : 
    4608                 : extern JS_PUBLIC_API(JSString *)
    4609                 : JS_InternString(JSContext *cx, const char *s);
    4610                 : 
    4611                 : extern JS_PUBLIC_API(JSString *)
    4612                 : JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
    4613                 : 
    4614                 : extern JS_PUBLIC_API(JSString *)
    4615                 : JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
    4616                 : 
    4617                 : extern JS_PUBLIC_API(JSString *)
    4618                 : JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
    4619                 : 
    4620                 : extern JS_PUBLIC_API(JSString *)
    4621                 : JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length);
    4622                 : 
    4623                 : extern JS_PUBLIC_API(JSString *)
    4624                 : JS_InternUCString(JSContext *cx, const jschar *s);
    4625                 : 
    4626                 : extern JS_PUBLIC_API(JSBool)
    4627                 : JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result);
    4628                 : 
    4629                 : extern JS_PUBLIC_API(JSBool)
    4630                 : JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, JSBool *match);
    4631                 : 
    4632                 : extern JS_PUBLIC_API(size_t)
    4633                 : JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote);
    4634                 : 
    4635                 : extern JS_PUBLIC_API(JSBool)
    4636                 : JS_FileEscapedString(FILE *fp, JSString *str, char quote);
    4637                 : 
    4638                 : /*
    4639                 :  * Extracting string characters and length.
    4640                 :  *
    4641                 :  * While getting the length of a string is infallible, getting the chars can
    4642                 :  * fail. As indicated by the lack of a JSContext parameter, there are two
    4643                 :  * special cases where getting the chars is infallible:
    4644                 :  *
    4645                 :  * The first case is interned strings, i.e., strings from JS_InternString or
    4646                 :  * JSID_TO_STRING(id), using JS_GetInternedStringChars*.
    4647                 :  *
    4648                 :  * The second case is "flat" strings that have been explicitly prepared in a
    4649                 :  * fallible context by JS_FlattenString. To catch errors, a separate opaque
    4650                 :  * JSFlatString type is returned by JS_FlattenString and expected by
    4651                 :  * JS_GetFlatStringChars. Note, though, that this is purely a syntactic
    4652                 :  * distinction: the input and output of JS_FlattenString are the same actual
    4653                 :  * GC-thing so only one needs to be rooted. If a JSString is known to be flat,
    4654                 :  * JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example:
    4655                 :  *
    4656                 :  *   // in a fallible context
    4657                 :  *   JSFlatString *fstr = JS_FlattenString(cx, str);
    4658                 :  *   if (!fstr)
    4659                 :  *     return JS_FALSE;
    4660                 :  *   JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str));
    4661                 :  *
    4662                 :  *   // in an infallible context, for the same 'str'
    4663                 :  *   const jschar *chars = JS_GetFlatStringChars(fstr)
    4664                 :  *   JS_ASSERT(chars);
    4665                 :  *
    4666                 :  * The CharsZ APIs guarantee that the returned array has a null character at
    4667                 :  * chars[length]. This can require additional copying so clients should prefer
    4668                 :  * APIs without CharsZ if possible. The infallible functions also return
    4669                 :  * null-terminated arrays. (There is no additional cost or non-Z alternative
    4670                 :  * for the infallible functions, so 'Z' is left out of the identifier.)
    4671                 :  */
    4672                 : 
    4673                 : extern JS_PUBLIC_API(size_t)
    4674                 : JS_GetStringLength(JSString *str);
    4675                 : 
    4676                 : extern JS_PUBLIC_API(const jschar *)
    4677                 : JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length);
    4678                 : 
    4679                 : extern JS_PUBLIC_API(const jschar *)
    4680                 : JS_GetInternedStringChars(JSString *str);
    4681                 : 
    4682                 : extern JS_PUBLIC_API(const jschar *)
    4683                 : JS_GetInternedStringCharsAndLength(JSString *str, size_t *length);
    4684                 : 
    4685                 : extern JS_PUBLIC_API(const jschar *)
    4686                 : JS_GetStringCharsZ(JSContext *cx, JSString *str);
    4687                 : 
    4688                 : extern JS_PUBLIC_API(const jschar *)
    4689                 : JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length);
    4690                 : 
    4691                 : extern JS_PUBLIC_API(JSFlatString *)
    4692                 : JS_FlattenString(JSContext *cx, JSString *str);
    4693                 : 
    4694                 : extern JS_PUBLIC_API(const jschar *)
    4695                 : JS_GetFlatStringChars(JSFlatString *str);
    4696                 : 
    4697                 : static JS_ALWAYS_INLINE JSFlatString *
    4698          213490 : JSID_TO_FLAT_STRING(jsid id)
    4699                 : {
    4700          213490 :     JS_ASSERT(JSID_IS_STRING(id));
    4701          213490 :     return (JSFlatString *)(JSID_BITS(id));
    4702                 : }
    4703                 : 
    4704                 : static JS_ALWAYS_INLINE JSFlatString *
    4705               0 : JS_ASSERT_STRING_IS_FLAT(JSString *str)
    4706                 : {
    4707               0 :     JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str));
    4708               0 :     return (JSFlatString *)str;
    4709                 : }
    4710                 : 
    4711                 : static JS_ALWAYS_INLINE JSString *
    4712               0 : JS_FORGET_STRING_FLATNESS(JSFlatString *fstr)
    4713                 : {
    4714               0 :     return (JSString *)fstr;
    4715                 : }
    4716                 : 
    4717                 : /*
    4718                 :  * Additional APIs that avoid fallibility when given a flat string.
    4719                 :  */
    4720                 : 
    4721                 : extern JS_PUBLIC_API(JSBool)
    4722                 : JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes);
    4723                 : 
    4724                 : extern JS_PUBLIC_API(size_t)
    4725                 : JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote);
    4726                 : 
    4727                 : /*
    4728                 :  * This function is now obsolete and behaves the same as JS_NewUCString.  Use
    4729                 :  * JS_NewUCString instead.
    4730                 :  */
    4731                 : extern JS_PUBLIC_API(JSString *)
    4732                 : JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length);
    4733                 : 
    4734                 : /*
    4735                 :  * Mutable string support.  A string's characters are never mutable in this JS
    4736                 :  * implementation, but a dependent string is a substring of another dependent
    4737                 :  * or immutable string, and a rope is a lazily concatenated string that creates
    4738                 :  * its underlying buffer the first time it is accessed.  Even after a rope
    4739                 :  * creates its underlying buffer, it still considered mutable.  The direct data
    4740                 :  * members of the (opaque to API clients) JSString struct may be changed in a
    4741                 :  * single-threaded way for dependent strings and ropes.
    4742                 :  *
    4743                 :  * Therefore mutable strings (ropes and dependent strings) cannot be used by
    4744                 :  * more than one thread at a time.  You may call JS_MakeStringImmutable to
    4745                 :  * convert the string from a mutable string to an immutable (and therefore
    4746                 :  * thread-safe) string.  The engine takes care of converting ropes and dependent
    4747                 :  * strings to immutable for you if you store strings in multi-threaded objects
    4748                 :  * using JS_SetProperty or kindred API entry points.
    4749                 :  *
    4750                 :  * If you store a JSString pointer in a native data structure that is (safely)
    4751                 :  * accessible to multiple threads, you must call JS_MakeStringImmutable before
    4752                 :  * retiring the store.
    4753                 :  */
    4754                 : 
    4755                 : /*
    4756                 :  * Create a dependent string, i.e., a string that owns no character storage,
    4757                 :  * but that refers to a slice of another string's chars.  Dependent strings
    4758                 :  * are mutable by definition, so the thread safety comments above apply.
    4759                 :  */
    4760                 : extern JS_PUBLIC_API(JSString *)
    4761                 : JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
    4762                 :                       size_t length);
    4763                 : 
    4764                 : /*
    4765                 :  * Concatenate two strings, possibly resulting in a rope.
    4766                 :  * See above for thread safety comments.
    4767                 :  */
    4768                 : extern JS_PUBLIC_API(JSString *)
    4769                 : JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
    4770                 : 
    4771                 : /*
    4772                 :  * Convert a dependent string into an independent one.  This function does not
    4773                 :  * change the string's mutability, so the thread safety comments above apply.
    4774                 :  */
    4775                 : extern JS_PUBLIC_API(const jschar *)
    4776                 : JS_UndependString(JSContext *cx, JSString *str);
    4777                 : 
    4778                 : /*
    4779                 :  * Convert a mutable string (either rope or dependent) into an immutable,
    4780                 :  * thread-safe one.
    4781                 :  */
    4782                 : extern JS_PUBLIC_API(JSBool)
    4783                 : JS_MakeStringImmutable(JSContext *cx, JSString *str);
    4784                 : 
    4785                 : /*
    4786                 :  * Return JS_TRUE if C (char []) strings passed via the API and internally
    4787                 :  * are UTF-8.
    4788                 :  */
    4789                 : JS_PUBLIC_API(JSBool)
    4790                 : JS_CStringsAreUTF8(void);
    4791                 : 
    4792                 : /*
    4793                 :  * Update the value to be returned by JS_CStringsAreUTF8(). Once set, it
    4794                 :  * can never be changed. This API must be called before the first call to
    4795                 :  * JS_NewRuntime.
    4796                 :  */
    4797                 : JS_PUBLIC_API(void)
    4798                 : JS_SetCStringsAreUTF8(void);
    4799                 : 
    4800                 : /*
    4801                 :  * Character encoding support.
    4802                 :  *
    4803                 :  * For both JS_EncodeCharacters and JS_DecodeBytes, set *dstlenp to the size
    4804                 :  * of the destination buffer before the call; on return, *dstlenp contains the
    4805                 :  * number of bytes (JS_EncodeCharacters) or jschars (JS_DecodeBytes) actually
    4806                 :  * stored.  To determine the necessary destination buffer size, make a sizing
    4807                 :  * call that passes NULL for dst.
    4808                 :  *
    4809                 :  * On errors, the functions report the error. In that case, *dstlenp contains
    4810                 :  * the number of characters or bytes transferred so far.  If cx is NULL, no
    4811                 :  * error is reported on failure, and the functions simply return JS_FALSE.
    4812                 :  *
    4813                 :  * NB: Neither function stores an additional zero byte or jschar after the
    4814                 :  * transcoded string.
    4815                 :  *
    4816                 :  * If JS_CStringsAreUTF8() is true then JS_EncodeCharacters encodes to
    4817                 :  * UTF-8, and JS_DecodeBytes decodes from UTF-8, which may create additional
    4818                 :  * errors if the character sequence is malformed.  If UTF-8 support is
    4819                 :  * disabled, the functions deflate and inflate, respectively.
    4820                 :  *
    4821                 :  * JS_DecodeUTF8() always behaves the same independently of JS_CStringsAreUTF8().
    4822                 :  */
    4823                 : JS_PUBLIC_API(JSBool)
    4824                 : JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst,
    4825                 :                     size_t *dstlenp);
    4826                 : 
    4827                 : JS_PUBLIC_API(JSBool)
    4828                 : JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst,
    4829                 :                size_t *dstlenp);
    4830                 : 
    4831                 : JS_PUBLIC_API(JSBool)
    4832                 : JS_DecodeUTF8(JSContext *cx, const char *src, size_t srclen, jschar *dst,
    4833                 :               size_t *dstlenp);
    4834                 : 
    4835                 : /*
    4836                 :  * A variation on JS_EncodeCharacters where a null terminated string is
    4837                 :  * returned that you are expected to call JS_free on when done.
    4838                 :  */
    4839                 : JS_PUBLIC_API(char *)
    4840                 : JS_EncodeString(JSContext *cx, JSString *str);
    4841                 : 
    4842                 : /*
    4843                 :  * Get number of bytes in the string encoding (without accounting for a
    4844                 :  * terminating zero bytes. The function returns (size_t) -1 if the string
    4845                 :  * can not be encoded into bytes and reports an error using cx accordingly.
    4846                 :  */
    4847                 : JS_PUBLIC_API(size_t)
    4848                 : JS_GetStringEncodingLength(JSContext *cx, JSString *str);
    4849                 : 
    4850                 : /*
    4851                 :  * Encode string into a buffer. The function does not stores an additional
    4852                 :  * zero byte. The function returns (size_t) -1 if the string can not be
    4853                 :  * encoded into bytes with no error reported. Otherwise it returns the number
    4854                 :  * of bytes that are necessary to encode the string. If that exceeds the
    4855                 :  * length parameter, the string will be cut and only length bytes will be
    4856                 :  * written into the buffer.
    4857                 :  *
    4858                 :  * If JS_CStringsAreUTF8() is true, the string does not fit into the buffer
    4859                 :  * and the the first length bytes ends in the middle of utf-8 encoding for
    4860                 :  * some character, then such partial utf-8 encoding is replaced by zero bytes.
    4861                 :  * This way the result always represents the valid UTF-8 sequence.
    4862                 :  */
    4863                 : JS_PUBLIC_API(size_t)
    4864                 : JS_EncodeStringToBuffer(JSString *str, char *buffer, size_t length);
    4865                 : 
    4866                 : #ifdef __cplusplus
    4867                 : 
    4868                 : class JSAutoByteString {
    4869                 :   public:
    4870          564592 :     JSAutoByteString(JSContext *cx, JSString *str JS_GUARD_OBJECT_NOTIFIER_PARAM)
    4871          564592 :       : mBytes(JS_EncodeString(cx, str)) {
    4872          564592 :         JS_ASSERT(cx);
    4873          564592 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    4874          564592 :     }
    4875                 : 
    4876          205348 :     JSAutoByteString(JS_GUARD_OBJECT_NOTIFIER_PARAM0)
    4877          205348 :       : mBytes(NULL) {
    4878          205348 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
    4879          205348 :     }
    4880                 : 
    4881         1539880 :     ~JSAutoByteString() {
    4882          769940 :         js::UnwantedForeground::free_(mBytes);
    4883          769940 :     }
    4884                 : 
    4885                 :     /* Take ownership of the given byte array. */
    4886                 :     void initBytes(char *bytes) {
    4887                 :         JS_ASSERT(!mBytes);
    4888                 :         mBytes = bytes;
    4889                 :     }
    4890                 : 
    4891          197484 :     char *encode(JSContext *cx, JSString *str) {
    4892          197484 :         JS_ASSERT(!mBytes);
    4893          197484 :         JS_ASSERT(cx);
    4894          197484 :         mBytes = JS_EncodeString(cx, str);
    4895          197484 :         return mBytes;
    4896                 :     }
    4897                 : 
    4898                 :     void clear() {
    4899                 :         js::UnwantedForeground::free_(mBytes);
    4900                 :         mBytes = NULL;
    4901                 :     }
    4902                 : 
    4903         1776338 :     char *ptr() const {
    4904         1776338 :         return mBytes;
    4905                 :     }
    4906                 : 
    4907          564592 :     bool operator!() const {
    4908          564592 :         return !mBytes;
    4909                 :     }
    4910                 : 
    4911                 :   private:
    4912                 :     char        *mBytes;
    4913                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
    4914                 : 
    4915                 :     /* Copy and assignment are not supported. */
    4916                 :     JSAutoByteString(const JSAutoByteString &another);
    4917                 :     JSAutoByteString &operator=(const JSAutoByteString &another);
    4918                 : };
    4919                 : 
    4920                 : #endif
    4921                 : 
    4922                 : /************************************************************************/
    4923                 : /*
    4924                 :  * JSON functions
    4925                 :  */
    4926                 : typedef JSBool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data);
    4927                 : 
    4928                 : /*
    4929                 :  * JSON.stringify as specified by ES5.
    4930                 :  */
    4931                 : JS_PUBLIC_API(JSBool)
    4932                 : JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
    4933                 :              JSONWriteCallback callback, void *data);
    4934                 : 
    4935                 : /*
    4936                 :  * JSON.parse as specified by ES5.
    4937                 :  */
    4938                 : JS_PUBLIC_API(JSBool)
    4939                 : JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, jsval *vp);
    4940                 : 
    4941                 : JS_PUBLIC_API(JSBool)
    4942                 : JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, jsval reviver,
    4943                 :                         jsval *vp);
    4944                 : 
    4945                 : /************************************************************************/
    4946                 : 
    4947                 : /* API for the HTML5 internal structured cloning algorithm. */
    4948                 : 
    4949                 : /* The maximum supported structured-clone serialization format version. */
    4950                 : #define JS_STRUCTURED_CLONE_VERSION 1
    4951                 : 
    4952                 : struct JSStructuredCloneCallbacks {
    4953                 :     ReadStructuredCloneOp read;
    4954                 :     WriteStructuredCloneOp write;
    4955                 :     StructuredCloneErrorOp reportError;
    4956                 : };
    4957                 : 
    4958                 : JS_PUBLIC_API(JSBool)
    4959                 : JS_ReadStructuredClone(JSContext *cx, const uint64_t *data, size_t nbytes,
    4960                 :                        uint32_t version, jsval *vp,
    4961                 :                        const JSStructuredCloneCallbacks *optionalCallbacks,
    4962                 :                        void *closure);
    4963                 : 
    4964                 : /* Note: On success, the caller is responsible for calling js::Foreground::free(*datap). */
    4965                 : JS_PUBLIC_API(JSBool)
    4966                 : JS_WriteStructuredClone(JSContext *cx, jsval v, uint64_t **datap, size_t *nbytesp,
    4967                 :                         const JSStructuredCloneCallbacks *optionalCallbacks,
    4968                 :                         void *closure);
    4969                 : 
    4970                 : JS_PUBLIC_API(JSBool)
    4971                 : JS_StructuredClone(JSContext *cx, jsval v, jsval *vp,
    4972                 :                    const JSStructuredCloneCallbacks *optionalCallbacks,
    4973                 :                    void *closure);
    4974                 : 
    4975                 : #ifdef __cplusplus
    4976                 : JS_END_EXTERN_C
    4977                 : 
    4978                 : /* RAII sugar for JS_WriteStructuredClone. */
    4979                 : class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) {
    4980                 :     uint64_t *data_;
    4981                 :     size_t nbytes_;
    4982                 :     uint32_t version_;
    4983                 : 
    4984                 :   public:
    4985            6342 :     JSAutoStructuredCloneBuffer()
    4986            6342 :         : data_(NULL), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {}
    4987                 : 
    4988            6342 :     ~JSAutoStructuredCloneBuffer() { clear(); }
    4989                 : 
    4990            8779 :     uint64_t *data() const { return data_; }
    4991            1837 :     size_t nbytes() const { return nbytes_; }
    4992                 : 
    4993                 :     void clear();
    4994                 : 
    4995                 :     /* Copy some memory. It will be automatically freed by the destructor. */
    4996                 :     bool copy(const uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION);
    4997                 : 
    4998                 :     /*
    4999                 :      * Adopt some memory. It will be automatically freed by the destructor.
    5000                 :      * data must have been allocated by the JS engine (e.g., extracted via
    5001                 :      * JSAutoStructuredCloneBuffer::steal).
    5002                 :      */
    5003                 :     void adopt(uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION);
    5004                 : 
    5005                 :     /*
    5006                 :      * Remove the buffer so that it will not be automatically freed.
    5007                 :      * After this, the caller is responsible for feeding the memory back to
    5008                 :      * JSAutoStructuredCloneBuffer::adopt.
    5009                 :      */
    5010                 :     void steal(uint64_t **datap, size_t *nbytesp, uint32_t *versionp=NULL);
    5011                 : 
    5012                 :     bool read(JSContext *cx, jsval *vp,
    5013                 :               const JSStructuredCloneCallbacks *optionalCallbacks=NULL,
    5014                 :               void *closure=NULL) const;
    5015                 : 
    5016                 :     bool write(JSContext *cx, jsval v,
    5017                 :                const JSStructuredCloneCallbacks *optionalCallbacks=NULL,
    5018                 :                void *closure=NULL);
    5019                 : 
    5020                 :     /**
    5021                 :      * Swap ownership with another JSAutoStructuredCloneBuffer.
    5022                 :      */
    5023                 :     void swap(JSAutoStructuredCloneBuffer &other);
    5024                 : 
    5025                 :   private:
    5026                 :     /* Copy and assignment are not supported. */
    5027                 :     JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other);
    5028                 :     JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other);
    5029                 : };
    5030                 : 
    5031                 : JS_BEGIN_EXTERN_C
    5032                 : #endif
    5033                 : 
    5034                 : /* API for implementing custom serialization behavior (for ImageData, File, etc.) */
    5035                 : 
    5036                 : /* The range of tag values the application may use for its own custom object types. */
    5037                 : #define JS_SCTAG_USER_MIN  ((uint32_t) 0xFFFF8000)
    5038                 : #define JS_SCTAG_USER_MAX  ((uint32_t) 0xFFFFFFFF)
    5039                 : 
    5040                 : #define JS_SCERR_RECURSION 0
    5041                 : 
    5042                 : JS_PUBLIC_API(void)
    5043                 : JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks);
    5044                 : 
    5045                 : JS_PUBLIC_API(JSBool)
    5046                 : JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32_t *p1, uint32_t *p2);
    5047                 : 
    5048                 : JS_PUBLIC_API(JSBool)
    5049                 : JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len);
    5050                 : 
    5051                 : JS_PUBLIC_API(JSBool)
    5052                 : JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data);
    5053                 : 
    5054                 : JS_PUBLIC_API(JSBool)
    5055                 : JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len);
    5056                 : 
    5057                 : /************************************************************************/
    5058                 : 
    5059                 : /*
    5060                 :  * Locale specific string conversion and error message callbacks.
    5061                 :  */
    5062            2352 : struct JSLocaleCallbacks {
    5063                 :     JSLocaleToUpperCase     localeToUpperCase;
    5064                 :     JSLocaleToLowerCase     localeToLowerCase;
    5065                 :     JSLocaleCompare         localeCompare;
    5066                 :     JSLocaleToUnicode       localeToUnicode;
    5067                 :     JSErrorCallback         localeGetErrorMessage;
    5068                 : };
    5069                 : 
    5070                 : /*
    5071                 :  * Establish locale callbacks. The pointer must persist as long as the
    5072                 :  * JSContext.  Passing NULL restores the default behaviour.
    5073                 :  */
    5074                 : extern JS_PUBLIC_API(void)
    5075                 : JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks);
    5076                 : 
    5077                 : /*
    5078                 :  * Return the address of the current locale callbacks struct, which may
    5079                 :  * be NULL.
    5080                 :  */
    5081                 : extern JS_PUBLIC_API(JSLocaleCallbacks *)
    5082                 : JS_GetLocaleCallbacks(JSContext *cx);
    5083                 : 
    5084                 : /************************************************************************/
    5085                 : 
    5086                 : /*
    5087                 :  * Error reporting.
    5088                 :  */
    5089                 : 
    5090                 : /*
    5091                 :  * Report an exception represented by the sprintf-like conversion of format
    5092                 :  * and its arguments.  This exception message string is passed to a pre-set
    5093                 :  * JSErrorReporter function (set by JS_SetErrorReporter).
    5094                 :  */
    5095                 : extern JS_PUBLIC_API(void)
    5096                 : JS_ReportError(JSContext *cx, const char *format, ...);
    5097                 : 
    5098                 : /*
    5099                 :  * Use an errorNumber to retrieve the format string, args are char *
    5100                 :  */
    5101                 : extern JS_PUBLIC_API(void)
    5102                 : JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
    5103                 :                      void *userRef, const unsigned errorNumber, ...);
    5104                 : 
    5105                 : /*
    5106                 :  * Use an errorNumber to retrieve the format string, args are jschar *
    5107                 :  */
    5108                 : extern JS_PUBLIC_API(void)
    5109                 : JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
    5110                 :                      void *userRef, const unsigned errorNumber, ...);
    5111                 : 
    5112                 : /*
    5113                 :  * As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
    5114                 :  * Return true if there was no error trying to issue the warning, and if the
    5115                 :  * warning was not converted into an error due to the JSOPTION_WERROR option
    5116                 :  * being set, false otherwise.
    5117                 :  */
    5118                 : extern JS_PUBLIC_API(JSBool)
    5119                 : JS_ReportWarning(JSContext *cx, const char *format, ...);
    5120                 : 
    5121                 : extern JS_PUBLIC_API(JSBool)
    5122                 : JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags,
    5123                 :                              JSErrorCallback errorCallback, void *userRef,
    5124                 :                              const unsigned errorNumber, ...);
    5125                 : 
    5126                 : extern JS_PUBLIC_API(JSBool)
    5127                 : JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags,
    5128                 :                                JSErrorCallback errorCallback, void *userRef,
    5129                 :                                const unsigned errorNumber, ...);
    5130                 : 
    5131                 : /*
    5132                 :  * Complain when out of memory.
    5133                 :  */
    5134                 : extern JS_PUBLIC_API(void)
    5135                 : JS_ReportOutOfMemory(JSContext *cx);
    5136                 : 
    5137                 : /*
    5138                 :  * Complain when an allocation size overflows the maximum supported limit.
    5139                 :  */
    5140                 : extern JS_PUBLIC_API(void)
    5141                 : JS_ReportAllocationOverflow(JSContext *cx);
    5142                 : 
    5143                 : struct JSErrorReport {
    5144                 :     const char      *filename;      /* source file name, URL, etc., or null */
    5145                 :     JSPrincipals    *originPrincipals; /* see 'originPrincipals' comment above */
    5146                 :     unsigned           lineno;         /* source line number */
    5147                 :     const char      *linebuf;       /* offending source line without final \n */
    5148                 :     const char      *tokenptr;      /* pointer to error token in linebuf */
    5149                 :     const jschar    *uclinebuf;     /* unicode (original) line buffer */
    5150                 :     const jschar    *uctokenptr;    /* unicode (original) token pointer */
    5151                 :     unsigned           flags;          /* error/warning, etc. */
    5152                 :     unsigned           errorNumber;    /* the error number, e.g. see js.msg */
    5153                 :     const jschar    *ucmessage;     /* the (default) error message */
    5154                 :     const jschar    **messageArgs;  /* arguments for the error message */
    5155                 : };
    5156                 : 
    5157                 : /*
    5158                 :  * JSErrorReport flag values.  These may be freely composed.
    5159                 :  */
    5160                 : #define JSREPORT_ERROR      0x0     /* pseudo-flag for default case */
    5161                 : #define JSREPORT_WARNING    0x1     /* reported via JS_ReportWarning */
    5162                 : #define JSREPORT_EXCEPTION  0x2     /* exception was thrown */
    5163                 : #define JSREPORT_STRICT     0x4     /* error or warning due to strict option */
    5164                 : 
    5165                 : /*
    5166                 :  * This condition is an error in strict mode code, a warning if
    5167                 :  * JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at
    5168                 :  * all.  We check the strictness of the context's top frame's script;
    5169                 :  * where that isn't appropriate, the caller should do the right checks
    5170                 :  * itself instead of using this flag.
    5171                 :  */
    5172                 : #define JSREPORT_STRICT_MODE_ERROR 0x8
    5173                 : 
    5174                 : /*
    5175                 :  * If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
    5176                 :  * has been thrown for this runtime error, and the host should ignore it.
    5177                 :  * Exception-aware hosts should also check for JS_IsExceptionPending if
    5178                 :  * JS_ExecuteScript returns failure, and signal or propagate the exception, as
    5179                 :  * appropriate.
    5180                 :  */
    5181                 : #define JSREPORT_IS_WARNING(flags)      (((flags) & JSREPORT_WARNING) != 0)
    5182                 : #define JSREPORT_IS_EXCEPTION(flags)    (((flags) & JSREPORT_EXCEPTION) != 0)
    5183                 : #define JSREPORT_IS_STRICT(flags)       (((flags) & JSREPORT_STRICT) != 0)
    5184                 : #define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) &                      \
    5185                 :                                               JSREPORT_STRICT_MODE_ERROR) != 0)
    5186                 : extern JS_PUBLIC_API(JSErrorReporter)
    5187                 : JS_GetErrorReporter(JSContext *cx);
    5188                 : 
    5189                 : extern JS_PUBLIC_API(JSErrorReporter)
    5190                 : JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
    5191                 : 
    5192                 : /************************************************************************/
    5193                 : 
    5194                 : /*
    5195                 :  * Dates.
    5196                 :  */
    5197                 : 
    5198                 : extern JS_PUBLIC_API(JSObject *)
    5199                 : JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec);
    5200                 : 
    5201                 : extern JS_PUBLIC_API(JSObject *)
    5202                 : JS_NewDateObjectMsec(JSContext *cx, double msec);
    5203                 : 
    5204                 : /*
    5205                 :  * Infallible predicate to test whether obj is a date object.
    5206                 :  */
    5207                 : extern JS_PUBLIC_API(JSBool)
    5208                 : JS_ObjectIsDate(JSContext *cx, JSObject *obj);
    5209                 : 
    5210                 : /************************************************************************/
    5211                 : 
    5212                 : /*
    5213                 :  * Regular Expressions.
    5214                 :  */
    5215                 : #define JSREG_FOLD      0x01    /* fold uppercase to lowercase */
    5216                 : #define JSREG_GLOB      0x02    /* global exec, creates array of matches */
    5217                 : #define JSREG_MULTILINE 0x04    /* treat ^ and $ as begin and end of line */
    5218                 : #define JSREG_STICKY    0x08    /* only match starting at lastIndex */
    5219                 : 
    5220                 : extern JS_PUBLIC_API(JSObject *)
    5221                 : JS_NewRegExpObject(JSContext *cx, JSObject *obj, char *bytes, size_t length, unsigned flags);
    5222                 : 
    5223                 : extern JS_PUBLIC_API(JSObject *)
    5224                 : JS_NewUCRegExpObject(JSContext *cx, JSObject *obj, jschar *chars, size_t length, unsigned flags);
    5225                 : 
    5226                 : extern JS_PUBLIC_API(void)
    5227                 : JS_SetRegExpInput(JSContext *cx, JSObject *obj, JSString *input, JSBool multiline);
    5228                 : 
    5229                 : extern JS_PUBLIC_API(void)
    5230                 : JS_ClearRegExpStatics(JSContext *cx, JSObject *obj);
    5231                 : 
    5232                 : extern JS_PUBLIC_API(JSBool)
    5233                 : JS_ExecuteRegExp(JSContext *cx, JSObject *obj, JSObject *reobj, jschar *chars, size_t length,
    5234                 :                  size_t *indexp, JSBool test, jsval *rval);
    5235                 : 
    5236                 : /* RegExp interface for clients without a global object. */
    5237                 : 
    5238                 : extern JS_PUBLIC_API(JSObject *)
    5239                 : JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned flags);
    5240                 : 
    5241                 : extern JS_PUBLIC_API(JSObject *)
    5242                 : JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, unsigned flags);
    5243                 : 
    5244                 : extern JS_PUBLIC_API(JSBool)
    5245                 : JS_ExecuteRegExpNoStatics(JSContext *cx, JSObject *reobj, jschar *chars, size_t length,
    5246                 :                           size_t *indexp, JSBool test, jsval *rval);
    5247                 : 
    5248                 : extern JS_PUBLIC_API(JSBool)
    5249                 : JS_ObjectIsRegExp(JSContext *cx, JSObject *obj);
    5250                 : 
    5251                 : extern JS_PUBLIC_API(unsigned)
    5252                 : JS_GetRegExpFlags(JSContext *cx, JSObject *obj);
    5253                 : 
    5254                 : extern JS_PUBLIC_API(JSString *)
    5255                 : JS_GetRegExpSource(JSContext *cx, JSObject *obj);
    5256                 : 
    5257                 : /************************************************************************/
    5258                 : 
    5259                 : extern JS_PUBLIC_API(JSBool)
    5260                 : JS_IsExceptionPending(JSContext *cx);
    5261                 : 
    5262                 : extern JS_PUBLIC_API(JSBool)
    5263                 : JS_GetPendingException(JSContext *cx, jsval *vp);
    5264                 : 
    5265                 : extern JS_PUBLIC_API(void)
    5266                 : JS_SetPendingException(JSContext *cx, jsval v);
    5267                 : 
    5268                 : extern JS_PUBLIC_API(void)
    5269                 : JS_ClearPendingException(JSContext *cx);
    5270                 : 
    5271                 : extern JS_PUBLIC_API(JSBool)
    5272                 : JS_ReportPendingException(JSContext *cx);
    5273                 : 
    5274                 : /*
    5275                 :  * Save the current exception state.  This takes a snapshot of cx's current
    5276                 :  * exception state without making any change to that state.
    5277                 :  *
    5278                 :  * The returned state pointer MUST be passed later to JS_RestoreExceptionState
    5279                 :  * (to restore that saved state, overriding any more recent state) or else to
    5280                 :  * JS_DropExceptionState (to free the state struct in case it is not correct
    5281                 :  * or desirable to restore it).  Both Restore and Drop free the state struct,
    5282                 :  * so callers must stop using the pointer returned from Save after calling the
    5283                 :  * Release or Drop API.
    5284                 :  */
    5285                 : extern JS_PUBLIC_API(JSExceptionState *)
    5286                 : JS_SaveExceptionState(JSContext *cx);
    5287                 : 
    5288                 : extern JS_PUBLIC_API(void)
    5289                 : JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
    5290                 : 
    5291                 : extern JS_PUBLIC_API(void)
    5292                 : JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
    5293                 : 
    5294                 : /*
    5295                 :  * If the given value is an exception object that originated from an error,
    5296                 :  * the exception will contain an error report struct, and this API will return
    5297                 :  * the address of that struct.  Otherwise, it returns NULL.  The lifetime of
    5298                 :  * the error report struct that might be returned is the same as the lifetime
    5299                 :  * of the exception object.
    5300                 :  */
    5301                 : extern JS_PUBLIC_API(JSErrorReport *)
    5302                 : JS_ErrorFromException(JSContext *cx, jsval v);
    5303                 : 
    5304                 : /*
    5305                 :  * Given a reported error's message and JSErrorReport struct pointer, throw
    5306                 :  * the corresponding exception on cx.
    5307                 :  */
    5308                 : extern JS_PUBLIC_API(JSBool)
    5309                 : JS_ThrowReportedError(JSContext *cx, const char *message,
    5310                 :                       JSErrorReport *reportp);
    5311                 : 
    5312                 : /*
    5313                 :  * Throws a StopIteration exception on cx.
    5314                 :  */
    5315                 : extern JS_PUBLIC_API(JSBool)
    5316                 : JS_ThrowStopIteration(JSContext *cx);
    5317                 : 
    5318                 : extern JS_PUBLIC_API(intptr_t)
    5319                 : JS_GetCurrentThread();
    5320                 : 
    5321                 : /*
    5322                 :  * A JS runtime always has an "owner thread". The owner thread is set when the
    5323                 :  * runtime is created (to the current thread) and practically all entry points
    5324                 :  * into the JS engine check that a runtime (or anything contained in the
    5325                 :  * runtime: context, compartment, object, etc) is only touched by its owner
    5326                 :  * thread. Embeddings may check this invariant outside the JS engine by calling
    5327                 :  * JS_AbortIfWrongThread (which will abort if not on the owner thread, even for
    5328                 :  * non-debug builds).
    5329                 :  *
    5330                 :  * It is possible to "move" a runtime between threads. This is accomplished by
    5331                 :  * calling JS_ClearRuntimeThread on a runtime's owner thread and then calling
    5332                 :  * JS_SetRuntimeThread on the new owner thread. The runtime must not be
    5333                 :  * accessed between JS_ClearRuntimeThread and JS_SetRuntimeThread. Also, the
    5334                 :  * caller is responsible for synchronizing the calls to Set/Clear.
    5335                 :  */
    5336                 : 
    5337                 : extern JS_PUBLIC_API(void)
    5338                 : JS_AbortIfWrongThread(JSRuntime *rt);
    5339                 : 
    5340                 : extern JS_PUBLIC_API(void)
    5341                 : JS_ClearRuntimeThread(JSRuntime *rt);
    5342                 : 
    5343                 : extern JS_PUBLIC_API(void)
    5344                 : JS_SetRuntimeThread(JSRuntime *rt);
    5345                 : 
    5346                 : #ifdef __cplusplus
    5347                 : JS_END_EXTERN_C
    5348                 : 
    5349                 : class JSAutoSetRuntimeThread
    5350                 : {
    5351                 :     JSRuntime *runtime;
    5352                 : 
    5353                 :   public:
    5354                 :     JSAutoSetRuntimeThread(JSRuntime *runtime) : runtime(runtime) {
    5355                 :         JS_SetRuntimeThread(runtime);
    5356                 :     }
    5357                 : 
    5358                 :     ~JSAutoSetRuntimeThread() {
    5359                 :         JS_ClearRuntimeThread(runtime);
    5360                 :     }
    5361                 : };
    5362                 : 
    5363                 : JS_BEGIN_EXTERN_C
    5364                 : #endif
    5365                 : 
    5366                 : /************************************************************************/
    5367                 : 
    5368                 : /*
    5369                 :  * JS_IsConstructing must be called from within a native given the
    5370                 :  * native's original cx and vp arguments. If JS_IsConstructing is true,
    5371                 :  * JS_THIS must not be used; the constructor should construct and return a
    5372                 :  * new object. Otherwise, the native is called as an ordinary function and
    5373                 :  * JS_THIS may be used.
    5374                 :  */
    5375                 : static JS_ALWAYS_INLINE JSBool
    5376                 : JS_IsConstructing(JSContext *cx, const jsval *vp)
    5377                 : {
    5378                 : #ifdef DEBUG
    5379                 :     JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
    5380                 :     if (JS_ObjectIsFunction(cx, callee)) {
    5381                 :         JSFunction *fun = JS_ValueToFunction(cx, JS_CALLEE(cx, vp));
    5382                 :         JS_ASSERT((JS_GetFunctionFlags(fun) & JSFUN_CONSTRUCTOR) != 0);
    5383                 :     } else {
    5384                 :         JS_ASSERT(JS_GetClass(callee)->construct != NULL);
    5385                 :     }
    5386                 : #else
    5387                 :     (void)cx;
    5388                 : #endif
    5389                 : 
    5390                 :     return JSVAL_IS_MAGIC_IMPL(JSVAL_TO_IMPL(vp[1]));
    5391                 : }
    5392                 : 
    5393                 : /*
    5394                 :  * If a constructor does not have any static knowledge about the type of
    5395                 :  * object to create, it can request that the JS engine create a default new
    5396                 :  * 'this' object, as is done for non-constructor natives when called with new.
    5397                 :  */
    5398                 : extern JS_PUBLIC_API(JSObject *)
    5399                 : JS_NewObjectForConstructor(JSContext *cx, const jsval *vp);
    5400                 : 
    5401                 : /************************************************************************/
    5402                 : 
    5403                 : #ifdef DEBUG
    5404                 : #define JS_GC_ZEAL 1
    5405                 : #endif
    5406                 : 
    5407                 : #ifdef JS_GC_ZEAL
    5408                 : #define JS_DEFAULT_ZEAL_FREQ 100
    5409                 : 
    5410                 : extern JS_PUBLIC_API(void)
    5411                 : JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency, JSBool compartment);
    5412                 : 
    5413                 : extern JS_PUBLIC_API(void)
    5414                 : JS_ScheduleGC(JSContext *cx, uint32_t count, JSBool compartment);
    5415                 : #endif
    5416                 : 
    5417                 : /*
    5418                 :  * Convert a uint32_t index into a jsid.
    5419                 :  */
    5420                 : extern JS_PUBLIC_API(JSBool)
    5421                 : JS_IndexToId(JSContext *cx, uint32_t index, jsid *id);
    5422                 : 
    5423                 : /*
    5424                 :  *  Test if the given string is a valid ECMAScript identifier
    5425                 :  */
    5426                 : extern JS_PUBLIC_API(JSBool)
    5427                 : JS_IsIdentifier(JSContext *cx, JSString *str, JSBool *isIdentifier);
    5428                 : 
    5429                 : /*
    5430                 :  * Return the current script and line number of the most currently running
    5431                 :  * frame. Returns true if a scripted frame was found, false otherwise.
    5432                 :  */
    5433                 : extern JS_PUBLIC_API(JSBool)
    5434                 : JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno);
    5435                 : 
    5436                 : 
    5437                 : JS_END_EXTERN_C
    5438                 : 
    5439                 : #endif /* jsapi_h___ */

Generated by: LCOV version 1.7