2010-03-17 07:29:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2008-02-18 00:12:33 +00:00
|
|
|
* vim: set ts=8 sw=4 et tw=78:
|
1998-03-28 02:44:41 +00:00
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-03-28 02:44:41 +00:00
|
|
|
|
|
|
|
#ifndef jsapi_h___
|
|
|
|
#define jsapi_h___
|
|
|
|
/*
|
|
|
|
* JavaScript API.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
|
2012-01-23 11:43:16 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/FloatingPoint.h"
|
2012-03-01 03:56:43 +00:00
|
|
|
#include "mozilla/StandardInteger.h"
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
#include <stddef.h>
|
1999-04-27 15:18:57 +00:00
|
|
|
#include <stdio.h>
|
2008-10-29 15:29:37 +00:00
|
|
|
#include "js-config.h"
|
1998-03-28 02:44:41 +00:00
|
|
|
#include "jspubtd.h"
|
2012-01-15 08:13:11 +00:00
|
|
|
#include "jsutil.h"
|
2011-09-19 16:34:49 +00:00
|
|
|
#include "jsval.h"
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-10-04 22:33:00 +00:00
|
|
|
#include "js/Utility.h"
|
2012-04-12 16:23:51 +00:00
|
|
|
#include "gc/Root.h"
|
2011-10-04 22:33:00 +00:00
|
|
|
|
2012-01-11 08:23:08 +00:00
|
|
|
#ifdef __cplusplus
|
2012-04-10 23:33:44 +00:00
|
|
|
#include <limits> /* for std::numeric_limits */
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
#include "jsalloc.h"
|
2012-01-15 08:13:11 +00:00
|
|
|
#include "js/Vector.h"
|
2012-01-11 08:23:08 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
/* JS::Value can store a full int32_t. */
|
2011-09-19 16:34:49 +00:00
|
|
|
#define JSVAL_INT_BITS 32
|
2012-03-02 02:54:01 +00:00
|
|
|
#define JSVAL_INT_MIN ((int32_t)0x80000000)
|
|
|
|
#define JSVAL_INT_MAX ((int32_t)0x7fffffff)
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protecting non-jsval, non-JSObject *, non-JSString * values from collection
|
|
|
|
*
|
|
|
|
* Most of the time, the garbage collector's conservative stack scanner works
|
|
|
|
* behind the scenes, finding all live values and protecting them from being
|
|
|
|
* collected. However, when JSAPI client code obtains a pointer to data the
|
|
|
|
* scanner does not know about, owned by an object the scanner does know about,
|
|
|
|
* Care Must Be Taken.
|
|
|
|
*
|
|
|
|
* The scanner recognizes only a select set of types: pointers to JSObjects and
|
|
|
|
* similar things (JSFunctions, and so on), pointers to JSStrings, and jsvals.
|
|
|
|
* So while the scanner finds all live |JSString| pointers, it does not notice
|
|
|
|
* |jschar| pointers.
|
|
|
|
*
|
|
|
|
* So suppose we have:
|
|
|
|
*
|
|
|
|
* void f(JSString *str) {
|
|
|
|
* const jschar *ch = JS_GetStringCharsZ(str);
|
|
|
|
* ... do stuff with ch, but no uses of str ...;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* After the call to |JS_GetStringCharsZ|, there are no further uses of
|
|
|
|
* |str|, which means that the compiler is within its rights to not store
|
|
|
|
* it anywhere. But because the stack scanner will not notice |ch|, there
|
|
|
|
* is no longer any live value in this frame that would keep the string
|
|
|
|
* alive. If |str| is the last reference to that |JSString|, and the
|
|
|
|
* collector runs while we are using |ch|, the string's array of |jschar|s
|
|
|
|
* may be freed out from under us.
|
|
|
|
*
|
|
|
|
* Note that there is only an issue when 1) we extract a thing X the scanner
|
|
|
|
* doesn't recognize from 2) a thing Y the scanner does recognize, and 3) if Y
|
|
|
|
* gets garbage-collected, then X gets freed. If we have code like this:
|
|
|
|
*
|
|
|
|
* void g(JSObject *obj) {
|
|
|
|
* jsval x;
|
|
|
|
* JS_GetProperty(obj, "x", &x);
|
|
|
|
* ... do stuff with x ...
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* there's no problem, because the value we've extracted, x, is a jsval, a
|
|
|
|
* type that the conservative scanner recognizes.
|
|
|
|
*
|
|
|
|
* Conservative GC frees us from the obligation to explicitly root the types it
|
|
|
|
* knows about, but when we work with derived values like |ch|, we must root
|
|
|
|
* their owners, as the derived value alone won't keep them alive.
|
|
|
|
*
|
|
|
|
* A JS::Anchor is a kind of GC root that allows us to keep the owners of
|
|
|
|
* derived values like |ch| alive throughout the Anchor's lifetime. We could
|
|
|
|
* fix the above code as follows:
|
|
|
|
*
|
|
|
|
* void f(JSString *str) {
|
|
|
|
* JS::Anchor<JSString *> a_str(str);
|
|
|
|
* const jschar *ch = JS_GetStringCharsZ(str);
|
|
|
|
* ... do stuff with ch, but no uses of str ...;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* This simply ensures that |str| will be live until |a_str| goes out of scope.
|
|
|
|
* As long as we don't retain a pointer to the string's characters for longer
|
|
|
|
* than that, we have avoided all garbage collection hazards.
|
|
|
|
*/
|
|
|
|
template<typename T> class AnchorPermitted;
|
|
|
|
template<> class AnchorPermitted<JSObject *> { };
|
|
|
|
template<> class AnchorPermitted<const JSObject *> { };
|
|
|
|
template<> class AnchorPermitted<JSFunction *> { };
|
|
|
|
template<> class AnchorPermitted<const JSFunction *> { };
|
|
|
|
template<> class AnchorPermitted<JSString *> { };
|
|
|
|
template<> class AnchorPermitted<const JSString *> { };
|
|
|
|
template<> class AnchorPermitted<Value> { };
|
2012-04-05 22:44:55 +00:00
|
|
|
template<> class AnchorPermitted<const JSScript *> { };
|
|
|
|
template<> class AnchorPermitted<JSScript *> { };
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Anchor: AnchorPermitted<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Anchor() { }
|
|
|
|
explicit Anchor(T t) { hold = t; }
|
|
|
|
inline ~Anchor();
|
|
|
|
T &get() { return hold; }
|
|
|
|
const T &get() const { return hold; }
|
|
|
|
void set(const T &t) { hold = t; }
|
2012-04-05 22:44:55 +00:00
|
|
|
void operator=(const T &t) { hold = t; }
|
2011-09-19 16:34:49 +00:00
|
|
|
void clear() { hold = 0; }
|
|
|
|
private:
|
|
|
|
T hold;
|
2012-04-05 22:44:55 +00:00
|
|
|
Anchor(const Anchor &) MOZ_DELETE;
|
|
|
|
const Anchor &operator=(const Anchor &) MOZ_DELETE;
|
2011-09-19 16:34:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
template<typename T>
|
|
|
|
inline Anchor<T>::~Anchor()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No code is generated for this. But because this is marked 'volatile', G++ will
|
|
|
|
* assume it has important side-effects, and won't delete it. (G++ never looks at
|
|
|
|
* the actual text and notices it's empty.) And because we have passed |hold| to
|
|
|
|
* it, GCC will keep |hold| alive until this point.
|
|
|
|
*
|
|
|
|
* The "memory" clobber operand ensures that G++ will not move prior memory
|
|
|
|
* accesses after the asm --- it's a barrier. Unfortunately, it also means that
|
|
|
|
* G++ will assume that all memory has changed after the asm, as it would for a
|
|
|
|
* call to an unknown function. I don't know of a way to avoid that consequence.
|
|
|
|
*/
|
|
|
|
asm volatile("":: "g" (hold) : "memory");
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
template<typename T>
|
|
|
|
inline Anchor<T>::~Anchor()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* An adequate portable substitute, for non-structure types.
|
|
|
|
*
|
|
|
|
* The compiler promises that, by the end of an expression statement, the
|
|
|
|
* last-stored value to a volatile object is the same as it would be in an
|
|
|
|
* unoptimized, direct implementation (the "abstract machine" whose behavior the
|
|
|
|
* language spec describes). However, the compiler is still free to reorder
|
|
|
|
* non-volatile accesses across this store --- which is what we must prevent. So
|
|
|
|
* assigning the held value to a volatile variable, as we do here, is not enough.
|
|
|
|
*
|
|
|
|
* In our case, however, garbage collection only occurs at function calls, so it
|
|
|
|
* is sufficient to ensure that the destructor's store isn't moved earlier across
|
|
|
|
* any function calls that could collect. It is hard to imagine the compiler
|
|
|
|
* analyzing the program so thoroughly that it could prove that such motion was
|
|
|
|
* safe. In practice, compilers treat calls to the collector as opaque operations
|
|
|
|
* --- in particular, as operations which could access volatile variables, across
|
|
|
|
* which this destructor must not be moved.
|
|
|
|
*
|
|
|
|
* ("Objection, your honor! *Alleged* killer whale!")
|
|
|
|
*
|
|
|
|
* The disadvantage of this approach is that it does generate code for the store.
|
|
|
|
* We do need to use Anchors in some cases where cycles are tight.
|
|
|
|
*
|
|
|
|
* NB: there is a Anchor<Value>::~Anchor() specialization below.
|
|
|
|
*/
|
|
|
|
volatile T sink;
|
|
|
|
sink = hold;
|
|
|
|
}
|
|
|
|
#endif /* defined(__GNUC__) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JS::Value is the C++ interface for a single JavaScript Engine value.
|
|
|
|
* A few general notes on JS::Value:
|
|
|
|
*
|
|
|
|
* - JS::Value has setX() and isX() members for X in
|
|
|
|
*
|
|
|
|
* { Int32, Double, String, Boolean, Undefined, Null, Object, Magic }
|
|
|
|
*
|
|
|
|
* JS::Value also contains toX() for each of the non-singleton types.
|
|
|
|
*
|
|
|
|
* - Magic is a singleton type whose payload contains a JSWhyMagic "reason" for
|
|
|
|
* the magic value. By providing JSWhyMagic values when creating and checking
|
|
|
|
* for magic values, it is possible to assert, at runtime, that only magic
|
|
|
|
* values with the expected reason flow through a particular value. For
|
|
|
|
* example, if cx->exception has a magic value, the reason must be
|
|
|
|
* JS_GENERATOR_CLOSING.
|
|
|
|
*
|
2012-01-02 23:06:15 +00:00
|
|
|
* - A key difference between JSVAL_* and JS::Value operations is that
|
|
|
|
* JS::Value gives null a separate type. Thus
|
2011-09-19 16:34:49 +00:00
|
|
|
*
|
|
|
|
* JSVAL_IS_OBJECT(v) === v.isObjectOrNull()
|
|
|
|
* !JSVAL_IS_PRIMITIVE(v) === v.isObject()
|
|
|
|
*
|
|
|
|
* To help prevent mistakenly boxing a nullable JSObject* as an object,
|
|
|
|
* Value::setObject takes a JSObject&. (Conversely, Value::asObject returns a
|
|
|
|
* JSObject&. A convenience member Value::setObjectOrNull is provided.
|
|
|
|
*
|
|
|
|
* - JSVAL_VOID is the same as the singleton value of the Undefined type.
|
|
|
|
*
|
|
|
|
* - Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on
|
|
|
|
* 32-bit user code should avoid copying jsval/JS::Value as much as possible,
|
|
|
|
* preferring to pass by const Value &.
|
|
|
|
*/
|
|
|
|
class Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
* N.B. the default constructor leaves Value unitialized. Adding a default
|
|
|
|
* constructor prevents Value from being stored in a union.
|
|
|
|
*/
|
|
|
|
|
2011-09-20 21:34:11 +00:00
|
|
|
/*** Mutators ***/
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setNull() {
|
|
|
|
data.asBits = BUILD_JSVAL(JSVAL_TAG_NULL, 0).asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setUndefined() {
|
|
|
|
data.asBits = BUILD_JSVAL(JSVAL_TAG_UNDEFINED, 0).asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
void setInt32(int32_t i) {
|
2011-09-19 16:34:49 +00:00
|
|
|
data = INT32_TO_JSVAL_IMPL(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int32_t &getInt32Ref() {
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_ASSERT(isInt32());
|
|
|
|
return data.s.payload.i32;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setDouble(double d) {
|
|
|
|
data = DOUBLE_TO_JSVAL_IMPL(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
double &getDoubleRef() {
|
|
|
|
JS_ASSERT(isDouble());
|
|
|
|
return data.asDouble;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setString(JSString *str) {
|
2011-12-31 14:32:04 +00:00
|
|
|
JS_ASSERT(!IsPoisonedPtr(str));
|
2011-09-19 16:34:49 +00:00
|
|
|
data = STRING_TO_JSVAL_IMPL(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setString(const JS::Anchor<JSString *> &str) {
|
|
|
|
setString(str.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setObject(JSObject &obj) {
|
2011-12-31 14:32:04 +00:00
|
|
|
JS_ASSERT(!IsPoisonedPtr(&obj));
|
2011-09-19 16:34:49 +00:00
|
|
|
data = OBJECT_TO_JSVAL_IMPL(&obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setBoolean(bool b) {
|
|
|
|
data = BOOLEAN_TO_JSVAL_IMPL(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setMagic(JSWhyMagic why) {
|
|
|
|
data = MAGIC_TO_JSVAL_IMPL(why);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
bool setNumber(uint32_t ui) {
|
2011-09-19 16:34:49 +00:00
|
|
|
if (ui > JSVAL_INT_MAX) {
|
|
|
|
setDouble((double)ui);
|
|
|
|
return false;
|
|
|
|
} else {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
setInt32((int32_t)ui);
|
2011-09-19 16:34:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool setNumber(double d) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int32_t i;
|
2012-01-23 11:43:16 +00:00
|
|
|
if (MOZ_DOUBLE_IS_INT32(d, &i)) {
|
2011-09-19 16:34:49 +00:00
|
|
|
setInt32(i);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
setDouble(d);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setObjectOrNull(JSObject *arg) {
|
|
|
|
if (arg)
|
|
|
|
setObject(*arg);
|
|
|
|
else
|
|
|
|
setNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void swap(Value &rhs) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint64_t tmp = rhs.data.asBits;
|
2011-09-19 16:34:49 +00:00
|
|
|
rhs.data.asBits = data.asBits;
|
|
|
|
data.asBits = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Value type queries ***/
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isUndefined() const {
|
|
|
|
return JSVAL_IS_UNDEFINED_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isNull() const {
|
|
|
|
return JSVAL_IS_NULL_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isNullOrUndefined() const {
|
|
|
|
return isNull() || isUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isInt32() const {
|
|
|
|
return JSVAL_IS_INT32_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
bool isInt32(int32_t i32) const {
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_SPECIFIC_INT32_IMPL(data, i32);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isDouble() const {
|
|
|
|
return JSVAL_IS_DOUBLE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isNumber() const {
|
|
|
|
return JSVAL_IS_NUMBER_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isString() const {
|
|
|
|
return JSVAL_IS_STRING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isObject() const {
|
|
|
|
return JSVAL_IS_OBJECT_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isPrimitive() const {
|
|
|
|
return JSVAL_IS_PRIMITIVE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isObjectOrNull() const {
|
|
|
|
return JSVAL_IS_OBJECT_OR_NULL_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isGCThing() const {
|
|
|
|
return JSVAL_IS_GCTHING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isBoolean() const {
|
|
|
|
return JSVAL_IS_BOOLEAN_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isTrue() const {
|
|
|
|
return JSVAL_IS_SPECIFIC_BOOLEAN(data, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isFalse() const {
|
|
|
|
return JSVAL_IS_SPECIFIC_BOOLEAN(data, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isMagic() const {
|
|
|
|
return JSVAL_IS_MAGIC_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isMagic(JSWhyMagic why) const {
|
|
|
|
JS_ASSERT_IF(isMagic(), data.s.payload.why == why);
|
|
|
|
return JSVAL_IS_MAGIC_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool isMarkable() const {
|
|
|
|
return JSVAL_IS_TRACEABLE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
JSGCTraceKind gcKind() const {
|
|
|
|
JS_ASSERT(isMarkable());
|
|
|
|
return JSGCTraceKind(JSVAL_TRACE_KIND_IMPL(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
JSWhyMagic whyMagic() const {
|
|
|
|
JS_ASSERT(isMagic());
|
|
|
|
return data.s.payload.why;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Comparison ***/
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool operator==(const Value &rhs) const {
|
|
|
|
return data.asBits == rhs.data.asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool operator!=(const Value &rhs) const {
|
|
|
|
return data.asBits != rhs.data.asBits;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline bool SameType(const Value &lhs, const Value &rhs);
|
|
|
|
|
|
|
|
/*** Extract the value's typed payload ***/
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int32_t toInt32() const {
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_ASSERT(isInt32());
|
|
|
|
return JSVAL_TO_INT32_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
double toDouble() const {
|
|
|
|
JS_ASSERT(isDouble());
|
|
|
|
return data.asDouble;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
double toNumber() const {
|
|
|
|
JS_ASSERT(isNumber());
|
|
|
|
return isDouble() ? toDouble() : double(toInt32());
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
JSString *toString() const {
|
|
|
|
JS_ASSERT(isString());
|
|
|
|
return JSVAL_TO_STRING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
JSObject &toObject() const {
|
|
|
|
JS_ASSERT(isObject());
|
|
|
|
return *JSVAL_TO_OBJECT_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
JSObject *toObjectOrNull() const {
|
|
|
|
JS_ASSERT(isObjectOrNull());
|
|
|
|
return JSVAL_TO_OBJECT_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void *toGCThing() const {
|
|
|
|
JS_ASSERT(isGCThing());
|
|
|
|
return JSVAL_TO_GCTHING_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
bool toBoolean() const {
|
|
|
|
JS_ASSERT(isBoolean());
|
|
|
|
return JSVAL_TO_BOOLEAN_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t payloadAsRawUint32() const {
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_ASSERT(!isDouble());
|
|
|
|
return data.s.payload.u32;
|
|
|
|
}
|
|
|
|
|
2012-01-20 12:11:43 +00:00
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
uint64_t asRawBits() const {
|
|
|
|
return data.asBits;
|
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
JSValueType extractNonDoubleType() const {
|
|
|
|
return JSVAL_EXTRACT_NON_DOUBLE_TYPE_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private API
|
|
|
|
*
|
|
|
|
* Private setters/getters allow the caller to read/write arbitrary types
|
|
|
|
* that fit in the 64-bit payload. It is the caller's responsibility, after
|
|
|
|
* storing to a value with setPrivateX to read only using getPrivateX.
|
|
|
|
* Privates values are given a type type which ensures they are not marked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setPrivate(void *ptr) {
|
|
|
|
data = PRIVATE_PTR_TO_JSVAL_IMPL(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void *toPrivate() const {
|
|
|
|
JS_ASSERT(JSVAL_IS_DOUBLE_IMPL(data));
|
|
|
|
return JSVAL_TO_PRIVATE_PTR_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
void setPrivateUint32(uint32_t ui) {
|
2011-09-19 16:34:49 +00:00
|
|
|
data = PRIVATE_UINT32_TO_JSVAL_IMPL(ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t toPrivateUint32() const {
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_DOUBLE_IMPL(data));
|
|
|
|
return JSVAL_TO_PRIVATE_UINT32_IMPL(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t &getPrivateUint32Ref() {
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_ASSERT(isDouble());
|
|
|
|
return data.s.payload.u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An unmarked value is just a void* cast as a Value. Thus, the Value is
|
|
|
|
* not safe for GC and must not be marked. This API avoids raw casts
|
|
|
|
* and the ensuing strict-aliasing warnings.
|
|
|
|
*/
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void setUnmarkedPtr(void *ptr) {
|
|
|
|
data.asPtr = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE
|
|
|
|
void *toUnmarkedPtr() const {
|
|
|
|
return data.asPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t *payloadWord() const {
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
return &data.s.payload.word;
|
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
return &data.asWord;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-22 06:45:13 +00:00
|
|
|
const uintptr_t *payloadUIntPtr() const {
|
|
|
|
#if JS_BITS_PER_WORD == 32
|
|
|
|
return &data.s.payload.uintptr;
|
|
|
|
#elif JS_BITS_PER_WORD == 64
|
|
|
|
return &data.asUIntPtr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-27 02:51:49 +00:00
|
|
|
#if !defined(_MSC_VER) && !defined(__sparc)
|
2011-10-11 22:46:29 +00:00
|
|
|
/* To make jsval binary compatible when linking across C and C++ with MSVC,
|
|
|
|
* JS::Value needs to be POD. Otherwise, jsval will be passed in memory
|
|
|
|
* in C++ but by value in C (bug 645111).
|
2012-03-27 02:51:49 +00:00
|
|
|
* Same issue for SPARC ABI. (bug 737344).
|
2011-10-11 22:46:29 +00:00
|
|
|
*/
|
|
|
|
private:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
jsval_layout data;
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
private:
|
|
|
|
void staticAssertions() {
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueType) == 1);
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueTag) == 4);
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSBool) == 4);
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4);
|
|
|
|
JS_STATIC_ASSERT(sizeof(Value) == 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend jsval_layout (::JSVAL_TO_IMPL)(Value);
|
|
|
|
friend Value (::IMPL_TO_JSVAL)(jsval_layout l);
|
2012-01-15 04:39:32 +00:00
|
|
|
};
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2011-12-31 14:32:04 +00:00
|
|
|
inline bool
|
|
|
|
IsPoisonedValue(const Value &v)
|
|
|
|
{
|
|
|
|
if (v.isString())
|
|
|
|
return IsPoisonedPtr(v.toString());
|
|
|
|
if (v.isObject())
|
|
|
|
return IsPoisonedPtr(&v.toObject());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NullValue()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNull();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
UndefinedValue()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setUndefined();
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
Int32Value(int32_t i32)
|
2011-09-19 16:34:49 +00:00
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setInt32(i32);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
DoubleValue(double dbl)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setDouble(dbl);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
StringValue(JSString *str)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setString(str);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
BooleanValue(bool boo)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setBoolean(boo);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
ObjectValue(JSObject &obj)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setObject(obj);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-06-12 19:24:31 +00:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
ObjectValueCrashOnTouch()
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setObject(*reinterpret_cast<JSObject *>(0x42));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
MagicValue(JSWhyMagic why)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setMagic(why);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-04-10 23:33:44 +00:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(float f)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNumber(f);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(double dbl)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNumber(dbl);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-04-10 23:33:44 +00:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(int8_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(uint8_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(int16_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(uint16_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(int32_t i)
|
|
|
|
{
|
|
|
|
return Int32Value(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(uint32_t i)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setNumber(i);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template <bool Signed>
|
|
|
|
class MakeNumberValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
static inline Value create(const T t)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
if (JSVAL_INT_MIN <= t && t <= JSVAL_INT_MAX)
|
|
|
|
v.setInt32(int32_t(t));
|
|
|
|
else
|
|
|
|
v.setDouble(double(t));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class MakeNumberValue<false>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
static inline Value create(const T t)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
if (t <= JSVAL_INT_MAX)
|
|
|
|
v.setInt32(int32_t(t));
|
|
|
|
else
|
|
|
|
v.setDouble(double(t));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace detail */
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
NumberValue(const T t)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(T(double(t)) == t, "value creation would be lossy");
|
|
|
|
return detail::MakeNumberValue<std::numeric_limits<T>::is_signed>::create(t);
|
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
ObjectOrNullValue(JSObject *obj)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setObjectOrNull(obj);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
|
|
|
PrivateValue(void *ptr)
|
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setPrivate(ptr);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE Value
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
PrivateUint32Value(uint32_t ui)
|
2011-09-19 16:34:49 +00:00
|
|
|
{
|
|
|
|
Value v;
|
|
|
|
v.setPrivateUint32(ui);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
SameType(const Value &lhs, const Value &rhs)
|
|
|
|
{
|
|
|
|
return JSVAL_SAME_TYPE_IMPL(lhs.data, rhs.data);
|
|
|
|
}
|
|
|
|
|
2012-07-12 10:01:59 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2012-04-12 16:23:51 +00:00
|
|
|
template <> struct RootMethods<const Value>
|
|
|
|
{
|
|
|
|
static Value initial() { return UndefinedValue(); }
|
|
|
|
static ThingRootKind kind() { return THING_ROOT_VALUE; }
|
|
|
|
static bool poisoned(const Value &v) { return IsPoisonedValue(v); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct RootMethods<Value>
|
|
|
|
{
|
|
|
|
static Value initial() { return UndefinedValue(); }
|
|
|
|
static ThingRootKind kind() { return THING_ROOT_VALUE; }
|
|
|
|
static bool poisoned(const Value &v) { return IsPoisonedValue(v); }
|
|
|
|
};
|
|
|
|
|
2012-07-12 10:01:59 +00:00
|
|
|
template <class Outer> class MutableValueOperations;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class designed for CRTP use in implementing the non-mutating parts of the
|
|
|
|
* Value interface in Value-like classes. Outer must be a class inheriting
|
|
|
|
* ValueOperations<Outer> with a visible extract() method returning the
|
|
|
|
* const Value* abstracted by Outer.
|
|
|
|
*/
|
|
|
|
template <class Outer>
|
|
|
|
class ValueOperations
|
|
|
|
{
|
|
|
|
friend class MutableValueOperations<Outer>;
|
|
|
|
const Value * value() const { return static_cast<const Outer*>(this)->extract(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool isUndefined() const { return value()->isUndefined(); }
|
|
|
|
bool isNull() const { return value()->isNull(); }
|
|
|
|
bool isBoolean() const { return value()->isBoolean(); }
|
|
|
|
bool isTrue() const { return value()->isTrue(); }
|
|
|
|
bool isFalse() const { return value()->isFalse(); }
|
|
|
|
bool isNumber() const { return value()->isNumber(); }
|
|
|
|
bool isInt32() const { return value()->isInt32(); }
|
|
|
|
bool isDouble() const { return value()->isDouble(); }
|
|
|
|
bool isString() const { return value()->isString(); }
|
|
|
|
bool isObject() const { return value()->isObject(); }
|
|
|
|
bool isMagic() const { return value()->isMagic(); }
|
|
|
|
bool isMagic(JSWhyMagic why) const { return value()->isMagic(why); }
|
|
|
|
bool isMarkable() const { return value()->isMarkable(); }
|
|
|
|
bool isPrimitive() const { return value()->isPrimitive(); }
|
2012-06-21 01:48:56 +00:00
|
|
|
bool isGCThing() const { return value()->isGCThing(); }
|
2012-07-12 10:01:59 +00:00
|
|
|
|
2012-07-30 11:19:09 +00:00
|
|
|
bool isNullOrUndefined() const { return value()->isNullOrUndefined(); }
|
|
|
|
bool isObjectOrNull() const { return value()->isObjectOrNull(); }
|
|
|
|
|
2012-07-12 10:01:59 +00:00
|
|
|
bool toBoolean() const { return value()->toBoolean(); }
|
|
|
|
double toNumber() const { return value()->toNumber(); }
|
|
|
|
int32_t toInt32() const { return value()->toInt32(); }
|
|
|
|
double toDouble() const { return value()->toDouble(); }
|
|
|
|
JSString *toString() const { return value()->toString(); }
|
|
|
|
JSObject &toObject() const { return value()->toObject(); }
|
|
|
|
JSObject *toObjectOrNull() const { return value()->toObjectOrNull(); }
|
|
|
|
void *toGCThing() const { return value()->toGCThing(); }
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSWhyMagic whyMagic() const { return value()->whyMagic(); }
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A class designed for CRTP use in implementing the mutating parts of the
|
|
|
|
* Value interface in Value-like classes. Outer must be a class inheriting
|
|
|
|
* MutableValueOperations<Outer> with visible extractMutable() and extract()
|
|
|
|
* methods returning the const Value* and Value* abstracted by Outer.
|
|
|
|
*/
|
|
|
|
template <class Outer>
|
|
|
|
class MutableValueOperations : public ValueOperations<Outer>
|
|
|
|
{
|
|
|
|
Value * value() { return static_cast<Outer*>(this)->extractMutable(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setNull() { value()->setNull(); }
|
|
|
|
void setUndefined() { value()->setUndefined(); }
|
|
|
|
void setInt32(int32_t i) { value()->setInt32(i); }
|
|
|
|
void setDouble(double d) { value()->setDouble(d); }
|
|
|
|
void setString(JSString *str) { value()->setString(str); }
|
|
|
|
void setString(const JS::Anchor<JSString *> &str) { value()->setString(str); }
|
|
|
|
void setObject(JSObject &obj) { value()->setObject(obj); }
|
|
|
|
void setBoolean(bool b) { value()->setBoolean(b); }
|
|
|
|
void setMagic(JSWhyMagic why) { value()->setMagic(why); }
|
|
|
|
bool setNumber(uint32_t ui) { return value()->setNumber(ui); }
|
|
|
|
bool setNumber(double d) { return value()->setNumber(d); }
|
2012-07-30 11:19:09 +00:00
|
|
|
void setObjectOrNull(JSObject *arg) { value()->setObjectOrNull(arg); }
|
2012-07-12 10:01:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Augment the generic Handle<T> interface when T = Value with type-querying
|
|
|
|
* and value-extracting operations.
|
|
|
|
*/
|
|
|
|
template <>
|
|
|
|
class HandleBase<Value> : public ValueOperations<Handle<Value> >
|
|
|
|
{
|
|
|
|
friend class ValueOperations<Handle<Value> >;
|
|
|
|
const Value * extract() const {
|
|
|
|
return static_cast<const Handle<Value>*>(this)->address();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Augment the generic MutableHandle<T> interface when T = Value with
|
|
|
|
* type-querying, value-extracting, and mutating operations.
|
|
|
|
*/
|
|
|
|
template <>
|
|
|
|
class MutableHandleBase<Value> : public MutableValueOperations<MutableHandle<Value> >
|
|
|
|
{
|
2012-07-13 19:04:33 +00:00
|
|
|
friend class ValueOperations<MutableHandle<Value> >;
|
2012-07-12 10:01:59 +00:00
|
|
|
const Value * extract() const {
|
|
|
|
return static_cast<const MutableHandle<Value>*>(this)->address();
|
|
|
|
}
|
|
|
|
|
2012-07-13 19:04:33 +00:00
|
|
|
friend class MutableValueOperations<MutableHandle<Value> >;
|
2012-07-12 10:01:59 +00:00
|
|
|
Value * extractMutable() {
|
|
|
|
return static_cast<MutableHandle<Value>*>(this)->address();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Augment the generic Rooted<T> interface when T = Value with type-querying,
|
|
|
|
* value-extracting, and mutating operations.
|
|
|
|
*/
|
|
|
|
template <>
|
|
|
|
class RootedBase<Value> : public MutableValueOperations<Rooted<Value> >
|
|
|
|
{
|
|
|
|
friend class ValueOperations<Rooted<Value> >;
|
|
|
|
const Value * extract() const {
|
|
|
|
return static_cast<const Rooted<Value>*>(this)->address();
|
|
|
|
}
|
|
|
|
|
2012-07-30 11:19:09 +00:00
|
|
|
friend class MutableValueOperations<Rooted<Value> >;
|
2012-07-12 10:01:59 +00:00
|
|
|
Value * extractMutable() {
|
|
|
|
return static_cast<Rooted<Value>*>(this)->address();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2011-09-22 19:01:49 +00:00
|
|
|
#ifndef __GNUC__
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* The default assignment operator for |struct C| has the signature:
|
|
|
|
*
|
|
|
|
* C& C::operator=(const C&)
|
|
|
|
*
|
|
|
|
* And in particular requires implicit conversion of |this| to type |C| for the
|
|
|
|
* return value. But |volatile C| cannot thus be converted to |C|, so just
|
|
|
|
* doing |sink = hold| as in the non-specialized version would fail to compile.
|
|
|
|
* Do the assignment on asBits instead, since I don't think we want to give
|
|
|
|
* jsval_layout an assignment operator returning |volatile jsval_layout|.
|
|
|
|
*/
|
|
|
|
template<>
|
|
|
|
inline Anchor<Value>::~Anchor()
|
|
|
|
{
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
volatile uint64_t bits;
|
2012-01-02 23:06:15 +00:00
|
|
|
bits = JSVAL_TO_IMPL(hold).asBits;
|
2011-09-19 16:34:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 19:01:49 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-11 08:23:08 +00:00
|
|
|
#if defined JS_THREADSAFE && defined DEBUG
|
|
|
|
|
|
|
|
class JS_PUBLIC_API(AutoCheckRequestDepth)
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
public:
|
|
|
|
AutoCheckRequestDepth(JSContext *cx);
|
|
|
|
~AutoCheckRequestDepth();
|
|
|
|
};
|
|
|
|
|
|
|
|
# define CHECK_REQUEST(cx) \
|
|
|
|
JS::AutoCheckRequestDepth _autoCheckRequestDepth(cx)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
# define CHECK_REQUEST(cx) \
|
|
|
|
((void) 0)
|
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
#endif /* JS_THREADSAFE && DEBUG */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-02 19:59:30 +00:00
|
|
|
/*
|
|
|
|
* Assert that we're not doing GC on cx, that we're in a request as
|
|
|
|
* needed, and that the compartments for cx and v are correct.
|
|
|
|
* Also check that GC would be safe at this point.
|
|
|
|
*/
|
2012-03-28 23:35:21 +00:00
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
AssertArgumentsAreSane(JSContext *cx, const Value &v);
|
|
|
|
#else
|
|
|
|
inline void AssertArgumentsAreSane(JSContext *cx, const Value &v) {
|
|
|
|
/* Do nothing */
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
2012-01-11 08:23:08 +00:00
|
|
|
|
|
|
|
class JS_PUBLIC_API(AutoGCRooter) {
|
|
|
|
public:
|
|
|
|
AutoGCRooter(JSContext *cx, ptrdiff_t tag);
|
2012-02-29 12:18:16 +00:00
|
|
|
|
|
|
|
~AutoGCRooter() {
|
|
|
|
JS_ASSERT(this == *stackTop);
|
|
|
|
*stackTop = down;
|
|
|
|
}
|
2012-01-11 08:23:08 +00:00
|
|
|
|
|
|
|
/* Implemented in jsgc.cpp. */
|
|
|
|
inline void trace(JSTracer *trc);
|
2012-02-29 12:18:16 +00:00
|
|
|
static void traceAll(JSTracer *trc);
|
2012-01-11 08:23:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
AutoGCRooter * const down;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discriminates actual subclass of this being used. If non-negative, the
|
|
|
|
* subclass roots an array of values of the length stored in this field.
|
|
|
|
* If negative, meaning is indicated by the corresponding value in the enum
|
|
|
|
* below. Any other negative value indicates some deeper problem such as
|
|
|
|
* memory corruption.
|
|
|
|
*/
|
|
|
|
ptrdiff_t tag;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
JSVAL = -1, /* js::AutoValueRooter */
|
|
|
|
VALARRAY = -2, /* js::AutoValueArrayRooter */
|
2012-07-09 18:54:28 +00:00
|
|
|
PARSER = -3, /* js::frontend::Parser */
|
2012-01-11 08:23:08 +00:00
|
|
|
SHAPEVECTOR = -4, /* js::AutoShapeVector */
|
|
|
|
ENUMERATOR = -5, /* js::AutoEnumStateRooter */
|
|
|
|
IDARRAY = -6, /* js::AutoIdArray */
|
|
|
|
DESCRIPTORS = -7, /* js::AutoPropDescArrayRooter */
|
|
|
|
NAMESPACES = -8, /* js::AutoNamespaceArray */
|
|
|
|
XML = -9, /* js::AutoXMLRooter */
|
|
|
|
OBJECT = -10, /* js::AutoObjectRooter */
|
|
|
|
ID = -11, /* js::AutoIdRooter */
|
|
|
|
VALVECTOR = -12, /* js::AutoValueVector */
|
|
|
|
DESCRIPTOR = -13, /* js::AutoPropertyDescriptorRooter */
|
|
|
|
STRING = -14, /* js::AutoStringRooter */
|
|
|
|
IDVECTOR = -15, /* js::AutoIdVector */
|
2012-03-03 01:19:56 +00:00
|
|
|
OBJVECTOR = -16, /* js::AutoObjectVector */
|
2012-05-24 15:52:21 +00:00
|
|
|
SCRIPTVECTOR =-17, /* js::AutoScriptVector */
|
|
|
|
PROPDESC = -18, /* js::PropDesc::AutoRooter */
|
|
|
|
SHAPERANGE = -19, /* js::Shape::Range::AutoRooter */
|
|
|
|
STACKSHAPE = -20, /* js::StackShape::AutoRooter */
|
|
|
|
STACKBASESHAPE=-21,/* js::StackBaseShape::AutoRooter */
|
|
|
|
BINDINGS = -22, /* js::Bindings::AutoRooter */
|
|
|
|
GETTERSETTER =-23, /* js::AutoRooterGetterSetter */
|
|
|
|
REGEXPSTATICS=-24, /* js::RegExpStatics::AutoRooter */
|
|
|
|
HASHABLEVALUE=-25
|
2012-01-11 08:23:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2012-02-29 12:18:16 +00:00
|
|
|
AutoGCRooter ** const stackTop;
|
|
|
|
|
2012-01-11 08:23:08 +00:00
|
|
|
/* No copy or assignment semantics. */
|
|
|
|
AutoGCRooter(AutoGCRooter &ida) MOZ_DELETE;
|
|
|
|
void operator=(AutoGCRooter &ida) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
2012-01-11 08:23:08 +00:00
|
|
|
class AutoValueRooter : private AutoGCRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoValueRooter(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, JSVAL), val(NullValue())
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoValueRooter(JSContext *cx, const Value &v
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, JSVAL), val(v)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If you are looking for Object* overloads, use AutoObjectRooter instead;
|
|
|
|
* rooting Object*s as a js::Value requires discerning whether or not it is
|
|
|
|
* a function object. Also, AutoObjectRooter is smaller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void set(Value v) {
|
|
|
|
JS_ASSERT(tag == JSVAL);
|
|
|
|
val = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value &value() const {
|
|
|
|
JS_ASSERT(tag == JSVAL);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *addr() {
|
|
|
|
JS_ASSERT(tag == JSVAL);
|
|
|
|
return &val;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value &jsval_value() const {
|
|
|
|
JS_ASSERT(tag == JSVAL);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *jsval_addr() {
|
|
|
|
JS_ASSERT(tag == JSVAL);
|
|
|
|
return &val;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Value val;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-11 08:23:08 +00:00
|
|
|
class AutoObjectRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoObjectRooter(JSContext *cx, JSObject *obj = NULL
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, OBJECT), obj(obj)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setObject(JSObject *obj) {
|
|
|
|
this->obj = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject * object() const {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject ** addr() {
|
|
|
|
return &obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSObject *obj;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-11 08:23:08 +00:00
|
|
|
class AutoStringRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoStringRooter(JSContext *cx, JSString *str = NULL
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, STRING), str(str)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setString(JSString *str) {
|
|
|
|
this->str = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString * string() const {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSString ** addr() {
|
|
|
|
return &str;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSString *str;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
class AutoArrayRooter : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoArrayRooter(JSContext *cx, size_t len, Value *vec
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-05-01 00:10:30 +00:00
|
|
|
: AutoGCRooter(cx, len), array(vec), skip(cx, array, len)
|
2012-01-11 08:23:09 +00:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_ASSERT(tag >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeLength(size_t newLength) {
|
|
|
|
tag = ptrdiff_t(newLength);
|
|
|
|
JS_ASSERT(tag >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeArray(Value *newArray, size_t newLength) {
|
|
|
|
changeLength(newLength);
|
|
|
|
array = newArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *array;
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-05-01 00:10:30 +00:00
|
|
|
|
|
|
|
SkipRoot skip;
|
2012-01-11 08:23:09 +00:00
|
|
|
};
|
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
/* The auto-root for enumeration object and its state. */
|
|
|
|
class AutoEnumStateRooter : private AutoGCRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoEnumStateRooter(JSContext *cx, JSObject *obj
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-02-29 12:18:16 +00:00
|
|
|
: AutoGCRooter(cx, ENUMERATOR), obj(obj), stateValue(), context(cx)
|
2012-01-11 08:23:09 +00:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_ASSERT(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoEnumStateRooter();
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
const Value &state() const { return stateValue; }
|
|
|
|
Value *addr() { return &stateValue; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void trace(JSTracer *trc);
|
|
|
|
|
2012-02-14 23:19:55 +00:00
|
|
|
JSObject *obj;
|
2012-01-11 08:23:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Value stateValue;
|
2012-02-29 12:18:16 +00:00
|
|
|
JSContext *context;
|
2012-01-11 08:23:09 +00:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
template<class T>
|
|
|
|
class AutoVectorRooter : protected AutoGCRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoVectorRooter(JSContext *cx, ptrdiff_t tag
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-04-12 16:23:51 +00:00
|
|
|
: AutoGCRooter(cx, tag), vector(cx), vectorRoot(cx, &vector)
|
2012-01-15 08:13:11 +00:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t length() const { return vector.length(); }
|
|
|
|
|
|
|
|
bool append(const T &v) { return vector.append(v); }
|
|
|
|
|
|
|
|
/* For use when space has already been reserved. */
|
|
|
|
void infallibleAppend(const T &v) { vector.infallibleAppend(v); }
|
|
|
|
|
|
|
|
void popBack() { vector.popBack(); }
|
|
|
|
T popCopy() { return vector.popCopy(); }
|
|
|
|
|
|
|
|
bool growBy(size_t inc) {
|
|
|
|
size_t oldLength = vector.length();
|
|
|
|
if (!vector.growByUninitialized(inc))
|
|
|
|
return false;
|
|
|
|
makeRangeGCSafe(oldLength);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool resize(size_t newLength) {
|
|
|
|
size_t oldLength = vector.length();
|
|
|
|
if (newLength <= oldLength) {
|
|
|
|
vector.shrinkBy(oldLength - newLength);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!vector.growByUninitialized(newLength - oldLength))
|
|
|
|
return false;
|
|
|
|
makeRangeGCSafe(oldLength);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() { vector.clear(); }
|
|
|
|
|
|
|
|
bool reserve(size_t newLength) {
|
|
|
|
return vector.reserve(newLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
T &operator[](size_t i) { return vector[i]; }
|
|
|
|
const T &operator[](size_t i) const { return vector[i]; }
|
|
|
|
|
2012-07-18 21:31:24 +00:00
|
|
|
JS::MutableHandle<T> handleAt(size_t i) { return JS::MutableHandle<T>::fromMarkedLocation(&vector[i]); }
|
2012-06-21 21:18:02 +00:00
|
|
|
JS::Handle<T> handleAt(size_t i) const { return JS::Handle<T>::fromMarkedLocation(&vector[i]); }
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
const T *begin() const { return vector.begin(); }
|
|
|
|
T *begin() { return vector.begin(); }
|
|
|
|
|
|
|
|
const T *end() const { return vector.end(); }
|
|
|
|
T *end() { return vector.end(); }
|
|
|
|
|
|
|
|
const T &back() const { return vector.back(); }
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void makeRangeGCSafe(size_t oldLength) {
|
|
|
|
T *t = vector.begin() + oldLength;
|
|
|
|
for (size_t i = oldLength; i < vector.length(); ++i, ++t)
|
|
|
|
memset(t, 0, sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef js::Vector<T, 8> VectorImpl;
|
|
|
|
VectorImpl vector;
|
2012-04-12 16:23:51 +00:00
|
|
|
|
|
|
|
/* Prevent overwriting of inline elements in vector. */
|
|
|
|
SkipRoot vectorRoot;
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
class AutoValueVector : public AutoVectorRooter<Value>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoValueVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<Value>(cx, VALVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-01-15 08:13:11 +00:00
|
|
|
class AutoIdVector : public AutoVectorRooter<jsid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoIdVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<jsid>(cx, IDVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-03-03 01:19:56 +00:00
|
|
|
class AutoScriptVector : public AutoVectorRooter<JSScript *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoScriptVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<JSScript *>(cx, SCRIPTVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-07-03 16:08:23 +00:00
|
|
|
class CallReceiver
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
#ifdef DEBUG
|
|
|
|
mutable bool usedRval_;
|
|
|
|
void setUsedRval() const { usedRval_ = true; }
|
|
|
|
void clearUsedRval() const { usedRval_ = false; }
|
|
|
|
#else
|
|
|
|
void setUsedRval() const {}
|
|
|
|
void clearUsedRval() const {}
|
|
|
|
#endif
|
|
|
|
Value *argv_;
|
|
|
|
public:
|
|
|
|
friend CallReceiver CallReceiverFromVp(Value *);
|
|
|
|
friend CallReceiver CallReceiverFromArgv(Value *);
|
|
|
|
Value *base() const { return argv_ - 2; }
|
|
|
|
JSObject &callee() const { JS_ASSERT(!usedRval_); return argv_[-2].toObject(); }
|
|
|
|
Value &calleev() const { JS_ASSERT(!usedRval_); return argv_[-2]; }
|
|
|
|
Value &thisv() const { return argv_[-1]; }
|
|
|
|
|
2012-07-30 11:19:09 +00:00
|
|
|
JS::MutableHandleValue rval() const {
|
2012-07-03 16:08:23 +00:00
|
|
|
setUsedRval();
|
2012-07-30 11:19:09 +00:00
|
|
|
return JS::MutableHandleValue::fromMarkedLocation(&argv_[-2]);
|
2012-07-03 16:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Value *spAfterCall() const {
|
|
|
|
setUsedRval();
|
|
|
|
return argv_ - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCallee(Value calleev) {
|
|
|
|
clearUsedRval();
|
|
|
|
this->calleev() = calleev;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE CallReceiver
|
|
|
|
CallReceiverFromArgv(Value *argv)
|
|
|
|
{
|
|
|
|
CallReceiver receiver;
|
|
|
|
receiver.clearUsedRval();
|
|
|
|
receiver.argv_ = argv;
|
|
|
|
return receiver;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE CallReceiver
|
|
|
|
CallReceiverFromVp(Value *vp)
|
|
|
|
{
|
|
|
|
return CallReceiverFromArgv(vp + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
class CallArgs : public CallReceiver
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
unsigned argc_;
|
|
|
|
public:
|
|
|
|
friend CallArgs CallArgsFromVp(unsigned, Value *);
|
|
|
|
friend CallArgs CallArgsFromArgv(unsigned, Value *);
|
|
|
|
friend CallArgs CallArgsFromSp(unsigned, Value *);
|
|
|
|
Value &operator[](unsigned i) const { JS_ASSERT(i < argc_); return argv_[i]; }
|
|
|
|
Value *array() const { return argv_; }
|
|
|
|
unsigned length() const { return argc_; }
|
|
|
|
Value *end() const { return argv_ + argc_; }
|
|
|
|
bool hasDefined(unsigned i) const { return i < argc_ && !argv_[i].isUndefined(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE CallArgs
|
|
|
|
CallArgsFromArgv(unsigned argc, Value *argv)
|
|
|
|
{
|
|
|
|
CallArgs args;
|
|
|
|
args.clearUsedRval();
|
|
|
|
args.argv_ = argv;
|
|
|
|
args.argc_ = argc;
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE CallArgs
|
|
|
|
CallArgsFromVp(unsigned argc, Value *vp)
|
|
|
|
{
|
|
|
|
return CallArgsFromArgv(argc, vp + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE CallArgs
|
|
|
|
CallArgsFromSp(unsigned argc, Value *sp)
|
|
|
|
{
|
|
|
|
return CallArgsFromArgv(argc, sp - argc);
|
|
|
|
}
|
|
|
|
|
2012-07-04 00:44:22 +00:00
|
|
|
/* Returns true if |v| is considered an acceptable this-value. */
|
|
|
|
typedef bool (*IsAcceptableThis)(const Value &v);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implements the guts of a method; guaranteed to be provided an acceptable
|
|
|
|
* this-value, as determined by a corresponding IsAcceptableThis method.
|
|
|
|
*/
|
|
|
|
typedef bool (*NativeImpl)(JSContext *cx, CallArgs args);
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
/* DON'T CALL THIS DIRECTLY. It's for use only by CallNonGenericMethod! */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args);
|
|
|
|
|
|
|
|
} /* namespace detail */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Methods usually act upon |this| objects only from a single global object and
|
|
|
|
* compartment. Sometimes, however, a method must act upon |this| values from
|
|
|
|
* multiple global objects or compartments. In such cases the |this| value a
|
|
|
|
* method might see will be wrapped, such that various access to the object --
|
|
|
|
* to its class, its private data, its reserved slots, and so on -- will not
|
|
|
|
* work properly without entering that object's compartment. This method
|
|
|
|
* implements a solution to this problem.
|
|
|
|
*
|
|
|
|
* To implement a method that accepts |this| values from multiple compartments,
|
|
|
|
* define two functions. The first function matches the IsAcceptableThis type
|
|
|
|
* and indicates whether the provided value is an acceptable |this| for the
|
|
|
|
* method; it must be a pure function only of its argument.
|
|
|
|
*
|
|
|
|
* static JSClass AnswerClass = { ... };
|
|
|
|
*
|
|
|
|
* static bool
|
|
|
|
* IsAnswerObject(const Value &v)
|
|
|
|
* {
|
|
|
|
* if (!v.isObject())
|
|
|
|
* return false;
|
|
|
|
* return JS_GetClass(&v.toObject()) == &AnswerClass;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* The second function implements the NativeImpl signature and defines the
|
|
|
|
* behavior of the method when it is provided an acceptable |this| value.
|
|
|
|
* Aside from some typing niceties -- see the CallArgs interface for details --
|
|
|
|
* its interface is the same as that of JSNative.
|
|
|
|
*
|
|
|
|
* static bool
|
|
|
|
* answer_getAnswer_impl(JSContext *cx, JS::CallArgs args)
|
|
|
|
* {
|
|
|
|
* args.rval().setInt32(42);
|
|
|
|
* return true;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* The implementation function is guaranteed to be called *only* with a |this|
|
|
|
|
* value which is considered acceptable.
|
|
|
|
*
|
|
|
|
* Now to implement the actual method, write a JSNative that calls the method
|
|
|
|
* declared below, passing the appropriate arguments.
|
|
|
|
*
|
|
|
|
* static JSBool
|
|
|
|
* answer_getAnswer(JSContext *cx, unsigned argc, JS::Value *vp)
|
|
|
|
* {
|
|
|
|
* JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
|
|
|
* return JS::CallNonGenericMethod(cx, IsAnswerObject,
|
|
|
|
answer_getAnswer_impl, args);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* JS::CallNonGenericMethod will test whether |args.thisv()| is acceptable. If
|
|
|
|
* it is, it will call the provided implementation function, which will return
|
|
|
|
* a value and indicate success. If it is not, it will attempt to unwrap
|
|
|
|
* |this| and call the implementation function on the unwrapped |this|. If
|
|
|
|
* that succeeds, all well and good. If it doesn't succeed, a TypeError will
|
|
|
|
* be thrown.
|
|
|
|
*
|
|
|
|
* Note: JS::CallNonGenericMethod will only work correctly if it's called in
|
|
|
|
* tail position in a JSNative. Do not call it from any other place.
|
|
|
|
*/
|
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
CallNonGenericMethod(JSContext *cx, IsAcceptableThis test, NativeImpl impl, CallArgs args)
|
|
|
|
{
|
|
|
|
const Value &thisv = args.thisv();
|
|
|
|
if (test(thisv))
|
|
|
|
return impl(cx, args);
|
|
|
|
|
|
|
|
return detail::CallMethodIfWrapped(cx, test, impl, args);
|
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JS::Value and jsval are the same type; jsval is the old name, kept around
|
|
|
|
* for backwards compatibility along with all the JSVAL_* operations below.
|
|
|
|
* jsval_layout is an implementation detail and should not be used externally.
|
|
|
|
*/
|
|
|
|
typedef JS::Value jsval;
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval_layout
|
|
|
|
JSVAL_TO_IMPL(jsval v)
|
|
|
|
{
|
|
|
|
return v.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
IMPL_TO_JSVAL(jsval_layout l)
|
|
|
|
{
|
|
|
|
JS::Value v;
|
|
|
|
v.data = l;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-01-15 04:39:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
struct JSValueAlignmentTester { char c; JS::Value v; };
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSValueAlignmentTester) == 16);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
#else /* defined(__cplusplus) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For SpiderMonkey C clients, there is no JS::Value class, only the
|
|
|
|
* traditional jsval with the traditional JSVAL_* operations. Since
|
|
|
|
* SpiderMonkey itself is always compiled as C++, this relies on the binary
|
|
|
|
* compatibility of jsval_layout and JS::Value (statically asserted below).
|
|
|
|
*/
|
|
|
|
typedef union jsval_layout jsval;
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval_layout
|
|
|
|
JSVAL_TO_IMPL(jsval v)
|
|
|
|
{
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
IMPL_TO_JSVAL(jsval_layout l)
|
|
|
|
{
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(__cplusplus) */
|
|
|
|
|
2012-01-15 04:39:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
typedef struct { char c; jsval_layout l; } JSLayoutAlignmentTester;
|
|
|
|
JS_STATIC_ASSERT(sizeof(JSLayoutAlignmentTester) == 16);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_STATIC_ASSERT(sizeof(jsval_layout) == sizeof(jsval));
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2012-05-19 22:03:45 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
typedef JS::Handle<JSObject*> JSHandleObject;
|
2012-07-18 21:31:24 +00:00
|
|
|
typedef JS::Handle<JSString*> JSHandleString;
|
2012-05-19 22:03:45 +00:00
|
|
|
typedef JS::Handle<jsid> JSHandleId;
|
2012-07-23 20:37:31 +00:00
|
|
|
typedef JS::Handle<JS::Value> JSHandleValue;
|
2012-07-04 18:12:16 +00:00
|
|
|
typedef JS::MutableHandle<JSObject*> JSMutableHandleObject;
|
2012-07-18 21:31:24 +00:00
|
|
|
typedef JS::MutableHandle<JS::Value> JSMutableHandleValue;
|
2012-07-23 20:37:31 +00:00
|
|
|
typedef JS::RawObject JSRawObject;
|
2012-05-19 22:03:45 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle support for C API users. Handles must be destroyed in the reverse
|
|
|
|
* order that they were created (as in a stack).
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct { JSObject **_; } JSHandleObject;
|
2012-07-23 20:37:31 +00:00
|
|
|
typedef struct { jsval _; } JSHandleValue;
|
2012-07-18 21:31:24 +00:00
|
|
|
typedef struct { JSString **_; } JSHandleString;
|
2012-07-04 18:12:16 +00:00
|
|
|
typedef struct { JSObject **_; } JSMutableHandleObject;
|
2012-07-30 11:19:09 +00:00
|
|
|
typedef struct { jsid *_; } JSHandleId;
|
2012-07-23 20:37:31 +00:00
|
|
|
typedef struct { jsval *_; } JSMutableHandleValue;
|
|
|
|
typedef JSObject *JSRawObject;
|
2012-05-19 22:03:45 +00:00
|
|
|
|
|
|
|
JSBool JS_CreateHandleObject(JSContext *cx, JSObject *obj, JSHandleObject *phandle);
|
|
|
|
void JS_DestroyHandleObject(JSContext *cx, JSHandleObject handle);
|
|
|
|
|
2012-07-04 18:12:16 +00:00
|
|
|
JSBool JS_CreateMutableHandleObject(JSContext *cx, JSObject *obj, JSMutableHandleObject *phandle);
|
|
|
|
void JS_DestroyMutableHandleObject(JSContext *cx, JSMutableHandleObject handle);
|
|
|
|
|
2012-05-19 22:03:45 +00:00
|
|
|
JSBool JS_CreateHandleId(JSContext *cx, jsid id, JSHandleId *phandle);
|
|
|
|
void JS_DestroyHandleId(JSContext *cx, JSHandleId handle);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-09-20 18:40:24 +00:00
|
|
|
/* JSClass operation signatures. */
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add, delete, or get a property named by id in obj. Note the jsid id
|
|
|
|
* type -- id may be a string (Unicode property identifier) or an int (element
|
|
|
|
* index). The *vp out parameter, on success, is the new property value after
|
|
|
|
* an add or get. After a successful delete, *vp is JSVAL_FALSE iff
|
|
|
|
* obj[id] can't be deleted (because it's permanent).
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-07-30 11:19:09 +00:00
|
|
|
(* JSPropertyOp)(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a property named by id in obj, treating the assignment as strict
|
|
|
|
* mode code if strict is true. Note the jsid id type -- id may be a string
|
|
|
|
* (Unicode property identifier) or an int (element index). The *vp out
|
|
|
|
* parameter, on success, is the new property value after the
|
|
|
|
* set.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-07-30 11:19:09 +00:00
|
|
|
(* JSStrictPropertyOp)(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function type is used for callbacks that enumerate the properties of
|
|
|
|
* a JSObject. The behavior depends on the value of enum_op:
|
|
|
|
*
|
|
|
|
* JSENUMERATE_INIT
|
|
|
|
* A new, opaque iterator state should be allocated and stored in *statep.
|
|
|
|
* (You can use PRIVATE_TO_JSVAL() to tag the pointer to be stored).
|
|
|
|
*
|
|
|
|
* The number of properties that will be enumerated should be returned as
|
|
|
|
* an integer jsval in *idp, if idp is non-null, and provided the number of
|
|
|
|
* enumerable properties is known. If idp is non-null and the number of
|
|
|
|
* enumerable properties can't be computed in advance, *idp should be set
|
|
|
|
* to JSVAL_ZERO.
|
|
|
|
*
|
|
|
|
* JSENUMERATE_INIT_ALL
|
|
|
|
* Used identically to JSENUMERATE_INIT, but exposes all properties of the
|
|
|
|
* object regardless of enumerability.
|
|
|
|
*
|
|
|
|
* JSENUMERATE_NEXT
|
|
|
|
* A previously allocated opaque iterator state is passed in via statep.
|
|
|
|
* Return the next jsid in the iteration using *idp. The opaque iterator
|
|
|
|
* state pointed at by statep is destroyed and *statep is set to JSVAL_NULL
|
|
|
|
* if there are no properties left to enumerate.
|
|
|
|
*
|
|
|
|
* JSENUMERATE_DESTROY
|
|
|
|
* Destroy the opaque iterator state previously allocated in *statep by a
|
|
|
|
* call to this function when enum_op was JSENUMERATE_INIT or
|
|
|
|
* JSENUMERATE_INIT_ALL.
|
|
|
|
*
|
|
|
|
* The return value is used to indicate success, with a value of JS_FALSE
|
|
|
|
* indicating failure.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSNewEnumerateOp)(JSContext *cx, JSHandleObject obj, JSIterateOp enum_op,
|
2011-09-19 16:34:49 +00:00
|
|
|
jsval *statep, jsid *idp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The old-style JSClass.enumerate op should define all lazy properties not
|
|
|
|
* yet reflected in obj.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSEnumerateOp)(JSContext *cx, JSHandleObject obj);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Resolve a lazy property named by id in obj by defining it directly in obj.
|
|
|
|
* Lazy properties are those reflected from some peer native property space
|
|
|
|
* (e.g., the DOM attributes for a given node reflected as obj) on demand.
|
|
|
|
*
|
|
|
|
* JS looks for a property in an object, and if not found, tries to resolve
|
|
|
|
* the given id. If resolve succeeds, the engine looks again in case resolve
|
|
|
|
* defined obj[id]. If no such property exists directly in obj, the process
|
|
|
|
* is repeated with obj's prototype, etc.
|
|
|
|
*
|
|
|
|
* NB: JSNewResolveOp provides a cheaper way to resolve lazy properties.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSResolveOp)(JSContext *cx, JSHandleObject obj, JSHandleId id);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Like JSResolveOp, but flags provide contextual information as follows:
|
|
|
|
*
|
|
|
|
* JSRESOLVE_QUALIFIED a qualified property id: obj.id or obj[id], not id
|
|
|
|
* JSRESOLVE_ASSIGNING obj[id] is on the left-hand side of an assignment
|
|
|
|
* JSRESOLVE_DETECTING 'if (o.p)...' or similar detection opcode sequence
|
|
|
|
*
|
|
|
|
* The *objp out parameter, on success, should be null to indicate that id
|
|
|
|
* was not resolved; and non-null, referring to obj or one of its prototypes,
|
2012-06-06 00:39:30 +00:00
|
|
|
* if id was resolved. The hook may assume *objp is null on entry.
|
2011-09-19 16:34:49 +00:00
|
|
|
*
|
|
|
|
* This hook instead of JSResolveOp is called via the JSClass.resolve member
|
|
|
|
* if JSCLASS_NEW_RESOLVE is set in JSClass.flags.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSNewResolveOp)(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags,
|
2012-07-04 18:12:16 +00:00
|
|
|
JSMutableHandleObject objp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert obj to the given type, returning true with the resulting value in
|
|
|
|
* *vp on success, and returning false on error or exception.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-07-30 11:19:09 +00:00
|
|
|
(* JSConvertOp)(JSContext *cx, JSHandleObject obj, JSType type, JSMutableHandleValue vp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Delegate typeof to an object so it can cloak a primitive or another object.
|
|
|
|
*/
|
|
|
|
typedef JSType
|
2012-07-23 20:37:31 +00:00
|
|
|
(* JSTypeOfOp)(JSContext *cx, JSHandleObject obj);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2012-03-19 14:34:55 +00:00
|
|
|
typedef struct JSFreeOp JSFreeOp;
|
|
|
|
|
|
|
|
struct JSFreeOp {
|
|
|
|
#ifndef __cplusplus
|
|
|
|
JSRuntime *runtime;
|
|
|
|
#else
|
|
|
|
private:
|
|
|
|
JSRuntime *runtime_;
|
|
|
|
|
|
|
|
protected:
|
2012-03-19 14:34:58 +00:00
|
|
|
JSFreeOp(JSRuntime *rt)
|
|
|
|
: runtime_(rt) { }
|
2012-03-19 14:34:55 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
JSRuntime *runtime() const {
|
|
|
|
return runtime_;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* Finalize obj, which the garbage collector has determined to be unreachable
|
|
|
|
* from other live objects or from GC roots. Obviously, finalizers must never
|
|
|
|
* store a reference to obj.
|
|
|
|
*/
|
|
|
|
typedef void
|
2012-03-19 14:34:55 +00:00
|
|
|
(* JSFinalizeOp)(JSFreeOp *fop, JSObject *obj);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
2012-02-07 18:44:54 +00:00
|
|
|
* Finalizes external strings created by JS_NewExternalString.
|
2011-09-19 16:34:49 +00:00
|
|
|
*/
|
2012-02-07 18:44:54 +00:00
|
|
|
typedef struct JSStringFinalizer JSStringFinalizer;
|
|
|
|
|
|
|
|
struct JSStringFinalizer {
|
|
|
|
void (*finalize)(const JSStringFinalizer *fin, jschar *chars);
|
|
|
|
};
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* JSClass.checkAccess type: check whether obj[id] may be accessed per mode,
|
|
|
|
* returning false on error/exception, true on success with obj[id]'s last-got
|
|
|
|
* value in *vp, and its attributes in *attrsp. As for JSPropertyOp above, id
|
|
|
|
* is either a string or an int jsval.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSCheckAccessOp)(JSContext *cx, JSHandleObject obj, JSHandleId id, JSAccessMode mode,
|
2011-09-19 16:34:49 +00:00
|
|
|
jsval *vp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether v is an instance of obj. Return false on error or exception,
|
|
|
|
* true on success with JS_TRUE in *bp if v is an instance of obj, JS_FALSE in
|
|
|
|
* *bp otherwise.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSHasInstanceOp)(JSContext *cx, JSHandleObject obj, const jsval *v, JSBool *bp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function type for trace operation of the class called to enumerate all
|
|
|
|
* traceable things reachable from obj's private data structure. For each such
|
|
|
|
* thing, a trace implementation must call
|
|
|
|
*
|
|
|
|
* JS_CallTracer(trc, thing, kind);
|
|
|
|
*
|
|
|
|
* or one of its convenience macros as described in jsapi.h.
|
|
|
|
*
|
|
|
|
* JSTraceOp implementation can assume that no other threads mutates object
|
|
|
|
* state. It must not change state of the object or corresponding native
|
|
|
|
* structures. The only exception for this rule is the case when the embedding
|
|
|
|
* needs a tight integration with GC. In that case the embedding can check if
|
|
|
|
* the traversal is a part of the marking phase through calling
|
|
|
|
* JS_IsGCMarkingTracer and apply a special code like emptying caches or
|
|
|
|
* marking its native structures.
|
|
|
|
*/
|
|
|
|
typedef void
|
|
|
|
(* JSTraceOp)(JSTracer *trc, JSObject *obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEBUG only callback that JSTraceOp implementation can provide to return
|
|
|
|
* a string describing the reference traced with JS_CallTracer.
|
|
|
|
*/
|
|
|
|
typedef void
|
|
|
|
(* JSTraceNamePrinter)(JSTracer *trc, char *buf, size_t bufsize);
|
|
|
|
|
|
|
|
typedef JSBool
|
2012-05-19 22:03:45 +00:00
|
|
|
(* JSEqualityOp)(JSContext *cx, JSHandleObject obj, const jsval *v, JSBool *bp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Typedef for native functions called by the JS VM.
|
|
|
|
*
|
|
|
|
* See jsapi.h, the JS_CALLEE, JS_THIS, etc. macros.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef JSBool
|
2012-02-28 23:11:11 +00:00
|
|
|
(* JSNative)(JSContext *cx, unsigned argc, jsval *vp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/* Callbacks and their arguments. */
|
|
|
|
|
|
|
|
typedef enum JSContextOp {
|
|
|
|
JSCONTEXT_NEW,
|
|
|
|
JSCONTEXT_DESTROY
|
|
|
|
} JSContextOp;
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-06-30 22:25:47 +00:00
|
|
|
/*
|
2011-09-19 16:34:49 +00:00
|
|
|
* The possible values for contextOp when the runtime calls the callback are:
|
|
|
|
* JSCONTEXT_NEW JS_NewContext successfully created a new JSContext
|
|
|
|
* instance. The callback can initialize the instance as
|
|
|
|
* required. If the callback returns false, the instance
|
|
|
|
* will be destroyed and JS_NewContext returns null. In
|
|
|
|
* this case the callback is not called again.
|
|
|
|
* JSCONTEXT_DESTROY One of JS_DestroyContext* methods is called. The
|
|
|
|
* callback may perform its own cleanup and must always
|
|
|
|
* return true.
|
|
|
|
* Any other value For future compatibility the callback must do nothing
|
|
|
|
* and return true in this case.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
2012-02-28 23:11:11 +00:00
|
|
|
(* JSContextCallback)(JSContext *cx, unsigned contextOp);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
typedef enum JSGCStatus {
|
|
|
|
JSGC_BEGIN,
|
2012-02-29 20:23:38 +00:00
|
|
|
JSGC_END
|
2012-03-01 00:18:22 +00:00
|
|
|
} JSGCStatus;
|
2012-02-29 20:23:38 +00:00
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
typedef void
|
|
|
|
(* JSGCCallback)(JSRuntime *rt, JSGCStatus status);
|
|
|
|
|
|
|
|
typedef enum JSFinalizeStatus {
|
|
|
|
JSFINALIZE_START,
|
|
|
|
JSFINALIZE_END
|
|
|
|
} JSFinalizeStatus;
|
|
|
|
|
|
|
|
typedef void
|
2012-05-25 18:06:13 +00:00
|
|
|
(* JSFinalizeCallback)(JSFreeOp *fop, JSFinalizeStatus status, JSBool isCompartment);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic trace operation that calls JS_CallTracer on each traceable thing
|
|
|
|
* stored in data.
|
|
|
|
*/
|
|
|
|
typedef void
|
|
|
|
(* JSTraceDataOp)(JSTracer *trc, void *data);
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSOperationCallback)(JSContext *cx);
|
|
|
|
|
|
|
|
typedef void
|
|
|
|
(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report);
|
|
|
|
|
2011-12-01 19:25:37 +00:00
|
|
|
#ifdef MOZ_TRACE_JSCALLS
|
|
|
|
typedef void
|
|
|
|
(* JSFunctionCallback)(const JSFunction *fun,
|
|
|
|
const JSScript *scr,
|
|
|
|
const JSContext *cx,
|
|
|
|
int entering);
|
|
|
|
#endif
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* Possible exception types. These types are part of a JSErrorFormatString
|
|
|
|
* structure. They define which error to throw in case of a runtime error.
|
|
|
|
* JSEXN_NONE marks an unthrowable error.
|
|
|
|
*/
|
|
|
|
typedef enum JSExnType {
|
|
|
|
JSEXN_NONE = -1,
|
|
|
|
JSEXN_ERR,
|
|
|
|
JSEXN_INTERNALERR,
|
|
|
|
JSEXN_EVALERR,
|
|
|
|
JSEXN_RANGEERR,
|
|
|
|
JSEXN_REFERENCEERR,
|
|
|
|
JSEXN_SYNTAXERR,
|
|
|
|
JSEXN_TYPEERR,
|
|
|
|
JSEXN_URIERR,
|
|
|
|
JSEXN_LIMIT
|
|
|
|
} JSExnType;
|
|
|
|
|
|
|
|
typedef struct JSErrorFormatString {
|
|
|
|
/* The error format string (UTF-8 if js_CStringsAreUTF8). */
|
|
|
|
const char *format;
|
|
|
|
|
|
|
|
/* The number of arguments to expand in the formatted error message. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint16_t argCount;
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/* One of the JSExnType constants above. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int16_t exnType;
|
2011-09-19 16:34:49 +00:00
|
|
|
} JSErrorFormatString;
|
|
|
|
|
|
|
|
typedef const JSErrorFormatString *
|
|
|
|
(* JSErrorCallback)(void *userRef, const char *locale,
|
2012-02-28 23:11:11 +00:00
|
|
|
const unsigned errorNumber);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
#ifdef va_start
|
|
|
|
#define JS_ARGUMENT_FORMATTER_DEFINED 1
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSArgumentFormatter)(JSContext *cx, const char *format, JSBool fromJS,
|
|
|
|
jsval **vpp, va_list *app);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSLocaleToUpperCase)(JSContext *cx, JSString *src, jsval *rval);
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSLocaleToLowerCase)(JSContext *cx, JSString *src, jsval *rval);
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSLocaleCompare)(JSContext *cx, JSString *src1, JSString *src2,
|
|
|
|
jsval *rval);
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSLocaleToUnicode)(JSContext *cx, const char *src, jsval *rval);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Security protocol types.
|
|
|
|
*/
|
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
typedef void
|
|
|
|
(* JSDestroyPrincipalsOp)(JSPrincipals *principals);
|
|
|
|
|
|
|
|
typedef JSBool
|
|
|
|
(* JSSubsumePrincipalsOp)(JSPrincipals *principals1, JSPrincipals *principals2);
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* Return a weak reference to the principals associated with obj, possibly via
|
|
|
|
* the immutable parent chain leading from obj to a top-level container (e.g.,
|
|
|
|
* a window object in the DOM level 0). If there are no principals associated
|
|
|
|
* with obj, return null. Therefore null does not mean an error was reported;
|
|
|
|
* in no event should an error be reported or an exception be thrown by this
|
|
|
|
* callback's implementation.
|
|
|
|
*/
|
|
|
|
typedef JSPrincipals *
|
2012-03-09 09:48:50 +00:00
|
|
|
(* JSObjectPrincipalsFinder)(JSObject *obj);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Used to check if a CSP instance wants to disable eval() and friends.
|
|
|
|
* See js_CheckCSPPermitsJSAction() in jsobj.
|
|
|
|
*/
|
|
|
|
typedef JSBool
|
|
|
|
(* JSCSPEvalChecker)(JSContext *cx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback used to ask the embedding for the cross compartment wrapper handler
|
|
|
|
* that implements the desired prolicy for this kind of object in the
|
|
|
|
* destination compartment.
|
|
|
|
*/
|
|
|
|
typedef JSObject *
|
|
|
|
(* JSWrapObjectCallback)(JSContext *cx, JSObject *obj, JSObject *proto, JSObject *parent,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback used by the wrap hook to ask the embedding to prepare an object
|
|
|
|
* for wrapping in a context. This might include unwrapping other wrappers
|
|
|
|
* or even finding a more suitable object for the new compartment.
|
|
|
|
*/
|
|
|
|
typedef JSObject *
|
2012-02-28 23:11:11 +00:00
|
|
|
(* JSPreWrapCallback)(JSContext *cx, JSObject *scope, JSObject *obj, unsigned flags);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2012-05-14 21:30:07 +00:00
|
|
|
/*
|
|
|
|
* Callback used when wrapping determines that the underlying object is already
|
|
|
|
* in the compartment for which it is being wrapped. This allows consumers to
|
|
|
|
* maintain same-compartment wrapping invariants.
|
|
|
|
*
|
|
|
|
* |obj| is guaranteed to be same-compartment as |cx|, but it may (or may not)
|
|
|
|
* be a security or cross-compartment wrapper. This is an unfortunate contract,
|
|
|
|
* but is important for to avoid unnecessarily recomputing every cross-
|
|
|
|
* compartment wrapper that gets passed to wrap.
|
|
|
|
*/
|
|
|
|
typedef JSObject *
|
|
|
|
(* JSSameCompartmentWrapObjectCallback)(JSContext *cx, JSObject *obj);
|
|
|
|
|
2012-03-20 10:22:05 +00:00
|
|
|
typedef void
|
|
|
|
(* JSDestroyCompartmentCallback)(JSFreeOp *fop, JSCompartment *compartment);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
2012-07-26 01:25:47 +00:00
|
|
|
typedef void
|
|
|
|
(* JSCompartmentNameCallback)(JSRuntime *rt, JSCompartment *compartment,
|
|
|
|
char *buf, size_t bufsize);
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* Read structured data from the reader r. This hook is used to read a value
|
|
|
|
* previously serialized by a call to the WriteStructuredCloneOp hook.
|
2010-06-30 22:25:47 +00:00
|
|
|
*
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* tag and data are the pair of uint32_t values from the header. The callback
|
|
|
|
* may use the JS_Read* APIs to read any other relevant parts of the object
|
|
|
|
* from the reader r. closure is any value passed to the JS_ReadStructuredClone
|
2011-09-19 16:34:49 +00:00
|
|
|
* function. Return the new object on success, NULL on error/exception.
|
|
|
|
*/
|
|
|
|
typedef JSObject *(*ReadStructuredCloneOp)(JSContext *cx, JSStructuredCloneReader *r,
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t tag, uint32_t data, void *closure);
|
2011-09-19 16:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Structured data serialization hook. The engine can write primitive values,
|
|
|
|
* Objects, Arrays, Dates, RegExps, TypedArrays, and ArrayBuffers. Any other
|
|
|
|
* type of object requires application support. This callback must first use
|
|
|
|
* the JS_WriteUint32Pair API to write an object header, passing a value
|
|
|
|
* greater than JS_SCTAG_USER to the tag parameter. Then it can use the
|
|
|
|
* JS_Write* APIs to write any other relevant parts of the value v to the
|
|
|
|
* writer w. closure is any value passed to the JS_WriteStructuredCLone function.
|
2010-06-30 22:25:47 +00:00
|
|
|
*
|
2011-09-19 16:34:49 +00:00
|
|
|
* Return true on success, false on error/exception.
|
2010-06-30 22:25:47 +00:00
|
|
|
*/
|
2011-09-19 16:34:49 +00:00
|
|
|
typedef JSBool (*WriteStructuredCloneOp)(JSContext *cx, JSStructuredCloneWriter *w,
|
|
|
|
JSObject *obj, void *closure);
|
2010-06-30 22:25:47 +00:00
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* This is called when JS_WriteStructuredClone finds that the object to be
|
|
|
|
* written is recursive. To follow HTML5, the application must throw a
|
|
|
|
* DATA_CLONE_ERR DOMException. errorid is always JS_SCERR_RECURSION.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
typedef void (*StructuredCloneErrorOp)(JSContext *cx, uint32_t errorid);
|
2010-06-30 22:25:47 +00:00
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/************************************************************************/
|
2010-06-30 22:25:47 +00:00
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
JS_BEGIN_EXTERN_C
|
2010-06-30 22:25:47 +00:00
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* Silence warning about returning JS::Value (aka jsval) from functions with C
|
|
|
|
* linkage. For C JSAPI clients, jsval will be jsval_layout, which should be
|
|
|
|
* ABI compatible.
|
|
|
|
*/
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning(disable:4190)
|
2010-06-29 01:08:28 +00:00
|
|
|
#endif
|
2009-07-27 20:14:12 +00:00
|
|
|
|
2010-06-30 22:25:47 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* JS constants. For efficiency, prefer predicates (e.g., JSVAL_IS_NULL).
|
|
|
|
* N.B. These constants are initialized at startup.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_NULL;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_ZERO;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_ONE;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_FALSE;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_TRUE;
|
|
|
|
extern JS_PUBLIC_DATA(const jsval) JSVAL_VOID;
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_IS_NULL(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_NULL_IMPL(JSVAL_TO_IMPL(v));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_IS_VOID(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_UNDEFINED_IMPL(JSVAL_TO_IMPL(v));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_IS_INT(jsval v)
|
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_INT32_IMPL(JSVAL_TO_IMPL(v));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-02 02:54:01 +00:00
|
|
|
static JS_ALWAYS_INLINE int32_t
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_TO_INT(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_INT(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_TO_INT32_IMPL(JSVAL_TO_IMPL(v));
|
2010-05-17 23:52:38 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
INT_TO_JSVAL(int32_t i)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2010-06-29 01:08:28 +00:00
|
|
|
return IMPL_TO_JSVAL(INT32_TO_JSVAL_IMPL(i));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
2009-08-12 23:39:23 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_IS_DOUBLE(jsval v)
|
2009-08-12 23:39:23 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_DOUBLE_IMPL(JSVAL_TO_IMPL(v));
|
2009-08-12 23:39:23 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 22:19:52 +00:00
|
|
|
static JS_ALWAYS_INLINE double
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_TO_DOUBLE(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2010-06-08 01:21:51 +00:00
|
|
|
jsval_layout l;
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_DOUBLE(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
l = JSVAL_TO_IMPL(v);
|
2010-05-25 18:20:59 +00:00
|
|
|
return l.asDouble;
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
2012-02-24 22:19:52 +00:00
|
|
|
DOUBLE_TO_JSVAL(double d)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2011-09-23 12:25:16 +00:00
|
|
|
/* This is a manually inlined version of:
|
|
|
|
* d = JS_CANONICALIZE_NAN(d);
|
|
|
|
* return IMPL_TO_JSVAL(DOUBLE_TO_JSVAL_IMPL(d));
|
|
|
|
* because GCC from XCode 3.1.4 miscompiles the above code. */
|
|
|
|
jsval_layout l;
|
|
|
|
if (JS_UNLIKELY(d != d)) {
|
|
|
|
l.asBits = 0x7FF8000000000000LL;
|
|
|
|
} else {
|
|
|
|
l.asDouble = d;
|
|
|
|
}
|
|
|
|
return IMPL_TO_JSVAL(l);
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 01:21:51 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
UINT_TO_JSVAL(uint32_t i)
|
2010-06-08 01:21:51 +00:00
|
|
|
{
|
|
|
|
if (i <= JSVAL_INT_MAX)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
return INT_TO_JSVAL((int32_t)i);
|
2012-02-24 22:19:52 +00:00
|
|
|
return DOUBLE_TO_JSVAL((double)i);
|
2010-06-08 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 20:14:12 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_IS_NUMBER(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_IS_STRING(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE JSString *
|
|
|
|
JSVAL_TO_STRING(jsval v)
|
2009-07-27 20:14:12 +00:00
|
|
|
{
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_STRING(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v));
|
2009-07-27 20:14:12 +00:00
|
|
|
}
|
2009-02-03 21:56:25 +00:00
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
STRING_TO_JSVAL(JSString *str)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2010-06-29 01:08:28 +00:00
|
|
|
return IMPL_TO_JSVAL(STRING_TO_JSVAL_IMPL(str));
|
2010-05-11 05:01:31 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 21:56:25 +00:00
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
|
|
|
JSVAL_TO_OBJECT(jsval v)
|
|
|
|
{
|
2012-06-02 18:15:38 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_OBJECT_OR_NULL_IMPL(JSVAL_TO_IMPL(v)));
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_TO_OBJECT_IMPL(JSVAL_TO_IMPL(v));
|
2009-02-03 21:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
OBJECT_TO_JSVAL(JSObject *obj)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2010-06-30 05:33:52 +00:00
|
|
|
if (obj)
|
|
|
|
return IMPL_TO_JSVAL(OBJECT_TO_JSVAL_IMPL(obj));
|
|
|
|
return JSVAL_NULL;
|
2009-02-03 21:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_IS_BOOLEAN(jsval v)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_BOOLEAN_IMPL(JSVAL_TO_IMPL(v));
|
2009-02-03 21:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_TO_BOOLEAN(jsval v)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_TO_BOOLEAN_IMPL(JSVAL_TO_IMPL(v));
|
2009-02-03 21:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsval
|
2010-05-11 05:01:31 +00:00
|
|
|
BOOLEAN_TO_JSVAL(JSBool b)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2010-06-29 01:08:28 +00:00
|
|
|
return IMPL_TO_JSVAL(BOOLEAN_TO_JSVAL_IMPL(b));
|
2009-08-09 12:25:53 +00:00
|
|
|
}
|
2009-02-03 21:56:25 +00:00
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_IS_PRIMITIVE(jsval v)
|
2009-08-09 12:25:53 +00:00
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_PRIMITIVE_IMPL(JSVAL_TO_IMPL(v));
|
2009-08-09 12:25:53 +00:00
|
|
|
}
|
2009-02-03 21:56:25 +00:00
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_IS_GCTHING(jsval v)
|
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_GCTHING_IMPL(JSVAL_TO_IMPL(v));
|
2010-05-11 05:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void *
|
|
|
|
JSVAL_TO_GCTHING(jsval v)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_GCTHING(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_TO_GCTHING_IMPL(JSVAL_TO_IMPL(v));
|
2009-02-03 21:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-05-26 23:36:47 +00:00
|
|
|
/* To be GC-safe, privates are tagged as doubles. */
|
|
|
|
|
2009-02-03 21:56:25 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
2010-05-11 05:01:31 +00:00
|
|
|
PRIVATE_TO_JSVAL(void *ptr)
|
2009-02-03 21:56:25 +00:00
|
|
|
{
|
2010-06-29 01:08:28 +00:00
|
|
|
return IMPL_TO_JSVAL(PRIVATE_PTR_TO_JSVAL_IMPL(ptr));
|
2009-02-03 21:56:25 +00:00
|
|
|
}
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE void *
|
|
|
|
JSVAL_TO_PRIVATE(jsval v)
|
|
|
|
{
|
2010-05-26 23:36:47 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_DOUBLE(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_TO_PRIVATE_PTR_IMPL(JSVAL_TO_IMPL(v));
|
2010-05-11 05:01:31 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 00:59:47 +00:00
|
|
|
static JS_ALWAYS_INLINE jsval
|
|
|
|
JS_NumberValue(double d)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
d = JS_CANONICALIZE_NAN(d);
|
|
|
|
if (MOZ_DOUBLE_IS_INT32(d, &i))
|
|
|
|
return INT_TO_JSVAL(i);
|
|
|
|
return DOUBLE_TO_JSVAL(d);
|
|
|
|
}
|
|
|
|
|
2010-06-17 01:21:34 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2010-06-18 07:59:10 +00:00
|
|
|
/*
|
|
|
|
* A jsid is an identifier for a property or method of an object which is
|
|
|
|
* either a 31-bit signed integer, interned string or object. If XML is
|
|
|
|
* enabled, there is an additional singleton jsid value; see
|
|
|
|
* JS_DEFAULT_XML_NAMESPACE_ID below. Finally, there is an additional jsid
|
|
|
|
* value, JSID_VOID, which does not occur in JS scripts but may be used to
|
|
|
|
* indicate the absence of a valid jsid.
|
|
|
|
*
|
|
|
|
* A jsid is not implicitly convertible to or from a jsval; JS_ValueToId or
|
|
|
|
* JS_IdToValue must be used instead.
|
|
|
|
*/
|
|
|
|
|
2010-07-05 08:41:42 +00:00
|
|
|
#define JSID_TYPE_STRING 0x0
|
|
|
|
#define JSID_TYPE_INT 0x1
|
|
|
|
#define JSID_TYPE_VOID 0x2
|
|
|
|
#define JSID_TYPE_OBJECT 0x4
|
|
|
|
#define JSID_TYPE_DEFAULT_XML_NAMESPACE 0x6
|
2010-06-17 01:21:34 +00:00
|
|
|
#define JSID_TYPE_MASK 0x7
|
|
|
|
|
2010-06-22 18:54:27 +00:00
|
|
|
/*
|
2010-08-29 18:57:08 +00:00
|
|
|
* Avoid using canonical 'id' for jsid parameters since this is a magic word in
|
2010-06-22 18:54:27 +00:00
|
|
|
* Objective-C++ which, apparently, wants to be able to #include jsapi.h.
|
|
|
|
*/
|
2010-08-29 18:57:08 +00:00
|
|
|
#define id iden
|
2010-06-22 18:54:27 +00:00
|
|
|
|
2010-06-17 01:21:34 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_IS_STRING(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
return (JSID_BITS(id) & JSID_TYPE_MASK) == 0;
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSString *
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_TO_STRING(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
JS_ASSERT(JSID_IS_STRING(id));
|
2011-09-19 16:34:49 +00:00
|
|
|
return (JSString *)JSID_BITS(id);
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 00:20:22 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSID_IS_ZERO(jsid id)
|
|
|
|
{
|
2010-11-09 19:50:24 +00:00
|
|
|
return JSID_BITS(id) == 0;
|
2010-11-09 00:20:22 +00:00
|
|
|
}
|
|
|
|
|
2010-06-18 06:51:54 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
2011-05-17 19:15:12 +00:00
|
|
|
JS_StringHasBeenInterned(JSContext *cx, JSString *str);
|
2010-06-18 06:51:54 +00:00
|
|
|
|
2011-05-17 19:15:12 +00:00
|
|
|
/*
|
|
|
|
* Only JSStrings that have been interned via the JSAPI can be turned into
|
|
|
|
* jsids by API clients.
|
|
|
|
*
|
|
|
|
* N.B. if a jsid is backed by a string which has not been interned, that
|
|
|
|
* string must be appropriately rooted to avoid being collected by the GC.
|
|
|
|
*/
|
2012-05-06 20:45:19 +00:00
|
|
|
JS_PUBLIC_API(jsid)
|
|
|
|
INTERNED_STRING_TO_JSID(JSContext *cx, JSString *str);
|
2010-06-18 06:51:54 +00:00
|
|
|
|
2010-06-17 01:21:34 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_IS_INT(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
return !!(JSID_BITS(id) & JSID_TYPE_INT);
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
static JS_ALWAYS_INLINE int32_t
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_TO_INT(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
JS_ASSERT(JSID_IS_INT(id));
|
2012-05-06 20:45:19 +00:00
|
|
|
return ((uint32_t)JSID_BITS(id)) >> 1;
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 20:45:19 +00:00
|
|
|
#define JSID_INT_MIN 0
|
2012-05-06 23:43:15 +00:00
|
|
|
#define JSID_INT_MAX INT32_MAX
|
2010-06-17 01:21:34 +00:00
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
INT_FITS_IN_JSID(int32_t i)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2012-05-06 20:45:19 +00:00
|
|
|
return i >= 0;
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsid
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
INT_TO_JSID(int32_t i)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
jsid id;
|
2010-06-18 06:51:54 +00:00
|
|
|
JS_ASSERT(INT_FITS_IN_JSID(i));
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_BITS(id) = ((i << 1) | JSID_TYPE_INT);
|
|
|
|
return id;
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_IS_OBJECT(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
return (JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_OBJECT &&
|
|
|
|
(size_t)JSID_BITS(id) != JSID_TYPE_OBJECT;
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSObject *
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_TO_OBJECT(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
JS_ASSERT(JSID_IS_OBJECT(id));
|
|
|
|
return (JSObject *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK);
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE jsid
|
2012-07-23 20:37:31 +00:00
|
|
|
OBJECT_TO_JSID(JSRawObject obj)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
jsid id;
|
2010-06-17 05:58:31 +00:00
|
|
|
JS_ASSERT(obj != NULL);
|
2010-06-17 01:21:34 +00:00
|
|
|
JS_ASSERT(((size_t)obj & JSID_TYPE_MASK) == 0);
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_BITS(id) = ((size_t)obj | JSID_TYPE_OBJECT);
|
|
|
|
return id;
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_IS_GCTHING(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
return JSID_IS_STRING(id) || JSID_IS_OBJECT(id);
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void *
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_TO_GCTHING(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
return (void *)(JSID_BITS(id) & ~(size_t)JSID_TYPE_MASK);
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The magic XML namespace id is not a valid jsid. Global object classes in
|
|
|
|
* embeddings that enable JS_HAS_XML_SUPPORT (E4X) should handle this id.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_IS_DEFAULT_XML_NAMESPACE(jsid id)
|
2010-06-17 01:21:34 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_DEFAULT_XML_NAMESPACE,
|
|
|
|
JSID_BITS(id) == JSID_TYPE_DEFAULT_XML_NAMESPACE);
|
|
|
|
return ((size_t)JSID_BITS(id) == JSID_TYPE_DEFAULT_XML_NAMESPACE);
|
2010-06-17 01:21:34 +00:00
|
|
|
}
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
#ifdef JS_USE_JSID_STRUCT_TYPES
|
2010-07-15 06:19:36 +00:00
|
|
|
extern JS_PUBLIC_DATA(jsid) JS_DEFAULT_XML_NAMESPACE_ID;
|
|
|
|
#else
|
2011-09-19 16:34:49 +00:00
|
|
|
# define JS_DEFAULT_XML_NAMESPACE_ID ((jsid)JSID_TYPE_DEFAULT_XML_NAMESPACE)
|
2010-07-15 06:19:36 +00:00
|
|
|
#endif
|
2010-06-17 01:21:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A void jsid is not a valid id and only arises as an exceptional API return
|
2010-06-30 22:25:47 +00:00
|
|
|
* value, such as in JS_NextProperty. Embeddings must not pass JSID_VOID into
|
|
|
|
* JSAPI entry points expecting a jsid and do not need to handle JSID_VOID in
|
|
|
|
* hooks receiving a jsid except when explicitly noted in the API contract.
|
2010-06-17 01:21:34 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-15 22:43:41 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
2010-08-29 18:57:08 +00:00
|
|
|
JSID_IS_VOID(jsid id)
|
2010-06-15 22:43:41 +00:00
|
|
|
{
|
2010-08-29 18:57:08 +00:00
|
|
|
JS_ASSERT_IF(((size_t)JSID_BITS(id) & JSID_TYPE_MASK) == JSID_TYPE_VOID,
|
|
|
|
JSID_BITS(id) == JSID_TYPE_VOID);
|
|
|
|
return ((size_t)JSID_BITS(id) == JSID_TYPE_VOID);
|
2010-06-15 22:43:41 +00:00
|
|
|
}
|
|
|
|
|
2010-08-29 18:57:08 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSID_IS_EMPTY(jsid id)
|
|
|
|
{
|
|
|
|
return ((size_t)JSID_BITS(id) == JSID_TYPE_OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef id
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
#ifdef JS_USE_JSID_STRUCT_TYPES
|
2010-06-18 06:51:54 +00:00
|
|
|
extern JS_PUBLIC_DATA(jsid) JSID_VOID;
|
2010-08-29 18:57:08 +00:00
|
|
|
extern JS_PUBLIC_DATA(jsid) JSID_EMPTY;
|
2010-06-18 06:51:54 +00:00
|
|
|
#else
|
2011-09-19 16:34:49 +00:00
|
|
|
# define JSID_VOID ((jsid)JSID_TYPE_VOID)
|
|
|
|
# define JSID_EMPTY ((jsid)JSID_TYPE_OBJECT)
|
2010-06-18 06:51:54 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-08 01:01:29 +00:00
|
|
|
/*
|
|
|
|
* Returns true iff the given jsval is immune to GC and can be used across
|
|
|
|
* multiple JSRuntimes without requiring any conversion API.
|
|
|
|
*/
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_IS_UNIVERSAL(jsval v)
|
|
|
|
{
|
|
|
|
return !JSVAL_IS_GCTHING(v);
|
|
|
|
}
|
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class AutoIdRooter : private AutoGCRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoIdRooter(JSContext *cx, jsid id = INT_TO_JSID(0)
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, ID), id_(id)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsid id() {
|
|
|
|
return id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsid * addr() {
|
|
|
|
return &id_;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
jsid id_;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2010-06-17 01:21:34 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
/* Lock and unlock the GC thing held by a jsval. */
|
|
|
|
#define JSVAL_LOCK(cx,v) (JSVAL_IS_GCTHING(v) \
|
|
|
|
? JS_LockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
|
|
|
: JS_TRUE)
|
|
|
|
#define JSVAL_UNLOCK(cx,v) (JSVAL_IS_GCTHING(v) \
|
|
|
|
? JS_UnlockGCThing(cx, JSVAL_TO_GCTHING(v)) \
|
|
|
|
: JS_TRUE)
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/* Property attributes, set in JSPropertySpec and passed to API functions. */
|
1998-03-28 02:44:41 +00:00
|
|
|
#define JSPROP_ENUMERATE 0x01 /* property is visible to for/in loop */
|
2011-12-15 19:40:57 +00:00
|
|
|
#define JSPROP_READONLY 0x02 /* not settable: assignment is no-op.
|
|
|
|
This flag is only valid when neither
|
|
|
|
JSPROP_GETTER nor JSPROP_SETTER is
|
|
|
|
set. */
|
1998-03-28 02:44:41 +00:00
|
|
|
#define JSPROP_PERMANENT 0x04 /* property cannot be deleted */
|
1999-09-21 00:13:48 +00:00
|
|
|
#define JSPROP_GETTER 0x10 /* property holds getter function */
|
|
|
|
#define JSPROP_SETTER 0x20 /* property holds setter function */
|
2000-12-05 21:47:23 +00:00
|
|
|
#define JSPROP_SHARED 0x40 /* don't allocate a value slot for this
|
|
|
|
property; don't copy the property on
|
|
|
|
set of the same-named property in an
|
|
|
|
object that delegates to a prototype
|
|
|
|
containing this property */
|
2012-03-02 02:54:01 +00:00
|
|
|
#define JSPROP_INDEX 0x80 /* name is actually (int) index */
|
2011-04-18 22:42:07 +00:00
|
|
|
#define JSPROP_SHORTID 0x100 /* set in JS_DefineProperty attrs
|
2010-05-19 02:21:43 +00:00
|
|
|
if getters/setters use a shortid */
|
2011-04-18 22:42:07 +00:00
|
|
|
#define JSPROP_NATIVE_ACCESSORS 0x08 /* set in JSPropertyDescriptor.flags
|
|
|
|
if getters/setters are JSNatives */
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-04-18 22:42:07 +00:00
|
|
|
/* Function flags, internal use only, returned by JS_GetFunctionFlags. */
|
2001-04-10 01:10:28 +00:00
|
|
|
#define JSFUN_LAMBDA 0x08 /* expressed, not declared, function */
|
2000-02-04 02:01:49 +00:00
|
|
|
#define JSFUN_HEAVYWEIGHT 0x80 /* activation requires a Call object */
|
2006-07-06 18:40:03 +00:00
|
|
|
|
2010-07-05 08:50:08 +00:00
|
|
|
#define JSFUN_HEAVYWEIGHT_TEST(f) ((f) & JSFUN_HEAVYWEIGHT)
|
2006-07-06 18:40:03 +00:00
|
|
|
|
2012-05-23 15:31:35 +00:00
|
|
|
#define JSFUN_HAS_REST 0x0100 /* function has a rest (...) parameter */
|
2012-05-26 13:33:53 +00:00
|
|
|
#define JSFUN_CONSTRUCTOR 0x0200 /* native that can be called as a ctor
|
2010-11-03 00:40:46 +00:00
|
|
|
without creating a this object */
|
2012-05-26 13:33:53 +00:00
|
|
|
#define JSFUN_HAS_DEFAULTS 0x0400 /* function has at least one default
|
|
|
|
parameter */
|
2006-07-06 18:40:03 +00:00
|
|
|
|
2010-11-03 00:40:46 +00:00
|
|
|
#define JSFUN_FLAGS_MASK 0x07f8 /* overlay JSFUN_* attributes --
|
2009-04-06 04:17:22 +00:00
|
|
|
bits 12-15 are used internally to
|
|
|
|
flag interpreted functions */
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2008-02-07 23:18:45 +00:00
|
|
|
#define JSFUN_STUB_GSOPS 0x1000 /* use JS_PropertyStub getter/setter
|
|
|
|
instead of defaulting to class gsops
|
|
|
|
for property holding function */
|
|
|
|
|
2005-08-30 04:28:45 +00:00
|
|
|
/*
|
|
|
|
* Re-use JSFUN_LAMBDA, which applies only to scripted functions, for use in
|
|
|
|
* JSFunctionSpec arrays that specify generic native prototype methods, i.e.,
|
|
|
|
* methods of a class prototype that are exposed as static methods taking an
|
|
|
|
* extra leading argument: the generic |this| parameter.
|
|
|
|
*
|
|
|
|
* If you set this flag in a JSFunctionSpec struct's flags initializer, then
|
|
|
|
* that struct must live at least as long as the native static method object
|
|
|
|
* created due to this flag by JS_DefineFunctions or JS_InitClass. Typically
|
|
|
|
* JSFunctionSpec structs are allocated in static arrays.
|
|
|
|
*/
|
|
|
|
#define JSFUN_GENERIC_NATIVE JSFUN_LAMBDA
|
|
|
|
|
2011-09-11 18:37:43 +00:00
|
|
|
/*
|
|
|
|
* The first call to JS_CallOnce by any thread in a process will call 'func'.
|
|
|
|
* Later calls to JS_CallOnce with the same JSCallOnceType object will be
|
|
|
|
* suppressed.
|
|
|
|
*
|
|
|
|
* Equivalently: each distinct JSCallOnceType object will allow one JS_CallOnce
|
|
|
|
* to invoke its JSInitCallback.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_CallOnce(JSCallOnceType *once, JSInitCallback func);
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
/* Microseconds since the epoch, midnight, January 1, 1970 UTC. */
|
|
|
|
extern JS_PUBLIC_API(int64_t)
|
2007-11-07 09:17:35 +00:00
|
|
|
JS_Now(void);
|
2002-02-27 09:17:21 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/* Don't want to export data, so provide accessors for non-inline jsvals. */
|
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetNaNValue(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetNegativeInfinityValue(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetPositiveInfinityValue(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetEmptyStringValue(JSContext *cx);
|
|
|
|
|
2010-11-24 16:56:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_GetEmptyString(JSRuntime *rt);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/*
|
|
|
|
* Format is a string of the following characters (spaces are insignificant),
|
|
|
|
* specifying the tabulated type conversions:
|
|
|
|
*
|
|
|
|
* b JSBool Boolean
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* c uint16_t/jschar ECMA uint16_t, Unicode char
|
|
|
|
* i int32_t ECMA int32_t
|
|
|
|
* u uint32_t ECMA uint32_t
|
|
|
|
* j int32_t Rounded int32_t (coordinate)
|
2012-02-24 22:19:52 +00:00
|
|
|
* d double IEEE double
|
|
|
|
* I double Integral IEEE double
|
1999-03-02 02:38:45 +00:00
|
|
|
* S JSString * Unicode string, accessed by a JSString pointer
|
|
|
|
* W jschar * Unicode character vector, 0-terminated (W for wide)
|
1998-04-24 00:31:11 +00:00
|
|
|
* o JSObject * Object reference
|
|
|
|
* f JSFunction * Function private
|
|
|
|
* v jsval Argument value (no conversion)
|
|
|
|
* * N/A Skip this argument (no vararg)
|
|
|
|
* / N/A End of required arguments
|
|
|
|
*
|
|
|
|
* The variable argument list after format must consist of &b, &c, &s, e.g.,
|
|
|
|
* where those variables have the types given above. For the pointer types
|
|
|
|
* char *, JSString *, and JSObject *, the pointed-at memory returned belongs
|
1998-08-25 08:23:34 +00:00
|
|
|
* to the JS runtime, not to the calling native code. The runtime promises
|
1998-04-24 00:31:11 +00:00
|
|
|
* to keep this memory valid so long as argv refers to allocated stack space
|
|
|
|
* (so long as the native function is active).
|
|
|
|
*
|
|
|
|
* Fewer arguments than format specifies may be passed only if there is a /
|
|
|
|
* in format after the last required argument specifier and argc is at least
|
|
|
|
* the number of required arguments. More arguments than format specifies
|
|
|
|
* may be passed without error; it is up to the caller to deal with trailing
|
|
|
|
* unconverted arguments.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_ConvertArguments(JSContext *cx, unsigned argc, jsval *argv, const char *format,
|
2000-09-08 21:24:14 +00:00
|
|
|
...);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
1999-06-08 02:15:57 +00:00
|
|
|
#ifdef va_start
|
1999-11-23 01:02:28 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv,
|
2000-09-08 21:24:14 +00:00
|
|
|
const char *format, va_list ap);
|
1999-06-08 02:15:57 +00:00
|
|
|
#endif
|
|
|
|
|
1999-06-28 04:50:37 +00:00
|
|
|
#ifdef JS_ARGUMENT_FORMATTER_DEFINED
|
|
|
|
|
1999-06-28 03:13:21 +00:00
|
|
|
/*
|
|
|
|
* Add and remove a format string handler for JS_{Convert,Push}Arguments{,VA}.
|
2011-09-19 16:34:49 +00:00
|
|
|
* The handler function has this signature:
|
1999-06-28 03:13:21 +00:00
|
|
|
*
|
|
|
|
* JSBool MyArgumentFormatter(JSContext *cx, const char *format,
|
|
|
|
* JSBool fromJS, jsval **vpp, va_list *app);
|
|
|
|
*
|
|
|
|
* It should return true on success, and return false after reporting an error
|
|
|
|
* or detecting an already-reported error.
|
|
|
|
*
|
|
|
|
* For a given format string, for example "AA", the formatter is called from
|
|
|
|
* JS_ConvertArgumentsVA like so:
|
|
|
|
*
|
|
|
|
* formatter(cx, "AA...", JS_TRUE, &sp, &ap);
|
|
|
|
*
|
|
|
|
* sp points into the arguments array on the JS stack, while ap points into
|
|
|
|
* the stdarg.h va_list on the C stack. The JS_TRUE passed for fromJS tells
|
|
|
|
* the formatter to convert zero or more jsvals at sp to zero or more C values
|
|
|
|
* accessed via pointers-to-values at ap, updating both sp (via *vpp) and ap
|
|
|
|
* (via *app) to point past the converted arguments and their result pointers
|
|
|
|
* on the C stack.
|
|
|
|
*
|
|
|
|
* When called from JS_PushArgumentsVA, the formatter is invoked thus:
|
|
|
|
*
|
|
|
|
* formatter(cx, "AA...", JS_FALSE, &sp, &ap);
|
|
|
|
*
|
|
|
|
* where JS_FALSE for fromJS means to wrap the C values at ap according to the
|
|
|
|
* format specifier and store them at sp, updating ap and sp appropriately.
|
|
|
|
*
|
|
|
|
* The "..." after "AA" is the rest of the format string that was passed into
|
|
|
|
* JS_{Convert,Push}Arguments{,VA}. The actual format trailing substring used
|
|
|
|
* in each Convert or PushArguments call is passed to the formatter, so that
|
|
|
|
* one such function may implement several formats, in order to share code.
|
|
|
|
*
|
|
|
|
* Remove just forgets about any handler associated with format. Add does not
|
|
|
|
* copy format, it points at the string storage allocated by the caller, which
|
|
|
|
* is typically a string constant. If format is in dynamic storage, it is up
|
|
|
|
* to the caller to keep the string alive until Remove is called.
|
|
|
|
*/
|
1999-06-29 00:20:21 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1999-06-28 03:13:21 +00:00
|
|
|
JS_AddArgumentFormatter(JSContext *cx, const char *format,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSArgumentFormatter formatter);
|
1999-06-28 03:13:21 +00:00
|
|
|
|
1999-06-29 00:20:21 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1999-06-28 03:13:21 +00:00
|
|
|
JS_RemoveArgumentFormatter(JSContext *cx, const char *format);
|
1999-06-28 04:50:37 +00:00
|
|
|
|
|
|
|
#endif /* JS_ARGUMENT_FORMATTER_DEFINED */
|
1999-06-28 03:13:21 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ValueToObject(JSContext *cx, jsval v, JSObject **objp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ValueToFunction(JSContext *cx, jsval v);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
|
|
JS_ValueToConstructor(JSContext *cx, jsval v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ValueToString(JSContext *cx, jsval v);
|
|
|
|
|
2008-11-03 22:28:36 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_ValueToSource(JSContext *cx, jsval v);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-24 22:19:52 +00:00
|
|
|
JS_ValueToNumber(JSContext *cx, jsval v, double *dp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace js {
|
|
|
|
/*
|
|
|
|
* DO NOT CALL THIS. Use JS::ToNumber
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToNumberSlow(JSContext *cx, JS::Value v, double *dp);
|
2012-07-25 05:59:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DO NOT CALL THIS. Use JS::ToBoolean
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToBooleanSlow(const JS::Value &v);
|
2012-03-28 23:35:21 +00:00
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/* ES5 9.3 ToNumber. */
|
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToNumber(JSContext *cx, const Value &v, double *out)
|
|
|
|
{
|
|
|
|
AssertArgumentsAreSane(cx, v);
|
2012-08-02 19:59:30 +00:00
|
|
|
{
|
|
|
|
JS::SkipRoot root(cx, &v);
|
|
|
|
MaybeCheckStackRoots(cx);
|
|
|
|
}
|
2012-05-01 00:10:30 +00:00
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
if (v.isNumber()) {
|
|
|
|
*out = v.toNumber();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return js::ToNumberSlow(cx, v, out);
|
|
|
|
}
|
|
|
|
|
2012-07-25 05:59:55 +00:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToBoolean(const Value &v)
|
|
|
|
{
|
|
|
|
if (v.isBoolean())
|
|
|
|
return v.toBoolean();
|
|
|
|
if (v.isInt32())
|
|
|
|
return v.toInt32() != 0;
|
|
|
|
if (v.isObject())
|
|
|
|
return true;
|
|
|
|
if (v.isNullOrUndefined())
|
|
|
|
return false;
|
|
|
|
if (v.isDouble()) {
|
|
|
|
double d = v.toDouble();
|
|
|
|
return !MOZ_DOUBLE_IS_NaN(d) && d != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Slow path. Handle Strings. */
|
|
|
|
return js::ToBooleanSlow(v);
|
|
|
|
}
|
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2010-03-01 21:30:23 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-03-02 02:54:01 +00:00
|
|
|
JS_DoubleIsInt32(double d, int32_t *ip);
|
2010-03-01 21:30:23 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(int32_t)
|
2012-02-24 22:19:52 +00:00
|
|
|
JS_DoubleToInt32(double d);
|
2011-03-30 02:19:15 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
2012-02-24 22:19:52 +00:00
|
|
|
JS_DoubleToUint32(double d);
|
2011-03-30 02:19:15 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* Convert a value to a number, then to an int32_t, according to the ECMA rules
|
1998-04-24 00:31:11 +00:00
|
|
|
* for ToInt32.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ValueToECMAInt32(JSContext *cx, jsval v, int32_t *ip);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-08-03 22:15:04 +00:00
|
|
|
/*
|
|
|
|
* Convert a value to a number, then to an int64_t, according to the WebIDL
|
|
|
|
* rules for ToInt64: http://dev.w3.org/2006/webapi/WebIDL/#es-long-long
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ValueToInt64(JSContext *cx, jsval v, int64_t *ip);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a value to a number, then to an uint64_t, according to the WebIDL
|
|
|
|
* rules for ToUint64: http://dev.w3.org/2006/webapi/WebIDL/#es-unsigned-long-long
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ValueToUint64(JSContext *cx, jsval v, uint64_t *ip);
|
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace js {
|
2012-08-02 19:59:30 +00:00
|
|
|
/* DO NOT CALL THIS. Use JS::ToInt16. */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToUint16Slow(JSContext *cx, const JS::Value &v, uint16_t *out);
|
|
|
|
|
|
|
|
/* DO NOT CALL THIS. Use JS::ToInt32. */
|
2012-03-28 23:35:21 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToInt32Slow(JSContext *cx, const JS::Value &v, int32_t *out);
|
2012-08-02 19:59:30 +00:00
|
|
|
|
|
|
|
/* DO NOT CALL THIS. Use JS::ToUint32. */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToUint32Slow(JSContext *cx, const JS::Value &v, uint32_t *out);
|
2012-08-03 22:15:04 +00:00
|
|
|
|
|
|
|
/* DO NOT CALL THIS. Use JS::ToInt64. */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToInt64Slow(JSContext *cx, const JS::Value &v, int64_t *out);
|
|
|
|
|
|
|
|
/* DO NOT CALL THIS. Use JS::ToUint64. */
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
ToUint64Slow(JSContext *cx, const JS::Value &v, uint64_t *out);
|
2012-03-28 23:35:21 +00:00
|
|
|
} /* namespace js */
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2012-08-02 19:59:30 +00:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToUint16(JSContext *cx, const js::Value &v, uint16_t *out)
|
|
|
|
{
|
|
|
|
AssertArgumentsAreSane(cx, v);
|
|
|
|
{
|
|
|
|
SkipRoot skip(cx, &v);
|
|
|
|
MaybeCheckStackRoots(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v.isInt32()) {
|
|
|
|
*out = uint16_t(v.toInt32());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return js::ToUint16Slow(cx, v, out);
|
|
|
|
}
|
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToInt32(JSContext *cx, const js::Value &v, int32_t *out)
|
|
|
|
{
|
|
|
|
AssertArgumentsAreSane(cx, v);
|
2012-08-02 19:59:30 +00:00
|
|
|
{
|
|
|
|
JS::SkipRoot root(cx, &v);
|
|
|
|
MaybeCheckStackRoots(cx);
|
|
|
|
}
|
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
if (v.isInt32()) {
|
|
|
|
*out = v.toInt32();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return js::ToInt32Slow(cx, v, out);
|
|
|
|
}
|
|
|
|
|
2012-08-02 19:59:30 +00:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToUint32(JSContext *cx, const js::Value &v, uint32_t *out)
|
|
|
|
{
|
|
|
|
AssertArgumentsAreSane(cx, v);
|
|
|
|
{
|
|
|
|
JS::SkipRoot root(cx, &v);
|
|
|
|
MaybeCheckStackRoots(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v.isInt32()) {
|
|
|
|
*out = uint32_t(v.toInt32());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return js::ToUint32Slow(cx, v, out);
|
|
|
|
}
|
|
|
|
|
2012-08-03 22:15:04 +00:00
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToInt64(JSContext *cx, const js::Value &v, int64_t *out)
|
|
|
|
{
|
|
|
|
AssertArgumentsAreSane(cx, v);
|
|
|
|
{
|
|
|
|
JS::SkipRoot skip(cx, &v);
|
|
|
|
MaybeCheckStackRoots(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v.isInt32()) {
|
|
|
|
*out = int64_t(v.toInt32());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return js::ToInt64Slow(cx, v, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ALWAYS_INLINE bool
|
|
|
|
ToUint64(JSContext *cx, const js::Value &v, uint64_t *out)
|
|
|
|
{
|
|
|
|
AssertArgumentsAreSane(cx, v);
|
|
|
|
{
|
|
|
|
SkipRoot skip(cx, &v);
|
|
|
|
MaybeCheckStackRoots(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v.isInt32()) {
|
|
|
|
// Account for sign extension of negatives into the longer 64bit space.
|
|
|
|
*out = uint64_t(int64_t(v.toInt32()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return js::ToUint64Slow(cx, v, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-28 23:35:21 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/*
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* Convert a value to a number, then to a uint32_t, according to the ECMA rules
|
1998-04-24 00:31:11 +00:00
|
|
|
* for ToUint32.
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ValueToECMAUint32(JSContext *cx, jsval v, uint32_t *ip);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
/*
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* Convert a value to a number, then to an int32_t if it fits by rounding to
|
1998-04-24 00:31:11 +00:00
|
|
|
* nearest; but failing with an error report if the double is out of range
|
|
|
|
* or unordered.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ValueToInt32(JSContext *cx, jsval v, int32_t *ip);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/*
|
|
|
|
* ECMA ToUint16, for mapping a jsval to a Unicode point.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ValueToUint16(JSContext *cx, jsval v, uint16_t *ip);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSType)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_TypeOfValue(JSContext *cx, jsval v);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetTypeName(JSContext *cx, JSType type);
|
|
|
|
|
2009-05-15 19:51:02 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal);
|
2009-05-15 19:51:02 +00:00
|
|
|
|
2011-03-21 17:04:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal);
|
|
|
|
|
2009-09-09 18:51:52 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_SameValue(JSContext *cx, jsval v1, jsval v2, JSBool *same);
|
2009-09-09 18:51:52 +00:00
|
|
|
|
2011-03-03 03:57:44 +00:00
|
|
|
/* True iff fun is the global eval function. */
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsBuiltinEvalFunction(JSFunction *fun);
|
|
|
|
|
|
|
|
/* True iff fun is the Function constructor. */
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsBuiltinFunctionConstructor(JSFunction *fun);
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization, locking, contexts, and memory allocation.
|
2007-02-08 19:49:35 +00:00
|
|
|
*
|
|
|
|
* It is important that the first runtime and first context be created in a
|
|
|
|
* single-threaded fashion, otherwise the behavior of the library is undefined.
|
|
|
|
* See: http://developer.mozilla.org/en/docs/Category:JSAPI_Reference
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
#define JS_NewRuntime JS_Init
|
|
|
|
#define JS_DestroyRuntime JS_Finish
|
|
|
|
#define JS_LockRuntime JS_Lock
|
|
|
|
#define JS_UnlockRuntime JS_Unlock
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_NewRuntime(uint32_t maxbytes);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-09-21 12:58:19 +00:00
|
|
|
/* Deprecated. */
|
2011-01-04 23:47:12 +00:00
|
|
|
#define JS_CommenceRuntimeShutDown(rt) ((void) 0)
|
2009-08-18 23:31:20 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DestroyRuntime(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ShutDown(void);
|
|
|
|
|
2000-05-17 06:23:03 +00:00
|
|
|
JS_PUBLIC_API(void *)
|
|
|
|
JS_GetRuntimePrivate(JSRuntime *rt);
|
|
|
|
|
2011-07-18 21:54:48 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
|
|
|
JS_GetRuntime(JSContext *cx);
|
|
|
|
|
2000-05-17 06:23:03 +00:00
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetRuntimePrivate(JSRuntime *rt, void *data);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_BeginRequest(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_EndRequest(JSContext *cx);
|
|
|
|
|
1998-06-09 21:39:58 +00:00
|
|
|
/* Yield to pending GC operations, regardless of request depth */
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_YieldRequest(JSContext *cx);
|
|
|
|
|
2012-03-01 19:43:17 +00:00
|
|
|
extern JS_PUBLIC_API(unsigned)
|
1998-04-24 00:31:11 +00:00
|
|
|
JS_SuspendRequest(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2012-03-01 19:43:17 +00:00
|
|
|
JS_ResumeRequest(JSContext *cx, unsigned saveDepth);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2010-11-26 14:11:14 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2011-07-18 21:54:48 +00:00
|
|
|
JS_IsInRequest(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsInSuspendedRequest(JSRuntime *rt);
|
2010-11-26 14:11:14 +00:00
|
|
|
|
2005-08-17 16:26:14 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
2012-04-12 16:23:51 +00:00
|
|
|
namespace JS {
|
|
|
|
|
2011-12-31 14:32:04 +00:00
|
|
|
inline bool
|
|
|
|
IsPoisonedId(jsid iden)
|
|
|
|
{
|
|
|
|
if (JSID_IS_STRING(iden))
|
|
|
|
return JS::IsPoisonedPtr(JSID_TO_STRING(iden));
|
|
|
|
if (JSID_IS_OBJECT(iden))
|
|
|
|
return JS::IsPoisonedPtr(JSID_TO_OBJECT(iden));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-12 16:23:51 +00:00
|
|
|
template <> struct RootMethods<const jsid>
|
|
|
|
{
|
|
|
|
static jsid initial() { return JSID_VOID; }
|
|
|
|
static ThingRootKind kind() { return THING_ROOT_ID; }
|
|
|
|
static bool poisoned(jsid id) { return IsPoisonedId(id); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct RootMethods<jsid>
|
|
|
|
{
|
|
|
|
static jsid initial() { return JSID_VOID; }
|
|
|
|
static ThingRootKind kind() { return THING_ROOT_ID; }
|
|
|
|
static bool poisoned(jsid id) { return IsPoisonedId(id); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
2005-08-17 16:26:14 +00:00
|
|
|
class JSAutoRequest {
|
|
|
|
public:
|
2009-09-28 06:17:47 +00:00
|
|
|
JSAutoRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mContext(cx), mSaveDepth(0) {
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2005-08-17 16:26:14 +00:00
|
|
|
JS_BeginRequest(mContext);
|
|
|
|
}
|
|
|
|
~JSAutoRequest() {
|
|
|
|
JS_EndRequest(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void suspend() {
|
|
|
|
mSaveDepth = JS_SuspendRequest(mContext);
|
|
|
|
}
|
|
|
|
void resume() {
|
|
|
|
JS_ResumeRequest(mContext, mSaveDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
JSContext *mContext;
|
2012-03-01 19:43:17 +00:00
|
|
|
unsigned mSaveDepth;
|
2009-09-28 06:17:47 +00:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2005-08-17 16:26:14 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
private:
|
|
|
|
static void *operator new(size_t) CPP_THROW_NEW { return 0; };
|
|
|
|
static void operator delete(void *, size_t) { };
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2008-07-17 16:37:32 +00:00
|
|
|
class JSAutoSuspendRequest {
|
|
|
|
public:
|
2009-09-28 06:17:47 +00:00
|
|
|
JSAutoSuspendRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mContext(cx), mSaveDepth(0) {
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2008-07-17 16:37:32 +00:00
|
|
|
if (mContext) {
|
|
|
|
mSaveDepth = JS_SuspendRequest(mContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~JSAutoSuspendRequest() {
|
|
|
|
resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void resume() {
|
|
|
|
if (mContext) {
|
|
|
|
JS_ResumeRequest(mContext, mSaveDepth);
|
|
|
|
mContext = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
JSContext *mContext;
|
2012-03-01 19:43:17 +00:00
|
|
|
unsigned mSaveDepth;
|
2009-09-28 06:17:47 +00:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2008-07-17 16:37:32 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
private:
|
|
|
|
static void *operator new(size_t) CPP_THROW_NEW { return 0; };
|
|
|
|
static void operator delete(void *, size_t) { };
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-11-26 14:11:14 +00:00
|
|
|
class JSAutoCheckRequest {
|
|
|
|
public:
|
|
|
|
JSAutoCheckRequest(JSContext *cx JS_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
#if defined JS_THREADSAFE && defined DEBUG
|
|
|
|
mContext = cx;
|
2011-07-18 21:54:48 +00:00
|
|
|
JS_ASSERT(JS_IsInRequest(JS_GetRuntime(cx)));
|
2010-11-26 14:11:14 +00:00
|
|
|
#endif
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2011-01-04 23:47:12 +00:00
|
|
|
|
2010-11-26 14:11:14 +00:00
|
|
|
~JSAutoCheckRequest() {
|
|
|
|
#if defined JS_THREADSAFE && defined DEBUG
|
2011-07-18 21:54:48 +00:00
|
|
|
JS_ASSERT(JS_IsInRequest(JS_GetRuntime(mContext)));
|
2010-11-26 14:11:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
#if defined JS_THREADSAFE && defined DEBUG
|
|
|
|
JSContext *mContext;
|
|
|
|
#endif
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2005-08-17 16:26:14 +00:00
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
#endif
|
|
|
|
|
2006-06-27 12:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSContextCallback)
|
|
|
|
JS_SetContextCallback(JSRuntime *rt, JSContextCallback cxCallback);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSContext *)
|
2000-03-23 23:50:29 +00:00
|
|
|
JS_NewContext(JSRuntime *rt, size_t stackChunkSize);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DestroyContext(JSContext *cx);
|
|
|
|
|
1999-06-23 14:18:56 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DestroyContextNoGC(JSContext *cx);
|
|
|
|
|
2000-02-04 02:01:49 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
1998-04-24 00:31:11 +00:00
|
|
|
JS_GetContextPrivate(JSContext *cx);
|
|
|
|
|
1999-11-23 01:02:28 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-07-31 00:07:22 +00:00
|
|
|
JS_SetContextPrivate(JSContext *cx, void *data);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-01-11 08:23:07 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
|
|
|
JS_GetSecondContextPrivate(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetSecondContextPrivate(JSContext *cx, void *data);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetRuntime(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSContext *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetVersion(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_SetVersion(JSContext *cx, JSVersion version);
|
|
|
|
|
1999-10-29 22:44:35 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
|
|
JS_VersionToString(JSVersion version);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSVersion)
|
|
|
|
JS_StringToVersion(const char *string);
|
|
|
|
|
1999-11-12 06:03:40 +00:00
|
|
|
/*
|
|
|
|
* JS options are orthogonal to version, and may be freely composed with one
|
|
|
|
* another as well as with version.
|
2001-01-20 02:02:48 +00:00
|
|
|
*
|
|
|
|
* JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
|
|
|
|
* prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
|
1999-11-12 06:03:40 +00:00
|
|
|
*/
|
2000-01-18 11:06:05 +00:00
|
|
|
#define JSOPTION_STRICT JS_BIT(0) /* warn on dubious practice */
|
|
|
|
#define JSOPTION_WERROR JS_BIT(1) /* convert warning to error */
|
2001-01-20 01:41:55 +00:00
|
|
|
#define JSOPTION_VAROBJFIX JS_BIT(2) /* make JS_EvaluateScript use
|
|
|
|
the last object on its 'obj'
|
|
|
|
param's scope chain as the
|
|
|
|
ECMA 'variables object' */
|
2001-08-07 05:27:42 +00:00
|
|
|
#define JSOPTION_PRIVATE_IS_NSISUPPORTS \
|
|
|
|
JS_BIT(3) /* context private data points
|
|
|
|
to an nsISupports subclass */
|
2004-04-13 01:25:17 +00:00
|
|
|
#define JSOPTION_COMPILE_N_GO JS_BIT(4) /* caller of JS_Compile*Script
|
|
|
|
promises to execute compiled
|
|
|
|
script once only; enables
|
|
|
|
compile-time scope chain
|
|
|
|
resolution of consts. */
|
2004-06-11 00:55:59 +00:00
|
|
|
#define JSOPTION_ATLINE JS_BIT(5) /* //@line number ["filename"]
|
|
|
|
option supported for the
|
|
|
|
XUL preprocessor and kindred
|
|
|
|
beasts. */
|
2012-05-30 20:05:59 +00:00
|
|
|
#define JSOPTION_ALLOW_XML JS_BIT(6) /* enable E4X syntax (deprecated)
|
|
|
|
and define the E4X-related
|
|
|
|
globals: XML, XMLList,
|
|
|
|
Namespace, etc. */
|
2012-05-30 20:05:59 +00:00
|
|
|
#define JSOPTION_MOAR_XML JS_BIT(7) /* enable E4X even in versions
|
|
|
|
that don't normally get it;
|
2004-10-05 10:19:07 +00:00
|
|
|
parse <!-- --> as a token,
|
|
|
|
not backward compatible with
|
|
|
|
the comment-hiding hack used
|
|
|
|
in HTML script tags. */
|
2012-05-30 20:05:59 +00:00
|
|
|
#define JSOPTION_DONT_REPORT_UNCAUGHT \
|
2006-01-18 00:29:35 +00:00
|
|
|
JS_BIT(8) /* When returning from the
|
|
|
|
outermost API call, prevent
|
|
|
|
uncaught exceptions from
|
|
|
|
being converted to error
|
|
|
|
reports */
|
1999-11-12 06:03:40 +00:00
|
|
|
|
2007-02-17 06:33:09 +00:00
|
|
|
#define JSOPTION_RELIMIT JS_BIT(9) /* Throw exception on any
|
|
|
|
regular expression which
|
|
|
|
backtracks more than n^3
|
|
|
|
times, where n is length
|
|
|
|
of the input string */
|
2011-06-21 16:53:19 +00:00
|
|
|
/* JS_BIT(10) is currently unused. */
|
2007-02-17 06:33:09 +00:00
|
|
|
|
2011-11-28 22:57:31 +00:00
|
|
|
/* JS_BIT(11) is currently unused. */
|
2008-06-27 08:22:53 +00:00
|
|
|
|
2008-07-25 23:23:12 +00:00
|
|
|
#define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12) /* A promise to the compiler
|
|
|
|
that a null rval out-param
|
|
|
|
will be passed to each call
|
|
|
|
to JS_ExecuteScript. */
|
2008-12-15 06:40:10 +00:00
|
|
|
#define JSOPTION_UNROOTED_GLOBAL JS_BIT(13) /* The GC will not root the
|
2009-01-28 03:56:55 +00:00
|
|
|
contexts' global objects
|
|
|
|
(see JS_GetGlobalObject),
|
|
|
|
leaving that up to the
|
|
|
|
embedding. */
|
2008-07-25 23:23:12 +00:00
|
|
|
|
2010-05-23 00:09:52 +00:00
|
|
|
#define JSOPTION_METHODJIT JS_BIT(14) /* Whole-method JIT. */
|
2011-11-28 22:57:31 +00:00
|
|
|
|
|
|
|
/* JS_BIT(15) is currently unused. */
|
|
|
|
|
2011-02-12 00:31:32 +00:00
|
|
|
#define JSOPTION_METHODJIT_ALWAYS \
|
|
|
|
JS_BIT(16) /* Always whole-method JIT,
|
|
|
|
don't tune at run-time. */
|
2011-05-10 18:26:39 +00:00
|
|
|
#define JSOPTION_PCCOUNT JS_BIT(17) /* Collect per-op execution counts */
|
2010-05-23 00:09:52 +00:00
|
|
|
|
2011-07-01 23:24:32 +00:00
|
|
|
#define JSOPTION_TYPE_INFERENCE JS_BIT(18) /* Perform type inference. */
|
2012-05-05 19:26:16 +00:00
|
|
|
#define JSOPTION_STRICT_MODE JS_BIT(19) /* Provides a way to force
|
|
|
|
strict mode for all code
|
|
|
|
without requiring
|
|
|
|
"use strict" annotations. */
|
2012-07-20 18:19:02 +00:00
|
|
|
/* JS_BIT(20) is taken in jsfriendapi.h! */
|
2011-03-03 22:07:48 +00:00
|
|
|
|
2011-01-27 10:54:58 +00:00
|
|
|
/* Options which reflect compile-time properties of scripts. */
|
2012-05-30 20:05:59 +00:00
|
|
|
#define JSCOMPILEOPTION_MASK (JSOPTION_ALLOW_XML | JSOPTION_MOAR_XML)
|
2011-01-27 10:54:58 +00:00
|
|
|
|
2012-07-20 18:19:02 +00:00
|
|
|
#define JSRUNOPTION_MASK (JS_BITMASK(21) & ~JSCOMPILEOPTION_MASK)
|
2011-01-27 10:54:58 +00:00
|
|
|
#define JSALLOPTION_MASK (JSCOMPILEOPTION_MASK | JSRUNOPTION_MASK)
|
2010-05-23 00:09:52 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
1999-11-12 06:03:40 +00:00
|
|
|
JS_GetOptions(JSContext *cx);
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
|
|
|
JS_SetOptions(JSContext *cx, uint32_t options);
|
1999-11-12 06:03:40 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
|
|
|
JS_ToggleOptions(JSContext *cx, uint32_t options);
|
1999-11-12 06:03:40 +00:00
|
|
|
|
2012-02-14 05:36:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetJitHardening(JSRuntime *rt, JSBool enabled);
|
|
|
|
|
1998-07-31 00:07:22 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
|
|
JS_GetImplementationVersion(void);
|
|
|
|
|
2012-03-20 10:22:05 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetDestroyCompartmentCallback(JSRuntime *rt, JSDestroyCompartmentCallback callback);
|
2010-07-19 20:36:49 +00:00
|
|
|
|
2012-07-26 01:25:47 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetCompartmentNameCallback(JSRuntime *rt, JSCompartmentNameCallback callback);
|
|
|
|
|
2010-06-24 21:45:32 +00:00
|
|
|
extern JS_PUBLIC_API(JSWrapObjectCallback)
|
2010-10-10 22:36:38 +00:00
|
|
|
JS_SetWrapObjectCallbacks(JSRuntime *rt,
|
|
|
|
JSWrapObjectCallback callback,
|
2012-05-14 21:30:07 +00:00
|
|
|
JSSameCompartmentWrapObjectCallback sccallback,
|
2010-10-10 22:36:38 +00:00
|
|
|
JSPreWrapCallback precallback);
|
2010-06-24 21:45:32 +00:00
|
|
|
|
2010-06-23 21:35:10 +00:00
|
|
|
extern JS_PUBLIC_API(JSCrossCompartmentCall *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_EnterCrossCompartmentCall(JSContext *cx, JSRawObject target);
|
2010-06-23 21:35:10 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_LeaveCrossCompartmentCall(JSCrossCompartmentCall *call);
|
|
|
|
|
2012-02-29 12:18:16 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetCompartmentPrivate(JSCompartment *compartment, void *data);
|
2010-07-19 20:36:49 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
2012-02-29 12:18:16 +00:00
|
|
|
JS_GetCompartmentPrivate(JSCompartment *compartment);
|
2010-07-19 20:36:49 +00:00
|
|
|
|
2010-08-23 22:14:38 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-09-16 18:32:18 +00:00
|
|
|
JS_WrapObject(JSContext *cx, JSObject **objp);
|
2010-08-23 22:14:38 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-09-16 18:32:18 +00:00
|
|
|
JS_WrapValue(JSContext *cx, jsval *vp);
|
2010-08-23 22:14:38 +00:00
|
|
|
|
2010-09-17 21:54:40 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2010-11-16 01:21:25 +00:00
|
|
|
JS_TransplantObject(JSContext *cx, JSObject *origobj, JSObject *target);
|
2010-09-17 21:54:40 +00:00
|
|
|
|
2011-02-12 00:17:25 +00:00
|
|
|
extern JS_FRIEND_API(JSObject *)
|
|
|
|
js_TransplantObjectWithWrapper(JSContext *cx,
|
|
|
|
JSObject *origobj,
|
|
|
|
JSObject *origwrapper,
|
|
|
|
JSObject *targetobj,
|
|
|
|
JSObject *targetwrapper);
|
|
|
|
|
2012-05-14 10:52:16 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_RefreshCrossCompartmentWrappers(JSContext *cx, JSObject *ob);
|
2011-02-12 00:17:25 +00:00
|
|
|
|
2010-06-24 21:44:18 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
2012-04-05 21:02:34 +00:00
|
|
|
namespace js {
|
2012-04-05 23:31:26 +00:00
|
|
|
class AutoCompartment;
|
2012-04-05 21:02:34 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 22:55:15 +00:00
|
|
|
class JS_PUBLIC_API(JSAutoEnterCompartment)
|
2010-06-24 21:44:18 +00:00
|
|
|
{
|
2011-10-04 19:25:18 +00:00
|
|
|
/*
|
|
|
|
* This is a poor man's Maybe<AutoCompartment>, because we don't have
|
|
|
|
* access to the AutoCompartment definition here. We statically assert in
|
|
|
|
* jsapi.cpp that we have the right size here.
|
2011-10-10 19:51:59 +00:00
|
|
|
*
|
2012-07-27 01:27:08 +00:00
|
|
|
* In practice, 32-bit Windows and Android get 16-word |bytes|, while other
|
|
|
|
* platforms get 12-word |bytes|.
|
2011-10-04 19:25:18 +00:00
|
|
|
*/
|
2012-07-27 01:27:08 +00:00
|
|
|
void* bytes[sizeof(void*) == 4 && MOZ_ALIGNOF(uint64_t) == 8 ? 16 : 12];
|
2011-10-04 19:25:18 +00:00
|
|
|
|
2012-04-05 21:02:34 +00:00
|
|
|
protected:
|
|
|
|
js::AutoCompartment *getAutoCompartment() {
|
|
|
|
JS_ASSERT(state == STATE_OTHER_COMPARTMENT);
|
|
|
|
return reinterpret_cast<js::AutoCompartment*>(bytes);
|
|
|
|
}
|
|
|
|
|
2011-10-04 19:25:18 +00:00
|
|
|
/*
|
|
|
|
* This object may be in one of three states. If enter() or
|
|
|
|
* enterAndIgnoreErrors() hasn't been called, it's in STATE_UNENTERED.
|
|
|
|
* Otherwise, if we were asked to enter into the current compartment, our
|
|
|
|
* state is STATE_SAME_COMPARTMENT. If we actually created an
|
|
|
|
* AutoCompartment and entered another compartment, our state is
|
|
|
|
* STATE_OTHER_COMPARTMENT.
|
|
|
|
*/
|
|
|
|
enum State {
|
|
|
|
STATE_UNENTERED,
|
|
|
|
STATE_SAME_COMPARTMENT,
|
|
|
|
STATE_OTHER_COMPARTMENT
|
|
|
|
} state;
|
2010-09-27 22:55:15 +00:00
|
|
|
|
2010-06-24 21:44:18 +00:00
|
|
|
public:
|
2011-10-04 19:25:18 +00:00
|
|
|
JSAutoEnterCompartment() : state(STATE_UNENTERED) {}
|
2010-06-24 21:44:18 +00:00
|
|
|
|
2012-07-23 20:37:31 +00:00
|
|
|
bool enter(JSContext *cx, JSRawObject target);
|
2010-06-24 21:44:18 +00:00
|
|
|
|
2012-07-23 20:37:31 +00:00
|
|
|
void enterAndIgnoreErrors(JSContext *cx, JSRawObject target);
|
2010-09-27 22:55:15 +00:00
|
|
|
|
2011-10-04 19:25:18 +00:00
|
|
|
bool entered() const { return state != STATE_UNENTERED; }
|
2010-09-09 16:13:06 +00:00
|
|
|
|
2012-06-13 09:44:24 +00:00
|
|
|
/*
|
|
|
|
* In general, consumers should try to avoid calling leave() explicitly,
|
|
|
|
* and defer to the destructor by scoping the JSAutoEnterCompartment
|
|
|
|
* appropriately. Sometimes, though, it's unavoidable.
|
|
|
|
*/
|
|
|
|
void leave();
|
|
|
|
|
2011-10-04 19:25:18 +00:00
|
|
|
~JSAutoEnterCompartment();
|
2010-06-24 21:44:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
#endif
|
|
|
|
|
2012-02-29 20:23:53 +00:00
|
|
|
typedef void (*JSIterateCompartmentCallback)(JSRuntime *rt, void *data, JSCompartment *compartment);
|
2012-02-17 06:10:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function calls |compartmentCallback| on every compartment. Beware that
|
|
|
|
* there is no guarantee that the compartment will survive after the callback
|
|
|
|
* returns.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2012-02-29 20:23:53 +00:00
|
|
|
JS_IterateCompartments(JSRuntime *rt, void *data,
|
2012-02-17 06:10:39 +00:00
|
|
|
JSIterateCompartmentCallback compartmentCallback);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetGlobalObject(JSContext *cx);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_SetGlobalObject(JSContext *cx, JSRawObject obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2000-08-19 08:37:07 +00:00
|
|
|
/*
|
|
|
|
* Initialize standard JS class constructors, prototypes, and any top-level
|
|
|
|
* functions and constants associated with the standard classes (e.g. isNaN
|
|
|
|
* for Number).
|
|
|
|
*
|
|
|
|
* NB: This sets cx's global object to obj if it was null.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_InitStandardClasses(JSContext *cx, JSObject *obj);
|
|
|
|
|
2000-08-19 08:37:07 +00:00
|
|
|
/*
|
|
|
|
* Resolve id, which must contain either a string or an int, to a standard
|
|
|
|
* class name in obj if possible, defining the class's constructor and/or
|
|
|
|
* prototype and storing true in *resolved. If id does not name a standard
|
|
|
|
* class or a top-level property induced by initializing a standard class,
|
|
|
|
* store false in *resolved and just return true. Return false on error,
|
|
|
|
* as usual for JSBool result-typed API entry points.
|
|
|
|
*
|
|
|
|
* This API can be called directly from a global object class's resolve op,
|
|
|
|
* to define standard classes lazily. The class's enumerate op should call
|
|
|
|
* JS_EnumerateStandardClasses(cx, obj), to define eagerly during for..in
|
|
|
|
* loops any classes not yet resolved lazily.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-06-10 04:59:18 +00:00
|
|
|
JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsid id,
|
2000-08-19 08:37:07 +00:00
|
|
|
JSBool *resolved);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj);
|
|
|
|
|
2005-06-16 21:43:15 +00:00
|
|
|
/*
|
|
|
|
* Enumerate any already-resolved standard class ids into ida, or into a new
|
|
|
|
* JSIdArray if ida is null. Return the augmented array on success, null on
|
|
|
|
* failure with ida (if it was non-null on entry) destroyed.
|
|
|
|
*/
|
2005-06-16 04:24:03 +00:00
|
|
|
extern JS_PUBLIC_API(JSIdArray *)
|
2005-06-16 21:43:15 +00:00
|
|
|
JS_EnumerateResolvedStandardClasses(JSContext *cx, JSObject *obj,
|
|
|
|
JSIdArray *ida);
|
2005-06-16 04:24:03 +00:00
|
|
|
|
2006-04-19 00:22:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetClassObject(JSContext *cx, JSRawObject obj, JSProtoKey key, JSObject **objp);
|
2006-04-19 00:22:43 +00:00
|
|
|
|
2012-07-27 10:15:46 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetClassPrototype(JSContext *cx, JSProtoKey key, JSObject **objp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSProtoKey)
|
|
|
|
JS_IdentifyClassPrototype(JSContext *cx, JSObject *obj);
|
|
|
|
|
2012-02-10 22:49:39 +00:00
|
|
|
/*
|
|
|
|
* Returns the original value of |Function.prototype| from the global object in
|
|
|
|
* which |forObj| was created.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetFunctionPrototype(JSContext *cx, JSRawObject forObj);
|
2012-02-10 22:49:39 +00:00
|
|
|
|
2012-02-07 19:45:18 +00:00
|
|
|
/*
|
|
|
|
* Returns the original value of |Object.prototype| from the global object in
|
|
|
|
* which |forObj| was created.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetObjectPrototype(JSContext *cx, JSRawObject forObj);
|
2012-02-07 19:45:18 +00:00
|
|
|
|
2007-08-09 22:19:59 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetGlobalForObject(JSContext *cx, JSRawObject obj);
|
2007-08-09 22:19:59 +00:00
|
|
|
|
2012-07-06 04:12:37 +00:00
|
|
|
/*
|
|
|
|
* May return NULL, if |c| never had a global (e.g. the atoms compartment), or
|
|
|
|
* if |c|'s global has been collected.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetGlobalForCompartmentOrNull(JSContext *cx, JSCompartment *c);
|
|
|
|
|
2010-05-21 12:27:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetGlobalForScopeChain(JSContext *cx);
|
|
|
|
|
2012-04-16 19:30:04 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_GetScriptedGlobal(JSContext *cx);
|
|
|
|
|
2011-06-28 17:57:16 +00:00
|
|
|
/*
|
|
|
|
* Initialize the 'Reflect' object on a global object.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_InitReflect(JSContext *cx, JSObject *global);
|
|
|
|
|
2010-04-02 20:07:41 +00:00
|
|
|
#ifdef JS_HAS_CTYPES
|
|
|
|
/*
|
|
|
|
* Initialize the 'ctypes' object on a global variable 'obj'. The 'ctypes'
|
|
|
|
* object will be sealed.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_InitCTypesClass(JSContext *cx, JSObject *global);
|
2010-09-13 17:54:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a unicode string 'source' of length 'slen' to the platform native
|
|
|
|
* charset, returning a null-terminated string allocated with JS_malloc. On
|
|
|
|
* failure, this function should report an error.
|
|
|
|
*/
|
|
|
|
typedef char *
|
|
|
|
(* JSCTypesUnicodeToNativeFun)(JSContext *cx, const jschar *source, size_t slen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set of function pointers that ctypes can use for various internal functions.
|
|
|
|
* See JS_SetCTypesCallbacks below. Providing NULL for a function is safe,
|
|
|
|
* and will result in the applicable ctypes functionality not being available.
|
|
|
|
*/
|
|
|
|
struct JSCTypesCallbacks {
|
|
|
|
JSCTypesUnicodeToNativeFun unicodeToNative;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct JSCTypesCallbacks JSCTypesCallbacks;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the callbacks on the provided 'ctypesObj' object. 'callbacks' should be a
|
|
|
|
* pointer to static data that exists for the lifetime of 'ctypesObj', but it
|
|
|
|
* may safely be altered after calling this function and without having
|
|
|
|
* to call this function again.
|
|
|
|
*/
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_SetCTypesCallbacks(JSRawObject ctypesObj, JSCTypesCallbacks *callbacks);
|
2010-04-02 20:07:41 +00:00
|
|
|
#endif
|
|
|
|
|
2011-07-08 00:31:18 +00:00
|
|
|
typedef JSBool
|
|
|
|
(* JSEnumerateDiagnosticMemoryCallback)(void *ptr, size_t length);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enumerate memory regions that contain diagnostic information
|
|
|
|
* intended to be included in crash report minidumps.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_EnumerateDiagnosticMemoryRegions(JSEnumerateDiagnosticMemoryCallback callback);
|
|
|
|
|
2007-08-02 04:33:52 +00:00
|
|
|
/*
|
|
|
|
* Macros to hide interpreter stack layout details from a JSFastNative using
|
|
|
|
* its jsval *vp parameter. The stack layout underlying invocation can't change
|
|
|
|
* without breaking source and binary compatibility (argv[-2] is well-known to
|
|
|
|
* be the callee jsval, and argv[-1] is as well known to be |this|).
|
|
|
|
*
|
2008-02-18 00:12:33 +00:00
|
|
|
* Note well: However, argv[-1] may be JSVAL_NULL where with slow natives it
|
|
|
|
* is the global object, so embeddings implementing fast natives *must* call
|
|
|
|
* JS_THIS or JS_THIS_OBJECT and test for failure indicated by a null return,
|
|
|
|
* which should propagate as a false return from native functions and hooks.
|
|
|
|
*
|
|
|
|
* To reduce boilerplace checks, JS_InstanceOf and JS_GetInstancePrivate now
|
|
|
|
* handle a null obj parameter by returning false (throwing a TypeError if
|
|
|
|
* given non-null argv), so most native functions that type-check their |this|
|
|
|
|
* parameter need not add null checking.
|
|
|
|
*
|
2007-08-02 04:33:52 +00:00
|
|
|
* NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
|
|
|
|
* methods that may inspect their callee must defer setting their return value
|
|
|
|
* until after any such possible inspection. Otherwise the return value will be
|
|
|
|
* inspected instead of the callee function object.
|
|
|
|
*
|
|
|
|
* WARNING: These are not (yet) mandatory macros, but new code outside of the
|
|
|
|
* engine should use them. In the Mozilla 2.0 milestone their definitions may
|
|
|
|
* change incompatibly.
|
2010-08-16 19:35:04 +00:00
|
|
|
*
|
|
|
|
* N.B. constructors must not use JS_THIS, as no 'this' object has been created.
|
2007-08-02 04:33:52 +00:00
|
|
|
*/
|
2010-08-16 19:35:04 +00:00
|
|
|
|
2007-08-02 04:33:52 +00:00
|
|
|
#define JS_CALLEE(cx,vp) ((vp)[0])
|
2008-03-01 22:15:21 +00:00
|
|
|
#define JS_THIS(cx,vp) JS_ComputeThis(cx, vp)
|
2010-05-11 05:01:31 +00:00
|
|
|
#define JS_THIS_OBJECT(cx,vp) (JSVAL_TO_OBJECT(JS_THIS(cx,vp)))
|
2007-08-02 04:33:52 +00:00
|
|
|
#define JS_ARGV(cx,vp) ((vp) + 2)
|
|
|
|
#define JS_RVAL(cx,vp) (*(vp))
|
|
|
|
#define JS_SET_RVAL(cx,vp,v) (*(vp) = (v))
|
|
|
|
|
2008-02-18 00:12:33 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
|
|
|
JS_ComputeThis(JSContext *cx, jsval *vp);
|
|
|
|
|
2010-06-29 23:28:17 +00:00
|
|
|
#ifdef __cplusplus
|
2010-07-03 04:52:25 +00:00
|
|
|
#undef JS_THIS
|
2010-06-29 05:24:21 +00:00
|
|
|
static inline jsval
|
|
|
|
JS_THIS(JSContext *cx, jsval *vp)
|
|
|
|
{
|
|
|
|
return JSVAL_IS_PRIMITIVE(vp[1]) ? JS_ComputeThis(cx, vp) : vp[1];
|
|
|
|
}
|
2010-06-29 23:28:17 +00:00
|
|
|
#endif
|
2010-06-29 05:24:21 +00:00
|
|
|
|
2011-01-26 21:37:45 +00:00
|
|
|
/*
|
|
|
|
* |this| is passed to functions in ES5 without change. Functions themselves
|
|
|
|
* do any post-processing they desire to box |this|, compute the global object,
|
|
|
|
* &c. Use this macro to retrieve a function's unboxed |this| value.
|
|
|
|
*
|
|
|
|
* This macro must not be used in conjunction with JS_THIS or JS_THIS_OBJECT,
|
|
|
|
* or vice versa. Either use the provided this value with this macro, or
|
|
|
|
* compute the boxed this value using those.
|
|
|
|
*
|
|
|
|
* N.B. constructors must not use JS_THIS_VALUE, as no 'this' object has been
|
|
|
|
* created.
|
|
|
|
*/
|
|
|
|
#define JS_THIS_VALUE(cx,vp) ((vp)[1])
|
|
|
|
|
2012-03-08 02:07:41 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_MallocInCompartment(JSCompartment *comp, size_t nbytes);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_FreeInCompartment(JSCompartment *comp, size_t nbytes);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_malloc(JSContext *cx, size_t nbytes);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_realloc(JSContext *cx, void *p, size_t nbytes);
|
|
|
|
|
2012-03-19 14:34:55 +00:00
|
|
|
/*
|
|
|
|
* A wrapper for js_free(p) that may delay js_free(p) invocation as a
|
|
|
|
* performance optimization.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_free(JSContext *cx, void *p);
|
|
|
|
|
2012-03-19 14:34:55 +00:00
|
|
|
/*
|
|
|
|
* A wrapper for js_free(p) that may delay js_free(p) invocation as a
|
|
|
|
* performance optimization as specified by the given JSFreeOp instance.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_freeop(JSFreeOp *fop, void *p);
|
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(JSFreeOp *)
|
2012-05-19 19:56:17 +00:00
|
|
|
JS_GetDefaultFreeOp(JSRuntime *rt);
|
2012-03-19 14:34:58 +00:00
|
|
|
|
2009-10-29 18:48:18 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_updateMallocCounter(JSContext *cx, size_t nbytes);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(char *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_strdup(JSContext *cx, const char *s);
|
|
|
|
|
2010-05-18 01:49:58 +00:00
|
|
|
|
2000-05-14 23:00:51 +00:00
|
|
|
/*
|
2010-06-08 00:05:02 +00:00
|
|
|
* A GC root is a pointer to a jsval, JSObject * or JSString * that itself
|
|
|
|
* points into the GC heap. JS_AddValueRoot takes a pointer to a jsval and
|
|
|
|
* JS_AddGCThingRoot takes a pointer to a JSObject * or JString *.
|
2010-05-11 05:01:31 +00:00
|
|
|
*
|
2010-06-08 00:05:02 +00:00
|
|
|
* Note that, since JS_Add*Root stores the address of a variable (of type
|
|
|
|
* jsval, JSString *, or JSObject *), that variable must live until
|
|
|
|
* JS_Remove*Root is called to remove that variable. For example, after:
|
2000-05-14 23:00:51 +00:00
|
|
|
*
|
2010-06-08 00:05:02 +00:00
|
|
|
* void some_function() {
|
|
|
|
* jsval v;
|
|
|
|
* JS_AddNamedRootedValue(cx, &v, "name");
|
2010-05-11 05:01:31 +00:00
|
|
|
*
|
|
|
|
* the caller must perform
|
|
|
|
*
|
2010-06-08 00:05:02 +00:00
|
|
|
* JS_RemoveRootedValue(cx, &v);
|
2010-05-11 05:01:31 +00:00
|
|
|
*
|
2010-06-08 00:05:02 +00:00
|
|
|
* before some_function() returns.
|
2000-05-14 23:00:51 +00:00
|
|
|
*
|
2010-06-08 00:05:02 +00:00
|
|
|
* Also, use JS_AddNamed*Root(cx, &structPtr->memberObj, "structPtr->memberObj")
|
|
|
|
* in preference to JS_Add*Root(cx, &structPtr->memberObj), in order to identify
|
2000-05-14 23:00:51 +00:00
|
|
|
* roots by their source callsites. This way, you can find the callsite while
|
2010-06-08 00:05:02 +00:00
|
|
|
* debugging if you should fail to do JS_Remove*Root(cx, &structPtr->memberObj)
|
2000-05-14 23:00:51 +00:00
|
|
|
* before freeing structPtr's memory.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-05-18 04:21:44 +00:00
|
|
|
JS_AddValueRoot(JSContext *cx, jsval *vp);
|
2010-05-11 05:01:31 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AddStringRoot(JSContext *cx, JSString **rp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AddObjectRoot(JSContext *cx, JSObject **rp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-06-04 23:55:08 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AddGCThingRoot(JSContext *cx, void **rp);
|
|
|
|
|
2003-02-25 03:29:24 +00:00
|
|
|
#ifdef NAME_ALL_GC_ROOTS
|
|
|
|
#define JS_DEFINE_TO_TOKEN(def) #def
|
|
|
|
#define JS_DEFINE_TO_STRING(def) JS_DEFINE_TO_TOKEN(def)
|
2010-05-11 05:01:31 +00:00
|
|
|
#define JS_AddValueRoot(cx,vp) JS_AddNamedValueRoot((cx), (vp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
|
|
|
|
#define JS_AddStringRoot(cx,rp) JS_AddNamedStringRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
|
|
|
|
#define JS_AddObjectRoot(cx,rp) JS_AddNamedObjectRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
|
2010-06-08 00:05:02 +00:00
|
|
|
#define JS_AddGCThingRoot(cx,rp) JS_AddNamedGCThingRoot((cx), (rp), (__FILE__ ":" JS_TOKEN_TO_STRING(__LINE__))
|
2003-02-25 03:29:24 +00:00
|
|
|
#endif
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-05-18 04:21:44 +00:00
|
|
|
JS_AddNamedValueRoot(JSContext *cx, jsval *vp, const char *name);
|
2010-05-11 05:01:31 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AddNamedStringRoot(JSContext *cx, JSString **rp, const char *name);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AddNamedObjectRoot(JSContext *cx, JSObject **rp, const char *name);
|
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AddNamedScriptRoot(JSContext *cx, JSScript **rp, const char *name);
|
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-06-04 23:55:08 +00:00
|
|
|
JS_AddNamedGCThingRoot(JSContext *cx, void **rp, const char *name);
|
2010-05-11 05:01:31 +00:00
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2010-05-18 04:21:44 +00:00
|
|
|
JS_RemoveValueRoot(JSContext *cx, jsval *vp);
|
2010-05-11 05:01:31 +00:00
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_RemoveStringRoot(JSContext *cx, JSString **rp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2010-05-11 05:01:31 +00:00
|
|
|
JS_RemoveObjectRoot(JSContext *cx, JSObject **rp);
|
1999-06-23 14:18:56 +00:00
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2011-09-02 06:46:00 +00:00
|
|
|
JS_RemoveScriptRoot(JSContext *cx, JSScript **rp);
|
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2010-06-04 23:55:08 +00:00
|
|
|
JS_RemoveGCThingRoot(JSContext *cx, void **rp);
|
2001-03-27 06:04:44 +00:00
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RemoveValueRootRT(JSRuntime *rt, jsval *vp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RemoveStringRootRT(JSRuntime *rt, JSString **rp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RemoveObjectRootRT(JSRuntime *rt, JSObject **rp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RemoveScriptRootRT(JSRuntime *rt, JSScript **rp);
|
|
|
|
|
2010-06-04 23:55:08 +00:00
|
|
|
/* TODO: remove these APIs */
|
2010-05-11 05:01:31 +00:00
|
|
|
|
2010-06-04 23:55:08 +00:00
|
|
|
extern JS_FRIEND_API(JSBool)
|
|
|
|
js_AddRootRT(JSRuntime *rt, jsval *vp, const char *name);
|
|
|
|
|
|
|
|
extern JS_FRIEND_API(JSBool)
|
|
|
|
js_AddGCThingRootRT(JSRuntime *rt, void **rp, const char *name);
|
|
|
|
|
2012-03-19 14:34:58 +00:00
|
|
|
extern JS_FRIEND_API(void)
|
2010-06-04 23:55:08 +00:00
|
|
|
js_RemoveRoot(JSRuntime *rt, void *rp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-02-03 13:06:21 +00:00
|
|
|
/*
|
|
|
|
* C-compatible version of the Anchor class. It should be called after the last
|
|
|
|
* use of the variable it protects.
|
|
|
|
*/
|
|
|
|
extern JS_NEVER_INLINE JS_PUBLIC_API(void)
|
|
|
|
JS_AnchorPtr(void *p);
|
|
|
|
|
2001-10-26 02:38:10 +00:00
|
|
|
/*
|
2010-06-08 00:05:02 +00:00
|
|
|
* This symbol may be used by embedders to detect the change from the old
|
|
|
|
* JS_AddRoot(JSContext *, void *) APIs to the new ones above.
|
2004-08-19 17:57:36 +00:00
|
|
|
*/
|
2010-06-08 00:05:02 +00:00
|
|
|
#define JS_TYPED_ROOTING_API
|
2006-01-26 07:19:25 +00:00
|
|
|
|
2010-06-23 16:37:35 +00:00
|
|
|
/* Obsolete rooting APIs. */
|
2010-06-28 21:14:31 +00:00
|
|
|
#define JS_EnterLocalRootScope(cx) (JS_TRUE)
|
2010-06-23 16:37:35 +00:00
|
|
|
#define JS_LeaveLocalRootScope(cx) ((void) 0)
|
|
|
|
#define JS_LeaveLocalRootScopeWithResult(cx, rval) ((void) 0)
|
|
|
|
#define JS_ForgetLocalRoot(cx, thing) ((void) 0)
|
2005-08-17 16:26:14 +00:00
|
|
|
|
2010-05-11 05:01:31 +00:00
|
|
|
typedef enum JSGCRootType {
|
|
|
|
JS_GC_ROOT_VALUE_PTR,
|
|
|
|
JS_GC_ROOT_GCTHING_PTR
|
|
|
|
} JSGCRootType;
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
#ifdef DEBUG
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DumpNamedRoots(JSRuntime *rt,
|
2010-05-11 05:01:31 +00:00
|
|
|
void (*dump)(const char *name, void *rp, JSGCRootType type, void *data),
|
2000-09-08 21:24:14 +00:00
|
|
|
void *data);
|
1998-03-28 02:44:41 +00:00
|
|
|
#endif
|
|
|
|
|
2001-03-21 01:33:39 +00:00
|
|
|
/*
|
|
|
|
* Call JS_MapGCRoots to map the GC's roots table using map(rp, name, data).
|
|
|
|
* The root is pointed at by rp; if the root is unnamed, name is null; data is
|
|
|
|
* supplied from the third parameter to JS_MapGCRoots.
|
|
|
|
*
|
|
|
|
* The map function should return JS_MAP_GCROOT_REMOVE to cause the currently
|
|
|
|
* enumerated root to be removed. To stop enumeration, set JS_MAP_GCROOT_STOP
|
|
|
|
* in the return value. To keep on mapping, return JS_MAP_GCROOT_NEXT. These
|
|
|
|
* constants are flags; you can OR them together.
|
|
|
|
*
|
2010-05-11 05:01:31 +00:00
|
|
|
* The JSGCRootType parameter indicates whether rp is a pointer to a Value
|
|
|
|
* (which is obtained by '(Value *)rp') or a pointer to a GC-thing pointer
|
|
|
|
* (which is obtained by '(void **)rp').
|
|
|
|
*
|
2001-03-21 01:33:39 +00:00
|
|
|
* JS_MapGCRoots returns the count of roots that were successfully mapped.
|
|
|
|
*/
|
|
|
|
#define JS_MAP_GCROOT_NEXT 0 /* continue mapping entries */
|
|
|
|
#define JS_MAP_GCROOT_STOP 1 /* stop mapping entries */
|
|
|
|
#define JS_MAP_GCROOT_REMOVE 2 /* remove and free the current entry */
|
|
|
|
|
2012-02-28 23:11:11 +00:00
|
|
|
typedef int
|
2010-05-11 05:01:31 +00:00
|
|
|
(* JSGCRootMapFun)(void *rp, JSGCRootType type, const char *name, void *data);
|
2001-03-21 01:33:39 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
2001-03-21 01:33:39 +00:00
|
|
|
JS_MapGCRoots(JSRuntime *rt, JSGCRootMapFun map, void *data);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_LockGCThing(JSContext *cx, void *thing);
|
|
|
|
|
2002-05-04 05:28:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_LockGCThingRT(JSRuntime *rt, void *thing);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_UnlockGCThing(JSContext *cx, void *thing);
|
|
|
|
|
2002-05-04 05:28:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_UnlockGCThingRT(JSRuntime *rt, void *thing);
|
|
|
|
|
2007-05-01 10:09:46 +00:00
|
|
|
/*
|
|
|
|
* Register externally maintained GC roots.
|
|
|
|
*
|
|
|
|
* traceOp: the trace operation. For each root the implementation should call
|
|
|
|
* JS_CallTracer whenever the root contains a traceable thing.
|
|
|
|
* data: the data argument to pass to each invocation of traceOp.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2011-10-10 17:25:46 +00:00
|
|
|
JS_SetExtraGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);
|
2007-05-01 10:09:46 +00:00
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
/*
|
|
|
|
* JS_CallTracer API and related macros for implementors of JSTraceOp, to
|
|
|
|
* enumerate all references to traceable things reachable via a property or
|
|
|
|
* other strong ref identified for debugging purposes by name or index or
|
2007-06-10 22:08:17 +00:00
|
|
|
* a naming callback.
|
2000-08-26 02:30:22 +00:00
|
|
|
*
|
2011-09-19 16:34:49 +00:00
|
|
|
* See the JSTraceOp typedef.
|
2007-04-17 06:53:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the following macros to check if a particular jsval is a traceable
|
|
|
|
* thing and to extract the thing and its kind to pass to JS_CallTracer.
|
|
|
|
*/
|
2010-05-11 05:01:31 +00:00
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JSVAL_IS_TRACEABLE(jsval v)
|
|
|
|
{
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_TRACEABLE_IMPL(JSVAL_TO_IMPL(v));
|
2010-05-11 05:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void *
|
|
|
|
JSVAL_TO_TRACEABLE(jsval v)
|
|
|
|
{
|
|
|
|
return JSVAL_TO_GCTHING(v);
|
|
|
|
}
|
|
|
|
|
2011-09-01 18:43:46 +00:00
|
|
|
static JS_ALWAYS_INLINE JSGCTraceKind
|
2010-05-11 05:01:31 +00:00
|
|
|
JSVAL_TRACE_KIND(jsval v)
|
|
|
|
{
|
2010-05-25 18:20:59 +00:00
|
|
|
JS_ASSERT(JSVAL_IS_GCTHING(v));
|
2011-09-19 16:34:49 +00:00
|
|
|
return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(JSVAL_TO_IMPL(v));
|
2010-05-11 05:01:31 +00:00
|
|
|
}
|
2007-04-17 06:53:37 +00:00
|
|
|
|
2011-09-01 18:43:46 +00:00
|
|
|
/*
|
|
|
|
* Tracer callback, called for each traceable thing directly referenced by a
|
|
|
|
* particular object or runtime structure. It is the callback responsibility
|
|
|
|
* to ensure the traversal of the full object graph via calling eventually
|
|
|
|
* JS_TraceChildren on the passed thing. In this case the callback must be
|
|
|
|
* prepared to deal with cycles in the traversal graph.
|
|
|
|
*
|
|
|
|
* kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting
|
|
|
|
* internal implementation-specific traversal kind. In the latter case the only
|
|
|
|
* operations on thing that the callback can do is to call JS_TraceChildren or
|
2012-06-14 15:52:54 +00:00
|
|
|
* JS_GetTraceThingInfo.
|
2011-09-04 18:25:49 +00:00
|
|
|
*
|
|
|
|
* If eagerlyTraceWeakMaps is true, when we trace a WeakMap visit all
|
|
|
|
* of its mappings. This should be used in cases where the tracer
|
|
|
|
* wants to use the existing liveness of entries.
|
2011-09-01 18:43:46 +00:00
|
|
|
*/
|
|
|
|
typedef void
|
2012-02-16 00:28:41 +00:00
|
|
|
(* JSTraceCallback)(JSTracer *trc, void **thingp, JSGCTraceKind kind);
|
2011-09-01 18:43:46 +00:00
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
struct JSTracer {
|
2011-10-25 23:07:42 +00:00
|
|
|
JSRuntime *runtime;
|
2007-04-17 06:53:37 +00:00
|
|
|
JSTraceCallback callback;
|
|
|
|
JSTraceNamePrinter debugPrinter;
|
|
|
|
const void *debugPrintArg;
|
|
|
|
size_t debugPrintIndex;
|
2011-09-04 18:25:49 +00:00
|
|
|
JSBool eagerlyTraceWeakMaps;
|
2012-06-21 01:48:56 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
2012-04-05 23:10:53 +00:00
|
|
|
void *realLocation;
|
|
|
|
#endif
|
2007-04-17 06:53:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2007-06-10 22:08:17 +00:00
|
|
|
* The method to call on each reference to a traceable thing stored in a
|
2007-04-17 06:53:37 +00:00
|
|
|
* particular JSObject or other runtime structure. With DEBUG defined the
|
|
|
|
* caller before calling JS_CallTracer must initialize JSTracer fields
|
2007-04-17 21:14:18 +00:00
|
|
|
* describing the reference using the macros below.
|
2000-08-26 02:30:22 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2011-09-01 18:43:46 +00:00
|
|
|
JS_CallTracer(JSTracer *trc, void *thing, JSGCTraceKind kind);
|
2007-04-17 06:53:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set debugging information about a reference to a traceable thing to prepare
|
|
|
|
* for the following call to JS_CallTracer.
|
|
|
|
*
|
|
|
|
* When printer is null, arg must be const char * or char * C string naming
|
|
|
|
* the reference and index must be either (size_t)-1 indicating that the name
|
|
|
|
* alone describes the reference or it must be an index into some array vector
|
|
|
|
* that stores the reference.
|
|
|
|
*
|
|
|
|
* When printer callback is not null, the arg and index arguments are
|
Bug 672736: Implement the 'findReferences' shell function. r=jorendorff
findReferences(thing)
Walk the entire heap, looking for references to |thing|, and return a
"references object" describing what we found.
Each property of the references object describes one kind of reference. The
property's name is the label supplied to MarkObject, JS_CALL_TRACER, or what
have you, prefixed with "edge: " to avoid collisions with system properties
(like "toString" and "__proto__"). The property's value is an array of things
that refer to |thing| via that kind of reference. Ordinary references from
one object to another are named after the property name (with the "edge: "
prefix).
Garbage collection roots appear as references from 'null'. We use the name
given to the root (with the "edge: " prefix) as the name of the reference.
Note that the references object does record references from objects that are
only reachable via |thing| itself, not just the references reachable
themselves from roots that keep |thing| from being collected. (We could make
this distinction if it is useful.)
If any references are found by the conservative scanner, the references
object will have a property named "edge: machine stack"; the referrers will
be 'null', because they are roots.
js> var o = { x: { y: { z: {} } }}
js> findReferences(o.x.y.z)
({'edge: z':[{z:{}}], 'edge: machine stack':[null, null, null, null, null]})
js> o = { get x() { return 42 } }
({get x () {return 42;}})
js> findReferences(Object.getOwnPropertyDescriptor(o, 'x').get)
({'edge: shape; x getter':[{get x () {return 42;}}],
'edge: constructor':[{}],
'edge: machine stack':[null, null, null, null, null],
'edge: get':[{configurable:true,
enumerable:true,
get:#1=(function () {return 42;}),
set:(void 0)}]})
js> findReferences(Math.atan2)
({'edge: atan2':[Math], 'edge: machine stack':[null, null, null, null, null]})
js> findReferences(o)
({'edge: o':[{o:{get x () {return 42;}}}], 'edge: machine stack':[null, null, null, null, null]})
js>
2011-08-04 03:19:38 +00:00
|
|
|
* available to the callback as debugPrintArg and debugPrintIndex fields
|
2007-04-17 06:53:37 +00:00
|
|
|
* of JSTracer.
|
|
|
|
*
|
|
|
|
* The storage for name or callback's arguments needs to live only until
|
|
|
|
* the following call to JS_CallTracer returns.
|
|
|
|
*/
|
|
|
|
# define JS_SET_TRACING_DETAILS(trc, printer, arg, index) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
(trc)->debugPrinter = (printer); \
|
|
|
|
(trc)->debugPrintArg = (arg); \
|
|
|
|
(trc)->debugPrintIndex = (index); \
|
|
|
|
JS_END_MACRO
|
2000-08-26 02:30:22 +00:00
|
|
|
|
2012-04-05 23:10:53 +00:00
|
|
|
/*
|
|
|
|
* Sets the real location for a marked reference, when passing the address
|
|
|
|
* directly is not feasable.
|
2012-06-21 01:48:56 +00:00
|
|
|
*
|
|
|
|
* FIXME: This is currently overcomplicated by our need to nest calls for Values
|
|
|
|
* stored as keys in hash tables, but will get simplified once we can rekey
|
|
|
|
* in-place.
|
2012-04-05 23:10:53 +00:00
|
|
|
*/
|
2012-06-21 01:48:56 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
2012-04-05 23:10:53 +00:00
|
|
|
# define JS_SET_TRACING_LOCATION(trc, location) \
|
|
|
|
JS_BEGIN_MACRO \
|
2012-07-30 20:58:18 +00:00
|
|
|
if (!(trc)->realLocation || !(location)) \
|
2012-06-21 01:48:56 +00:00
|
|
|
(trc)->realLocation = (location); \
|
2012-04-05 23:10:53 +00:00
|
|
|
JS_END_MACRO
|
|
|
|
#else
|
|
|
|
# define JS_SET_TRACING_LOCATION(trc, location) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
JS_END_MACRO
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
/*
|
|
|
|
* Convenience macro to describe the argument of JS_CallTracer using C string
|
|
|
|
* and index.
|
|
|
|
*/
|
|
|
|
# define JS_SET_TRACING_INDEX(trc, name, index) \
|
|
|
|
JS_SET_TRACING_DETAILS(trc, NULL, name, index)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macro to describe the argument of JS_CallTracer using C string.
|
|
|
|
*/
|
|
|
|
# define JS_SET_TRACING_NAME(trc, name) \
|
|
|
|
JS_SET_TRACING_DETAILS(trc, NULL, name, (size_t)-1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macro to invoke JS_CallTracer using C string as the name for
|
|
|
|
* the reference to a traceable thing.
|
|
|
|
*/
|
|
|
|
# define JS_CALL_TRACER(trc, thing, kind, name) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
JS_SET_TRACING_NAME(trc, name); \
|
|
|
|
JS_CallTracer((trc), (thing), (kind)); \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convenience macros to invoke JS_CallTracer when jsval represents a
|
|
|
|
* reference to a traceable thing.
|
|
|
|
*/
|
|
|
|
#define JS_CALL_VALUE_TRACER(trc, val, name) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
if (JSVAL_IS_TRACEABLE(val)) { \
|
|
|
|
JS_CALL_TRACER((trc), JSVAL_TO_GCTHING(val), \
|
|
|
|
JSVAL_TRACE_KIND(val), name); \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define JS_CALL_OBJECT_TRACER(trc, object, name) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
JSObject *obj_ = (object); \
|
2007-05-04 18:34:56 +00:00
|
|
|
JS_ASSERT(obj_); \
|
2007-04-17 06:53:37 +00:00
|
|
|
JS_CALL_TRACER((trc), obj_, JSTRACE_OBJECT, name); \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
#define JS_CALL_STRING_TRACER(trc, string, name) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
JSString *str_ = (string); \
|
2007-05-04 18:34:56 +00:00
|
|
|
JS_ASSERT(str_); \
|
2007-04-17 06:53:37 +00:00
|
|
|
JS_CALL_TRACER((trc), str_, JSTRACE_STRING, name); \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
|
|
|
/*
|
|
|
|
* API for JSTraceCallback implementations.
|
|
|
|
*/
|
2012-01-15 08:13:10 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-02-29 20:23:38 +00:00
|
|
|
JS_TracerInit(JSTracer *trc, JSRuntime *rt, JSTraceCallback callback);
|
2007-04-17 06:53:37 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2011-09-01 18:43:46 +00:00
|
|
|
JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind);
|
2007-04-17 06:53:37 +00:00
|
|
|
|
2007-04-25 13:43:18 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_TraceRuntime(JSTracer *trc);
|
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-06-14 15:52:54 +00:00
|
|
|
JS_GetTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
|
|
|
|
void *thing, JSGCTraceKind kind, JSBool includeDetails);
|
2007-04-29 21:49:00 +00:00
|
|
|
|
2011-10-20 16:25:31 +00:00
|
|
|
extern JS_PUBLIC_API(const char *)
|
|
|
|
JS_GetTraceEdgeName(JSTracer *trc, char *buffer, int bufferSize);
|
|
|
|
|
2012-06-14 15:52:54 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
2007-04-25 13:43:18 +00:00
|
|
|
/*
|
2007-04-29 21:49:00 +00:00
|
|
|
* DEBUG-only method to dump the object graph of heap-allocated things.
|
2007-04-25 13:43:18 +00:00
|
|
|
*
|
2007-04-29 21:49:00 +00:00
|
|
|
* fp: file for the dump output.
|
|
|
|
* start: when non-null, dump only things reachable from start
|
|
|
|
* thing. Otherwise dump all things reachable from the
|
|
|
|
* runtime roots.
|
2011-09-01 18:43:46 +00:00
|
|
|
* startKind: trace kind of start if start is not null. Must be
|
|
|
|
* JSTRACE_OBJECT when start is null.
|
2007-04-29 21:49:00 +00:00
|
|
|
* thingToFind: dump only paths in the object graph leading to thingToFind
|
|
|
|
* when non-null.
|
|
|
|
* maxDepth: the upper bound on the number of edges to descend from the
|
|
|
|
* graph roots.
|
|
|
|
* thingToIgnore: thing to ignore during the graph traversal when non-null.
|
2007-04-25 13:43:18 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-29 20:23:38 +00:00
|
|
|
JS_DumpHeap(JSRuntime *rt, FILE *fp, void* startThing, JSGCTraceKind kind,
|
2007-04-29 21:49:00 +00:00
|
|
|
void *thingToFind, size_t maxDepth, void *thingToIgnore);
|
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Garbage collector API.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-03-28 10:13:30 +00:00
|
|
|
JS_GC(JSRuntime *rt);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_MaybeGC(JSContext *cx);
|
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetGCCallback(JSRuntime *rt, JSGCCallback cb);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetFinalizeCallback(JSRuntime *rt, JSFinalizeCallback cb);
|
2000-05-14 23:00:51 +00:00
|
|
|
|
2007-04-17 06:53:37 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsGCMarkingTracer(JSTracer *trc);
|
|
|
|
|
2001-02-02 08:44:24 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-08 00:51:32 +00:00
|
|
|
JS_IsAboutToBeFinalized(void *thing);
|
2001-02-02 08:44:24 +00:00
|
|
|
|
2006-02-22 05:52:13 +00:00
|
|
|
typedef enum JSGCParamKey {
|
2008-01-30 02:11:30 +00:00
|
|
|
/* Maximum nominal heap before last ditch GC. */
|
|
|
|
JSGC_MAX_BYTES = 0,
|
|
|
|
|
2009-08-25 21:42:42 +00:00
|
|
|
/* Number of JS_malloc bytes before last ditch GC. */
|
|
|
|
JSGC_MAX_MALLOC_BYTES = 1,
|
|
|
|
|
2009-01-27 17:21:51 +00:00
|
|
|
/* Amount of bytes allocated by the GC. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_BYTES = 3,
|
2009-01-27 17:21:51 +00:00
|
|
|
|
|
|
|
/* Number of times when GC was invoked. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_NUMBER = 4,
|
2009-04-22 23:52:59 +00:00
|
|
|
|
|
|
|
/* Max size of the code cache in bytes. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_MAX_CODE_CACHE_BYTES = 5,
|
2011-01-10 06:57:21 +00:00
|
|
|
|
|
|
|
/* Select GC mode. */
|
2011-05-11 05:37:11 +00:00
|
|
|
JSGC_MODE = 6,
|
2011-02-20 06:59:49 +00:00
|
|
|
|
2011-09-23 14:14:26 +00:00
|
|
|
/* Number of cached empty GC chunks. */
|
2011-07-29 22:17:41 +00:00
|
|
|
JSGC_UNUSED_CHUNKS = 7,
|
|
|
|
|
|
|
|
/* Total number of allocated GC chunks. */
|
2012-02-17 22:35:20 +00:00
|
|
|
JSGC_TOTAL_CHUNKS = 8,
|
|
|
|
|
|
|
|
/* Max milliseconds to spend in an incremental GC slice. */
|
2012-02-24 18:42:42 +00:00
|
|
|
JSGC_SLICE_TIME_BUDGET = 9,
|
|
|
|
|
|
|
|
/* Maximum size the GC mark stack can grow to. */
|
2012-07-11 18:09:53 +00:00
|
|
|
JSGC_MARK_STACK_LIMIT = 10,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GCs less than this far apart in time will be considered 'high-frequency GCs'.
|
|
|
|
* See setGCLastBytes in jsgc.cpp.
|
|
|
|
*/
|
|
|
|
JSGC_HIGH_FREQUENCY_TIME_LIMIT = 11,
|
|
|
|
|
|
|
|
/* Start of dynamic heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_LOW_LIMIT = 12,
|
|
|
|
|
|
|
|
/* End of dynamic heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_HIGH_LIMIT = 13,
|
|
|
|
|
|
|
|
/* Upper bound of heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX = 14,
|
|
|
|
|
|
|
|
/* Lower bound of heap growth. */
|
|
|
|
JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MIN = 15,
|
|
|
|
|
|
|
|
/* Heap growth for low frequency GCs. */
|
|
|
|
JSGC_LOW_FREQUENCY_HEAP_GROWTH = 16,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If false, the heap growth factor is fixed at 3. If true, it is determined
|
|
|
|
* based on whether GCs are high- or low- frequency.
|
|
|
|
*/
|
|
|
|
JSGC_DYNAMIC_HEAP_GROWTH = 17,
|
|
|
|
|
|
|
|
/* If true, high-frequency GCs will use a longer mark slice. */
|
|
|
|
JSGC_DYNAMIC_MARK_SLICE = 18
|
2006-02-22 05:52:13 +00:00
|
|
|
} JSGCParamKey;
|
|
|
|
|
2011-01-10 06:57:21 +00:00
|
|
|
typedef enum JSGCMode {
|
|
|
|
/* Perform only global GCs. */
|
|
|
|
JSGC_MODE_GLOBAL = 0,
|
|
|
|
|
|
|
|
/* Perform per-compartment GCs until too much garbage has accumulated. */
|
2012-02-17 22:35:20 +00:00
|
|
|
JSGC_MODE_COMPARTMENT = 1,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect in short time slices rather than all at once. Implies
|
|
|
|
* JSGC_MODE_COMPARTMENT.
|
|
|
|
*/
|
|
|
|
JSGC_MODE_INCREMENTAL = 2
|
2011-01-10 06:57:21 +00:00
|
|
|
} JSGCMode;
|
|
|
|
|
2006-02-22 05:52:13 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_SetGCParameter(JSRuntime *rt, JSGCParamKey key, uint32_t value);
|
2006-02-22 05:52:13 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
2009-01-27 17:21:51 +00:00
|
|
|
JS_GetGCParameter(JSRuntime *rt, JSGCParamKey key);
|
|
|
|
|
2009-04-22 23:52:59 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_SetGCParameterForThread(JSContext *cx, JSGCParamKey key, uint32_t value);
|
2009-04-22 23:52:59 +00:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint32_t)
|
2009-04-22 23:52:59 +00:00
|
|
|
JS_GetGCParameterForThread(JSContext *cx, JSGCParamKey key);
|
|
|
|
|
2000-09-02 20:37:37 +00:00
|
|
|
/*
|
|
|
|
* Create a new JSString whose chars member refers to external memory, i.e.,
|
2012-02-07 18:44:54 +00:00
|
|
|
* memory requiring application-specific finalization.
|
2011-04-21 01:34:49 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2012-02-07 18:44:54 +00:00
|
|
|
JS_NewExternalString(JSContext *cx, const jschar *chars, size_t length,
|
|
|
|
const JSStringFinalizer *fin);
|
2011-04-21 01:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return whether 'str' was created with JS_NewExternalString or
|
|
|
|
* JS_NewExternalStringWithClosure.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-07 18:44:54 +00:00
|
|
|
JS_IsExternalString(JSString *str);
|
2011-04-21 01:34:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the 'closure' arg passed to JS_NewExternalStringWithClosure or NULL
|
|
|
|
* if the external string was created via JS_NewExternalString.
|
|
|
|
*/
|
2012-02-07 18:44:54 +00:00
|
|
|
extern JS_PUBLIC_API(const JSStringFinalizer *)
|
|
|
|
JS_GetExternalStringFinalizer(JSString *str);
|
2000-09-02 20:37:37 +00:00
|
|
|
|
2010-05-19 08:29:05 +00:00
|
|
|
/*
|
|
|
|
* Set the size of the native stack that should not be exceed. To disable
|
|
|
|
* stack size checking pass 0.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
2012-01-31 22:28:22 +00:00
|
|
|
JS_SetNativeStackQuota(JSRuntime *cx, size_t stackSize);
|
2010-05-19 08:29:05 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Classes, objects, and properties.
|
|
|
|
*/
|
2010-06-12 16:29:04 +00:00
|
|
|
typedef void (*JSClassInternal)();
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
struct JSClass {
|
2000-08-19 19:17:32 +00:00
|
|
|
const char *name;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t flags;
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
/* Mandatory non-null function pointer members. */
|
|
|
|
JSPropertyOp addProperty;
|
|
|
|
JSPropertyOp delProperty;
|
|
|
|
JSPropertyOp getProperty;
|
2011-02-09 19:31:40 +00:00
|
|
|
JSStrictPropertyOp setProperty;
|
1998-04-24 00:31:11 +00:00
|
|
|
JSEnumerateOp enumerate;
|
|
|
|
JSResolveOp resolve;
|
|
|
|
JSConvertOp convert;
|
|
|
|
JSFinalizeOp finalize;
|
|
|
|
|
|
|
|
/* Optionally non-null members start here. */
|
|
|
|
JSCheckAccessOp checkAccess;
|
|
|
|
JSNative call;
|
|
|
|
JSHasInstanceOp hasInstance;
|
2012-05-07 19:44:08 +00:00
|
|
|
JSNative construct;
|
2011-03-05 22:50:11 +00:00
|
|
|
JSTraceOp trace;
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-08-12 18:26:48 +00:00
|
|
|
void *reserved[40];
|
2004-11-17 07:43:01 +00:00
|
|
|
};
|
|
|
|
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
#define JSCLASS_HAS_PRIVATE (1<<0) /* objects have private slot */
|
|
|
|
#define JSCLASS_NEW_ENUMERATE (1<<1) /* has JSNewEnumerateOp hook */
|
|
|
|
#define JSCLASS_NEW_RESOLVE (1<<2) /* has JSNewResolveOp hook */
|
|
|
|
#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) /* private is (nsISupports *) */
|
2012-07-12 03:55:19 +00:00
|
|
|
#define JSCLASS_IS_DOMJSCLASS (1<<4) /* objects are DOM */
|
2012-02-17 22:35:20 +00:00
|
|
|
#define JSCLASS_IMPLEMENTS_BARRIERS (1<<5) /* Correctly implements GC read
|
|
|
|
and write barriers */
|
2011-09-30 03:29:13 +00:00
|
|
|
#define JSCLASS_DOCUMENT_OBSERVER (1<<6) /* DOM document observer */
|
2012-03-28 21:50:31 +00:00
|
|
|
#define JSCLASS_USERBIT1 (1<<7) /* Reserved for embeddings. */
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To reserve slots fetched and stored via JS_Get/SetReservedSlot, bitwise-or
|
|
|
|
* JSCLASS_HAS_RESERVED_SLOTS(n) into the initializer for JSClass.flags, where
|
|
|
|
* n is a constant in [1, 255]. Reserved slots are indexed from 0 to n-1.
|
|
|
|
*/
|
|
|
|
#define JSCLASS_RESERVED_SLOTS_SHIFT 8 /* room for 8 flags below */
|
|
|
|
#define JSCLASS_RESERVED_SLOTS_WIDTH 8 /* and 16 above this field */
|
|
|
|
#define JSCLASS_RESERVED_SLOTS_MASK JS_BITMASK(JSCLASS_RESERVED_SLOTS_WIDTH)
|
2004-04-13 01:25:17 +00:00
|
|
|
#define JSCLASS_HAS_RESERVED_SLOTS(n) (((n) & JSCLASS_RESERVED_SLOTS_MASK) \
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
<< JSCLASS_RESERVED_SLOTS_SHIFT)
|
|
|
|
#define JSCLASS_RESERVED_SLOTS(clasp) (((clasp)->flags \
|
2004-04-13 01:25:17 +00:00
|
|
|
>> JSCLASS_RESERVED_SLOTS_SHIFT) \
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
& JSCLASS_RESERVED_SLOTS_MASK)
|
2000-08-26 02:30:22 +00:00
|
|
|
|
2004-11-17 07:43:01 +00:00
|
|
|
#define JSCLASS_HIGH_FLAGS_SHIFT (JSCLASS_RESERVED_SLOTS_SHIFT + \
|
|
|
|
JSCLASS_RESERVED_SLOTS_WIDTH)
|
|
|
|
|
2012-07-03 21:34:56 +00:00
|
|
|
#define JSCLASS_IS_ANONYMOUS (1<<(JSCLASS_HIGH_FLAGS_SHIFT+0))
|
|
|
|
#define JSCLASS_IS_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+1))
|
|
|
|
#define JSCLASS_INTERNAL_FLAG2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+2))
|
|
|
|
#define JSCLASS_INTERNAL_FLAG3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+3))
|
2010-07-07 07:53:50 +00:00
|
|
|
|
2010-10-23 23:24:32 +00:00
|
|
|
/* Indicate whether the proto or ctor should be frozen. */
|
2012-07-03 21:34:56 +00:00
|
|
|
#define JSCLASS_FREEZE_PROTO (1<<(JSCLASS_HIGH_FLAGS_SHIFT+4))
|
|
|
|
#define JSCLASS_FREEZE_CTOR (1<<(JSCLASS_HIGH_FLAGS_SHIFT+5))
|
2010-10-23 23:24:32 +00:00
|
|
|
|
2012-07-03 21:34:56 +00:00
|
|
|
#define JSCLASS_XPCONNECT_GLOBAL (1<<(JSCLASS_HIGH_FLAGS_SHIFT+6))
|
2011-05-24 10:45:39 +00:00
|
|
|
|
2012-03-28 21:50:31 +00:00
|
|
|
/* Reserved for embeddings. */
|
2012-07-03 21:34:56 +00:00
|
|
|
#define JSCLASS_USERBIT2 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+7))
|
|
|
|
#define JSCLASS_USERBIT3 (1<<(JSCLASS_HIGH_FLAGS_SHIFT+8))
|
2012-03-28 21:50:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bits 26 through 31 are reserved for the CACHED_PROTO_KEY mechanism, see
|
|
|
|
* below.
|
|
|
|
*/
|
|
|
|
|
2011-02-14 04:55:33 +00:00
|
|
|
/* Global flags. */
|
|
|
|
#define JSGLOBAL_FLAGS_CLEARED 0x1
|
2010-08-03 06:52:12 +00:00
|
|
|
|
2006-05-20 22:27:28 +00:00
|
|
|
/*
|
|
|
|
* ECMA-262 requires that most constructors used internally create objects
|
|
|
|
* with "the original Foo.prototype value" as their [[Prototype]] (__proto__)
|
|
|
|
* member initial value. The "original ... value" verbiage is there because
|
|
|
|
* in ECMA-262, global properties naming class objects are read/write and
|
|
|
|
* deleteable, for the most part.
|
|
|
|
*
|
|
|
|
* Implementing this efficiently requires that global objects have classes
|
2010-05-22 21:46:18 +00:00
|
|
|
* with the following flags. Failure to use JSCLASS_GLOBAL_FLAGS was
|
|
|
|
* prevously allowed, but is now an ES5 violation and thus unsupported.
|
2006-05-20 22:27:28 +00:00
|
|
|
*/
|
2012-07-09 22:11:39 +00:00
|
|
|
#define JSCLASS_GLOBAL_SLOT_COUNT (JSProto_LIMIT * 3 + 24)
|
2011-05-24 10:45:39 +00:00
|
|
|
#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \
|
|
|
|
(JSCLASS_IS_GLOBAL | JSCLASS_HAS_RESERVED_SLOTS(JSCLASS_GLOBAL_SLOT_COUNT + (n)))
|
2010-08-03 06:52:12 +00:00
|
|
|
#define JSCLASS_GLOBAL_FLAGS \
|
2011-05-24 10:45:39 +00:00
|
|
|
JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(0)
|
|
|
|
#define JSCLASS_HAS_GLOBAL_FLAG_AND_SLOTS(clasp) \
|
|
|
|
(((clasp)->flags & JSCLASS_IS_GLOBAL) \
|
|
|
|
&& JSCLASS_RESERVED_SLOTS(clasp) >= JSCLASS_GLOBAL_SLOT_COUNT)
|
2006-04-19 00:22:43 +00:00
|
|
|
|
|
|
|
/* Fast access to the original value of each standard class's prototype. */
|
2012-03-28 21:50:31 +00:00
|
|
|
#define JSCLASS_CACHED_PROTO_SHIFT (JSCLASS_HIGH_FLAGS_SHIFT + 10)
|
|
|
|
#define JSCLASS_CACHED_PROTO_WIDTH 6
|
2006-04-19 00:22:43 +00:00
|
|
|
#define JSCLASS_CACHED_PROTO_MASK JS_BITMASK(JSCLASS_CACHED_PROTO_WIDTH)
|
2012-03-26 02:14:27 +00:00
|
|
|
#define JSCLASS_HAS_CACHED_PROTO(key) (uint32_t(key) << JSCLASS_CACHED_PROTO_SHIFT)
|
2007-07-05 20:37:47 +00:00
|
|
|
#define JSCLASS_CACHED_PROTO_KEY(clasp) ((JSProtoKey) \
|
|
|
|
(((clasp)->flags \
|
|
|
|
>> JSCLASS_CACHED_PROTO_SHIFT) \
|
|
|
|
& JSCLASS_CACHED_PROTO_MASK))
|
2004-11-17 07:43:01 +00:00
|
|
|
|
2000-08-26 02:30:22 +00:00
|
|
|
/* Initializer for unused members of statically initialized JSClass structs. */
|
2012-02-13 08:02:21 +00:00
|
|
|
#define JSCLASS_NO_INTERNAL_MEMBERS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
|
|
|
|
#define JSCLASS_NO_OPTIONAL_MEMBERS 0,0,0,0,0,JSCLASS_NO_INTERNAL_MEMBERS
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-03-02 02:54:01 +00:00
|
|
|
extern JS_PUBLIC_API(int)
|
2011-10-25 23:07:42 +00:00
|
|
|
JS_IdArrayLength(JSContext *cx, JSIdArray *ida);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(jsid)
|
2012-03-02 02:54:01 +00:00
|
|
|
JS_IdArrayGet(JSContext *cx, JSIdArray *ida, int index);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DestroyIdArray(JSContext *cx, JSIdArray *ida);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-01-11 08:23:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class AutoIdArray : private AutoGCRooter {
|
|
|
|
public:
|
|
|
|
AutoIdArray(JSContext *cx, JSIdArray *ida JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-02-29 12:18:16 +00:00
|
|
|
: AutoGCRooter(cx, IDARRAY), context(cx), idArray(ida)
|
2012-01-11 08:23:09 +00:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
~AutoIdArray() {
|
|
|
|
if (idArray)
|
|
|
|
JS_DestroyIdArray(context, idArray);
|
|
|
|
}
|
|
|
|
bool operator!() {
|
|
|
|
return !idArray;
|
|
|
|
}
|
|
|
|
jsid operator[](size_t i) const {
|
|
|
|
JS_ASSERT(idArray);
|
|
|
|
JS_ASSERT(i < length());
|
|
|
|
return JS_IdArrayGet(context, idArray, i);
|
|
|
|
}
|
|
|
|
size_t length() const {
|
|
|
|
return JS_IdArrayLength(context, idArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
JSIdArray *steal() {
|
|
|
|
JSIdArray *copy = idArray;
|
|
|
|
idArray = NULL;
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
inline void trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
2012-02-29 12:18:16 +00:00
|
|
|
JSContext *context;
|
2012-01-11 08:23:09 +00:00
|
|
|
JSIdArray *idArray;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
/* No copy or assignment semantics. */
|
|
|
|
AutoIdArray(AutoIdArray &ida) MOZ_DELETE;
|
|
|
|
void operator=(AutoIdArray &ida) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ValueToId(JSContext *cx, jsval v, jsid *idp);
|
|
|
|
|
2010-06-04 23:55:08 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-04-24 00:31:11 +00:00
|
|
|
JS_IdToValue(JSContext *cx, jsid id, jsval *vp);
|
|
|
|
|
2004-10-05 10:19:07 +00:00
|
|
|
/*
|
|
|
|
* JSNewResolveOp flag bits.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
#define JSRESOLVE_QUALIFIED 0x01 /* resolve a qualified property id */
|
|
|
|
#define JSRESOLVE_ASSIGNING 0x02 /* resolve on the left of assignment */
|
2004-06-16 21:15:35 +00:00
|
|
|
#define JSRESOLVE_DETECTING 0x04 /* 'if (o.p)...' or '(o.p) ?...:...' */
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2011-10-14 23:27:50 +00:00
|
|
|
/*
|
|
|
|
* Invoke the [[DefaultValue]] hook (see ES5 8.6.2) with the provided hint on
|
|
|
|
* the specified object, computing a primitive default value for the object.
|
|
|
|
* The hint must be JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_VOID (no hint). On
|
|
|
|
* success the resulting value is stored in *vp.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
|
|
|
|
|
2010-05-19 16:55:27 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-30 11:19:09 +00:00
|
|
|
JS_PropertyStub(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp);
|
2010-05-19 16:55:27 +00:00
|
|
|
|
2011-02-09 19:31:40 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-30 11:19:09 +00:00
|
|
|
JS_StrictPropertyStub(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict, JSMutableHandleValue vp);
|
2011-02-09 19:31:40 +00:00
|
|
|
|
2010-05-19 16:55:27 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-05-19 22:03:45 +00:00
|
|
|
JS_EnumerateStub(JSContext *cx, JSHandleObject obj);
|
2010-05-19 16:55:27 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-05-19 22:03:45 +00:00
|
|
|
JS_ResolveStub(JSContext *cx, JSHandleObject obj, JSHandleId id);
|
2010-05-19 16:55:27 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-30 11:19:09 +00:00
|
|
|
JS_ConvertStub(JSContext *cx, JSHandleObject obj, JSType type, JSMutableHandleValue vp);
|
2010-05-19 16:55:27 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
struct JSConstDoubleSpec {
|
2012-02-24 22:19:52 +00:00
|
|
|
double dval;
|
1998-03-28 02:44:41 +00:00
|
|
|
const char *name;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint8_t flags;
|
|
|
|
uint8_t spare[3];
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To define an array element rather than a named property member, cast the
|
|
|
|
* element's index to (const char *) and initialize name with it, and set the
|
|
|
|
* JSPROP_INDEX bit in flags.
|
|
|
|
*/
|
|
|
|
struct JSPropertySpec {
|
2011-02-09 19:31:40 +00:00
|
|
|
const char *name;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int8_t tinyid;
|
|
|
|
uint8_t flags;
|
2011-02-09 19:31:40 +00:00
|
|
|
JSPropertyOp getter;
|
|
|
|
JSStrictPropertyOp setter;
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct JSFunctionSpec {
|
|
|
|
const char *name;
|
|
|
|
JSNative call;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint16_t nargs;
|
|
|
|
uint16_t flags;
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
2007-08-02 04:33:52 +00:00
|
|
|
/*
|
|
|
|
* Terminating sentinel initializer to put at the end of a JSFunctionSpec array
|
|
|
|
* that's passed to JS_DefineFunctions or JS_InitClass.
|
|
|
|
*/
|
2010-08-16 19:35:04 +00:00
|
|
|
#define JS_FS_END JS_FS(NULL,NULL,0,0)
|
2007-08-02 04:33:52 +00:00
|
|
|
|
|
|
|
/*
|
2010-08-16 19:35:04 +00:00
|
|
|
* Initializer macros for a JSFunctionSpec array element. JS_FN (whose name
|
|
|
|
* pays homage to the old JSNative/JSFastNative split) simply adds the flag
|
|
|
|
* JSFUN_STUB_GSOPS.
|
2007-08-02 04:33:52 +00:00
|
|
|
*/
|
2010-08-16 19:35:04 +00:00
|
|
|
#define JS_FS(name,call,nargs,flags) \
|
2011-06-11 02:03:57 +00:00
|
|
|
{name, call, nargs, flags}
|
2010-08-16 19:35:04 +00:00
|
|
|
#define JS_FN(name,call,nargs,flags) \
|
2011-06-11 02:03:57 +00:00
|
|
|
{name, call, nargs, (flags) | JSFUN_STUB_GSOPS}
|
2007-08-02 04:33:52 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
2012-02-28 23:11:11 +00:00
|
|
|
JSClass *clasp, JSNative constructor, unsigned nargs,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSPropertySpec *ps, JSFunctionSpec *fs,
|
2011-05-30 20:28:01 +00:00
|
|
|
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-02-01 03:40:49 +00:00
|
|
|
/*
|
|
|
|
* Set up ctor.prototype = proto and proto.constructor = ctor with the
|
|
|
|
* right property flags.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto);
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
extern JS_PUBLIC_API(JSClass *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetClass(JSRawObject obj);
|
1999-11-12 06:03:40 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv);
|
|
|
|
|
2005-05-10 19:53:44 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_HasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetPrivate(JSRawObject obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_SetPrivate(JSRawObject obj, void *data);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetInstancePrivate(JSContext *cx, JSObject *obj, JSClass *clasp,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *argv);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetPrototype(JSRawObject obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_SetPrototype(JSContext *cx, JSObject *obj, JSObject *proto);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetParent(JSRawObject obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetConstructor(JSContext *cx, JSObject *proto);
|
|
|
|
|
2003-12-22 06:10:51 +00:00
|
|
|
/*
|
|
|
|
* Get a unique identifier for obj, good for the lifetime of obj (even if it
|
|
|
|
* is moved by a copying GC). Return false on failure (likely out of memory),
|
|
|
|
* and true with *idp containing the unique id on success.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetObjectId(JSContext *cx, JSRawObject obj, jsid *idp);
|
2003-12-22 06:10:51 +00:00
|
|
|
|
2010-06-23 21:35:10 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-06-20 15:57:29 +00:00
|
|
|
JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals);
|
2010-06-23 21:35:10 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2010-12-19 04:44:51 +00:00
|
|
|
JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-09-21 18:35:30 +00:00
|
|
|
/* Queries the [[Extensible]] property of the object. */
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_IsExtensible(JSRawObject obj);
|
2010-09-21 18:35:30 +00:00
|
|
|
|
2011-04-08 21:21:08 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_IsNative(JSRawObject obj);
|
2011-04-08 21:21:08 +00:00
|
|
|
|
2012-02-29 20:23:38 +00:00
|
|
|
extern JS_PUBLIC_API(JSRuntime *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetObjectRuntime(JSRawObject obj);
|
2012-02-29 20:23:38 +00:00
|
|
|
|
2008-02-14 05:10:42 +00:00
|
|
|
/*
|
|
|
|
* Unlike JS_NewObject, JS_NewObjectWithGivenProto does not compute a default
|
|
|
|
* proto if proto's actual parameter value is null.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewObjectWithGivenProto(JSContext *cx, JSClass *clasp, JSObject *proto,
|
2010-12-19 04:44:51 +00:00
|
|
|
JSObject *parent);
|
2008-02-14 05:10:42 +00:00
|
|
|
|
2010-09-21 18:35:29 +00:00
|
|
|
/*
|
|
|
|
* Freeze obj, and all objects it refers to, recursively. This will not recurse
|
|
|
|
* through non-extensible objects, on the assumption that those are already
|
|
|
|
* deep-frozen.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DeepFreezeObject(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Freezes an object; see ES5's Object.freeze(obj) method.
|
|
|
|
*/
|
2003-03-14 05:24:58 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-09-21 18:35:29 +00:00
|
|
|
JS_FreezeObject(JSContext *cx, JSObject *obj);
|
2003-03-14 05:24:58 +00:00
|
|
|
|
2010-03-17 15:22:13 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_New(JSContext *cx, JSObject *ctor, unsigned argc, jsval *argv);
|
2010-03-17 15:22:13 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
|
2012-02-28 23:11:11 +00:00
|
|
|
JSObject *proto, unsigned attrs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DefineProperties(JSContext *cx, JSObject *obj, JSPropertySpec *ps);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DefineProperty(JSContext *cx, JSObject *obj, const char *name, jsval value,
|
2012-02-28 23:11:11 +00:00
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, jsval value,
|
2012-02-28 23:11:11 +00:00
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
|
2008-10-24 17:09:09 +00:00
|
|
|
|
2010-03-24 19:36:42 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DefineOwnProperty(JSContext *cx, JSObject *obj, jsid id, jsval descriptor, JSBool *bp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/*
|
|
|
|
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
|
|
|
*
|
|
|
|
* If the object does not have a property by that name, *foundp will be
|
|
|
|
* JS_FALSE and the value of *attrsp is undefined.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned *attrsp, JSBool *foundp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2005-04-26 04:11:59 +00:00
|
|
|
/*
|
|
|
|
* The same, but if the property is native, return its getter and setter via
|
|
|
|
* *getterp and *setterp, respectively (and only if the out parameter pointer
|
|
|
|
* is not null).
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
|
|
|
|
const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned *attrsp, JSBool *foundp,
|
2005-04-26 04:11:59 +00:00
|
|
|
JSPropertyOp *getterp,
|
2011-02-09 19:31:40 +00:00
|
|
|
JSStrictPropertyOp *setterp);
|
2005-04-26 04:11:59 +00:00
|
|
|
|
2009-01-23 23:44:01 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyAttrsGetterAndSetterById(JSContext *cx, JSObject *obj,
|
|
|
|
jsid id,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned *attrsp, JSBool *foundp,
|
2009-01-23 23:44:01 +00:00
|
|
|
JSPropertyOp *getterp,
|
2011-02-09 19:31:40 +00:00
|
|
|
JSStrictPropertyOp *setterp);
|
2009-01-23 23:44:01 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/*
|
|
|
|
* Set the attributes of a property on a given object.
|
|
|
|
*
|
|
|
|
* If the object does not have a property by that name, *foundp will be
|
|
|
|
* JS_FALSE and nothing will be altered.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned attrs, JSBool *foundp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DefinePropertyWithTinyId(JSContext *cx, JSObject *obj, const char *name,
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int8_t tinyid, jsval value,
|
2011-02-09 19:31:40 +00:00
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned attrs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2007-11-13 08:28:47 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AlreadyHasOwnProperty(JSContext *cx, JSObject *obj, const char *name,
|
|
|
|
JSBool *foundp);
|
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AlreadyHasOwnPropertyById(JSContext *cx, JSObject *obj, jsid id,
|
|
|
|
JSBool *foundp);
|
|
|
|
|
2004-07-17 02:39:55 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_HasProperty(JSContext *cx, JSObject *obj, const char *name, JSBool *foundp);
|
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_HasPropertyById(JSContext *cx, JSObject *obj, jsid id, JSBool *foundp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_LookupPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
|
|
|
|
|
2004-09-01 20:51:39 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_LookupPropertyWithFlags(JSContext *cx, JSObject *obj, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags, jsval *vp);
|
2004-09-01 20:51:39 +00:00
|
|
|
|
2008-09-25 16:13:31 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2008-10-24 17:09:09 +00:00
|
|
|
JS_LookupPropertyWithFlagsById(JSContext *cx, JSObject *obj, jsid id,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags, JSObject **objp, jsval *vp);
|
2008-09-25 16:13:31 +00:00
|
|
|
|
2009-03-10 22:21:25 +00:00
|
|
|
struct JSPropertyDescriptor {
|
2011-02-09 19:31:40 +00:00
|
|
|
JSObject *obj;
|
2012-04-17 17:45:38 +00:00
|
|
|
unsigned attrs;
|
|
|
|
unsigned shortid;
|
2011-02-09 19:31:40 +00:00
|
|
|
JSPropertyOp getter;
|
|
|
|
JSStrictPropertyOp setter;
|
|
|
|
jsval value;
|
2009-03-10 22:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like JS_GetPropertyAttrsGetterAndSetterById but will return a property on
|
|
|
|
* an object on the prototype chain (returned in objp). If data->obj is null,
|
|
|
|
* then this property was not found on the prototype chain.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_GetPropertyDescriptorById(JSContext *cx, JSObject *obj, jsid id, unsigned flags,
|
2009-03-10 22:21:25 +00:00
|
|
|
JSPropertyDescriptor *desc);
|
|
|
|
|
2010-03-24 19:36:42 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetOwnPropertyDescriptor(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
|
|
|
|
2010-10-19 16:00:51 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyDefault(JSContext *cx, JSObject *obj, const char *name, jsval def, jsval *vp);
|
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
|
|
|
|
|
2010-10-19 16:00:51 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPropertyByIdDefault(JSContext *cx, JSObject *obj, jsid id, jsval def, jsval *vp);
|
|
|
|
|
2011-11-04 16:18:38 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ForwardGetPropertyTo(JSContext *cx, JSObject *obj, jsid id, JSObject *onBehalfOf, jsval *vp);
|
|
|
|
|
2006-04-19 00:22:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetMethodById(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
|
|
|
|
jsval *vp);
|
|
|
|
|
2004-12-29 03:34:26 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetMethod(JSContext *cx, JSObject *obj, const char *name, JSObject **objp,
|
|
|
|
jsval *vp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_SetProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp);
|
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_DeleteProperty(JSContext *cx, JSObject *obj, const char *name);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DeleteProperty2(JSContext *cx, JSObject *obj, const char *name,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *rval);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2008-10-24 17:09:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DeletePropertyById(JSContext *cx, JSObject *obj, jsid id);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DeletePropertyById2(JSContext *cx, JSObject *obj, jsid id, jsval *rval);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DefineUCProperty(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen, jsval value,
|
2011-02-09 19:31:40 +00:00
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned attrs);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
|
|
|
*
|
|
|
|
* If the object does not have a property by that name, *foundp will be
|
|
|
|
* JS_FALSE and the value of *attrsp is undefined.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned *attrsp, JSBool *foundp);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2005-04-26 04:11:59 +00:00
|
|
|
/*
|
|
|
|
* The same, but if the property is native, return its getter and setter via
|
|
|
|
* *getterp and *setterp, respectively (and only if the out parameter pointer
|
|
|
|
* is not null).
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetUCPropertyAttrsGetterAndSetter(JSContext *cx, JSObject *obj,
|
|
|
|
const jschar *name, size_t namelen,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned *attrsp, JSBool *foundp,
|
2005-04-26 04:11:59 +00:00
|
|
|
JSPropertyOp *getterp,
|
2011-02-09 19:31:40 +00:00
|
|
|
JSStrictPropertyOp *setterp);
|
2005-04-26 04:11:59 +00:00
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* Set the attributes of a property on a given object.
|
|
|
|
*
|
|
|
|
* If the object does not have a property by that name, *foundp will be
|
|
|
|
* JS_FALSE and nothing will be altered.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned attrs, JSBool *foundp);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
int8_t tinyid, jsval value,
|
2011-02-09 19:31:40 +00:00
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned attrs);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2007-11-13 08:28:47 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_AlreadyHasOwnUCProperty(JSContext *cx, JSObject *obj, const jschar *name,
|
|
|
|
size_t namelen, JSBool *foundp);
|
|
|
|
|
2004-07-17 02:39:55 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_HasUCProperty(JSContext *cx, JSObject *obj,
|
|
|
|
const jschar *name, size_t namelen,
|
|
|
|
JSBool *vp);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_LookupUCProperty(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
|
|
|
jsval *vp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetUCProperty(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
|
|
|
jsval *vp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_SetUCProperty(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
|
|
|
jsval *vp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DeleteUCProperty2(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *name, size_t namelen,
|
|
|
|
jsval *rval);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-03-02 02:54:01 +00:00
|
|
|
JS_NewArrayObject(JSContext *cx, int length, jsval *vector);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_IsArrayObject(JSContext *cx, JSObject *obj);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-03-06 23:52:55 +00:00
|
|
|
JS_GetArrayLength(JSContext *cx, JSObject *obj, uint32_t *lengthp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-03-06 23:52:55 +00:00
|
|
|
JS_SetArrayLength(JSContext *cx, JSObject *obj, uint32_t length);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_DefineElement(JSContext *cx, JSObject *obj, uint32_t index, jsval value,
|
2012-02-28 23:11:11 +00:00
|
|
|
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_AlreadyHasOwnElement(JSContext *cx, JSObject *obj, uint32_t index, JSBool *foundp);
|
2007-11-13 08:28:47 +00:00
|
|
|
|
2004-07-17 02:39:55 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_HasElement(JSContext *cx, JSObject *obj, uint32_t index, JSBool *foundp);
|
2004-07-17 02:39:55 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_LookupElement(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_GetElement(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-11-04 16:18:38 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ForwardGetElementTo(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
|
|
|
|
jsval *vp);
|
2011-11-04 16:18:38 +00:00
|
|
|
|
2011-11-04 16:19:13 +00:00
|
|
|
/*
|
|
|
|
* Get the property with name given by |index|, if it has one. If
|
|
|
|
* not, |*present| will be set to false and the value of |vp| must not
|
|
|
|
* be relied on.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_GetElementIfPresent(JSContext *cx, JSObject *obj, uint32_t index, JSObject *onBehalfOf,
|
2011-11-04 16:19:13 +00:00
|
|
|
jsval *vp, JSBool* present);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_SetElement(JSContext *cx, JSObject *obj, uint32_t index, jsval *vp);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_DeleteElement(JSContext *cx, JSObject *obj, uint32_t index);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_DeleteElement2(JSContext *cx, JSObject *obj, uint32_t index, jsval *rval);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ClearScope(JSContext *cx, JSObject *obj);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSIdArray *)
|
|
|
|
JS_Enumerate(JSContext *cx, JSObject *obj);
|
|
|
|
|
2005-09-29 23:39:48 +00:00
|
|
|
/*
|
|
|
|
* Create an object to iterate over enumerable properties of obj, in arbitrary
|
|
|
|
* property definition order. NB: This differs from longstanding for..in loop
|
|
|
|
* order, which uses order of property definition in obj.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewPropertyIterator(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true on success with *idp containing the id of the next enumerable
|
2010-06-17 01:21:34 +00:00
|
|
|
* property to visit using iterobj, or JSID_IS_VOID if there is no such property
|
2005-09-29 23:39:48 +00:00
|
|
|
* left to visit. Return false on error.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_NextProperty(JSContext *cx, JSObject *iterobj, jsid *idp);
|
|
|
|
|
2012-02-07 18:57:17 +00:00
|
|
|
/*
|
2012-07-03 21:34:56 +00:00
|
|
|
* A JSNative that creates and returns a new iterator that iterates over the
|
|
|
|
* elements of |this|, up to |this.length|, in index order. This can be used to
|
|
|
|
* make any array-like object iterable. Just give the object an obj.iterator()
|
|
|
|
* method using this JSNative as the implementation.
|
2012-02-07 18:57:17 +00:00
|
|
|
*/
|
2012-07-03 21:34:56 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ArrayIterator(JSContext *cx, unsigned argc, jsval *vp);
|
2012-02-07 18:57:17 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
|
2012-02-28 23:11:11 +00:00
|
|
|
jsval *vp, unsigned *attrsp);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(jsval)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_GetReservedSlot(JSRawObject obj, uint32_t index);
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
|
2012-02-05 20:07:23 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_SetReservedSlot(JSRawObject obj, uint32_t index, jsval v);
|
- Add JS_GetReservedSlot, JS_SetReservedSlot, and JSCLASS_HAS_RESERVED_SLOTS(n)
to the JS API, for per class extra slots beyond JSSLOT_PRIVATE (or starting
there for a class that lacks JSCLASS_HAS_PRIVATE). To avoid penalizing all
instances, these slots are allocated only upon first property-owned slot
allocation, or upon first JS_SetReservedSlot.
This entailed adding getRequiredSlot and setRequiredSlot hooks to the
JSObjectOps struct, and making obj->slots self-describing, a la BSTR. It
also afforded me a chance to clean up obj->slots locking so that non-native
JSObjectOps didn't risk unlocked accesses! Now there are thread-safe hooks
for all uses of obj.
First consumer is the new, DOM-glue-unifying XPConnect, which needs two
slots per wrapped function. Hence the change to js_FunctionClass.flags'
initializer.
- Commented the heck out of JSClass and JSObjectOps function typedefs in
jspubtd.h. I hope embedders see these comments!
- Fix JS_XDRValue's default case to handle int exclusively, there is no other
possible type (and therefore no JSMSG_BAD_JVAL_TYPE error).
- Clean up tabs in select old, tab-ridden files and sections.
- s/\<fh\>/file/g for stdio FILE * canonical variable names.
2001-04-05 01:53:24 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Security protocol.
|
|
|
|
*/
|
2001-07-31 19:05:34 +00:00
|
|
|
struct JSPrincipals {
|
1998-03-28 02:44:41 +00:00
|
|
|
/* Don't call "destroy"; use reference counting macros below. */
|
2012-03-01 19:43:17 +00:00
|
|
|
int refcount;
|
2005-07-08 23:26:36 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* A helper to facilitate principals debugging. */
|
|
|
|
uint32_t debugToken;
|
|
|
|
#endif
|
2003-11-02 01:04:50 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
void setDebugToken(uint32_t token) {
|
|
|
|
# ifdef DEBUG
|
|
|
|
debugToken = token;
|
|
|
|
# endif
|
|
|
|
}
|
2003-11-02 01:04:50 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
/*
|
|
|
|
* This is not defined by the JS engine but should be provided by the
|
|
|
|
* embedding.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(void) dump();
|
2003-11-02 01:04:50 +00:00
|
|
|
#endif
|
2012-03-09 09:48:50 +00:00
|
|
|
};
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_HoldPrincipals(JSPrincipals *principals);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DropPrincipals(JSRuntime *rt, JSPrincipals *principals);
|
2001-07-31 19:05:34 +00:00
|
|
|
|
2008-09-05 23:24:53 +00:00
|
|
|
struct JSSecurityCallbacks {
|
2010-03-08 08:24:50 +00:00
|
|
|
JSCheckAccessOp checkObjectAccess;
|
2012-03-09 09:48:50 +00:00
|
|
|
JSSubsumePrincipalsOp subsumePrincipals;
|
2010-03-08 08:24:50 +00:00
|
|
|
JSObjectPrincipalsFinder findObjectPrincipals;
|
|
|
|
JSCSPEvalChecker contentSecurityPolicyAllows;
|
2008-09-05 23:24:53 +00:00
|
|
|
};
|
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetSecurityCallbacks(JSRuntime *rt, const JSSecurityCallbacks *callbacks);
|
2008-09-05 23:24:53 +00:00
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
extern JS_PUBLIC_API(const JSSecurityCallbacks *)
|
|
|
|
JS_GetSecurityCallbacks(JSRuntime *rt);
|
2003-11-02 01:04:50 +00:00
|
|
|
|
2011-06-30 16:26:56 +00:00
|
|
|
/*
|
|
|
|
* Code running with "trusted" principals will be given a deeper stack
|
|
|
|
* allocation than ordinary scripts. This allows trusted script to run after
|
|
|
|
* untrusted script has exhausted the stack. This function sets the
|
|
|
|
* runtime-wide trusted principal.
|
|
|
|
*
|
|
|
|
* This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since
|
|
|
|
* there is no available JSContext. Instead, the caller must ensure that the
|
|
|
|
* given principals stays valid for as long as 'rt' may point to it. If the
|
|
|
|
* principals would be destroyed before 'rt', JS_SetTrustedPrincipals must be
|
|
|
|
* called again, passing NULL for 'prin'.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetTrustedPrincipals(JSRuntime *rt, JSPrincipals *prin);
|
|
|
|
|
2012-03-09 09:48:50 +00:00
|
|
|
/*
|
|
|
|
* Initialize the callback that is called to destroy JSPrincipals instance
|
|
|
|
* when its reference counter drops to zero. The initialization can be done
|
|
|
|
* only once per JS runtime.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_InitDestroyPrincipalsCallback(JSRuntime *rt, JSDestroyPrincipalsOp destroyPrincipals);
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions and scripts.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewFunction(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
|
2011-05-30 20:28:01 +00:00
|
|
|
JSObject *parent, const char *name);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
/*
|
|
|
|
* Create the function with the name given by the id. JSID_IS_STRING(id) must
|
|
|
|
* be true.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewFunctionById(JSContext *cx, JSNative call, unsigned nargs, unsigned flags,
|
2010-10-28 15:15:53 +00:00
|
|
|
JSObject *parent, jsid id);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetFunctionObject(JSFunction *fun);
|
|
|
|
|
2002-03-12 21:58:27 +00:00
|
|
|
/*
|
|
|
|
* Return the function's identifier as a JSString, or null if fun is unnamed.
|
|
|
|
* The returned string lives as long as fun, so you don't need to root a saved
|
|
|
|
* reference to it if fun is well-connected or rooted, and provided you bound
|
|
|
|
* the use of the saved reference by fun's lifetime.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_GetFunctionId(JSFunction *fun);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return JSFUN_* flags for fun.
|
|
|
|
*/
|
2012-02-28 23:11:11 +00:00
|
|
|
extern JS_PUBLIC_API(unsigned)
|
2002-03-12 21:58:27 +00:00
|
|
|
JS_GetFunctionFlags(JSFunction *fun);
|
|
|
|
|
2006-06-07 20:21:40 +00:00
|
|
|
/*
|
|
|
|
* Return the arity (length) of fun.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
extern JS_PUBLIC_API(uint16_t)
|
2006-06-07 20:21:40 +00:00
|
|
|
JS_GetFunctionArity(JSFunction *fun);
|
|
|
|
|
2002-03-12 21:58:27 +00:00
|
|
|
/*
|
|
|
|
* Infallible predicate to test whether obj is a function object (faster than
|
|
|
|
* comparing obj's class name to "Function", but equivalent unless someone has
|
|
|
|
* overwritten the "Function" identifier with a different constructor and then
|
|
|
|
* created instances using that constructor that might be passed in as obj).
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_ObjectIsFunction(JSContext *cx, JSRawObject obj);
|
2002-03-12 21:58:27 +00:00
|
|
|
|
2011-01-11 22:24:52 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_ObjectIsCallable(JSContext *cx, JSRawObject obj);
|
2002-03-12 21:58:27 +00:00
|
|
|
|
2011-05-23 15:39:25 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_IsNativeFunction(JSRawObject funobj, JSNative call);
|
2011-05-23 15:39:25 +00:00
|
|
|
|
2012-04-05 17:14:52 +00:00
|
|
|
/*
|
|
|
|
* Bind the given callable to use the given object as "this".
|
|
|
|
*
|
|
|
|
* If |callable| is not callable, will throw and return NULL.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject*)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_BindCallable(JSContext *cx, JSObject *callable, JSRawObject newThis);
|
2012-04-05 17:14:52 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2011-05-16 23:15:37 +00:00
|
|
|
JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
2011-05-30 20:28:01 +00:00
|
|
|
JS_DefineFunction(JSContext *cx, JSObject *obj, const char *name, JSNative call,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, unsigned attrs);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2004-05-07 03:21:30 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
|
|
JS_DefineUCFunction(JSContext *cx, JSObject *obj,
|
|
|
|
const jschar *name, size_t namelen, JSNative call,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, unsigned attrs);
|
2004-05-07 03:21:30 +00:00
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
|
|
JS_DefineFunctionById(JSContext *cx, JSObject *obj, jsid id, JSNative call,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, unsigned attrs);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2012-07-03 17:24:36 +00:00
|
|
|
/*
|
|
|
|
* Clone a top-level function into a new scope. This function will dynamically
|
|
|
|
* fail if funobj was lexically nested inside some other function.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_CloneFunctionObject(JSContext *cx, JSObject *funobj, JSRawObject parent);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
2000-02-08 01:38:20 +00:00
|
|
|
/*
|
|
|
|
* Given a buffer, return JS_FALSE if the buffer might become a valid
|
|
|
|
* javascript statement with the addition of more lines. Otherwise return
|
|
|
|
* JS_TRUE. The intent is to support interactive compilation - accumulate
|
|
|
|
* lines in a buffer until JS_BufferIsCompilableUnit is true, then pass it to
|
|
|
|
* the compiler.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2011-04-16 18:11:10 +00:00
|
|
|
JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8,
|
|
|
|
JSObject *obj, const char *bytes, size_t length);
|
2000-02-08 01:38:20 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileScript(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const char *bytes, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileScriptForPrincipals(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSPrincipals *principals,
|
|
|
|
const char *bytes, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2010-11-02 00:33:22 +00:00
|
|
|
JS_CompileScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
|
|
|
const char *bytes, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno,
|
2010-11-02 00:33:22 +00:00
|
|
|
JSVersion version);
|
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileUCScript(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSPrincipals *principals,
|
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2010-09-13 16:38:22 +00:00
|
|
|
JS_CompileUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno,
|
2010-09-13 16:38:22 +00:00
|
|
|
JSVersion version);
|
2012-02-10 12:40:34 +00:00
|
|
|
/*
|
|
|
|
* If originPrincipals is null, then the value of principals is used as origin
|
|
|
|
* principals for the compiled script.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
JS_CompileUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
|
|
|
JSPrincipals *originPrincipals,
|
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno,
|
2012-02-10 12:40:34 +00:00
|
|
|
JSVersion version);
|
2010-09-13 16:38:22 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2011-12-16 19:08:59 +00:00
|
|
|
JS_CompileUTF8File(JSContext *cx, JSObject *obj, const char *filename);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2011-12-16 19:08:59 +00:00
|
|
|
JS_CompileUTF8FileHandle(JSContext *cx, JSObject *obj, const char *filename,
|
|
|
|
FILE *fh);
|
1999-04-27 15:18:57 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2011-12-16 19:08:59 +00:00
|
|
|
JS_CompileUTF8FileHandleForPrincipals(JSContext *cx, JSObject *obj,
|
|
|
|
const char *filename, FILE *fh,
|
|
|
|
JSPrincipals *principals);
|
2000-01-18 22:04:01 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
2011-12-16 19:08:59 +00:00
|
|
|
JS_CompileUTF8FileHandleForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
|
|
|
const char *filename, FILE *fh,
|
|
|
|
JSPrincipals *principals,
|
|
|
|
JSVersion version);
|
2010-11-02 00:33:22 +00:00
|
|
|
|
2011-09-02 06:46:00 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2011-09-22 10:08:55 +00:00
|
|
|
JS_GetGlobalFromScript(JSScript *script);
|
2011-09-02 06:46:00 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, const char **argnames,
|
2000-09-08 21:24:14 +00:00
|
|
|
const char *bytes, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSPrincipals *principals, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, const char **argnames,
|
2000-09-08 21:24:14 +00:00
|
|
|
const char *bytes, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileUCFunction(JSContext *cx, JSObject *obj, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, const char **argnames,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSPrincipals *principals, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, const char **argnames,
|
2000-09-08 21:24:14 +00:00
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-09-13 16:38:22 +00:00
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
|
|
JS_CompileUCFunctionForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals, const char *name,
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned nargs, const char **argnames,
|
2010-09-13 16:38:22 +00:00
|
|
|
const jschar *chars, size_t length,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *filename, unsigned lineno,
|
2010-09-13 16:38:22 +00:00
|
|
|
JSVersion version);
|
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
/* Options for JavaScript compilation. */
|
2012-08-02 21:07:31 +00:00
|
|
|
struct JS_PUBLIC_API(CompileOptions) {
|
2012-07-26 00:23:04 +00:00
|
|
|
JSPrincipals *principals;
|
|
|
|
JSPrincipals *originPrincipals;
|
|
|
|
JSVersion version;
|
|
|
|
bool versionSet;
|
|
|
|
bool utf8;
|
|
|
|
const char *filename;
|
|
|
|
unsigned lineno;
|
|
|
|
bool compileAndGo;
|
|
|
|
bool noScriptRval;
|
2012-07-09 22:11:39 +00:00
|
|
|
bool allowIntrinsicsCalls;
|
2012-07-26 00:23:04 +00:00
|
|
|
|
|
|
|
CompileOptions(JSContext *cx);
|
|
|
|
CompileOptions &setPrincipals(JSPrincipals *p) { principals = p; return *this; }
|
|
|
|
CompileOptions &setOriginPrincipals(JSPrincipals *p) { originPrincipals = p; return *this; }
|
|
|
|
CompileOptions &setVersion(JSVersion v) { version = v; versionSet = true; return *this; }
|
|
|
|
CompileOptions &setUTF8(bool u) { utf8 = u; return *this; }
|
|
|
|
CompileOptions &setFileAndLine(const char *f, unsigned l) {
|
|
|
|
filename = f; lineno = l; return *this;
|
|
|
|
}
|
|
|
|
CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; }
|
|
|
|
CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; }
|
2012-07-09 22:11:39 +00:00
|
|
|
CompileOptions &setAllowIntrinsicsCalls(bool aic) { allowIntrinsicsCalls = aic; return *this; }
|
2012-07-26 00:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
Compile(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const char *bytes, size_t length);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
Compile(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const jschar *chars, size_t length);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
Compile(JSContext *cx, JSHandleObject obj, CompileOptions options, FILE *file);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
Compile(JSContext *cx, JSHandleObject obj, CompileOptions options, const char *filename);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
|
|
CompileFunction(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const char *name, unsigned nargs, const char **argnames,
|
|
|
|
const char *bytes, size_t length);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSFunction *)
|
|
|
|
CompileFunction(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const char *name, unsigned nargs, const char **argnames,
|
|
|
|
const jschar *chars, size_t length);
|
|
|
|
|
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_DecompileScript(JSContext *cx, JSScript *script, const char *name, unsigned indent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1999-09-21 00:13:48 +00:00
|
|
|
/*
|
|
|
|
* API extension: OR this into indent to avoid pretty-printing the decompiled
|
|
|
|
* source resulting from JS_DecompileFunction{,Body}.
|
|
|
|
*/
|
2012-02-28 23:11:11 +00:00
|
|
|
#define JS_DONT_PRETTY_PRINT ((unsigned)0x8000)
|
1999-09-21 00:13:48 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_DecompileFunction(JSContext *cx, JSFunction *fun, unsigned indent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2001-01-20 01:41:55 +00:00
|
|
|
/*
|
2010-03-27 02:37:45 +00:00
|
|
|
* NB: JS_ExecuteScript and the JS_Evaluate*Script* quadruplets use the obj
|
|
|
|
* parameter as the initial scope chain header, the 'this' keyword value, and
|
|
|
|
* the variables object (ECMA parlance for where 'var' and 'function' bind
|
|
|
|
* names) of the execution context for script.
|
2001-01-20 01:41:55 +00:00
|
|
|
*
|
|
|
|
* Using obj as the variables object is problematic if obj's parent (which is
|
|
|
|
* the scope chain link; see JS_SetParent and JS_NewObject) is not null: in
|
|
|
|
* this case, variables created by 'var x = 0', e.g., go in obj, but variables
|
|
|
|
* created by assignment to an unbound id, 'x = 0', go in the last object on
|
|
|
|
* the scope chain linked by parent.
|
|
|
|
*
|
|
|
|
* ECMA calls that last scoping object the "global object", but note that many
|
|
|
|
* embeddings have several such objects. ECMA requires that "global code" be
|
|
|
|
* executed with the variables object equal to this global object. But these
|
|
|
|
* JS API entry points provide freedom to execute code against a "sub-global",
|
|
|
|
* i.e., a parented or scoped object, in which case the variables object will
|
|
|
|
* differ from the last object on the scope chain, resulting in confusing and
|
|
|
|
* non-ECMA explicit vs. implicit variable creation.
|
|
|
|
*
|
|
|
|
* Caveat embedders: unless you already depend on this buggy variables object
|
|
|
|
* binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or
|
|
|
|
* JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if
|
|
|
|
* someone may have set other options on cx already -- for each context in the
|
|
|
|
* application, if you pass parented objects as the obj parameter, or may ever
|
|
|
|
* pass such objects in the future.
|
|
|
|
*
|
|
|
|
* Why a runtime option? The alternative is to add six or so new API entry
|
|
|
|
* points with signatures matching the following six, and that doesn't seem
|
|
|
|
* worth the code bloat cost. Such new entry points would probably have less
|
|
|
|
* obvious names, too, so would not tend to be used. The JS_SetOption call,
|
|
|
|
* OTOH, can be more easily hacked into existing code that does not depend on
|
|
|
|
* the bug; such code can continue to use the familiar JS_EvaluateScript,
|
|
|
|
* etc., entry points.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2011-09-02 06:46:00 +00:00
|
|
|
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-11-02 00:33:22 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2011-09-02 06:46:00 +00:00
|
|
|
JS_ExecuteScriptVersion(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval,
|
2010-11-02 00:33:22 +00:00
|
|
|
JSVersion version);
|
|
|
|
|
2000-02-11 22:21:15 +00:00
|
|
|
/*
|
|
|
|
* Execute either the function-defining prolog of a script, or the script's
|
|
|
|
* main body, but not both.
|
|
|
|
*/
|
|
|
|
typedef enum JSExecPart { JSEXEC_PROLOG, JSEXEC_MAIN } JSExecPart;
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_EvaluateScript(JSContext *cx, JSObject *obj,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *bytes, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_EvaluateScriptForPrincipals(JSContext *cx, JSObject *obj,
|
2000-09-08 21:24:14 +00:00
|
|
|
JSPrincipals *principals,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *bytes, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-11-03 19:09:24 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_EvaluateScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
2012-02-28 23:11:11 +00:00
|
|
|
const char *bytes, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2010-11-03 19:09:24 +00:00
|
|
|
jsval *rval, JSVersion version);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
|
2012-02-28 23:11:11 +00:00
|
|
|
const jschar *chars, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-06-28 00:42:53 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_EvaluateUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
2012-02-28 23:11:11 +00:00
|
|
|
const jschar *chars, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2011-06-28 00:42:53 +00:00
|
|
|
jsval *rval);
|
|
|
|
|
2010-09-13 16:38:22 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_EvaluateUCScriptForPrincipalsVersion(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
2012-02-28 23:11:11 +00:00
|
|
|
const jschar *chars, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2010-09-13 16:38:22 +00:00
|
|
|
jsval *rval, JSVersion version);
|
|
|
|
|
2011-06-28 00:42:53 +00:00
|
|
|
/*
|
|
|
|
* JSAPI clients may optionally specify the 'originPrincipals' of a script.
|
|
|
|
* A script's originPrincipals may be retrieved through the debug API (via
|
|
|
|
* JS_GetScriptOriginPrincipals) and the originPrincipals are transitively
|
|
|
|
* assigned to any nested scripts (including scripts dynamically created via
|
2012-02-10 12:40:34 +00:00
|
|
|
* eval and the Function constructor). If originPrincipals is null, then the
|
|
|
|
* value of principals is used as origin principals for the script.
|
2011-06-28 00:42:53 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2011-06-28 00:42:53 +00:00
|
|
|
JS_EvaluateUCScriptForPrincipalsVersionOrigin(JSContext *cx, JSObject *obj,
|
|
|
|
JSPrincipals *principals,
|
|
|
|
JSPrincipals *originPrincipals,
|
2012-02-28 23:11:11 +00:00
|
|
|
const jschar *chars, unsigned length,
|
|
|
|
const char *filename, unsigned lineno,
|
2011-06-28 00:42:53 +00:00
|
|
|
jsval *rval, JSVersion version);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
Evaluate(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const jschar *chars, size_t length, jsval *rval);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
Evaluate(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const char *bytes, size_t length, jsval *rval);
|
|
|
|
|
2012-07-31 22:25:41 +00:00
|
|
|
extern JS_PUBLIC_API(bool)
|
|
|
|
Evaluate(JSContext *cx, JSHandleObject obj, CompileOptions options,
|
|
|
|
const char *filename, jsval *rval);
|
|
|
|
|
2012-07-26 00:23:04 +00:00
|
|
|
} /* namespace JS */
|
|
|
|
|
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
#endif
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_CallFunction(JSContext *cx, JSObject *obj, JSFunction *fun, unsigned argc,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *argv, jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_CallFunctionName(JSContext *cx, JSObject *obj, const char *name, unsigned argc,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *argv, jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval, unsigned argc,
|
2000-09-08 21:24:14 +00:00
|
|
|
jsval *argv, jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-10-12 18:50:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
static inline bool
|
2012-02-28 23:11:11 +00:00
|
|
|
Call(JSContext *cx, JSObject *thisObj, JSFunction *fun, unsigned argc, jsval *argv, jsval *rval) {
|
2010-10-12 18:50:03 +00:00
|
|
|
return !!JS_CallFunction(cx, thisObj, fun, argc, argv, rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2012-02-28 23:11:11 +00:00
|
|
|
Call(JSContext *cx, JSObject *thisObj, const char *name, unsigned argc, jsval *argv, jsval *rval) {
|
2010-10-12 18:50:03 +00:00
|
|
|
return !!JS_CallFunctionName(cx, thisObj, name, argc, argv, rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2012-02-28 23:11:11 +00:00
|
|
|
Call(JSContext *cx, JSObject *thisObj, jsval fun, unsigned argc, jsval *argv, jsval *rval) {
|
2010-10-12 18:50:03 +00:00
|
|
|
return !!JS_CallFunctionValue(cx, thisObj, fun, argc, argv, rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(bool)
|
2012-02-28 23:11:11 +00:00
|
|
|
Call(JSContext *cx, jsval thisv, jsval fun, unsigned argc, jsval *argv, jsval *rval);
|
2010-10-12 18:50:03 +00:00
|
|
|
|
|
|
|
static inline bool
|
2012-02-28 23:11:11 +00:00
|
|
|
Call(JSContext *cx, jsval thisv, JSObject *funObj, unsigned argc, jsval *argv, jsval *rval) {
|
2010-10-12 18:50:03 +00:00
|
|
|
return Call(cx, thisv, OBJECT_TO_JSVAL(funObj), argc, argv, rval);
|
|
|
|
}
|
|
|
|
|
2011-10-04 14:06:54 +00:00
|
|
|
} /* namespace JS */
|
2010-10-12 18:50:03 +00:00
|
|
|
|
|
|
|
JS_BEGIN_EXTERN_C
|
2010-10-27 02:48:51 +00:00
|
|
|
#endif /* __cplusplus */
|
2010-10-12 18:50:03 +00:00
|
|
|
|
2008-01-03 09:28:40 +00:00
|
|
|
/*
|
2009-02-10 11:45:36 +00:00
|
|
|
* These functions allow setting an operation callback that will be called
|
2012-02-24 11:03:28 +00:00
|
|
|
* from the JS thread some time after any thread triggered the callback using
|
|
|
|
* JS_TriggerOperationCallback(rt).
|
2009-07-28 01:40:12 +00:00
|
|
|
*
|
2012-02-24 11:03:28 +00:00
|
|
|
* To schedule the GC and for other activities the engine internally triggers
|
|
|
|
* operation callbacks. The embedding should thus not rely on callbacks being
|
|
|
|
* triggered through the external API only.
|
2009-07-28 01:40:12 +00:00
|
|
|
*
|
2009-02-10 11:45:36 +00:00
|
|
|
* Important note: Additional callbacks can occur inside the callback handler
|
|
|
|
* if it re-enters the JS engine. The embedding must ensure that the callback
|
|
|
|
* is disconnected before attempting such re-entry.
|
2008-01-03 09:28:40 +00:00
|
|
|
*/
|
2009-02-10 11:45:36 +00:00
|
|
|
extern JS_PUBLIC_API(JSOperationCallback)
|
|
|
|
JS_SetOperationCallback(JSContext *cx, JSOperationCallback callback);
|
2009-01-14 17:23:51 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSOperationCallback)
|
|
|
|
JS_GetOperationCallback(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2012-02-24 11:03:28 +00:00
|
|
|
JS_TriggerOperationCallback(JSRuntime *rt);
|
2009-02-20 12:47:46 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_IsRunning(JSContext *cx);
|
|
|
|
|
2007-04-13 19:20:22 +00:00
|
|
|
/*
|
|
|
|
* Saving and restoring frame chains.
|
|
|
|
*
|
2007-05-04 18:34:56 +00:00
|
|
|
* These two functions are used to set aside cx's call stack while that stack
|
|
|
|
* is inactive. After a call to JS_SaveFrameChain, it looks as if there is no
|
2007-04-13 19:20:22 +00:00
|
|
|
* code running on cx. Before calling JS_RestoreFrameChain, cx's call stack
|
|
|
|
* must be balanced and all nested calls to JS_SaveFrameChain must have had
|
|
|
|
* matching JS_RestoreFrameChain calls.
|
|
|
|
*
|
2011-05-13 15:56:26 +00:00
|
|
|
* JS_SaveFrameChain deals with cx not having any code running on it.
|
2007-04-13 19:20:22 +00:00
|
|
|
*/
|
2011-05-13 15:56:26 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2007-04-13 19:20:22 +00:00
|
|
|
JS_SaveFrameChain(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2011-05-13 15:56:26 +00:00
|
|
|
JS_RestoreFrameChain(JSContext *cx);
|
2007-04-13 19:20:22 +00:00
|
|
|
|
2011-12-01 19:25:37 +00:00
|
|
|
#ifdef MOZ_TRACE_JSCALLS
|
|
|
|
/*
|
|
|
|
* The callback is expected to be quick and noninvasive. It should not
|
|
|
|
* trigger interrupts, turn on debugging, or produce uncaught JS
|
|
|
|
* exceptions. The state of the stack and registers in the context
|
|
|
|
* cannot be relied upon, since this callback may be invoked directly
|
|
|
|
* from either JIT. The 'entering' field means we are entering a
|
|
|
|
* function if it is positive, leaving a function if it is zero or
|
|
|
|
* negative.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetFunctionCallback(JSContext *cx, JSFunctionCallback fcb);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSFunctionCallback)
|
|
|
|
JS_GetFunctionCallback(JSContext *cx);
|
|
|
|
#endif /* MOZ_TRACE_JSCALLS */
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strings.
|
2000-05-14 23:00:51 +00:00
|
|
|
*
|
2010-12-10 11:50:50 +00:00
|
|
|
* NB: JS_NewUCString takes ownership of bytes on success, avoiding a copy;
|
|
|
|
* but on error (signified by null return), it leaves chars owned by the
|
|
|
|
* caller. So the caller must free bytes in the error case, if it has no use
|
|
|
|
* for them. In contrast, all the JS_New*StringCopy* functions do not take
|
|
|
|
* ownership of the character memory passed to them -- they copy it.
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewStringCopyN(JSContext *cx, const char *s, size_t n);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewStringCopyZ(JSContext *cx, const char *s);
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_InternJSString(JSContext *cx, JSString *str);
|
|
|
|
|
2012-07-31 19:26:14 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_InternStringN(JSContext *cx, const char *s, size_t length);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_InternString(JSContext *cx, const char *s);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewUCString(JSContext *cx, jschar *chars, size_t length);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewUCStringCopyN(JSContext *cx, const jschar *s, size_t n);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_NewUCStringCopyZ(JSContext *cx, const jschar *s);
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_InternUCStringN(JSContext *cx, const jschar *s, size_t length);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_InternUCString(JSContext *cx, const jschar *s);
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_CompareStrings(JSContext *cx, JSString *str1, JSString *str2, int32_t *result);
|
2010-12-03 08:24:17 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_StringEqualsAscii(JSContext *cx, JSString *str, const char *asciiBytes, JSBool *match);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(size_t)
|
|
|
|
JS_PutEscapedString(JSContext *cx, char *buffer, size_t size, JSString *str, char quote);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_FileEscapedString(FILE *fp, JSString *str, char quote);
|
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
/*
|
2010-12-03 08:24:17 +00:00
|
|
|
* Extracting string characters and length.
|
|
|
|
*
|
|
|
|
* While getting the length of a string is infallible, getting the chars can
|
|
|
|
* fail. As indicated by the lack of a JSContext parameter, there are two
|
|
|
|
* special cases where getting the chars is infallible:
|
|
|
|
*
|
|
|
|
* The first case is interned strings, i.e., strings from JS_InternString or
|
|
|
|
* JSID_TO_STRING(id), using JS_GetInternedStringChars*.
|
|
|
|
*
|
|
|
|
* The second case is "flat" strings that have been explicitly prepared in a
|
|
|
|
* fallible context by JS_FlattenString. To catch errors, a separate opaque
|
|
|
|
* JSFlatString type is returned by JS_FlattenString and expected by
|
|
|
|
* JS_GetFlatStringChars. Note, though, that this is purely a syntactic
|
|
|
|
* distinction: the input and output of JS_FlattenString are the same actual
|
|
|
|
* GC-thing so only one needs to be rooted. If a JSString is known to be flat,
|
|
|
|
* JS_ASSERT_STRING_IS_FLAT can be used to make a debug-checked cast. Example:
|
|
|
|
*
|
|
|
|
* // in a fallible context
|
|
|
|
* JSFlatString *fstr = JS_FlattenString(cx, str);
|
|
|
|
* if (!fstr)
|
|
|
|
* return JS_FALSE;
|
|
|
|
* JS_ASSERT(fstr == JS_ASSERT_STRING_IS_FLAT(str));
|
|
|
|
*
|
|
|
|
* // in an infallible context, for the same 'str'
|
|
|
|
* const jschar *chars = JS_GetFlatStringChars(fstr)
|
|
|
|
* JS_ASSERT(chars);
|
|
|
|
*
|
|
|
|
* The CharsZ APIs guarantee that the returned array has a null character at
|
|
|
|
* chars[length]. This can require additional copying so clients should prefer
|
|
|
|
* APIs without CharsZ if possible. The infallible functions also return
|
|
|
|
* null-terminated arrays. (There is no additional cost or non-Z alternative
|
|
|
|
* for the infallible functions, so 'Z' is left out of the identifier.)
|
2010-10-28 15:15:53 +00:00
|
|
|
*/
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(size_t)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_GetStringLength(JSString *str);
|
|
|
|
|
2010-10-28 15:15:53 +00:00
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_GetStringCharsAndLength(JSContext *cx, JSString *str, size_t *length);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
|
|
|
JS_GetInternedStringChars(JSString *str);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
|
|
|
JS_GetInternedStringCharsAndLength(JSString *str, size_t *length);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2009-10-02 17:42:02 +00:00
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
|
|
|
JS_GetStringCharsZ(JSContext *cx, JSString *str);
|
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
|
|
|
JS_GetStringCharsZAndLength(JSContext *cx, JSString *str, size_t *length);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(JSFlatString *)
|
|
|
|
JS_FlattenString(JSContext *cx, JSString *str);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2010-12-03 08:24:17 +00:00
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
|
|
|
JS_GetFlatStringChars(JSFlatString *str);
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSFlatString *
|
|
|
|
JSID_TO_FLAT_STRING(jsid id)
|
|
|
|
{
|
|
|
|
JS_ASSERT(JSID_IS_STRING(id));
|
|
|
|
return (JSFlatString *)(JSID_BITS(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSFlatString *
|
|
|
|
JS_ASSERT_STRING_IS_FLAT(JSString *str)
|
|
|
|
{
|
|
|
|
JS_ASSERT(JS_GetFlatStringChars((JSFlatString *)str));
|
|
|
|
return (JSFlatString *)str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE JSString *
|
|
|
|
JS_FORGET_STRING_FLATNESS(JSFlatString *fstr)
|
|
|
|
{
|
|
|
|
return (JSString *)fstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Additional APIs that avoid fallibility when given a flat string.
|
|
|
|
*/
|
2010-10-28 15:15:53 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-12-03 08:24:17 +00:00
|
|
|
JS_FlatStringEqualsAscii(JSFlatString *str, const char *asciiBytes);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(size_t)
|
|
|
|
JS_PutEscapedFlatString(char *buffer, size_t size, JSFlatString *str, char quote);
|
2010-10-28 15:15:53 +00:00
|
|
|
|
2010-07-17 00:41:22 +00:00
|
|
|
/*
|
|
|
|
* This function is now obsolete and behaves the same as JS_NewUCString. Use
|
|
|
|
* JS_NewUCString instead.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_NewGrowableString(JSContext *cx, jschar *chars, size_t length);
|
|
|
|
|
2001-10-25 00:26:38 +00:00
|
|
|
/*
|
|
|
|
* Mutable string support. A string's characters are never mutable in this JS
|
2010-07-17 00:41:22 +00:00
|
|
|
* implementation, but a dependent string is a substring of another dependent
|
|
|
|
* or immutable string, and a rope is a lazily concatenated string that creates
|
|
|
|
* its underlying buffer the first time it is accessed. Even after a rope
|
|
|
|
* creates its underlying buffer, it still considered mutable. The direct data
|
|
|
|
* members of the (opaque to API clients) JSString struct may be changed in a
|
|
|
|
* single-threaded way for dependent strings and ropes.
|
|
|
|
*
|
|
|
|
* Therefore mutable strings (ropes and dependent strings) cannot be used by
|
|
|
|
* more than one thread at a time. You may call JS_MakeStringImmutable to
|
|
|
|
* convert the string from a mutable string to an immutable (and therefore
|
|
|
|
* thread-safe) string. The engine takes care of converting ropes and dependent
|
|
|
|
* strings to immutable for you if you store strings in multi-threaded objects
|
|
|
|
* using JS_SetProperty or kindred API entry points.
|
2001-10-25 00:26:38 +00:00
|
|
|
*
|
|
|
|
* If you store a JSString pointer in a native data structure that is (safely)
|
|
|
|
* accessible to multiple threads, you must call JS_MakeStringImmutable before
|
|
|
|
* retiring the store.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a dependent string, i.e., a string that owns no character storage,
|
|
|
|
* but that refers to a slice of another string's chars. Dependent strings
|
|
|
|
* are mutable by definition, so the thread safety comments above apply.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_NewDependentString(JSContext *cx, JSString *str, size_t start,
|
|
|
|
size_t length);
|
|
|
|
|
|
|
|
/*
|
2010-07-17 00:41:22 +00:00
|
|
|
* Concatenate two strings, possibly resulting in a rope.
|
|
|
|
* See above for thread safety comments.
|
2001-10-25 00:26:38 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_ConcatStrings(JSContext *cx, JSString *left, JSString *right);
|
|
|
|
|
|
|
|
/*
|
2003-02-26 01:29:55 +00:00
|
|
|
* Convert a dependent string into an independent one. This function does not
|
2001-10-25 00:26:38 +00:00
|
|
|
* change the string's mutability, so the thread safety comments above apply.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(const jschar *)
|
|
|
|
JS_UndependString(JSContext *cx, JSString *str);
|
|
|
|
|
|
|
|
/*
|
2010-07-17 00:41:22 +00:00
|
|
|
* Convert a mutable string (either rope or dependent) into an immutable,
|
2001-10-25 00:26:38 +00:00
|
|
|
* thread-safe one.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_MakeStringImmutable(JSContext *cx, JSString *str);
|
|
|
|
|
2005-11-05 01:06:30 +00:00
|
|
|
/*
|
2005-12-03 02:31:21 +00:00
|
|
|
* Return JS_TRUE if C (char []) strings passed via the API and internally
|
2007-12-11 10:09:58 +00:00
|
|
|
* are UTF-8.
|
2005-11-05 01:06:30 +00:00
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2007-11-07 09:17:35 +00:00
|
|
|
JS_CStringsAreUTF8(void);
|
2005-12-03 02:31:21 +00:00
|
|
|
|
2007-12-11 10:09:58 +00:00
|
|
|
/*
|
2008-01-03 09:28:40 +00:00
|
|
|
* Update the value to be returned by JS_CStringsAreUTF8(). Once set, it
|
|
|
|
* can never be changed. This API must be called before the first call to
|
2007-12-11 10:09:58 +00:00
|
|
|
* JS_NewRuntime.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(void)
|
2008-01-03 09:28:40 +00:00
|
|
|
JS_SetCStringsAreUTF8(void);
|
2007-12-11 10:09:58 +00:00
|
|
|
|
2005-12-03 02:31:21 +00:00
|
|
|
/*
|
|
|
|
* Character encoding support.
|
|
|
|
*
|
|
|
|
* For both JS_EncodeCharacters and JS_DecodeBytes, set *dstlenp to the size
|
|
|
|
* of the destination buffer before the call; on return, *dstlenp contains the
|
|
|
|
* number of bytes (JS_EncodeCharacters) or jschars (JS_DecodeBytes) actually
|
|
|
|
* stored. To determine the necessary destination buffer size, make a sizing
|
|
|
|
* call that passes NULL for dst.
|
|
|
|
*
|
|
|
|
* On errors, the functions report the error. In that case, *dstlenp contains
|
|
|
|
* the number of characters or bytes transferred so far. If cx is NULL, no
|
|
|
|
* error is reported on failure, and the functions simply return JS_FALSE.
|
|
|
|
*
|
|
|
|
* NB: Neither function stores an additional zero byte or jschar after the
|
|
|
|
* transcoded string.
|
|
|
|
*
|
2007-12-11 10:09:58 +00:00
|
|
|
* If JS_CStringsAreUTF8() is true then JS_EncodeCharacters encodes to
|
|
|
|
* UTF-8, and JS_DecodeBytes decodes from UTF-8, which may create additional
|
|
|
|
* errors if the character sequence is malformed. If UTF-8 support is
|
|
|
|
* disabled, the functions deflate and inflate, respectively.
|
2011-04-16 18:11:10 +00:00
|
|
|
*
|
|
|
|
* JS_DecodeUTF8() always behaves the same independently of JS_CStringsAreUTF8().
|
2005-11-05 01:06:30 +00:00
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2005-12-03 02:31:21 +00:00
|
|
|
JS_EncodeCharacters(JSContext *cx, const jschar *src, size_t srclen, char *dst,
|
|
|
|
size_t *dstlenp);
|
2005-11-05 01:06:30 +00:00
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2005-12-03 02:31:21 +00:00
|
|
|
JS_DecodeBytes(JSContext *cx, const char *src, size_t srclen, jschar *dst,
|
|
|
|
size_t *dstlenp);
|
2005-11-05 01:06:30 +00:00
|
|
|
|
2011-04-16 18:11:10 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DecodeUTF8(JSContext *cx, const char *src, size_t srclen, jschar *dst,
|
|
|
|
size_t *dstlenp);
|
|
|
|
|
2007-12-11 10:09:58 +00:00
|
|
|
/*
|
|
|
|
* A variation on JS_EncodeCharacters where a null terminated string is
|
|
|
|
* returned that you are expected to call JS_free on when done.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(char *)
|
|
|
|
JS_EncodeString(JSContext *cx, JSString *str);
|
|
|
|
|
2010-11-08 12:17:31 +00:00
|
|
|
/*
|
|
|
|
* Get number of bytes in the string encoding (without accounting for a
|
|
|
|
* terminating zero bytes. The function returns (size_t) -1 if the string
|
|
|
|
* can not be encoded into bytes and reports an error using cx accordingly.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(size_t)
|
|
|
|
JS_GetStringEncodingLength(JSContext *cx, JSString *str);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encode string into a buffer. The function does not stores an additional
|
|
|
|
* zero byte. The function returns (size_t) -1 if the string can not be
|
|
|
|
* encoded into bytes with no error reported. Otherwise it returns the number
|
|
|
|
* of bytes that are necessary to encode the string. If that exceeds the
|
|
|
|
* length parameter, the string will be cut and only length bytes will be
|
|
|
|
* written into the buffer.
|
|
|
|
*
|
|
|
|
* If JS_CStringsAreUTF8() is true, the string does not fit into the buffer
|
|
|
|
* and the the first length bytes ends in the middle of utf-8 encoding for
|
|
|
|
* some character, then such partial utf-8 encoding is replaced by zero bytes.
|
|
|
|
* This way the result always represents the valid UTF-8 sequence.
|
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(size_t)
|
|
|
|
JS_EncodeStringToBuffer(JSString *str, char *buffer, size_t length);
|
|
|
|
|
2010-11-11 20:40:29 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
class JSAutoByteString {
|
|
|
|
public:
|
|
|
|
JSAutoByteString(JSContext *cx, JSString *str JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mBytes(JS_EncodeString(cx, str)) {
|
|
|
|
JS_ASSERT(cx);
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSAutoByteString(JS_GUARD_OBJECT_NOTIFIER_PARAM0)
|
|
|
|
: mBytes(NULL) {
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSAutoByteString() {
|
2011-03-31 08:14:12 +00:00
|
|
|
js::UnwantedForeground::free_(mBytes);
|
2010-11-11 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
2010-12-09 10:22:15 +00:00
|
|
|
/* Take ownership of the given byte array. */
|
|
|
|
void initBytes(char *bytes) {
|
|
|
|
JS_ASSERT(!mBytes);
|
|
|
|
mBytes = bytes;
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:40:29 +00:00
|
|
|
char *encode(JSContext *cx, JSString *str) {
|
|
|
|
JS_ASSERT(!mBytes);
|
|
|
|
JS_ASSERT(cx);
|
|
|
|
mBytes = JS_EncodeString(cx, str);
|
|
|
|
return mBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
2011-03-31 08:14:12 +00:00
|
|
|
js::UnwantedForeground::free_(mBytes);
|
2010-11-11 20:40:29 +00:00
|
|
|
mBytes = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *ptr() const {
|
|
|
|
return mBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!() const {
|
|
|
|
return !mBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
char *mBytes;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
/* Copy and assignment are not supported. */
|
|
|
|
JSAutoByteString(const JSAutoByteString &another);
|
|
|
|
JSAutoByteString &operator=(const JSAutoByteString &another);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-10-01 06:13:58 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/*
|
|
|
|
* JSON functions
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
typedef JSBool (* JSONWriteCallback)(const jschar *buf, uint32_t len, void *data);
|
2008-10-01 06:13:58 +00:00
|
|
|
|
|
|
|
/*
|
2011-03-21 18:42:14 +00:00
|
|
|
* JSON.stringify as specified by ES5.
|
2008-10-01 06:13:58 +00:00
|
|
|
*/
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2009-05-07 20:28:21 +00:00
|
|
|
JS_Stringify(JSContext *cx, jsval *vp, JSObject *replacer, jsval space,
|
2008-10-01 06:13:58 +00:00
|
|
|
JSONWriteCallback callback, void *data);
|
|
|
|
|
|
|
|
/*
|
2011-03-21 18:42:14 +00:00
|
|
|
* JSON.parse as specified by ES5.
|
2008-10-01 06:13:58 +00:00
|
|
|
*/
|
2011-03-21 18:42:06 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ParseJSON(JSContext *cx, const jschar *chars, uint32_t len, jsval *vp);
|
2011-03-21 18:42:06 +00:00
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ParseJSONWithReviver(JSContext *cx, const jschar *chars, uint32_t len, jsval reviver,
|
|
|
|
jsval *vp);
|
2011-03-21 18:42:06 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2010-10-01 00:47:10 +00:00
|
|
|
/* API for the HTML5 internal structured cloning algorithm. */
|
|
|
|
|
|
|
|
/* The maximum supported structured-clone serialization format version. */
|
|
|
|
#define JS_STRUCTURED_CLONE_VERSION 1
|
|
|
|
|
2011-01-07 06:21:30 +00:00
|
|
|
struct JSStructuredCloneCallbacks {
|
|
|
|
ReadStructuredCloneOp read;
|
|
|
|
WriteStructuredCloneOp write;
|
|
|
|
StructuredCloneErrorOp reportError;
|
|
|
|
};
|
|
|
|
|
2010-10-01 00:47:10 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ReadStructuredClone(JSContext *cx, const uint64_t *data, size_t nbytes,
|
|
|
|
uint32_t version, jsval *vp,
|
2011-01-07 06:21:30 +00:00
|
|
|
const JSStructuredCloneCallbacks *optionalCallbacks,
|
|
|
|
void *closure);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
Bug 634155: Account for NewCompartment's memory, and change allocation APIs (r=nnethercote)
This changes the allocation API, in the following way:
js_malloc -> {cx->,rt->,OffTheBooks::}malloc
js_calloc -> {cx->,rt->,OffTheBooks::}calloc
js_realloc -> {cx->,rt->,OffTheBooks::}realloc
js_free -> {cx->,rt->,Foreground::,UnwantedForeground::}free
js_new -> {cx->,rt->,OffTheBooks::}new_
js_new_array -> {cx->,rt->,OffTheBooks::}new_array
js_delete -> {cx->,rt->,Foreground::,UnwantedForeground::}delete_
This is to move as many allocations as possible through a JSContext (so that they may be aken into account by gcMallocBytes) and to move as many deallocations to the background as possible (except on error paths).
2011-03-31 08:13:49 +00:00
|
|
|
/* Note: On success, the caller is responsible for calling js::Foreground::free(*datap). */
|
2010-10-01 00:47:10 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_WriteStructuredClone(JSContext *cx, jsval v, uint64_t **datap, size_t *nbytesp,
|
2011-01-07 06:21:30 +00:00
|
|
|
const JSStructuredCloneCallbacks *optionalCallbacks,
|
|
|
|
void *closure);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
2011-01-07 06:21:30 +00:00
|
|
|
JS_StructuredClone(JSContext *cx, jsval v, jsval *vp,
|
|
|
|
const JSStructuredCloneCallbacks *optionalCallbacks,
|
|
|
|
void *closure);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2011-07-12 17:42:24 +00:00
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
2010-10-01 00:47:10 +00:00
|
|
|
/* RAII sugar for JS_WriteStructuredClone. */
|
2011-07-12 17:42:24 +00:00
|
|
|
class JS_PUBLIC_API(JSAutoStructuredCloneBuffer) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint64_t *data_;
|
2010-10-01 00:47:10 +00:00
|
|
|
size_t nbytes_;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint32_t version_;
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
public:
|
2010-12-21 16:02:04 +00:00
|
|
|
JSAutoStructuredCloneBuffer()
|
2011-07-12 17:42:24 +00:00
|
|
|
: data_(NULL), nbytes_(0), version_(JS_STRUCTURED_CLONE_VERSION) {}
|
2010-11-24 20:14:02 +00:00
|
|
|
|
2010-10-01 00:47:10 +00:00
|
|
|
~JSAutoStructuredCloneBuffer() { clear(); }
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
uint64_t *data() const { return data_; }
|
2010-10-01 00:47:10 +00:00
|
|
|
size_t nbytes() const { return nbytes_; }
|
|
|
|
|
2011-07-12 17:42:24 +00:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
/* Copy some memory. It will be automatically freed by the destructor. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
bool copy(const uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adopt some memory. It will be automatically freed by the destructor.
|
2011-07-12 17:42:24 +00:00
|
|
|
* data must have been allocated by the JS engine (e.g., extracted via
|
|
|
|
* JSAutoStructuredCloneBuffer::steal).
|
2010-10-01 00:47:10 +00:00
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
void adopt(uint64_t *data, size_t nbytes, uint32_t version=JS_STRUCTURED_CLONE_VERSION);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the buffer so that it will not be automatically freed.
|
2011-07-12 17:42:24 +00:00
|
|
|
* After this, the caller is responsible for feeding the memory back to
|
|
|
|
* JSAutoStructuredCloneBuffer::adopt.
|
2010-10-01 00:47:10 +00:00
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
void steal(uint64_t **datap, size_t *nbytesp, uint32_t *versionp=NULL);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
2011-07-12 17:42:24 +00:00
|
|
|
bool read(JSContext *cx, jsval *vp,
|
2011-01-07 06:21:30 +00:00
|
|
|
const JSStructuredCloneCallbacks *optionalCallbacks=NULL,
|
2011-07-12 17:42:24 +00:00
|
|
|
void *closure=NULL) const;
|
2010-10-01 00:47:10 +00:00
|
|
|
|
2011-01-07 06:21:30 +00:00
|
|
|
bool write(JSContext *cx, jsval v,
|
|
|
|
const JSStructuredCloneCallbacks *optionalCallbacks=NULL,
|
2011-07-12 17:42:24 +00:00
|
|
|
void *closure=NULL);
|
2010-12-21 16:02:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Swap ownership with another JSAutoStructuredCloneBuffer.
|
|
|
|
*/
|
2011-07-12 17:42:24 +00:00
|
|
|
void swap(JSAutoStructuredCloneBuffer &other);
|
2010-12-21 16:02:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/* Copy and assignment are not supported. */
|
|
|
|
JSAutoStructuredCloneBuffer(const JSAutoStructuredCloneBuffer &other);
|
|
|
|
JSAutoStructuredCloneBuffer &operator=(const JSAutoStructuredCloneBuffer &other);
|
2010-10-01 00:47:10 +00:00
|
|
|
};
|
2011-07-12 17:42:24 +00:00
|
|
|
|
|
|
|
JS_BEGIN_EXTERN_C
|
2010-10-01 00:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* API for implementing custom serialization behavior (for ImageData, File, etc.) */
|
|
|
|
|
|
|
|
/* The range of tag values the application may use for its own custom object types. */
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
#define JS_SCTAG_USER_MIN ((uint32_t) 0xFFFF8000)
|
|
|
|
#define JS_SCTAG_USER_MAX ((uint32_t) 0xFFFFFFFF)
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
#define JS_SCERR_RECURSION 0
|
|
|
|
|
|
|
|
JS_PUBLIC_API(void)
|
|
|
|
JS_SetStructuredCloneCallbacks(JSRuntime *rt, const JSStructuredCloneCallbacks *callbacks);
|
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_ReadUint32Pair(JSStructuredCloneReader *r, uint32_t *p1, uint32_t *p2);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ReadBytes(JSStructuredCloneReader *r, void *p, size_t len);
|
|
|
|
|
2012-04-24 10:58:07 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ReadTypedArray(JSStructuredCloneReader *r, jsval *vp);
|
|
|
|
|
2010-10-01 00:47:10 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_WriteUint32Pair(JSStructuredCloneWriter *w, uint32_t tag, uint32_t data);
|
2010-10-01 00:47:10 +00:00
|
|
|
|
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_WriteBytes(JSStructuredCloneWriter *w, const void *p, size_t len);
|
|
|
|
|
2012-04-24 10:58:07 +00:00
|
|
|
JS_PUBLIC_API(JSBool)
|
|
|
|
JS_WriteTypedArray(JSStructuredCloneWriter *w, jsval v);
|
|
|
|
|
2010-10-01 00:47:10 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2000-08-09 21:46:03 +00:00
|
|
|
/*
|
2005-12-03 02:31:21 +00:00
|
|
|
* Locale specific string conversion and error message callbacks.
|
2000-08-09 21:46:03 +00:00
|
|
|
*/
|
|
|
|
struct JSLocaleCallbacks {
|
|
|
|
JSLocaleToUpperCase localeToUpperCase;
|
|
|
|
JSLocaleToLowerCase localeToLowerCase;
|
|
|
|
JSLocaleCompare localeCompare;
|
2004-06-15 16:38:43 +00:00
|
|
|
JSLocaleToUnicode localeToUnicode;
|
2005-12-03 02:31:21 +00:00
|
|
|
JSErrorCallback localeGetErrorMessage;
|
2000-08-09 21:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2000-09-08 21:24:14 +00:00
|
|
|
* Establish locale callbacks. The pointer must persist as long as the
|
|
|
|
* JSContext. Passing NULL restores the default behaviour.
|
2000-08-09 21:46:03 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetLocaleCallbacks(JSContext *cx, JSLocaleCallbacks *callbacks);
|
|
|
|
|
2000-09-08 21:24:14 +00:00
|
|
|
/*
|
|
|
|
* Return the address of the current locale callbacks struct, which may
|
|
|
|
* be NULL.
|
|
|
|
*/
|
2000-09-02 20:37:37 +00:00
|
|
|
extern JS_PUBLIC_API(JSLocaleCallbacks *)
|
2000-08-09 21:46:03 +00:00
|
|
|
JS_GetLocaleCallbacks(JSContext *cx);
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* Error reporting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report an exception represented by the sprintf-like conversion of format
|
|
|
|
* and its arguments. This exception message string is passed to a pre-set
|
2011-09-19 16:34:49 +00:00
|
|
|
* JSErrorReporter function (set by JS_SetErrorReporter).
|
1998-03-28 02:44:41 +00:00
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ReportError(JSContext *cx, const char *format, ...);
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* Use an errorNumber to retrieve the format string, args are char *
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
|
2012-02-28 23:11:11 +00:00
|
|
|
void *userRef, const unsigned errorNumber, ...);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2012-07-18 10:36:08 +00:00
|
|
|
#ifdef va_start
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumberVA(JSContext *cx, JSErrorCallback errorCallback,
|
|
|
|
void *userRef, const unsigned errorNumber, va_list ap);
|
|
|
|
#endif
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* Use an errorNumber to retrieve the format string, args are jschar *
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
|
2012-02-28 23:11:11 +00:00
|
|
|
void *userRef, const unsigned errorNumber, ...);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
|
|
|
/*
|
2000-01-18 11:06:05 +00:00
|
|
|
* As above, but report a warning instead (JSREPORT_IS_WARNING(report.flags)).
|
|
|
|
* Return true if there was no error trying to issue the warning, and if the
|
|
|
|
* warning was not converted into an error due to the JSOPTION_WERROR option
|
|
|
|
* being set, false otherwise.
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
2000-01-18 11:06:05 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
1998-10-14 10:22:38 +00:00
|
|
|
JS_ReportWarning(JSContext *cx, const char *format, ...);
|
|
|
|
|
2000-01-18 11:06:05 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_ReportErrorFlagsAndNumber(JSContext *cx, unsigned flags,
|
2000-01-18 11:06:05 +00:00
|
|
|
JSErrorCallback errorCallback, void *userRef,
|
2012-02-28 23:11:11 +00:00
|
|
|
const unsigned errorNumber, ...);
|
2000-01-18 11:06:05 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags,
|
2000-01-18 11:06:05 +00:00
|
|
|
JSErrorCallback errorCallback, void *userRef,
|
2012-02-28 23:11:11 +00:00
|
|
|
const unsigned errorNumber, ...);
|
2000-01-18 11:06:05 +00:00
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* Complain when out of memory.
|
|
|
|
*/
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_ReportOutOfMemory(JSContext *cx);
|
|
|
|
|
2008-03-12 23:07:47 +00:00
|
|
|
/*
|
|
|
|
* Complain when an allocation size overflows the maximum supported limit.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ReportAllocationOverflow(JSContext *cx);
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
struct JSErrorReport {
|
1998-10-14 10:22:38 +00:00
|
|
|
const char *filename; /* source file name, URL, etc., or null */
|
2011-06-28 00:42:53 +00:00
|
|
|
JSPrincipals *originPrincipals; /* see 'originPrincipals' comment above */
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned lineno; /* source line number */
|
1998-10-14 10:22:38 +00:00
|
|
|
const char *linebuf; /* offending source line without final \n */
|
|
|
|
const char *tokenptr; /* pointer to error token in linebuf */
|
|
|
|
const jschar *uclinebuf; /* unicode (original) line buffer */
|
|
|
|
const jschar *uctokenptr; /* unicode (original) token pointer */
|
2012-02-28 23:11:11 +00:00
|
|
|
unsigned flags; /* error/warning, etc. */
|
|
|
|
unsigned errorNumber; /* the error number, e.g. see js.msg */
|
1998-10-14 10:22:38 +00:00
|
|
|
const jschar *ucmessage; /* the (default) error message */
|
|
|
|
const jschar **messageArgs; /* arguments for the error message */
|
2012-07-18 10:36:08 +00:00
|
|
|
int16_t exnType; /* One of the JSExnType constants */
|
1998-03-28 02:44:41 +00:00
|
|
|
};
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
2000-01-18 11:06:05 +00:00
|
|
|
* JSErrorReport flag values. These may be freely composed.
|
1998-10-14 10:22:38 +00:00
|
|
|
*/
|
2000-01-18 11:06:05 +00:00
|
|
|
#define JSREPORT_ERROR 0x0 /* pseudo-flag for default case */
|
|
|
|
#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
|
|
|
|
#define JSREPORT_EXCEPTION 0x2 /* exception was thrown */
|
|
|
|
#define JSREPORT_STRICT 0x4 /* error or warning due to strict option */
|
1998-10-14 10:22:38 +00:00
|
|
|
|
2009-11-19 17:23:20 +00:00
|
|
|
/*
|
|
|
|
* This condition is an error in strict mode code, a warning if
|
|
|
|
* JS_HAS_STRICT_OPTION(cx), and otherwise should not be reported at
|
|
|
|
* all. We check the strictness of the context's top frame's script;
|
|
|
|
* where that isn't appropriate, the caller should do the right checks
|
|
|
|
* itself instead of using this flag.
|
|
|
|
*/
|
|
|
|
#define JSREPORT_STRICT_MODE_ERROR 0x8
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
/*
|
|
|
|
* If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
|
|
|
|
* has been thrown for this runtime error, and the host should ignore it.
|
|
|
|
* Exception-aware hosts should also check for JS_IsExceptionPending if
|
|
|
|
* JS_ExecuteScript returns failure, and signal or propagate the exception, as
|
|
|
|
* appropriate.
|
|
|
|
*/
|
2000-01-18 11:06:05 +00:00
|
|
|
#define JSREPORT_IS_WARNING(flags) (((flags) & JSREPORT_WARNING) != 0)
|
|
|
|
#define JSREPORT_IS_EXCEPTION(flags) (((flags) & JSREPORT_EXCEPTION) != 0)
|
|
|
|
#define JSREPORT_IS_STRICT(flags) (((flags) & JSREPORT_STRICT) != 0)
|
2009-11-19 17:23:20 +00:00
|
|
|
#define JSREPORT_IS_STRICT_MODE_ERROR(flags) (((flags) & \
|
|
|
|
JSREPORT_STRICT_MODE_ERROR) != 0)
|
2012-01-15 08:13:09 +00:00
|
|
|
extern JS_PUBLIC_API(JSErrorReporter)
|
|
|
|
JS_GetErrorReporter(JSContext *cx);
|
1998-10-14 10:22:38 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSErrorReporter)
|
1998-03-28 02:44:41 +00:00
|
|
|
JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2011-01-18 22:11:03 +00:00
|
|
|
/*
|
|
|
|
* Dates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_NewDateObject(JSContext *cx, int year, int mon, int mday, int hour, int min, int sec);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-24 22:19:52 +00:00
|
|
|
JS_NewDateObjectMsec(JSContext *cx, double msec);
|
2011-01-18 22:11:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Infallible predicate to test whether obj is a date object.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_ObjectIsDate(JSContext *cx, JSRawObject obj);
|
2011-01-18 22:11:03 +00:00
|
|
|
|
2012-07-13 22:56:08 +00:00
|
|
|
/*
|
|
|
|
* Clears the cache of calculated local time from each Date object.
|
|
|
|
* Call to propagate a system timezone change.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ClearDateCaches(JSContext *cx);
|
|
|
|
|
2011-01-18 22:11:03 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/*
|
|
|
|
* Regular Expressions.
|
|
|
|
*/
|
|
|
|
#define JSREG_FOLD 0x01 /* fold uppercase to lowercase */
|
|
|
|
#define JSREG_GLOB 0x02 /* global exec, creates array of matches */
|
1999-04-27 15:18:57 +00:00
|
|
|
#define JSREG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */
|
2007-03-11 19:36:59 +00:00
|
|
|
#define JSREG_STICKY 0x08 /* only match starting at lastIndex */
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewRegExpObject(JSContext *cx, JSObject *obj, char *bytes, size_t length, unsigned flags);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewUCRegExpObject(JSContext *cx, JSObject *obj, jschar *chars, size_t length, unsigned flags);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2010-09-13 22:53:50 +00:00
|
|
|
JS_SetRegExpInput(JSContext *cx, JSObject *obj, JSString *input, JSBool multiline);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2010-09-13 22:53:50 +00:00
|
|
|
JS_ClearRegExpStatics(JSContext *cx, JSObject *obj);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2010-08-18 19:26:22 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
2010-09-13 22:53:50 +00:00
|
|
|
JS_ExecuteRegExp(JSContext *cx, JSObject *obj, JSObject *reobj, jschar *chars, size_t length,
|
2010-08-18 19:26:22 +00:00
|
|
|
size_t *indexp, JSBool test, jsval *rval);
|
|
|
|
|
2010-09-13 22:53:50 +00:00
|
|
|
/* RegExp interface for clients without a global object. */
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewRegExpObjectNoStatics(JSContext *cx, char *bytes, size_t length, unsigned flags);
|
2010-09-13 22:53:50 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-02-28 23:11:11 +00:00
|
|
|
JS_NewUCRegExpObjectNoStatics(JSContext *cx, jschar *chars, size_t length, unsigned flags);
|
2010-09-13 22:53:50 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ExecuteRegExpNoStatics(JSContext *cx, JSObject *reobj, jschar *chars, size_t length,
|
|
|
|
size_t *indexp, JSBool test, jsval *rval);
|
1998-03-28 02:44:41 +00:00
|
|
|
|
2011-05-18 03:04:28 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ObjectIsRegExp(JSContext *cx, JSObject *obj);
|
|
|
|
|
2012-02-28 23:11:11 +00:00
|
|
|
extern JS_PUBLIC_API(unsigned)
|
2011-05-09 03:10:21 +00:00
|
|
|
JS_GetRegExpFlags(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSString *)
|
|
|
|
JS_GetRegExpSource(JSContext *cx, JSObject *obj);
|
|
|
|
|
1998-03-28 02:44:41 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsExceptionPending(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_GetPendingException(JSContext *cx, jsval *vp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetPendingException(JSContext *cx, jsval v);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ClearPendingException(JSContext *cx);
|
2004-07-17 02:39:55 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ReportPendingException(JSContext *cx);
|
1998-04-24 00:31:11 +00:00
|
|
|
|
1999-06-08 02:15:57 +00:00
|
|
|
/*
|
2002-02-09 06:28:58 +00:00
|
|
|
* Save the current exception state. This takes a snapshot of cx's current
|
1999-06-08 02:15:57 +00:00
|
|
|
* exception state without making any change to that state.
|
|
|
|
*
|
2002-02-09 06:28:58 +00:00
|
|
|
* The returned state pointer MUST be passed later to JS_RestoreExceptionState
|
|
|
|
* (to restore that saved state, overriding any more recent state) or else to
|
|
|
|
* JS_DropExceptionState (to free the state struct in case it is not correct
|
|
|
|
* or desirable to restore it). Both Restore and Drop free the state struct,
|
|
|
|
* so callers must stop using the pointer returned from Save after calling the
|
|
|
|
* Release or Drop API.
|
1999-06-08 02:15:57 +00:00
|
|
|
*/
|
1998-11-05 00:08:43 +00:00
|
|
|
extern JS_PUBLIC_API(JSExceptionState *)
|
|
|
|
JS_SaveExceptionState(JSContext *cx);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_RestoreExceptionState(JSContext *cx, JSExceptionState *state);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_DropExceptionState(JSContext *cx, JSExceptionState *state);
|
|
|
|
|
1999-10-05 21:07:23 +00:00
|
|
|
/*
|
2002-02-09 06:28:58 +00:00
|
|
|
* If the given value is an exception object that originated from an error,
|
|
|
|
* the exception will contain an error report struct, and this API will return
|
|
|
|
* the address of that struct. Otherwise, it returns NULL. The lifetime of
|
|
|
|
* the error report struct that might be returned is the same as the lifetime
|
|
|
|
* of the exception object.
|
1999-10-05 21:07:23 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSErrorReport *)
|
|
|
|
JS_ErrorFromException(JSContext *cx, jsval v);
|
|
|
|
|
2005-07-20 03:35:40 +00:00
|
|
|
/*
|
|
|
|
* Given a reported error's message and JSErrorReport struct pointer, throw
|
|
|
|
* the corresponding exception on cx.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ThrowReportedError(JSContext *cx, const char *message,
|
|
|
|
JSErrorReport *reportp);
|
|
|
|
|
2007-10-01 00:31:22 +00:00
|
|
|
/*
|
|
|
|
* Throws a StopIteration exception on cx.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_ThrowStopIteration(JSContext *cx);
|
|
|
|
|
2012-01-11 08:23:07 +00:00
|
|
|
extern JS_PUBLIC_API(intptr_t)
|
|
|
|
JS_GetCurrentThread();
|
|
|
|
|
2011-07-01 21:11:31 +00:00
|
|
|
/*
|
|
|
|
* A JS runtime always has an "owner thread". The owner thread is set when the
|
|
|
|
* runtime is created (to the current thread) and practically all entry points
|
|
|
|
* into the JS engine check that a runtime (or anything contained in the
|
|
|
|
* runtime: context, compartment, object, etc) is only touched by its owner
|
|
|
|
* thread. Embeddings may check this invariant outside the JS engine by calling
|
|
|
|
* JS_AbortIfWrongThread (which will abort if not on the owner thread, even for
|
|
|
|
* non-debug builds).
|
|
|
|
*
|
|
|
|
* It is possible to "move" a runtime between threads. This is accomplished by
|
|
|
|
* calling JS_ClearRuntimeThread on a runtime's owner thread and then calling
|
|
|
|
* JS_SetRuntimeThread on the new owner thread. The runtime must not be
|
|
|
|
* accessed between JS_ClearRuntimeThread and JS_SetRuntimeThread. Also, the
|
|
|
|
* caller is responsible for synchronizing the calls to Set/Clear.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_AbortIfWrongThread(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_ClearRuntimeThread(JSRuntime *rt);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
|
|
|
JS_SetRuntimeThread(JSRuntime *rt);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
|
|
|
class JSAutoSetRuntimeThread
|
|
|
|
{
|
|
|
|
JSRuntime *runtime;
|
|
|
|
|
|
|
|
public:
|
|
|
|
JSAutoSetRuntimeThread(JSRuntime *runtime) : runtime(runtime) {
|
|
|
|
JS_SetRuntimeThread(runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSAutoSetRuntimeThread() {
|
|
|
|
JS_ClearRuntimeThread(runtime);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
#endif
|
|
|
|
|
1998-04-24 00:31:11 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2010-08-16 19:35:04 +00:00
|
|
|
/*
|
|
|
|
* JS_IsConstructing must be called from within a native given the
|
|
|
|
* native's original cx and vp arguments. If JS_IsConstructing is true,
|
|
|
|
* JS_THIS must not be used; the constructor should construct and return a
|
|
|
|
* new object. Otherwise, the native is called as an ordinary function and
|
|
|
|
* JS_THIS may be used.
|
|
|
|
*/
|
|
|
|
static JS_ALWAYS_INLINE JSBool
|
|
|
|
JS_IsConstructing(JSContext *cx, const jsval *vp)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSObject *callee = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
|
|
|
|
if (JS_ObjectIsFunction(cx, callee)) {
|
|
|
|
JSFunction *fun = JS_ValueToFunction(cx, JS_CALLEE(cx, vp));
|
|
|
|
JS_ASSERT((JS_GetFunctionFlags(fun) & JSFUN_CONSTRUCTOR) != 0);
|
|
|
|
} else {
|
2012-02-04 00:54:57 +00:00
|
|
|
JS_ASSERT(JS_GetClass(callee)->construct != NULL);
|
2010-08-16 19:35:04 +00:00
|
|
|
}
|
2012-02-16 01:41:59 +00:00
|
|
|
#else
|
|
|
|
(void)cx;
|
2010-08-16 19:35:04 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-19 16:34:49 +00:00
|
|
|
return JSVAL_IS_MAGIC_IMPL(JSVAL_TO_IMPL(vp[1]));
|
2010-08-16 19:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-12 23:16:40 +00:00
|
|
|
* A constructor can request that the JS engine create a default new 'this'
|
|
|
|
* object of the given class, using the callee to determine parentage and
|
|
|
|
* [[Prototype]].
|
2010-08-16 19:35:04 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
2012-03-12 23:16:40 +00:00
|
|
|
JS_NewObjectForConstructor(JSContext *cx, JSClass *clasp, const jsval *vp);
|
2010-08-16 19:35:04 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2007-05-15 23:27:20 +00:00
|
|
|
#ifdef JS_GC_ZEAL
|
2011-06-02 00:48:52 +00:00
|
|
|
#define JS_DEFAULT_ZEAL_FREQ 100
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void)
|
2012-04-03 18:41:56 +00:00
|
|
|
JS_SetGCZeal(JSContext *cx, uint8_t zeal, uint32_t frequency);
|
2011-06-02 00:48:52 +00:00
|
|
|
|
2007-05-15 23:27:20 +00:00
|
|
|
extern JS_PUBLIC_API(void)
|
2012-04-03 18:41:56 +00:00
|
|
|
JS_ScheduleGC(JSContext *cx, uint32_t count);
|
2007-05-15 23:27:20 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-04 16:19:07 +00:00
|
|
|
/*
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
* Convert a uint32_t index into a jsid.
|
2011-11-04 16:19:07 +00:00
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-09 03:54:10 +00:00
|
|
|
JS_IndexToId(JSContext *cx, uint32_t index, jsid *id);
|
2011-11-04 16:19:07 +00:00
|
|
|
|
2011-11-21 14:56:24 +00:00
|
|
|
/*
|
|
|
|
* Test if the given string is a valid ECMAScript identifier
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_IsIdentifier(JSContext *cx, JSString *str, JSBool *isIdentifier);
|
|
|
|
|
2012-03-06 23:33:12 +00:00
|
|
|
/*
|
|
|
|
* Return the current script and line number of the most currently running
|
|
|
|
* frame. Returns true if a scripted frame was found, false otherwise.
|
|
|
|
*/
|
|
|
|
extern JS_PUBLIC_API(JSBool)
|
|
|
|
JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno);
|
|
|
|
|
|
|
|
|
2012-02-20 10:58:00 +00:00
|
|
|
/*
|
|
|
|
* Encode/Decode interpreted scripts and functions to/from memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
|
|
|
JS_EncodeScript(JSContext *cx, JSScript *script, uint32_t *lengthp);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(void *)
|
2012-07-23 20:37:31 +00:00
|
|
|
JS_EncodeInterpretedFunction(JSContext *cx, JSRawObject funobj, uint32_t *lengthp);
|
2012-02-20 10:58:00 +00:00
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSScript *)
|
|
|
|
JS_DecodeScript(JSContext *cx, const void *data, uint32_t length,
|
|
|
|
JSPrincipals *principals, JSPrincipals *originPrincipals);
|
|
|
|
|
|
|
|
extern JS_PUBLIC_API(JSObject *)
|
|
|
|
JS_DecodeInterpretedFunction(JSContext *cx, const void *data, uint32_t length,
|
|
|
|
JSPrincipals *principals, JSPrincipals *originPrincipals);
|
|
|
|
|
1998-10-14 10:22:38 +00:00
|
|
|
JS_END_EXTERN_C
|
1998-03-28 02:44:41 +00:00
|
|
|
|
|
|
|
#endif /* jsapi_h___ */
|