2009-06-10 18:29:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2007-03-22 10:30:00 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=78:
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-28 06:09:07 -08:00
|
|
|
/* JS execution context. */
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifndef jscntxt_h___
|
|
|
|
#define jscntxt_h___
|
2011-12-28 06:09:07 -08:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2010-02-19 09:44:23 -08:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-01-11 00:23:08 -08:00
|
|
|
#include "jsapi.h"
|
2011-10-11 10:38:26 -07:00
|
|
|
#include "jsfriendapi.h"
|
2010-07-26 21:52:00 -07:00
|
|
|
#include "jsprvtd.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsatom.h"
|
2011-10-04 07:06:54 -07:00
|
|
|
#include "jsclist.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsgc.h"
|
2010-03-24 14:16:01 -07:00
|
|
|
#include "jspropertycache.h"
|
2010-03-22 11:11:44 -07:00
|
|
|
#include "jspropertytree.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "jsutil.h"
|
2010-05-26 17:00:28 -07:00
|
|
|
#include "prmjtime.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
#include "ds/LifoAlloc.h"
|
2011-08-23 17:35:09 -07:00
|
|
|
#include "gc/Statistics.h"
|
2011-10-04 15:33:00 -07:00
|
|
|
#include "js/HashTable.h"
|
|
|
|
#include "js/Vector.h"
|
2012-01-20 19:49:33 -08:00
|
|
|
#include "vm/Stack.h"
|
2012-06-20 17:58:55 -07:00
|
|
|
#include "vm/SPSProfiler.h"
|
2011-04-13 09:27:37 -07:00
|
|
|
|
2010-03-04 20:44:09 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4100) /* Silence unreferenced formal parameter warnings */
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4355) /* Silence warning about "this" used in base member initializer list */
|
|
|
|
#endif
|
|
|
|
|
2011-06-09 01:12:21 -07:00
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
struct DtoaState;
|
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
2012-02-15 17:55:25 -08:00
|
|
|
struct JSSharpInfo {
|
|
|
|
bool hasGen;
|
|
|
|
bool isSharp;
|
|
|
|
|
|
|
|
JSSharpInfo() : hasGen(false), isSharp(false) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef js::HashMap<JSObject *, JSSharpInfo> JSSharpTable;
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
struct JSSharpObjectMap {
|
2012-03-01 11:43:17 -08:00
|
|
|
unsigned depth;
|
2012-02-15 17:55:25 -08:00
|
|
|
uint32_t sharpgen;
|
|
|
|
JSSharpTable table;
|
2012-02-07 10:39:58 -08:00
|
|
|
|
2012-02-15 17:55:25 -08:00
|
|
|
JSSharpObjectMap(JSContext *cx) : depth(0), sharpgen(0), table(js::TempAllocPolicy(cx)) {
|
|
|
|
table.init();
|
|
|
|
}
|
2011-10-04 07:06:54 -07:00
|
|
|
};
|
|
|
|
|
2010-01-22 14:49:18 -08:00
|
|
|
namespace js {
|
2009-10-28 16:44:44 -07:00
|
|
|
|
2010-08-11 11:23:29 -07:00
|
|
|
namespace mjit {
|
2012-05-03 00:12:47 -07:00
|
|
|
class JaegerRuntime;
|
2010-08-11 11:23:29 -07:00
|
|
|
}
|
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
class MathCache;
|
2011-06-14 19:21:47 -07:00
|
|
|
class WeakMapBase;
|
2011-11-22 14:41:43 -08:00
|
|
|
class InterpreterFrames;
|
2011-12-20 17:42:45 -08:00
|
|
|
class DebugScopes;
|
2011-06-14 19:21:47 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
/*
|
|
|
|
* GetSrcNote cache to avoid O(n^2) growth in finding a source note for a
|
|
|
|
* given pc in a script. We use the script->code pointer to tag the cache,
|
|
|
|
* instead of the script address itself, so that source notes are always found
|
|
|
|
* by offset from the bytecode with which they were generated.
|
|
|
|
*/
|
|
|
|
struct GSNCache {
|
|
|
|
typedef HashMap<jsbytecode *,
|
|
|
|
jssrcnote *,
|
|
|
|
PointerHasher<jsbytecode *, 0>,
|
|
|
|
SystemAllocPolicy> Map;
|
2009-04-05 21:17:22 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
jsbytecode *code;
|
|
|
|
Map map;
|
2009-01-27 16:40:40 -08:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
GSNCache() : code(NULL) { }
|
2010-08-01 09:58:03 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
void purge();
|
2010-06-03 18:12:01 -07:00
|
|
|
};
|
2011-07-25 04:04:02 -07:00
|
|
|
|
2011-03-13 07:45:02 -07:00
|
|
|
inline GSNCache *
|
|
|
|
GetGSNCache(JSContext *cx);
|
|
|
|
|
|
|
|
struct PendingProxyOperation {
|
|
|
|
PendingProxyOperation *next;
|
2012-05-24 16:05:18 -07:00
|
|
|
RootedObject object;
|
2012-04-30 17:10:30 -07:00
|
|
|
PendingProxyOperation(JSContext *cx, JSObject *object) : next(NULL), object(cx, object) {}
|
2011-03-13 07:45:02 -07:00
|
|
|
};
|
|
|
|
|
2012-04-01 13:24:56 -07:00
|
|
|
typedef Vector<ScriptAndCounts, 0, SystemAllocPolicy> ScriptAndCountsVector;
|
2012-01-24 17:32:30 -08:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
struct ConservativeGCData
|
|
|
|
{
|
2011-11-15 14:33:54 -08:00
|
|
|
/*
|
2011-07-18 14:54:48 -07:00
|
|
|
* The GC scans conservatively between ThreadData::nativeStackBase and
|
|
|
|
* nativeStackTop unless the latter is NULL.
|
2011-11-15 14:33:54 -08:00
|
|
|
*/
|
2011-07-18 14:54:48 -07:00
|
|
|
uintptr_t *nativeStackTop;
|
2011-11-07 13:42:31 -08:00
|
|
|
|
2012-04-30 17:10:30 -07:00
|
|
|
#if defined(JSGC_ROOT_ANALYSIS) && (JS_STACK_GROWTH_DIRECTION < 0)
|
|
|
|
/*
|
|
|
|
* Record old contents of the native stack from the last time there was a
|
|
|
|
* scan, to reduce the overhead involved in repeatedly rescanning the
|
|
|
|
* native stack during root analysis. oldStackData stores words in reverse
|
|
|
|
* order starting at oldStackEnd.
|
|
|
|
*/
|
|
|
|
uintptr_t *oldStackMin, *oldStackEnd;
|
|
|
|
uintptr_t *oldStackData;
|
|
|
|
size_t oldStackCapacity; // in sizeof(uintptr_t)
|
|
|
|
#endif
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
union {
|
|
|
|
jmp_buf jmpbuf;
|
|
|
|
uintptr_t words[JS_HOWMANY(sizeof(jmp_buf), sizeof(uintptr_t))];
|
|
|
|
} registerSnapshot;
|
2011-11-07 13:42:31 -08:00
|
|
|
|
2012-04-30 17:10:30 -07:00
|
|
|
ConservativeGCData() {
|
|
|
|
PodZero(this);
|
|
|
|
}
|
2012-01-24 17:32:30 -08:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
~ConservativeGCData() {
|
2012-01-24 17:32:30 -08:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-07-18 14:54:48 -07:00
|
|
|
/*
|
|
|
|
* The conservative GC scanner should be disabled when the thread leaves
|
|
|
|
* the last request.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(!hasStackToScan());
|
2011-07-18 14:54:48 -07:00
|
|
|
#endif
|
2011-07-18 14:54:48 -07:00
|
|
|
}
|
2011-03-13 07:45:02 -07:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
JS_NEVER_INLINE void recordStackTop();
|
2010-09-17 14:54:40 -07:00
|
|
|
|
2012-01-24 17:32:30 -08:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-07-18 14:54:48 -07:00
|
|
|
void updateForRequestEnd(unsigned suspendCount) {
|
|
|
|
if (suspendCount)
|
|
|
|
recordStackTop();
|
|
|
|
else
|
|
|
|
nativeStackTop = NULL;
|
2012-01-24 17:32:30 -08:00
|
|
|
}
|
2011-07-18 14:54:48 -07:00
|
|
|
#endif
|
2012-01-24 17:32:30 -08:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
bool hasStackToScan() const {
|
|
|
|
return !!nativeStackTop;
|
2012-01-24 17:32:30 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-20 11:17:38 -07:00
|
|
|
class SourceDataCache
|
2012-05-03 00:12:48 -07:00
|
|
|
{
|
2012-07-20 11:17:38 -07:00
|
|
|
typedef HashMap<ScriptSource *,
|
|
|
|
JSFixedString *,
|
|
|
|
DefaultHasher<ScriptSource *>,
|
2012-05-03 00:12:48 -07:00
|
|
|
SystemAllocPolicy> Map;
|
2012-07-20 11:17:38 -07:00
|
|
|
Map *map_;
|
|
|
|
public:
|
|
|
|
SourceDataCache() : map_(NULL) {}
|
|
|
|
JSFixedString *lookup(ScriptSource *ss);
|
|
|
|
void put(ScriptSource *ss, JSFixedString *);
|
|
|
|
void purge();
|
2012-05-03 00:12:48 -07:00
|
|
|
};
|
|
|
|
|
2012-07-03 10:24:35 -07:00
|
|
|
struct EvalCacheLookup
|
2012-05-03 00:12:48 -07:00
|
|
|
{
|
2012-07-03 10:24:35 -07:00
|
|
|
JSLinearString *str;
|
|
|
|
JSFunction *caller;
|
|
|
|
unsigned staticLevel;
|
|
|
|
JSVersion version;
|
|
|
|
JSCompartment *compartment;
|
|
|
|
};
|
2012-07-03 10:24:35 -07:00
|
|
|
|
2012-07-03 10:24:35 -07:00
|
|
|
struct EvalCacheHashPolicy
|
|
|
|
{
|
|
|
|
typedef EvalCacheLookup Lookup;
|
|
|
|
|
|
|
|
static HashNumber hash(const Lookup &l);
|
|
|
|
static bool match(JSScript *script, const EvalCacheLookup &l);
|
2012-05-03 00:12:48 -07:00
|
|
|
};
|
|
|
|
|
2012-07-03 10:24:35 -07:00
|
|
|
typedef HashSet<JSScript *, EvalCacheHashPolicy, SystemAllocPolicy> EvalCache;
|
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
class NativeIterCache
|
|
|
|
{
|
|
|
|
static const size_t SIZE = size_t(1) << 8;
|
|
|
|
|
|
|
|
/* Cached native iterators. */
|
2012-07-03 14:34:40 -07:00
|
|
|
PropertyIteratorObject *data[SIZE];
|
2012-05-03 00:12:47 -07:00
|
|
|
|
|
|
|
static size_t getIndex(uint32_t key) {
|
|
|
|
return size_t(key) % SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
/* Native iterator most recently started. */
|
2012-07-03 14:34:40 -07:00
|
|
|
PropertyIteratorObject *last;
|
2012-05-03 00:12:47 -07:00
|
|
|
|
|
|
|
NativeIterCache()
|
|
|
|
: last(NULL) {
|
|
|
|
PodArrayZero(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void purge() {
|
|
|
|
last = NULL;
|
|
|
|
PodArrayZero(data);
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:34:40 -07:00
|
|
|
PropertyIteratorObject *get(uint32_t key) const {
|
2012-05-03 00:12:47 -07:00
|
|
|
return data[getIndex(key)];
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:34:40 -07:00
|
|
|
void set(uint32_t key, PropertyIteratorObject *iterobj) {
|
2012-05-03 00:12:47 -07:00
|
|
|
data[getIndex(key)] = iterobj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
/*
|
|
|
|
* Cache for speeding up repetitive creation of objects in the VM.
|
|
|
|
* When an object is created which matches the criteria in the 'key' section
|
|
|
|
* below, an entry is filled with the resulting object.
|
|
|
|
*/
|
|
|
|
class NewObjectCache
|
|
|
|
{
|
|
|
|
/* Statically asserted to be equal to sizeof(JSObject_Slots16) */
|
|
|
|
static const unsigned MAX_OBJ_SIZE = 4 * sizeof(void*) + 16 * sizeof(Value);
|
|
|
|
static inline void staticAsserts();
|
|
|
|
|
|
|
|
struct Entry
|
|
|
|
{
|
|
|
|
/* Class of the constructed object. */
|
|
|
|
Class *clasp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Key with one of three possible values:
|
|
|
|
*
|
|
|
|
* - Global for the object. The object must have a standard class for
|
|
|
|
* which the global's prototype can be determined, and the object's
|
|
|
|
* parent will be the global.
|
|
|
|
*
|
|
|
|
* - Prototype for the object (cannot be global). The object's parent
|
|
|
|
* will be the prototype's parent.
|
|
|
|
*
|
|
|
|
* - Type for the object. The object's parent will be the type's
|
|
|
|
* prototype's parent.
|
|
|
|
*/
|
|
|
|
gc::Cell *key;
|
|
|
|
|
|
|
|
/* Allocation kind for the constructed object. */
|
|
|
|
gc::AllocKind kind;
|
|
|
|
|
|
|
|
/* Number of bytes to copy from the template object. */
|
|
|
|
uint32_t nbytes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Template object to copy from, with the initial values of fields,
|
|
|
|
* fixed slots (undefined) and private data (NULL).
|
|
|
|
*/
|
|
|
|
char templateObject[MAX_OBJ_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
Entry entries[41]; // TODO: reconsider size
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef int EntryIndex;
|
|
|
|
|
|
|
|
NewObjectCache() { PodZero(this); }
|
|
|
|
void purge() { PodZero(this); }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the entry index for the given lookup, return whether there was a hit
|
|
|
|
* on an existing entry.
|
|
|
|
*/
|
|
|
|
inline bool lookupProto(Class *clasp, JSObject *proto, gc::AllocKind kind, EntryIndex *pentry);
|
|
|
|
inline bool lookupGlobal(Class *clasp, js::GlobalObject *global, gc::AllocKind kind, EntryIndex *pentry);
|
|
|
|
inline bool lookupType(Class *clasp, js::types::TypeObject *type, gc::AllocKind kind, EntryIndex *pentry);
|
|
|
|
|
2012-07-10 18:17:29 -07:00
|
|
|
/*
|
|
|
|
* Return a new object from a cache hit produced by a lookup method, or
|
|
|
|
* NULL if returning the object could possibly trigger GC (does not
|
|
|
|
* indicate failure).
|
|
|
|
*/
|
2012-05-03 00:12:47 -07:00
|
|
|
inline JSObject *newObjectFromHit(JSContext *cx, EntryIndex entry);
|
|
|
|
|
|
|
|
/* Fill an entry after a cache miss. */
|
|
|
|
inline void fillProto(EntryIndex entry, Class *clasp, JSObject *proto, gc::AllocKind kind, JSObject *obj);
|
|
|
|
inline void fillGlobal(EntryIndex entry, Class *clasp, js::GlobalObject *global, gc::AllocKind kind, JSObject *obj);
|
|
|
|
inline void fillType(EntryIndex entry, Class *clasp, js::types::TypeObject *type, gc::AllocKind kind, JSObject *obj);
|
|
|
|
|
|
|
|
/* Invalidate any entries which might produce an object with shape/proto. */
|
|
|
|
void invalidateEntriesForShape(JSContext *cx, Shape *shape, JSObject *proto);
|
|
|
|
|
|
|
|
private:
|
|
|
|
inline bool lookup(Class *clasp, gc::Cell *key, gc::AllocKind kind, EntryIndex *pentry);
|
|
|
|
inline void fill(EntryIndex entry, Class *clasp, gc::Cell *key, gc::AllocKind kind, JSObject *obj);
|
|
|
|
static inline void copyCachedToObject(JSObject *dst, JSObject *src);
|
|
|
|
};
|
|
|
|
|
2012-04-04 10:03:14 -07:00
|
|
|
/*
|
|
|
|
* A FreeOp can do one thing: free memory. For convenience, it has delete_
|
|
|
|
* convenience methods that also call destructors.
|
|
|
|
*
|
|
|
|
* FreeOp is passed to finalizers and other sweep-phase hooks so that we do not
|
|
|
|
* need to pass a JSContext to those hooks.
|
|
|
|
*/
|
2012-03-19 07:34:58 -07:00
|
|
|
class FreeOp : public JSFreeOp {
|
|
|
|
bool shouldFreeLater_;
|
|
|
|
|
2012-03-20 03:22:05 -07:00
|
|
|
public:
|
2012-03-19 07:34:58 -07:00
|
|
|
static FreeOp *get(JSFreeOp *fop) {
|
|
|
|
return static_cast<FreeOp *>(fop);
|
|
|
|
}
|
|
|
|
|
2012-08-21 01:58:30 -07:00
|
|
|
FreeOp(JSRuntime *rt, bool shouldFreeLater)
|
2012-03-19 07:34:58 -07:00
|
|
|
: JSFreeOp(rt),
|
2012-08-21 01:58:30 -07:00
|
|
|
shouldFreeLater_(shouldFreeLater)
|
2012-03-19 07:34:58 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldFreeLater() const {
|
|
|
|
return shouldFreeLater_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void free_(void* p);
|
|
|
|
|
|
|
|
JS_DECLARE_DELETE_METHODS(free_, inline)
|
|
|
|
|
|
|
|
static void staticAsserts() {
|
|
|
|
/*
|
|
|
|
* Check that JSFreeOp is the first base class for FreeOp and we can
|
|
|
|
* reinterpret a pointer to JSFreeOp as a pointer to FreeOp without
|
2012-04-04 10:03:14 -07:00
|
|
|
* any offset adjustments. JSClass::finalize <-> Class::finalize depends
|
2012-03-19 07:34:58 -07:00
|
|
|
* on this.
|
|
|
|
*/
|
|
|
|
JS_STATIC_ASSERT(offsetof(FreeOp, shouldFreeLater_) == sizeof(JSFreeOp));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
} /* namespace js */
|
2012-01-24 17:32:30 -08:00
|
|
|
|
2012-05-15 19:29:14 -07:00
|
|
|
namespace JS {
|
|
|
|
struct RuntimeSizes;
|
|
|
|
}
|
|
|
|
|
2012-01-31 14:28:22 -08:00
|
|
|
struct JSRuntime : js::RuntimeFriendFields
|
2011-07-01 14:11:31 -07:00
|
|
|
{
|
2010-06-04 16:32:10 -07:00
|
|
|
/* Default compartment. */
|
2011-01-13 14:42:36 -08:00
|
|
|
JSCompartment *atomsCompartment;
|
2010-06-04 16:32:10 -07:00
|
|
|
|
|
|
|
/* List of compartments (protected by the GC lock). */
|
2011-03-08 20:58:38 -08:00
|
|
|
js::CompartmentVector compartments;
|
2010-06-04 16:32:10 -07:00
|
|
|
|
2011-07-01 14:11:31 -07:00
|
|
|
/* See comment for JS_AbortIfWrongThread in jsapi.h. */
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
public:
|
2011-07-18 14:54:48 -07:00
|
|
|
void *ownerThread() const { return ownerThread_; }
|
2011-07-01 14:11:31 -07:00
|
|
|
void clearOwnerThread();
|
|
|
|
void setOwnerThread();
|
|
|
|
JS_FRIEND_API(bool) onOwnerThread() const;
|
|
|
|
private:
|
|
|
|
void *ownerThread_;
|
|
|
|
public:
|
|
|
|
#else
|
|
|
|
public:
|
|
|
|
bool onOwnerThread() const { return true; }
|
|
|
|
#endif
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
/* Keeper of the contiguous stack used by all contexts in this thread. */
|
|
|
|
js::StackSpace stackSpace;
|
|
|
|
|
|
|
|
/* Temporary arena pool used while compiling and decompiling. */
|
2012-07-26 18:05:31 -07:00
|
|
|
static const size_t TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE = 4 * 1024;
|
2011-07-18 14:54:48 -07:00
|
|
|
js::LifoAlloc tempLifoAlloc;
|
|
|
|
|
2012-07-26 18:05:31 -07:00
|
|
|
/*
|
|
|
|
* Free LIFO blocks are transferred to this allocator before being freed on
|
|
|
|
* the background GC thread.
|
|
|
|
*/
|
|
|
|
js::LifoAlloc freeLifoAlloc;
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* Both of these allocators are used for regular expression code which is shared at the
|
|
|
|
* thread-data level.
|
|
|
|
*/
|
|
|
|
JSC::ExecutableAllocator *execAlloc_;
|
|
|
|
WTF::BumpPointerAllocator *bumpAlloc_;
|
2012-05-03 00:12:47 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
js::mjit::JaegerRuntime *jaegerRuntime_;
|
|
|
|
#endif
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2012-07-23 14:01:54 -07:00
|
|
|
JSObject *selfHostedGlobal_;
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
JSC::ExecutableAllocator *createExecutableAllocator(JSContext *cx);
|
|
|
|
WTF::BumpPointerAllocator *createBumpPointerAllocator(JSContext *cx);
|
2012-05-03 00:12:47 -07:00
|
|
|
js::mjit::JaegerRuntime *createJaegerRuntime(JSContext *cx);
|
2011-07-18 14:54:48 -07:00
|
|
|
|
|
|
|
public:
|
2012-05-03 00:12:47 -07:00
|
|
|
JSC::ExecutableAllocator *getExecAlloc(JSContext *cx) {
|
2011-07-18 14:54:48 -07:00
|
|
|
return execAlloc_ ? execAlloc_ : createExecutableAllocator(cx);
|
|
|
|
}
|
2012-05-03 00:12:47 -07:00
|
|
|
JSC::ExecutableAllocator &execAlloc() {
|
|
|
|
JS_ASSERT(execAlloc_);
|
|
|
|
return *execAlloc_;
|
|
|
|
}
|
2011-07-18 14:54:48 -07:00
|
|
|
WTF::BumpPointerAllocator *getBumpPointerAllocator(JSContext *cx) {
|
|
|
|
return bumpAlloc_ ? bumpAlloc_ : createBumpPointerAllocator(cx);
|
|
|
|
}
|
2012-05-03 00:12:47 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
js::mjit::JaegerRuntime *getJaegerRuntime(JSContext *cx) {
|
|
|
|
return jaegerRuntime_ ? jaegerRuntime_ : createJaegerRuntime(cx);
|
|
|
|
}
|
|
|
|
bool hasJaegerRuntime() const {
|
|
|
|
return jaegerRuntime_;
|
|
|
|
}
|
|
|
|
js::mjit::JaegerRuntime &jaegerRuntime() {
|
|
|
|
JS_ASSERT(hasJaegerRuntime());
|
|
|
|
return *jaegerRuntime_;
|
|
|
|
}
|
|
|
|
#endif
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2012-07-23 14:01:54 -07:00
|
|
|
bool initSelfHosting(JSContext *cx);
|
|
|
|
void markSelfHostedGlobal(JSTracer *trc);
|
|
|
|
JSFunction *getSelfHostedFunction(JSContext *cx, const char *name);
|
|
|
|
bool cloneSelfHostedValueById(JSContext *cx, jsid id, js::HandleObject holder, js::Value *vp);
|
|
|
|
|
2012-01-31 14:28:22 -08:00
|
|
|
/* Base address of the native stack for the current thread. */
|
|
|
|
uintptr_t nativeStackBase;
|
|
|
|
|
|
|
|
/* The native stack size limit that runtime should not exceed. */
|
|
|
|
size_t nativeStackQuota;
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
/*
|
|
|
|
* Frames currently running in js::Interpret. See InterpreterFrames for
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
js::InterpreterFrames *interpreterFrames;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Context create/destroy callback. */
|
|
|
|
JSContextCallback cxCallback;
|
|
|
|
|
2012-03-20 03:22:05 -07:00
|
|
|
/* Compartment destroy callback. */
|
|
|
|
JSDestroyCompartmentCallback destroyCompartmentCallback;
|
2010-07-19 13:36:49 -07:00
|
|
|
|
2012-07-25 18:25:47 -07:00
|
|
|
/* Call this to get the name of a compartment. */
|
|
|
|
JSCompartmentNameCallback compartmentNameCallback;
|
|
|
|
|
2012-01-15 00:13:10 -08:00
|
|
|
js::ActivityCallback activityCallback;
|
2010-08-09 16:39:28 -07:00
|
|
|
void *activityCallbackArg;
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* Number of JS_SuspendRequest calls withot JS_ResumeRequest. */
|
|
|
|
unsigned suspendCount;
|
|
|
|
|
|
|
|
/* The request depth for this thread. */
|
|
|
|
unsigned requestDepth;
|
|
|
|
|
|
|
|
# ifdef DEBUG
|
|
|
|
unsigned checkRequestDepth;
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Garbage collector state, used by jsgc.c. */
|
2011-07-26 00:55:23 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set of all GC chunks with at least one allocated thing. The
|
|
|
|
* conservative GC uses it to quickly check if a possible GC thing points
|
|
|
|
* into an allocated chunk.
|
|
|
|
*/
|
|
|
|
js::GCChunkSet gcChunkSet;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Doubly-linked lists of chunks from user and system compartments. The GC
|
|
|
|
* allocates its arenas from the corresponding list and when all arenas
|
|
|
|
* in the list head are taken, then the chunk is removed from the list.
|
|
|
|
* During the GC when all arenas in a chunk become free, that chunk is
|
|
|
|
* removed from the list and scheduled for release.
|
|
|
|
*/
|
|
|
|
js::gc::Chunk *gcSystemAvailableChunkListHead;
|
|
|
|
js::gc::Chunk *gcUserAvailableChunkListHead;
|
2011-09-23 07:14:26 -07:00
|
|
|
js::gc::ChunkPool gcChunkPool;
|
2010-08-05 05:16:56 -07:00
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
js::RootedValueMap gcRootsHash;
|
2010-05-20 13:50:08 -07:00
|
|
|
js::GCLocks gcLocksHash;
|
2012-03-01 11:43:17 -08:00
|
|
|
unsigned gcKeepAtoms;
|
2012-01-05 00:54:37 -08:00
|
|
|
size_t gcBytes;
|
2009-08-25 14:42:42 -07:00
|
|
|
size_t gcMaxBytes;
|
|
|
|
size_t gcMaxMallocBytes;
|
2011-12-19 14:07:24 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of the committed arenas in all GC chunks including empty chunks.
|
|
|
|
* The counter is volatile as it is read without the GC lock, see comments
|
|
|
|
* in MaybeGC.
|
|
|
|
*/
|
|
|
|
volatile uint32_t gcNumArenasFreeCommitted;
|
2012-03-01 10:39:13 -08:00
|
|
|
js::GCMarker gcMarker;
|
2012-06-20 18:48:56 -07:00
|
|
|
void *gcVerifyPreData;
|
|
|
|
void *gcVerifyPostData;
|
2011-06-20 14:44:26 -07:00
|
|
|
bool gcChunkAllocationSinceLastGC;
|
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-08 19:54:10 -08:00
|
|
|
int64_t gcNextFullGCTime;
|
2012-07-11 11:09:53 -07:00
|
|
|
int64_t gcLastGCTime;
|
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-08 19:54:10 -08:00
|
|
|
int64_t gcJitReleaseTime;
|
2011-01-09 22:57:21 -08:00
|
|
|
JSGCMode gcMode;
|
2012-07-11 11:09:53 -07:00
|
|
|
bool gcHighFrequencyGC;
|
|
|
|
uint64_t gcHighFrequencyTimeThreshold;
|
|
|
|
uint64_t gcHighFrequencyLowLimitBytes;
|
|
|
|
uint64_t gcHighFrequencyHighLimitBytes;
|
|
|
|
double gcHighFrequencyHeapGrowthMax;
|
|
|
|
double gcHighFrequencyHeapGrowthMin;
|
|
|
|
double gcLowFrequencyHeapGrowth;
|
|
|
|
bool gcDynamicHeapGrowth;
|
|
|
|
bool gcDynamicMarkSlice;
|
2012-04-02 17:02:25 -07:00
|
|
|
|
2012-05-22 14:06:58 -07:00
|
|
|
/* During shutdown, the GC needs to clean up every possible object. */
|
|
|
|
bool gcShouldCleanUpEverything;
|
|
|
|
|
2012-04-02 17:02:25 -07:00
|
|
|
/*
|
|
|
|
* These flags must be kept separate so that a thread requesting a
|
|
|
|
* compartment GC doesn't cancel another thread's concurrent request for a
|
|
|
|
* full GC.
|
|
|
|
*/
|
2012-01-11 00:23:05 -08:00
|
|
|
volatile uintptr_t gcIsNeeded;
|
2012-04-02 17:02:25 -07:00
|
|
|
|
2011-06-14 19:21:47 -07:00
|
|
|
js::WeakMapBase *gcWeakMapList;
|
2011-08-23 17:35:09 -07:00
|
|
|
js::gcstats::Statistics gcStats;
|
|
|
|
|
2012-02-17 14:35:20 -08:00
|
|
|
/* Incremented on every GC slice. */
|
|
|
|
uint64_t gcNumber;
|
|
|
|
|
|
|
|
/* The gcNumber at the time of the most recent GC's first slice. */
|
|
|
|
uint64_t gcStartNumber;
|
|
|
|
|
2012-08-02 15:35:59 -07:00
|
|
|
/* Whether the currently running GC can finish in multiple slices. */
|
|
|
|
int gcIsIncremental;
|
|
|
|
|
2012-04-12 11:14:43 -07:00
|
|
|
/* Whether all compartments are being collected in first GC slice. */
|
|
|
|
bool gcIsFull;
|
|
|
|
|
2011-08-23 17:35:09 -07:00
|
|
|
/* The reason that an interrupt-triggered GC should be called. */
|
2012-01-25 10:59:55 -08:00
|
|
|
js::gcreason::Reason gcTriggerReason;
|
2011-01-07 23:44:57 -08:00
|
|
|
|
2011-07-07 17:31:24 -07:00
|
|
|
/*
|
2012-04-02 17:02:25 -07:00
|
|
|
* If this is true, all marked objects must belong to a compartment being
|
|
|
|
* GCed. This is used to look for compartment bugs.
|
2011-07-07 17:31:24 -07:00
|
|
|
*/
|
2012-04-02 17:02:25 -07:00
|
|
|
bool gcStrictCompartmentChecking;
|
2011-07-07 17:31:24 -07:00
|
|
|
|
2012-06-18 17:04:48 -07:00
|
|
|
/*
|
|
|
|
* If this is 0, all cross-compartment proxies must be registered in the
|
|
|
|
* wrapper map. This checking must be disabled temporarily while creating
|
|
|
|
* new wrappers. When non-zero, this records the recursion depth of wrapper
|
|
|
|
* creation.
|
|
|
|
*/
|
|
|
|
uintptr_t gcDisableStrictProxyCheckingCount;
|
|
|
|
|
2012-02-17 14:35:20 -08:00
|
|
|
/*
|
|
|
|
* The current incremental GC phase. During non-incremental GC, this is
|
|
|
|
* always NO_INCREMENTAL.
|
|
|
|
*/
|
|
|
|
js::gc::State gcIncrementalState;
|
|
|
|
|
|
|
|
/* Indicates that the last incremental slice exhausted the mark stack. */
|
|
|
|
bool gcLastMarkSlice;
|
|
|
|
|
2012-07-26 01:31:52 -07:00
|
|
|
/* Whether any sweeping will take place in the separate GC helper thread. */
|
|
|
|
bool gcSweepOnBackgroundThread;
|
|
|
|
|
2012-08-21 01:45:33 -07:00
|
|
|
/* List head of compartments being swept. */
|
|
|
|
JSCompartment *gcSweepingCompartments;
|
|
|
|
|
2012-07-26 01:31:52 -07:00
|
|
|
/*
|
|
|
|
* Incremental sweep state.
|
|
|
|
*/
|
2012-08-21 01:45:33 -07:00
|
|
|
int gcSweepPhase;
|
|
|
|
ptrdiff_t gcSweepCompartmentIndex;
|
|
|
|
int gcSweepKindIndex;
|
2012-07-26 01:31:52 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List head of arenas allocated during the sweep phase.
|
|
|
|
*/
|
|
|
|
js::gc::ArenaHeader *gcArenasAllocatedDuringSweep;
|
|
|
|
|
2012-02-17 14:35:20 -08:00
|
|
|
/*
|
|
|
|
* Indicates that a GC slice has taken place in the middle of an animation
|
|
|
|
* frame, rather than at the beginning. In this case, the next slice will be
|
|
|
|
* delayed so that we don't get back-to-back slices.
|
|
|
|
*/
|
|
|
|
volatile uintptr_t gcInterFrameGC;
|
|
|
|
|
|
|
|
/* Default budget for incremental GC slice. See SliceBudget in jsgc.h. */
|
|
|
|
int64_t gcSliceBudget;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We disable incremental GC if we encounter a js::Class with a trace hook
|
|
|
|
* that does not implement write barriers.
|
|
|
|
*/
|
|
|
|
bool gcIncrementalEnabled;
|
|
|
|
|
2012-04-30 17:10:30 -07:00
|
|
|
/*
|
|
|
|
* Whether exact stack scanning is enabled for this runtime. This is
|
|
|
|
* currently only used for dynamic root analysis. Exact scanning starts out
|
|
|
|
* enabled, and is disabled if e4x has been used.
|
|
|
|
*/
|
|
|
|
bool gcExactScanningEnabled;
|
|
|
|
|
2012-02-17 14:35:20 -08:00
|
|
|
/*
|
|
|
|
* We save all conservative scanned roots in this vector so that
|
|
|
|
* conservative scanning can be "replayed" deterministically. In DEBUG mode,
|
|
|
|
* this allows us to run a non-incremental GC after every incremental GC to
|
|
|
|
* ensure that no objects were missed.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
struct SavedGCRoot {
|
|
|
|
void *thing;
|
|
|
|
JSGCTraceKind kind;
|
|
|
|
|
|
|
|
SavedGCRoot(void *thing, JSGCTraceKind kind) : thing(thing), kind(kind) {}
|
|
|
|
};
|
|
|
|
js::Vector<SavedGCRoot, 0, js::SystemAllocPolicy> gcSavedRoots;
|
|
|
|
#endif
|
|
|
|
|
2010-08-30 11:46:18 -07:00
|
|
|
bool gcPoke;
|
2012-07-03 17:24:03 -07:00
|
|
|
|
2012-07-13 09:13:50 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool relaxRootChecks;
|
|
|
|
#endif
|
|
|
|
|
2012-07-03 17:24:03 -07:00
|
|
|
enum HeapState {
|
|
|
|
Idle, // doing nothing with the GC heap
|
|
|
|
Tracing, // tracing the GC heap without collecting, e.g. IterateCompartments()
|
|
|
|
Collecting // doing a GC of the heap
|
|
|
|
};
|
|
|
|
|
|
|
|
HeapState heapState;
|
|
|
|
|
|
|
|
bool isHeapBusy() { return heapState != Idle; }
|
2009-07-27 14:29:02 -07:00
|
|
|
|
2012-08-14 03:10:50 -07:00
|
|
|
bool isHeapCollecting() { return heapState == Collecting; }
|
|
|
|
|
2011-06-01 17:48:52 -07:00
|
|
|
/*
|
|
|
|
* These options control the zealousness of the GC. The fundamental values
|
|
|
|
* are gcNextScheduled and gcDebugCompartmentGC. At every allocation,
|
|
|
|
* gcNextScheduled is decremented. When it reaches zero, we do either a
|
|
|
|
* full or a compartmental GC, based on gcDebugCompartmentGC.
|
|
|
|
*
|
2012-06-22 03:25:21 -07:00
|
|
|
* At this point, if gcZeal_ is one of the types that trigger periodic
|
|
|
|
* collection, then gcNextScheduled is reset to the value of
|
|
|
|
* gcZealFrequency. Otherwise, no additional GCs take place.
|
2011-06-01 17:48:52 -07:00
|
|
|
*
|
|
|
|
* You can control these values in several ways:
|
|
|
|
* - Pass the -Z flag to the shell (see the usage info for details)
|
|
|
|
* - Call gczeal() or schedulegc() from inside shell-executed JS code
|
|
|
|
* (see the help for details)
|
|
|
|
*
|
2012-02-17 14:35:20 -08:00
|
|
|
* If gzZeal_ == 1 then we perform GCs in select places (during MaybeGC and
|
|
|
|
* whenever a GC poke happens). This option is mainly useful to embedders.
|
2011-08-05 10:25:23 -07:00
|
|
|
*
|
|
|
|
* We use gcZeal_ == 4 to enable write barrier verification. See the comment
|
|
|
|
* in jsgc.cpp for more information about this.
|
2012-06-22 03:25:21 -07:00
|
|
|
*
|
|
|
|
* gcZeal_ values from 8 to 10 periodically run different types of
|
|
|
|
* incremental GC.
|
2011-06-01 17:48:52 -07:00
|
|
|
*/
|
2007-11-13 02:44:08 -08:00
|
|
|
#ifdef JS_GC_ZEAL
|
2011-06-01 17:48:52 -07:00
|
|
|
int gcZeal_;
|
|
|
|
int gcZealFrequency;
|
|
|
|
int gcNextScheduled;
|
2012-03-06 11:39:31 -08:00
|
|
|
bool gcDeterministicOnly;
|
2012-06-22 03:25:21 -07:00
|
|
|
int gcIncrementalLimit;
|
2011-06-01 17:48:52 -07:00
|
|
|
|
2012-04-04 15:07:36 -07:00
|
|
|
js::Vector<JSObject *, 0, js::SystemAllocPolicy> gcSelectedForMarking;
|
|
|
|
|
2011-06-01 17:48:52 -07:00
|
|
|
int gcZeal() { return gcZeal_; }
|
|
|
|
|
|
|
|
bool needZealousGC() {
|
|
|
|
if (gcNextScheduled > 0 && --gcNextScheduled == 0) {
|
2012-06-22 03:25:21 -07:00
|
|
|
if (gcZeal() == js::gc::ZealAllocValue ||
|
|
|
|
(gcZeal() >= js::gc::ZealIncrementalRootsThenFinish &&
|
|
|
|
gcZeal() <= js::gc::ZealIncrementalMultipleSlices))
|
|
|
|
{
|
2011-06-01 17:48:52 -07:00
|
|
|
gcNextScheduled = gcZealFrequency;
|
2012-06-22 03:25:21 -07:00
|
|
|
}
|
2011-06-01 17:48:52 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int gcZeal() { return 0; }
|
|
|
|
bool needZealousGC() { return false; }
|
2007-05-15 16:27:20 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-16 14:01:36 -07:00
|
|
|
bool gcValidate;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
JSGCCallback gcCallback;
|
2012-02-17 14:35:20 -08:00
|
|
|
js::GCSliceCallback gcSliceCallback;
|
2012-02-29 12:23:38 -08:00
|
|
|
JSFinalizeCallback gcFinalizeCallback;
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2012-05-21 16:44:19 -07:00
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* Malloc counter to measure memory pressure for GC scheduling. It runs
|
|
|
|
* from gcMaxMallocBytes down to zero.
|
|
|
|
*/
|
|
|
|
volatile ptrdiff_t gcMallocBytes;
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
public:
|
2007-05-01 03:09:46 -07:00
|
|
|
/*
|
2011-10-10 10:25:46 -07:00
|
|
|
* The trace operations to trace embedding-specific GC roots. One is for
|
|
|
|
* tracing through black roots and the other is for tracing through gray
|
|
|
|
* roots. The black/gray distinction is only relevant to the cycle
|
|
|
|
* collector.
|
2007-05-01 03:09:46 -07:00
|
|
|
*/
|
2011-10-10 10:25:46 -07:00
|
|
|
JSTraceDataOp gcBlackRootsTraceOp;
|
|
|
|
void *gcBlackRootsData;
|
|
|
|
JSTraceDataOp gcGrayRootsTraceOp;
|
|
|
|
void *gcGrayRootsData;
|
2007-05-01 03:09:46 -07:00
|
|
|
|
2012-02-29 04:18:16 -08:00
|
|
|
/* Stack of thread-stack-allocated GC roots. */
|
|
|
|
js::AutoGCRooter *autoGCRooters;
|
|
|
|
|
2011-12-16 13:11:08 -08:00
|
|
|
/* Strong references on scripts held for PCCount profiling API. */
|
2012-04-01 13:24:56 -07:00
|
|
|
js::ScriptAndCountsVector *scriptAndCountsVector;
|
2011-12-16 13:11:08 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Well-known numbers held for use by this runtime's contexts. */
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value NaNValue;
|
|
|
|
js::Value negativeInfinityValue;
|
|
|
|
js::Value positiveInfinityValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-21 02:00:36 -07:00
|
|
|
JSAtom *emptyString;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
/* List of active contexts sharing this runtime. */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSCList contextList;
|
|
|
|
|
2012-01-17 14:14:49 -08:00
|
|
|
bool hasContexts() const {
|
|
|
|
return !JS_CLIST_IS_EMPTY(&contextList);
|
|
|
|
}
|
2012-01-31 14:28:22 -08:00
|
|
|
|
2012-07-20 11:19:17 -07:00
|
|
|
JS_SourceHook sourceHook;
|
|
|
|
|
2007-06-14 23:44:18 -07:00
|
|
|
/* Per runtime debug hooks -- see jsprvtd.h and jsdbgapi.h. */
|
2012-02-28 02:54:40 -08:00
|
|
|
JSDebugHooks debugHooks;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-22 08:54:36 -07:00
|
|
|
/* If true, new compartments are initially in debug mode. */
|
Automatically turn debug mode on/off when adding/removing debuggees.
This allows most of the tests to run without the -d command-line flag.
Now a compartment is in debug mode if
* JSD1 wants debug mode on, thanks to a JS_SetDebugMode* call; OR
* JSD2 wants debug mode on, because a live Debug object has a debuggee
global in that compartment.
Since this patch only adds the second half of the rule, JSD1 should be
unaffected.
The new rule has three issues:
1. When removeDebuggee is called, it can cause debug mode to be turned
off for a compartment. If any scripts from that compartment are on
the stack, and the methodjit is enabled, returning to those stack
frames will crash.
2. When a Debug object is GC'd, it can cause debug mode to be turned off
for one or more compartments. This causes the same problem with
returning to deleted methodjit code, but the fix is different: such
Debug objects simply should not be GC'd.
3. Setting .enabled to false still does not turn off debug mode
anywhere, so it does not reduce overhead as much as it should.
A possible fix for issue #1 would be to make such removeDebuggee calls
throw; a different possibility is to turn off debug mode but leave all
the scripts alone, accepting the performance loss (as we do for JSD1 in
JSCompartment::setDebugModeFromC). The fix to issues #2 and #3 is to
tweak the rule--and to tweak the rule for Debug object GC-reachability.
--HG--
rename : js/src/jit-test/tests/debug/Debug-ctor.js => js/src/jit-test/tests/debug/Debug-ctor-01.js
2011-06-02 19:58:46 -07:00
|
|
|
bool debugMode;
|
2010-10-30 09:13:02 -07:00
|
|
|
|
2012-06-20 17:58:55 -07:00
|
|
|
/* SPS profiling metadata */
|
|
|
|
js::SPSProfiler spsProfiler;
|
|
|
|
|
2011-12-16 13:11:08 -08:00
|
|
|
/* If true, new scripts must be created with PC counter information. */
|
|
|
|
bool profilingScripts;
|
|
|
|
|
2012-05-09 14:14:10 -07:00
|
|
|
/* Always preserve JIT code during GCs, for testing. */
|
|
|
|
bool alwaysPreserveCode;
|
|
|
|
|
2011-05-18 12:34:17 -07:00
|
|
|
/* Had an out-of-memory error which did not populate an exception. */
|
|
|
|
JSBool hadOutOfMemory;
|
|
|
|
|
2011-05-20 22:40:33 -07:00
|
|
|
/*
|
2011-07-05 05:48:26 -07:00
|
|
|
* Linked list of all js::Debugger objects. This may be accessed by the GC
|
2011-05-20 22:40:33 -07:00
|
|
|
* thread, if any, or a thread that is in a request and holds gcLock.
|
|
|
|
*/
|
|
|
|
JSCList debuggerList;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-20 17:42:45 -08:00
|
|
|
/* Bookkeeping information for debug scope objects. */
|
|
|
|
js::DebugScopes *debugScopes;
|
|
|
|
|
2008-10-11 10:35:39 -07:00
|
|
|
/* Client opaque pointers */
|
2007-03-22 10:30:00 -07:00
|
|
|
void *data;
|
|
|
|
|
|
|
|
/* These combine to interlock the GC and new requests. */
|
|
|
|
PRLock *gcLock;
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
js::GCHelperThread gcHelperThread;
|
2011-08-03 17:43:39 -07:00
|
|
|
|
2012-07-20 11:17:38 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
js::SourceCompressorThread sourceCompressorThread;
|
|
|
|
#endif
|
|
|
|
|
2012-03-19 07:34:58 -07:00
|
|
|
private:
|
|
|
|
js::FreeOp defaultFreeOp_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
js::FreeOp *defaultFreeOp() {
|
|
|
|
return &defaultFreeOp_;
|
|
|
|
}
|
|
|
|
|
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-08 19:54:10 -08:00
|
|
|
uint32_t debuggerMutations;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-09 01:48:50 -08:00
|
|
|
const JSSecurityCallbacks *securityCallbacks;
|
2012-08-07 22:26:18 -07:00
|
|
|
const js::DOMCallbacks *DOMcallbacks;
|
2012-03-09 01:48:50 -08:00
|
|
|
JSDestroyPrincipalsOp destroyPrincipals;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-30 17:47:10 -07:00
|
|
|
/* Structured data callbacks are runtime-wide. */
|
|
|
|
const JSStructuredCloneCallbacks *structuredCloneCallbacks;
|
|
|
|
|
2011-10-11 10:38:26 -07:00
|
|
|
/* Call this to accumulate telemetry data. */
|
|
|
|
JSAccumulateTelemetryDataCallback telemetryCallback;
|
|
|
|
|
2010-03-22 11:11:44 -07:00
|
|
|
/*
|
2010-08-29 11:57:08 -07:00
|
|
|
* The propertyRemovals counter is incremented for every JSObject::clear,
|
|
|
|
* and for each JSObject::remove method call that frees a slot in the given
|
|
|
|
* object. See js_NativeGet and js_NativeSet in jsobj.cpp.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-07-11 22:23:56 -07:00
|
|
|
int32_t propertyRemovals;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Number localization, used by jsnum.c */
|
|
|
|
const char *thousandsSeparator;
|
|
|
|
const char *decimalSeparator;
|
|
|
|
const char *numGrouping;
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
/*
|
|
|
|
* Flag indicating that we are waiving any soft limits on the GC heap
|
|
|
|
* because we want allocations to be infallible (except when we hit OOM).
|
|
|
|
*/
|
|
|
|
bool waiveGCQuota;
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
private:
|
|
|
|
js::MathCache *mathCache_;
|
|
|
|
js::MathCache *createMathCache(JSContext *cx);
|
|
|
|
public:
|
|
|
|
js::MathCache *getMathCache(JSContext *cx) {
|
|
|
|
return mathCache_ ? mathCache_ : createMathCache(cx);
|
|
|
|
}
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
js::GSNCache gsnCache;
|
2011-07-18 14:54:48 -07:00
|
|
|
js::PropertyCache propertyCache;
|
2012-05-03 00:12:47 -07:00
|
|
|
js::NewObjectCache newObjectCache;
|
2012-05-03 00:12:47 -07:00
|
|
|
js::NativeIterCache nativeIterCache;
|
2012-07-20 11:17:38 -07:00
|
|
|
js::SourceDataCache sourceDataCache;
|
2012-05-03 00:12:48 -07:00
|
|
|
js::EvalCache evalCache;
|
2011-07-18 14:54:48 -07:00
|
|
|
|
|
|
|
/* State used by jsdtoa.cpp. */
|
|
|
|
DtoaState *dtoaState;
|
|
|
|
|
|
|
|
/* List of currently pending operations on proxies. */
|
|
|
|
js::PendingProxyOperation *pendingProxyOperation;
|
|
|
|
|
|
|
|
js::ConservativeGCData conservativeGC;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-30 09:26:56 -07:00
|
|
|
private:
|
|
|
|
JSPrincipals *trustedPrincipals_;
|
|
|
|
public:
|
|
|
|
void setTrustedPrincipals(JSPrincipals *p) { trustedPrincipals_ = p; }
|
|
|
|
JSPrincipals *trustedPrincipals() const { return trustedPrincipals_; }
|
|
|
|
|
2007-08-07 00:29:32 -07:00
|
|
|
/* Literal table maintained by jsatom.c functions. */
|
|
|
|
JSAtomState atomState;
|
|
|
|
|
2011-09-20 14:47:14 -07:00
|
|
|
/* Tables of strings that are pre-allocated in the atomsCompartment. */
|
|
|
|
js::StaticStrings staticStrings;
|
|
|
|
|
2012-05-14 14:30:07 -07:00
|
|
|
JSWrapObjectCallback wrapObjectCallback;
|
|
|
|
JSSameCompartmentWrapObjectCallback sameCompartmentWrapObjectCallback;
|
|
|
|
JSPreWrapCallback preWrapObjectCallback;
|
|
|
|
js::PreserveWrapperCallback preserveWrapperCallback;
|
2010-06-24 14:45:32 -07:00
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
js::ScriptFilenameTable scriptFilenameTable;
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
size_t noGCOrAllocationCheck;
|
|
|
|
#endif
|
|
|
|
|
2011-05-17 11:23:31 -07:00
|
|
|
/*
|
|
|
|
* To ensure that cx->malloc does not cause a GC, we set this flag during
|
|
|
|
* OOM reporting (in js_ReportOutOfMemory). If a GC is requested while
|
|
|
|
* reporting the OOM, we ignore it.
|
|
|
|
*/
|
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-08 19:54:10 -08:00
|
|
|
int32_t inOOMReport;
|
2011-05-17 11:23:31 -07:00
|
|
|
|
2012-02-13 21:36:11 -08:00
|
|
|
bool jitHardening;
|
|
|
|
|
2009-10-20 15:08:28 -07:00
|
|
|
JSRuntime();
|
|
|
|
~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-08 19:54:10 -08:00
|
|
|
bool init(uint32_t maxbytes);
|
2009-10-20 15:08:28 -07:00
|
|
|
|
2011-08-23 17:35:09 -07:00
|
|
|
JSRuntime *thisFromCtor() { return this; }
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* Call the system malloc while checking for GC memory pressure and
|
2011-05-17 11:23:31 -07:00
|
|
|
* reporting OOM error when cx is not null. We will not GC from here.
|
2010-09-07 14:08:20 -07:00
|
|
|
*/
|
2011-03-31 01:14:12 -07:00
|
|
|
void* malloc_(size_t bytes, JSContext *cx = NULL) {
|
2012-01-30 13:21:42 -08:00
|
|
|
updateMallocCounter(cx, bytes);
|
2010-09-07 14:08:20 -07:00
|
|
|
void *p = ::js_malloc(bytes);
|
|
|
|
return JS_LIKELY(!!p) ? p : onOutOfMemory(NULL, bytes, cx);
|
|
|
|
}
|
2009-07-27 21:10:12 -07:00
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* Call the system calloc while checking for GC memory pressure and
|
2011-05-17 11:23:31 -07:00
|
|
|
* reporting OOM error when cx is not null. We will not GC from here.
|
2010-09-07 14:08:20 -07:00
|
|
|
*/
|
2011-03-31 01:14:12 -07:00
|
|
|
void* calloc_(size_t bytes, JSContext *cx = NULL) {
|
2012-01-30 13:21:42 -08:00
|
|
|
updateMallocCounter(cx, bytes);
|
2010-09-07 14:08:20 -07:00
|
|
|
void *p = ::js_calloc(bytes);
|
|
|
|
return JS_LIKELY(!!p) ? p : onOutOfMemory(reinterpret_cast<void *>(1), bytes, cx);
|
|
|
|
}
|
2009-07-27 21:10:12 -07:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
void* realloc_(void* p, size_t oldBytes, size_t newBytes, JSContext *cx = NULL) {
|
2010-12-08 16:34:38 -08:00
|
|
|
JS_ASSERT(oldBytes < newBytes);
|
2012-01-30 13:21:42 -08:00
|
|
|
updateMallocCounter(cx, newBytes - oldBytes);
|
2010-12-08 16:34:38 -08:00
|
|
|
void *p2 = ::js_realloc(p, newBytes);
|
|
|
|
return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, newBytes, cx);
|
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
void* realloc_(void* p, size_t bytes, JSContext *cx = NULL) {
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* For compatibility we do not account for realloc that increases
|
|
|
|
* previously allocated memory.
|
|
|
|
*/
|
|
|
|
if (!p)
|
2012-01-30 13:21:42 -08:00
|
|
|
updateMallocCounter(cx, bytes);
|
2010-09-07 14:08:20 -07:00
|
|
|
void *p2 = ::js_realloc(p, bytes);
|
|
|
|
return JS_LIKELY(!!p2) ? p2 : onOutOfMemory(p, bytes, cx);
|
|
|
|
}
|
2010-07-23 15:17:42 -07:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void free_(void* p) {
|
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 01:13:49 -07:00
|
|
|
/* FIXME: Making this free in the background is buggy. Can it work? */
|
2011-03-31 01:14:12 -07:00
|
|
|
js::Foreground::free_(p);
|
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 01:13:49 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
JS_DECLARE_NEW_METHODS(malloc_, JS_ALWAYS_INLINE)
|
|
|
|
JS_DECLARE_DELETE_METHODS(free_, JS_ALWAYS_INLINE)
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2012-05-15 15:30:15 -07:00
|
|
|
void setGCMaxMallocBytes(size_t value);
|
2010-09-07 14:08:20 -07:00
|
|
|
|
2012-05-21 16:44:19 -07:00
|
|
|
void resetGCMallocBytes() { gcMallocBytes = ptrdiff_t(gcMaxMallocBytes); }
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* Call this after allocating memory held by GC things, to update memory
|
|
|
|
* pressure counters or report the OOM error if necessary. If oomError and
|
|
|
|
* cx is not null the function also reports OOM error.
|
|
|
|
*
|
|
|
|
* The function must be called outside the GC lock and in case of OOM error
|
|
|
|
* the caller must ensure that no deadlock possible during OOM reporting.
|
|
|
|
*/
|
2012-01-30 13:21:42 -08:00
|
|
|
void updateMallocCounter(JSContext *cx, size_t nbytes);
|
2012-05-21 16:44:19 -07:00
|
|
|
|
|
|
|
bool isTooMuchMalloc() const {
|
|
|
|
return gcMallocBytes <= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The function must be called outside the GC lock.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void) onTooMuchMalloc();
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
/*
|
|
|
|
* This should be called after system malloc/realloc returns NULL to try
|
|
|
|
* to recove some memory or to report an error. Failures in malloc and
|
|
|
|
* calloc are signaled by p == null and p == reinterpret_cast<void *>(1).
|
|
|
|
* Other values of p mean a realloc failure.
|
|
|
|
*
|
|
|
|
* The function must be called outside the GC lock.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes, JSContext *cx);
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2012-02-24 03:03:28 -08:00
|
|
|
void triggerOperationCallback();
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2012-02-13 21:36:11 -08:00
|
|
|
void setJitHardening(bool enabled);
|
|
|
|
bool getJitHardening() const {
|
|
|
|
return jitHardening;
|
|
|
|
}
|
|
|
|
|
2012-05-17 17:08:57 -07:00
|
|
|
void sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf, JS::RuntimeSizes *runtime);
|
2012-05-15 19:29:14 -07:00
|
|
|
size_t sizeOfExplicitNonHeap();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
/* Common macros to access thread-local caches in JSRuntime. */
|
|
|
|
#define JS_PROPERTY_CACHE(cx) (cx->runtime->propertyCache)
|
2009-01-27 16:40:40 -08:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
#define JS_KEEP_ATOMS(rt) (rt)->gcKeepAtoms++;
|
|
|
|
#define JS_UNKEEP_ATOMS(rt) (rt)->gcKeepAtoms--;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef JS_ARGUMENT_FORMATTER_DEFINED
|
|
|
|
/*
|
|
|
|
* Linked list mapping format strings for JS_{Convert,Push}Arguments{,VA} to
|
|
|
|
* formatter functions. Elements are sorted in non-increasing format string
|
|
|
|
* length order.
|
|
|
|
*/
|
|
|
|
struct JSArgumentFormatMap {
|
|
|
|
const char *format;
|
|
|
|
size_t length;
|
|
|
|
JSArgumentFormatter formatter;
|
|
|
|
JSArgumentFormatMap *next;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
namespace js {
|
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
struct AutoResolving;
|
2010-08-11 13:30:07 -07:00
|
|
|
|
2012-05-30 13:05:59 -07:00
|
|
|
static inline bool
|
|
|
|
OptionsHasAllowXML(uint32_t options)
|
|
|
|
{
|
|
|
|
return !!(options & JSOPTION_ALLOW_XML);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
2012-05-30 13:05:58 -07:00
|
|
|
OptionsHasMoarXML(uint32_t options)
|
2010-09-13 09:38:22 -07:00
|
|
|
{
|
2012-05-30 13:05:58 -07:00
|
|
|
return !!(options & JSOPTION_MOAR_XML);
|
2010-09-13 09:38:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
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-08 19:54:10 -08:00
|
|
|
OptionsSameVersionFlags(uint32_t self, uint32_t other)
|
2010-09-13 09:38:22 -07:00
|
|
|
{
|
2012-05-30 13:05:58 -07:00
|
|
|
static const uint32_t mask = JSOPTION_MOAR_XML;
|
2010-09-13 09:38:22 -07:00
|
|
|
return !((self & mask) ^ (other & mask));
|
|
|
|
}
|
|
|
|
|
2010-11-09 09:00:54 -08:00
|
|
|
/*
|
|
|
|
* Flags accompany script version data so that a) dynamically created scripts
|
|
|
|
* can inherit their caller's compile-time properties and b) scripts can be
|
|
|
|
* appropriately compared in the eval cache across global option changes. An
|
|
|
|
* example of the latter is enabling the top-level-anonymous-function-is-error
|
|
|
|
* option: subsequent evals of the same, previously-valid script text may have
|
|
|
|
* become invalid.
|
|
|
|
*/
|
2010-09-13 09:38:22 -07:00
|
|
|
namespace VersionFlags {
|
2012-05-30 13:05:58 -07:00
|
|
|
static const unsigned MASK = 0x0FFF; /* see JSVersion in jspubtd.h */
|
2012-05-30 13:05:59 -07:00
|
|
|
static const unsigned ALLOW_XML = 0x1000; /* flag induced by JSOPTION_ALLOW_XML */
|
|
|
|
static const unsigned MOAR_XML = 0x2000; /* flag induced by JSOPTION_MOAR_XML */
|
2012-05-30 13:05:58 -07:00
|
|
|
static const unsigned FULL_MASK = 0x3FFF;
|
2012-03-19 07:34:55 -07:00
|
|
|
} /* namespace VersionFlags */
|
2010-09-13 09:38:22 -07:00
|
|
|
|
2010-09-18 00:31:36 -07:00
|
|
|
static inline JSVersion
|
|
|
|
VersionNumber(JSVersion version)
|
|
|
|
{
|
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-08 19:54:10 -08:00
|
|
|
return JSVersion(uint32_t(version) & VersionFlags::MASK);
|
2010-09-18 00:31:36 -07:00
|
|
|
}
|
|
|
|
|
2012-05-30 13:05:59 -07:00
|
|
|
static inline bool
|
|
|
|
VersionHasAllowXML(JSVersion version)
|
|
|
|
{
|
|
|
|
return !!(version & VersionFlags::ALLOW_XML);
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
2012-05-30 13:05:58 -07:00
|
|
|
VersionHasMoarXML(JSVersion version)
|
2010-09-13 09:38:22 -07:00
|
|
|
{
|
2012-05-30 13:05:58 -07:00
|
|
|
return !!(version & VersionFlags::MOAR_XML);
|
2010-09-13 09:38:22 -07:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:31:36 -07:00
|
|
|
/* @warning This is a distinct condition from having the XML flag set. */
|
|
|
|
static inline bool
|
|
|
|
VersionShouldParseXML(JSVersion version)
|
|
|
|
{
|
2012-05-30 13:05:58 -07:00
|
|
|
return VersionHasMoarXML(version) || VersionNumber(version) >= JSVERSION_1_6;
|
2010-09-18 00:31:36 -07:00
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline JSVersion
|
|
|
|
VersionExtractFlags(JSVersion version)
|
|
|
|
{
|
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-08 19:54:10 -08:00
|
|
|
return JSVersion(uint32_t(version) & ~VersionFlags::MASK);
|
2010-09-13 09:38:22 -07:00
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
static inline void
|
|
|
|
VersionCopyFlags(JSVersion *version, JSVersion from)
|
|
|
|
{
|
|
|
|
*version = JSVersion(VersionNumber(*version) | VersionExtractFlags(from));
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
VersionHasFlags(JSVersion version)
|
|
|
|
{
|
|
|
|
return !!VersionExtractFlags(version);
|
|
|
|
}
|
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
static inline unsigned
|
2011-01-27 02:54:58 -08:00
|
|
|
VersionFlagsToOptions(JSVersion version)
|
|
|
|
{
|
2012-05-30 13:05:59 -07:00
|
|
|
unsigned copts = (VersionHasAllowXML(version) ? JSOPTION_ALLOW_XML : 0) |
|
|
|
|
(VersionHasMoarXML(version) ? JSOPTION_MOAR_XML : 0);
|
2011-01-27 02:54:58 -08:00
|
|
|
JS_ASSERT((copts & JSCOMPILEOPTION_MASK) == copts);
|
|
|
|
return copts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSVersion
|
2012-02-28 15:11:11 -08:00
|
|
|
OptionFlagsToVersion(unsigned options, JSVersion version)
|
2011-01-27 02:54:58 -08:00
|
|
|
{
|
2012-05-30 13:05:59 -07:00
|
|
|
uint32_t v = version;
|
|
|
|
v &= ~(VersionFlags::ALLOW_XML | VersionFlags::MOAR_XML);
|
|
|
|
if (OptionsHasAllowXML(options))
|
|
|
|
v |= VersionFlags::ALLOW_XML;
|
|
|
|
if (OptionsHasMoarXML(options))
|
|
|
|
v |= VersionFlags::MOAR_XML;
|
|
|
|
return JSVersion(v);
|
2011-01-27 02:54:58 -08:00
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
VersionIsKnown(JSVersion version)
|
|
|
|
{
|
|
|
|
return VersionNumber(version) != JSVERSION_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2011-03-29 15:46:51 -07:00
|
|
|
typedef HashSet<JSObject *,
|
|
|
|
DefaultHasher<JSObject *>,
|
|
|
|
SystemAllocPolicy> BusyArraysSet;
|
2011-01-24 09:47:25 -08:00
|
|
|
|
2012-03-19 07:34:58 -07:00
|
|
|
inline void
|
|
|
|
FreeOp::free_(void* p) {
|
|
|
|
if (shouldFreeLater()) {
|
|
|
|
runtime()->gcHelperThread.freeLater(p);
|
|
|
|
return;
|
2012-03-19 07:34:55 -07:00
|
|
|
}
|
2012-03-19 07:34:58 -07:00
|
|
|
runtime()->free_(p);
|
|
|
|
}
|
2012-03-19 07:34:55 -07:00
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
} /* namespace js */
|
2010-08-11 13:30:07 -07:00
|
|
|
|
2012-01-31 14:28:22 -08:00
|
|
|
struct JSContext : js::ContextFriendFields
|
2010-02-06 10:14:05 -08:00
|
|
|
{
|
2010-03-03 17:52:26 -08:00
|
|
|
explicit JSContext(JSRuntime *rt);
|
2011-04-13 09:27:37 -07:00
|
|
|
JSContext *thisDuringConstruction() { return this; }
|
2011-03-13 07:45:02 -07:00
|
|
|
~JSContext();
|
2010-02-06 10:14:05 -08:00
|
|
|
|
2008-12-18 07:24:34 -08:00
|
|
|
/* JSRuntime contextList linkage. */
|
|
|
|
JSCList link;
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
private:
|
|
|
|
/* See JSContext::findVersion. */
|
|
|
|
JSVersion defaultVersion; /* script compilation version */
|
|
|
|
JSVersion versionOverride; /* supercedes defaultVersion when valid */
|
|
|
|
bool hasVersionOverride;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
/* Exception state -- the exception member is a GC root by definition. */
|
2012-03-06 18:49:00 -08:00
|
|
|
JSBool throwing; /* is there a pending exception? */
|
|
|
|
js::Value exception; /* most-recently-thrown exception */
|
2011-01-07 02:03:14 -08:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/* Per-context run options. */
|
2012-03-06 18:49:00 -08:00
|
|
|
unsigned runOptions; /* see jsapi.h for JSOPTION_* */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
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-08 19:54:10 -08:00
|
|
|
int32_t reportGranularity; /* see jsprobes.h */
|
2011-03-29 10:25:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Locale specific callbacks for string conversion. */
|
|
|
|
JSLocaleCallbacks *localeCallbacks;
|
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
js::AutoResolving *resolvingList;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-06 18:49:00 -08:00
|
|
|
/* True if generating an error, to prevent runaway recursion. */
|
|
|
|
bool generatingError;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-21 14:15:12 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool rootingUnnecessary;
|
|
|
|
#endif
|
|
|
|
|
2010-06-04 16:32:10 -07:00
|
|
|
/* GC heap compartment. */
|
|
|
|
JSCompartment *compartment;
|
|
|
|
|
2011-04-01 17:26:34 -07:00
|
|
|
inline void setCompartment(JSCompartment *compartment);
|
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* Current execution stack. */
|
|
|
|
js::ContextStack stack;
|
2010-03-03 18:10:13 -08:00
|
|
|
|
2012-07-10 16:14:59 -07:00
|
|
|
/* Current global. */
|
|
|
|
inline js::Handle<js::GlobalObject*> global() const;
|
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* ContextStack convenience functions */
|
2012-01-20 19:49:33 -08:00
|
|
|
inline bool hasfp() const { return stack.hasfp(); }
|
|
|
|
inline js::StackFrame* fp() const { return stack.fp(); }
|
|
|
|
inline js::StackFrame* maybefp() const { return stack.maybefp(); }
|
|
|
|
inline js::FrameRegs& regs() const { return stack.regs(); }
|
|
|
|
inline js::FrameRegs* maybeRegs() const { return stack.maybeRegs(); }
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* Set cx->compartment based on the current scope chain. */
|
2010-09-27 18:24:24 -07:00
|
|
|
void resetCompartment();
|
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
/* Wrap cx->exception for the current compartment. */
|
|
|
|
void wrapPendingException();
|
2010-03-03 18:10:13 -08:00
|
|
|
|
2011-06-24 14:22:30 -07:00
|
|
|
private:
|
|
|
|
/* Lazily initialized pool of maps used during parse/emit. */
|
2012-07-09 11:54:28 -07:00
|
|
|
js::frontend::ParseMapPool *parseMapPool_;
|
2011-06-24 14:22:30 -07:00
|
|
|
|
|
|
|
public:
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Top-level object and pointer to top stack frame's scope chain. */
|
|
|
|
JSObject *globalObject;
|
|
|
|
|
|
|
|
/* State for object and array toSource conversion. */
|
|
|
|
JSSharpObjectMap sharpObjectMap;
|
2011-03-29 15:46:51 -07:00
|
|
|
js::BusyArraysSet busyArrays;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
|
|
|
|
JSArgumentFormatMap *argumentFormatMap;
|
|
|
|
|
2010-10-26 12:07:26 -07:00
|
|
|
/* Last message string and log file for debugging. */
|
2007-03-22 10:30:00 -07:00
|
|
|
char *lastMessage;
|
|
|
|
|
2008-01-03 01:28:40 -08:00
|
|
|
/* Per-context optional error reporter. */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSErrorReporter errorReporter;
|
|
|
|
|
2009-02-10 14:07:01 -08:00
|
|
|
/* Branch callback. */
|
2008-01-03 01:28:40 -08:00
|
|
|
JSOperationCallback operationCallback;
|
|
|
|
|
2008-10-11 10:35:39 -07:00
|
|
|
/* Client opaque pointers. */
|
2007-03-22 10:30:00 -07:00
|
|
|
void *data;
|
2008-10-11 10:35:39 -07:00
|
|
|
void *data2;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-13 15:53:50 -07:00
|
|
|
inline js::RegExpStatics *regExpStatics();
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2012-07-09 11:54:28 -07:00
|
|
|
js::frontend::ParseMapPool &parseMapPool() {
|
2011-06-24 14:22:30 -07:00
|
|
|
JS_ASSERT(parseMapPool_);
|
|
|
|
return *parseMapPool_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool ensureParseMapPool();
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* The default script compilation version can be set iff there is no code running.
|
|
|
|
* This typically occurs via the JSAPI right after a context is constructed.
|
|
|
|
*/
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool canSetDefaultVersion() const;
|
2010-09-13 09:38:22 -07:00
|
|
|
|
|
|
|
/* Force a version for future script compilation. */
|
2011-10-04 07:06:54 -07:00
|
|
|
inline void overrideVersion(JSVersion newVersion);
|
2010-09-13 09:38:22 -07:00
|
|
|
|
|
|
|
/* Set the default script compilation version. */
|
2010-11-15 13:35:20 -08:00
|
|
|
void setDefaultVersion(JSVersion version) {
|
|
|
|
defaultVersion = version;
|
|
|
|
}
|
2010-09-13 09:38:22 -07:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
void clearVersionOverride() { hasVersionOverride = false; }
|
|
|
|
JSVersion getDefaultVersion() const { return defaultVersion; }
|
|
|
|
bool isVersionOverridden() const { return hasVersionOverride; }
|
|
|
|
|
|
|
|
JSVersion getVersionOverride() const {
|
|
|
|
JS_ASSERT(isVersionOverridden());
|
|
|
|
return versionOverride;
|
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* Set the default version if possible; otherwise, force the version.
|
|
|
|
* Return whether an override occurred.
|
|
|
|
*/
|
2011-10-04 07:06:54 -07:00
|
|
|
inline bool maybeOverrideVersion(JSVersion newVersion);
|
2010-09-13 09:38:22 -07:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/*
|
2011-04-13 09:27:37 -07:00
|
|
|
* If there is no code on the stack, turn the override version into the
|
|
|
|
* default version.
|
2011-01-27 02:54:58 -08:00
|
|
|
*/
|
|
|
|
void maybeMigrateVersionOverride() {
|
2011-05-13 08:56:26 -07:00
|
|
|
JS_ASSERT(stack.empty());
|
|
|
|
if (JS_UNLIKELY(isVersionOverridden())) {
|
|
|
|
defaultVersion = versionOverride;
|
|
|
|
clearVersionOverride();
|
|
|
|
}
|
2011-01-27 02:54:58 -08:00
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* Return:
|
|
|
|
* - The override version, if there is an override version.
|
2011-02-17 16:17:45 -08:00
|
|
|
* - The newest scripted frame's version, if there is such a frame.
|
2011-09-06 22:50:26 -07:00
|
|
|
* - The default version.
|
2010-09-13 09:38:22 -07:00
|
|
|
*
|
2011-01-05 18:44:30 -08:00
|
|
|
* Note: if this ever shows up in a profile, just add caching!
|
2010-09-13 09:38:22 -07:00
|
|
|
*/
|
2011-10-04 07:06:54 -07:00
|
|
|
inline JSVersion findVersion() const;
|
2010-09-13 09:38:22 -07:00
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
void setRunOptions(unsigned ropts) {
|
2011-01-27 02:54:58 -08:00
|
|
|
JS_ASSERT((ropts & JSRUNOPTION_MASK) == ropts);
|
|
|
|
runOptions = ropts;
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/* Note: may override the version. */
|
2012-02-28 15:11:11 -08:00
|
|
|
inline void setCompileOptions(unsigned newcopts);
|
2010-11-15 13:35:20 -08:00
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned getRunOptions() const { return runOptions; }
|
|
|
|
inline unsigned getCompileOptions() const;
|
|
|
|
inline unsigned allOptions() const;
|
2011-01-27 02:54:58 -08:00
|
|
|
|
2012-02-28 15:11:11 -08:00
|
|
|
bool hasRunOption(unsigned ropt) const {
|
2011-01-27 02:54:58 -08:00
|
|
|
JS_ASSERT((ropt & JSRUNOPTION_MASK) == ropt);
|
|
|
|
return !!(runOptions & ropt);
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
bool hasStrictOption() const { return hasRunOption(JSOPTION_STRICT); }
|
|
|
|
bool hasWErrorOption() const { return hasRunOption(JSOPTION_WERROR); }
|
|
|
|
bool hasAtLineOption() const { return hasRunOption(JSOPTION_ATLINE); }
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
js::LifoAlloc &tempLifoAlloc() { return runtime->tempLifoAlloc; }
|
2011-09-22 13:22:30 -07:00
|
|
|
inline js::LifoAlloc &typeLifoAlloc();
|
2011-04-13 09:27:37 -07:00
|
|
|
|
2012-05-18 01:29:40 -07:00
|
|
|
inline js::PropertyTree &propertyTree();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2010-08-30 11:46:18 -07:00
|
|
|
unsigned outstandingRequests;/* number of JS_BeginRequest calls
|
|
|
|
without the corresponding
|
|
|
|
JS_EndRequest. */
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-09-25 09:13:31 -07:00
|
|
|
/* Stored here to avoid passing it around as a parameter. */
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned resolveFlags;
|
2009-02-03 16:25:12 -08:00
|
|
|
|
2010-03-18 08:27:26 -07:00
|
|
|
/* Random number generator state, used by jsmath.cpp. */
|
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-08 19:54:10 -08:00
|
|
|
int64_t rngSeed;
|
2010-03-18 08:27:26 -07:00
|
|
|
|
2011-07-19 09:00:43 -07:00
|
|
|
/* Location to stash the iteration value between JSOP_MOREITER and JSOP_ITERNEXT. */
|
2010-07-14 23:19:36 -07:00
|
|
|
js::Value iterValue;
|
2010-05-07 17:52:52 -07:00
|
|
|
|
2010-09-15 22:27:17 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
bool methodJitEnabled;
|
2011-04-13 09:27:37 -07:00
|
|
|
|
2012-05-03 00:12:47 -07:00
|
|
|
js::mjit::JaegerRuntime &jaegerRuntime() { return runtime->jaegerRuntime(); }
|
2009-02-03 16:25:12 -08:00
|
|
|
#endif
|
2010-09-15 22:27:17 -07:00
|
|
|
|
2011-04-01 17:26:34 -07:00
|
|
|
bool inferenceEnabled;
|
|
|
|
|
2011-06-02 10:40:27 -07:00
|
|
|
bool typeInferenceEnabled() { return inferenceEnabled; }
|
|
|
|
|
2010-09-15 22:27:17 -07:00
|
|
|
/* Caller must be holding runtime->gcLock. */
|
|
|
|
void updateJITEnabled();
|
2009-07-16 18:36:19 -07:00
|
|
|
|
2010-08-09 13:38:13 -07:00
|
|
|
#ifdef MOZ_TRACE_JSCALLS
|
|
|
|
/* Function entry/exit debugging callback. */
|
|
|
|
JSFunctionCallback functionCallback;
|
|
|
|
|
|
|
|
void doFunctionCallback(const JSFunction *fun,
|
|
|
|
const JSScript *scr,
|
2010-09-20 12:43:51 -07:00
|
|
|
int entering) const
|
2010-08-09 13:38:13 -07:00
|
|
|
{
|
|
|
|
if (functionCallback)
|
|
|
|
functionCallback(fun, scr, this, entering);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-26 17:00:28 -07:00
|
|
|
DSTOffsetCache dstOffsetCache;
|
|
|
|
|
2010-06-03 21:41:01 -07:00
|
|
|
/* List of currently active non-escaping enumerators (for-in). */
|
2012-07-03 14:34:40 -07:00
|
|
|
js::PropertyIteratorObject *enumerators;
|
2010-06-03 21:41:01 -07:00
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
private:
|
2012-02-23 13:59:10 -08:00
|
|
|
/* Innermost-executing generator or null if no generator are executing. */
|
|
|
|
JSGenerator *innermostGenerator_;
|
2010-03-03 17:52:26 -08:00
|
|
|
public:
|
2012-02-23 13:59:10 -08:00
|
|
|
JSGenerator *innermostGenerator() const { return innermostGenerator_; }
|
|
|
|
void enterGenerator(JSGenerator *gen);
|
|
|
|
void leaveGenerator(JSGenerator *gen);
|
2010-03-03 17:52:26 -08:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* malloc_(size_t bytes) {
|
|
|
|
return runtime->malloc_(bytes, this);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
|
|
|
|
2009-09-19 02:40:43 -07:00
|
|
|
inline void* mallocNoReport(size_t bytes) {
|
|
|
|
JS_ASSERT(bytes != 0);
|
2011-03-31 01:14:12 -07:00
|
|
|
return runtime->malloc_(bytes, NULL);
|
2009-09-19 02:40:43 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* calloc_(size_t bytes) {
|
|
|
|
return runtime->calloc_(bytes, this);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* realloc_(void* p, size_t bytes) {
|
|
|
|
return runtime->realloc_(p, bytes, this);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void* realloc_(void* p, size_t oldBytes, size_t newBytes) {
|
|
|
|
return runtime->realloc_(p, oldBytes, newBytes, this);
|
2010-12-08 16:34:38 -08:00
|
|
|
}
|
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
inline void free_(void* p) {
|
|
|
|
runtime->free_(p);
|
2009-07-27 21:10:12 -07:00
|
|
|
}
|
2009-09-01 18:46:19 -07:00
|
|
|
|
2011-03-31 01:14:12 -07:00
|
|
|
JS_DECLARE_NEW_METHODS(malloc_, inline)
|
|
|
|
JS_DECLARE_DELETE_METHODS(free_, inline)
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2010-02-19 09:44:23 -08:00
|
|
|
void purge();
|
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
bool isExceptionPending() {
|
|
|
|
return throwing;
|
|
|
|
}
|
2010-11-15 19:40:26 -08:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
js::Value getPendingException() {
|
|
|
|
JS_ASSERT(throwing);
|
|
|
|
return exception;
|
|
|
|
}
|
2010-07-28 11:20:19 -07:00
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
void setPendingException(js::Value v);
|
|
|
|
|
|
|
|
void clearPendingException() {
|
|
|
|
this->throwing = false;
|
|
|
|
this->exception.setUndefined();
|
|
|
|
}
|
|
|
|
|
2011-06-14 18:39:53 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Controls whether a quadratic-complexity assertion is performed during
|
2011-12-20 17:42:45 -08:00
|
|
|
* stack iteration; defaults to true.
|
2011-06-14 18:39:53 -07:00
|
|
|
*/
|
|
|
|
bool stackIterAssertionEnabled;
|
|
|
|
#endif
|
|
|
|
|
2011-12-20 17:42:45 -08:00
|
|
|
/*
|
|
|
|
* Count of currently active compilations.
|
|
|
|
* When there are compilations active for the context, the GC must not
|
|
|
|
* purge the ParseMapPool.
|
|
|
|
*/
|
|
|
|
unsigned activeCompilations;
|
|
|
|
|
2011-07-07 15:40:33 -07:00
|
|
|
/*
|
|
|
|
* See JS_SetTrustedPrincipals in jsapi.h.
|
|
|
|
* Note: !cx->compartment is treated as trusted.
|
|
|
|
*/
|
|
|
|
bool runningWithTrustedPrincipals() const;
|
|
|
|
|
2011-12-01 19:08:20 -08:00
|
|
|
JS_FRIEND_API(size_t) sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf) const;
|
|
|
|
|
2011-08-23 12:42:17 -07:00
|
|
|
static inline JSContext *fromLinkField(JSCList *link) {
|
|
|
|
JS_ASSERT(link);
|
|
|
|
return reinterpret_cast<JSContext *>(uintptr_t(link) - offsetof(JSContext, link));
|
|
|
|
}
|
|
|
|
|
2012-02-15 17:16:53 -08:00
|
|
|
void mark(JSTracer *trc);
|
|
|
|
|
2010-12-29 16:25:04 -08:00
|
|
|
private:
|
2010-07-28 11:20:19 -07:00
|
|
|
/*
|
|
|
|
* The allocation code calls the function to indicate either OOM failure
|
|
|
|
* when p is null or that a memory pressure counter has reached some
|
|
|
|
* threshold when p is not null. The function takes the pointer and not
|
|
|
|
* a boolean flag to minimize the amount of code in its inlined callers.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void) checkMallocGCPressure(void *p);
|
2010-11-15 19:40:26 -08:00
|
|
|
}; /* struct JSContext */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-13 09:27:37 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
struct AutoResolving {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
|
|
|
LOOKUP,
|
|
|
|
WATCH
|
|
|
|
};
|
|
|
|
|
2012-07-10 18:17:29 -07:00
|
|
|
AutoResolving(JSContext *cx, HandleObject obj, HandleId id, Kind kind = LOOKUP
|
2011-03-07 14:00:00 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: context(cx), object(obj), id(id), kind(kind), link(cx->resolvingList)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_ASSERT(obj);
|
|
|
|
cx->resolvingList = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoResolving() {
|
|
|
|
JS_ASSERT(context->resolvingList == this);
|
|
|
|
context->resolvingList = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool alreadyStarted() const {
|
|
|
|
return link && alreadyStartedSlow();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool alreadyStartedSlow() const;
|
|
|
|
|
|
|
|
JSContext *const context;
|
2012-07-10 18:17:29 -07:00
|
|
|
HandleObject object;
|
|
|
|
HandleId id;
|
2011-03-07 14:00:00 -08:00
|
|
|
Kind const kind;
|
|
|
|
AutoResolving *const link;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-05-14 16:53:30 -07:00
|
|
|
#if JS_HAS_XML_SUPPORT
|
2010-01-11 09:52:21 -08:00
|
|
|
class AutoXMLRooter : private AutoGCRooter {
|
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
AutoXMLRooter(JSContext *cx, JSXML *xml
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-01-11 09:52:21 -08:00
|
|
|
: AutoGCRooter(cx, XML), xml(xml)
|
|
|
|
{
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-01-11 09:52:21 -08:00
|
|
|
JS_ASSERT(xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSXML * const xml;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-01-11 09:52:21 -08:00
|
|
|
};
|
|
|
|
#endif /* JS_HAS_XML_SUPPORT */
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
# define JS_LOCK_GC(rt) PR_Lock((rt)->gcLock)
|
|
|
|
# define JS_UNLOCK_GC(rt) PR_Unlock((rt)->gcLock)
|
|
|
|
#else
|
2012-06-13 02:27:45 -07:00
|
|
|
# define JS_LOCK_GC(rt) do { } while (0)
|
|
|
|
# define JS_UNLOCK_GC(rt) do { } while (0)
|
2011-07-18 14:54:48 -07:00
|
|
|
#endif
|
|
|
|
|
2012-02-24 03:03:28 -08:00
|
|
|
class AutoLockGC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoLockGC(JSRuntime *rt = NULL
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: runtime(rt)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-03-12 18:12:54 -07:00
|
|
|
// Avoid MSVC warning C4390 for non-threadsafe builds.
|
2012-02-24 03:03:28 -08:00
|
|
|
if (rt)
|
|
|
|
JS_LOCK_GC(rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoLockGC()
|
|
|
|
{
|
|
|
|
if (runtime)
|
|
|
|
JS_UNLOCK_GC(runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool locked() const {
|
|
|
|
return !!runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lock(JSRuntime *rt) {
|
|
|
|
JS_ASSERT(rt);
|
|
|
|
JS_ASSERT(!runtime);
|
|
|
|
runtime = rt;
|
|
|
|
JS_LOCK_GC(rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSRuntime *runtime;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
class AutoUnlockGC {
|
2011-01-05 14:50:30 -08:00
|
|
|
private:
|
2012-06-11 17:17:19 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2010-04-08 05:54:18 -07:00
|
|
|
JSRuntime *rt;
|
2012-06-11 17:17:19 -07:00
|
|
|
#endif
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoUnlockGC(JSRuntime *rt
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-06-11 17:17:19 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-01-05 14:50:30 -08:00
|
|
|
: rt(rt)
|
2012-06-11 17:17:19 -07:00
|
|
|
#endif
|
2011-01-05 14:50:30 -08:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_UNLOCK_GC(rt);
|
|
|
|
}
|
2010-04-08 05:54:18 -07:00
|
|
|
~AutoUnlockGC() { JS_LOCK_GC(rt); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutoKeepAtoms {
|
|
|
|
JSRuntime *rt;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoKeepAtoms(JSRuntime *rt
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: rt(rt)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_KEEP_ATOMS(rt);
|
|
|
|
}
|
2010-04-08 05:54:18 -07:00
|
|
|
~AutoKeepAtoms() { JS_UNKEEP_ATOMS(rt); }
|
|
|
|
};
|
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
class AutoReleasePtr {
|
|
|
|
JSContext *cx;
|
|
|
|
void *ptr;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2011-12-28 06:09:07 -08:00
|
|
|
AutoReleasePtr(const AutoReleasePtr &other) MOZ_DELETE;
|
|
|
|
AutoReleasePtr operator=(const AutoReleasePtr &other) MOZ_DELETE;
|
2011-01-05 14:50:30 -08:00
|
|
|
|
2010-08-11 13:30:07 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoReleasePtr(JSContext *cx, void *ptr
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: cx(cx), ptr(ptr)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2011-03-31 01:14:12 -07:00
|
|
|
~AutoReleasePtr() { cx->free_(ptr); }
|
2010-08-11 13:30:07 -07:00
|
|
|
};
|
|
|
|
|
2010-10-19 09:00:51 -07:00
|
|
|
/*
|
|
|
|
* FIXME: bug 602774: cleaner API for AutoReleaseNullablePtr
|
|
|
|
*/
|
|
|
|
class AutoReleaseNullablePtr {
|
|
|
|
JSContext *cx;
|
|
|
|
void *ptr;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
2011-12-28 06:09:07 -08:00
|
|
|
AutoReleaseNullablePtr(const AutoReleaseNullablePtr &other) MOZ_DELETE;
|
|
|
|
AutoReleaseNullablePtr operator=(const AutoReleaseNullablePtr &other) MOZ_DELETE;
|
2011-01-05 14:50:30 -08:00
|
|
|
|
2010-10-19 09:00:51 -07:00
|
|
|
public:
|
2011-01-05 14:50:30 -08:00
|
|
|
explicit AutoReleaseNullablePtr(JSContext *cx, void *ptr
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: cx(cx), ptr(ptr)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2010-10-19 09:00:51 -07:00
|
|
|
void reset(void *ptr2) {
|
|
|
|
if (ptr)
|
2011-03-31 01:14:12 -07:00
|
|
|
cx->free_(ptr);
|
2010-10-19 09:00:51 -07:00
|
|
|
ptr = ptr2;
|
|
|
|
}
|
2011-03-31 01:14:12 -07:00
|
|
|
~AutoReleaseNullablePtr() { if (ptr) cx->free_(ptr); }
|
2010-10-19 09:00:51 -07:00
|
|
|
};
|
|
|
|
|
2010-03-26 21:53:40 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2008-09-25 09:13:31 -07:00
|
|
|
class JSAutoResolveFlags
|
|
|
|
{
|
|
|
|
public:
|
2012-02-28 15:11:11 -08:00
|
|
|
JSAutoResolveFlags(JSContext *cx, unsigned flags
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-01-11 09:52:21 -08:00
|
|
|
: mContext(cx), mSaved(cx->resolveFlags)
|
|
|
|
{
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2008-09-25 09:13:31 -07:00
|
|
|
cx->resolveFlags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
~JSAutoResolveFlags() { mContext->resolveFlags = mSaved; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSContext *mContext;
|
2012-02-28 15:11:11 -08:00
|
|
|
unsigned mSaved;
|
2009-09-27 23:17:47 -07:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2008-09-25 09:13:31 -07:00
|
|
|
};
|
2009-01-23 14:33:42 -08:00
|
|
|
|
2010-05-13 10:50:43 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-08-23 12:42:17 -07:00
|
|
|
/*
|
2012-02-29 04:18:16 -08:00
|
|
|
* Enumerate all contexts in a runtime.
|
2011-08-23 12:42:17 -07:00
|
|
|
*/
|
2012-02-29 04:18:16 -08:00
|
|
|
class ContextIter {
|
2011-08-23 12:42:17 -07:00
|
|
|
JSCList *begin;
|
|
|
|
JSCList *end;
|
|
|
|
|
|
|
|
public:
|
2012-02-29 04:18:16 -08:00
|
|
|
explicit ContextIter(JSRuntime *rt) {
|
|
|
|
end = &rt->contextList;
|
2011-08-23 12:42:17 -07:00
|
|
|
begin = end->next;
|
|
|
|
}
|
|
|
|
|
2012-02-29 04:18:16 -08:00
|
|
|
bool done() const {
|
|
|
|
return begin == end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void next() {
|
|
|
|
JS_ASSERT(!done());
|
|
|
|
begin = begin->next;
|
|
|
|
}
|
2011-08-23 12:42:17 -07:00
|
|
|
|
2012-02-29 04:18:16 -08:00
|
|
|
JSContext *get() const {
|
|
|
|
JS_ASSERT(!done());
|
2011-08-23 12:42:17 -07:00
|
|
|
return JSContext::fromLinkField(begin);
|
|
|
|
}
|
2012-02-29 04:18:16 -08:00
|
|
|
|
|
|
|
operator JSContext *() const {
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *operator ->() const {
|
|
|
|
return get();
|
|
|
|
}
|
2011-08-23 12:42:17 -07:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Create and destroy functions for JSContext, which is manually allocated
|
|
|
|
* and exclusively owned.
|
|
|
|
*/
|
|
|
|
extern JSContext *
|
2012-03-28 03:13:30 -07:00
|
|
|
NewContext(JSRuntime *rt, size_t stackChunkSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-28 03:13:30 -07:00
|
|
|
enum DestroyContextMode {
|
|
|
|
DCM_NO_GC,
|
|
|
|
DCM_FORCE_GC,
|
|
|
|
DCM_NEW_FAILED
|
|
|
|
};
|
2011-07-18 14:54:48 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern void
|
2012-03-28 03:13:30 -07:00
|
|
|
DestroyContext(JSContext *cx, DestroyContextMode mode);
|
|
|
|
|
|
|
|
} /* namespace js */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef va_start
|
|
|
|
extern JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
js_ReportErrorVA(JSContext *cx, unsigned flags, const char *format, va_list ap);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback,
|
|
|
|
void *userRef, const unsigned errorNumber,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSBool charArgs, va_list ap);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
2012-02-28 15:11:11 -08:00
|
|
|
void *userRef, const unsigned errorNumber,
|
2007-03-22 10:30:00 -07:00
|
|
|
char **message, JSErrorReport *reportp,
|
2009-11-19 09:23:20 -08:00
|
|
|
bool charArgs, va_list ap);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-03-06 11:38:44 -08:00
|
|
|
namespace js {
|
|
|
|
|
|
|
|
/* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
|
|
|
|
extern void
|
2012-07-23 13:37:31 -07:00
|
|
|
ReportUsageError(JSContext *cx, HandleObject callee, const char *msg);
|
2012-03-06 11:38:44 -08:00
|
|
|
|
|
|
|
} /* namespace js */
|
|
|
|
|
2010-07-28 11:20:19 -07:00
|
|
|
extern void
|
|
|
|
js_ReportOutOfMemory(JSContext *cx);
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
extern JS_FRIEND_API(void)
|
2008-03-12 16:07:47 -07:00
|
|
|
js_ReportAllocationOverflow(JSContext *cx);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Report an exception using a previously composed JSErrorReport.
|
|
|
|
* XXXbe remove from "friend" API
|
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_ReportIsNotDefined(JSContext *cx, const char *name);
|
|
|
|
|
2007-11-12 21:23:22 -08:00
|
|
|
/*
|
|
|
|
* Report an attempt to access the property of a null or undefined value (v).
|
|
|
|
*/
|
|
|
|
extern JSBool
|
2012-08-12 18:50:49 -07:00
|
|
|
js_ReportIsNullOrUndefined(JSContext *cx, int spindex, js::HandleValue v,
|
|
|
|
js::HandleString fallback);
|
2007-11-12 21:23:22 -08:00
|
|
|
|
2008-08-08 09:02:50 -07:00
|
|
|
extern void
|
2012-08-12 18:50:49 -07:00
|
|
|
js_ReportMissingArg(JSContext *cx, js::HandleValue v, unsigned arg);
|
2008-08-08 09:02:50 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Report error using js_DecompileValueGenerator(cx, spindex, v, fallback) as
|
|
|
|
* the first argument for the error message. If the error message has less
|
|
|
|
* then 3 arguments, use null for arg1 or arg2.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
2012-02-28 15:11:11 -08:00
|
|
|
js_ReportValueErrorFlags(JSContext *cx, unsigned flags, const unsigned errorNumber,
|
2012-08-12 18:50:49 -07:00
|
|
|
int spindex, js::HandleValue v, js::HandleString fallback,
|
2007-03-22 10:30:00 -07:00
|
|
|
const char *arg1, const char *arg2);
|
|
|
|
|
|
|
|
#define js_ReportValueError(cx,errorNumber,spindex,v,fallback) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, NULL, NULL))
|
|
|
|
|
|
|
|
#define js_ReportValueError2(cx,errorNumber,spindex,v,fallback,arg1) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, arg1, NULL))
|
|
|
|
|
|
|
|
#define js_ReportValueError3(cx,errorNumber,spindex,v,fallback,arg1,arg2) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, arg1, arg2))
|
|
|
|
|
|
|
|
extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
|
|
|
|
|
2010-07-23 09:32:50 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2011-07-18 14:54:48 -07:00
|
|
|
# define JS_ASSERT_REQUEST_DEPTH(cx) JS_ASSERT((cx)->runtime->requestDepth >= 1)
|
2010-07-23 09:32:50 -07:00
|
|
|
#else
|
|
|
|
# define JS_ASSERT_REQUEST_DEPTH(cx) ((void) 0)
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2009-02-10 14:07:01 -08:00
|
|
|
* Invoke the operation callback and return false if the current execution
|
|
|
|
* is to be terminated.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
extern JSBool
|
2009-02-10 14:07:01 -08:00
|
|
|
js_InvokeOperationCallback(JSContext *cx);
|
2009-01-14 09:23:51 -08:00
|
|
|
|
2010-06-07 23:55:13 -07:00
|
|
|
extern JSBool
|
|
|
|
js_HandleExecutionInterrupt(JSContext *cx);
|
|
|
|
|
2009-03-20 17:07:30 -07:00
|
|
|
extern jsbytecode*
|
|
|
|
js_GetCurrentBytecodePC(JSContext* cx);
|
|
|
|
|
2010-09-20 12:43:53 -07:00
|
|
|
extern JSScript *
|
|
|
|
js_GetCurrentScript(JSContext* cx);
|
|
|
|
|
2012-04-11 17:03:07 -07:00
|
|
|
/*
|
|
|
|
* If the operation callback flag was set, call the operation callback.
|
|
|
|
* This macro can run the full GC. Return true if it is OK to continue and
|
|
|
|
* false otherwise.
|
|
|
|
*/
|
|
|
|
static MOZ_ALWAYS_INLINE bool
|
|
|
|
JS_CHECK_OPERATION_LIMIT(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT_REQUEST_DEPTH(cx);
|
|
|
|
return !cx->runtime->interrupt || js_InvokeOperationCallback(cx);
|
|
|
|
}
|
|
|
|
|
2010-01-22 14:49:18 -08:00
|
|
|
namespace js {
|
|
|
|
|
2011-03-26 19:07:13 -07:00
|
|
|
#ifdef JS_METHODJIT
|
|
|
|
namespace mjit {
|
2011-08-01 09:09:39 -07:00
|
|
|
void ExpandInlineFrames(JSCompartment *compartment);
|
2011-03-26 19:07:13 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
2010-01-22 14:49:18 -08:00
|
|
|
|
2011-08-01 09:09:39 -07:00
|
|
|
/* How much expansion of inlined frames to do when inspecting the stack. */
|
|
|
|
enum FrameExpandKind {
|
|
|
|
FRAME_EXPAND_NONE = 0,
|
|
|
|
FRAME_EXPAND_ALL = 1
|
|
|
|
};
|
|
|
|
|
2009-10-20 15:08:28 -07:00
|
|
|
namespace js {
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(Value *vec, size_t len)
|
|
|
|
{
|
|
|
|
PodZero(vec, len);
|
|
|
|
}
|
2011-03-26 19:07:13 -07:00
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(Value *beg, Value *end)
|
|
|
|
{
|
|
|
|
PodZero(beg, end - beg);
|
2009-02-18 10:47:16 -08:00
|
|
|
}
|
2008-12-09 08:38:32 -08:00
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(jsid *beg, jsid *end)
|
|
|
|
{
|
|
|
|
for (jsid *id = beg; id != end; ++id)
|
|
|
|
*id = INT_TO_JSID(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(jsid *vec, size_t len)
|
|
|
|
{
|
|
|
|
MakeRangeGCSafe(vec, vec + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
2012-07-04 19:33:41 -07:00
|
|
|
MakeRangeGCSafe(Shape **beg, Shape **end)
|
2011-10-04 07:06:54 -07:00
|
|
|
{
|
|
|
|
PodZero(beg, end - beg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
2012-07-04 19:33:41 -07:00
|
|
|
MakeRangeGCSafe(Shape **vec, size_t len)
|
2011-10-04 07:06:54 -07:00
|
|
|
{
|
|
|
|
PodZero(vec, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToUndefined(Value *beg, Value *end)
|
|
|
|
{
|
|
|
|
for (Value *v = beg; v != end; ++v)
|
|
|
|
v->setUndefined();
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToUndefined(Value *vec, size_t len)
|
|
|
|
{
|
|
|
|
SetValueRangeToUndefined(vec, vec + len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToNull(Value *beg, Value *end)
|
|
|
|
{
|
|
|
|
for (Value *v = beg; v != end; ++v)
|
|
|
|
v->setNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
SetValueRangeToNull(Value *vec, size_t len)
|
|
|
|
{
|
|
|
|
SetValueRangeToNull(vec, vec + len);
|
|
|
|
}
|
2009-10-20 15:08:28 -07:00
|
|
|
|
2011-08-23 12:45:21 -07:00
|
|
|
class AutoObjectVector : public AutoVectorRooter<JSObject *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoObjectVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<JSObject *>(cx, OBJVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-08-12 18:50:49 -07:00
|
|
|
class AutoStringVector : public AutoVectorRooter<JSString *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoStringVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<JSString *>(cx, STRINGVECTOR)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-07-04 19:33:41 -07:00
|
|
|
class AutoShapeVector : public AutoVectorRooter<Shape *>
|
2011-02-07 12:06:32 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoShapeVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-07-04 19:33:41 -07:00
|
|
|
: AutoVectorRooter<Shape *>(cx, SHAPEVECTOR)
|
2011-02-07 12:06:32 -08:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2010-03-01 14:46:15 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-04-24 07:56:56 -07:00
|
|
|
class AutoValueArray : public AutoGCRooter
|
|
|
|
{
|
2012-02-15 17:16:53 -08:00
|
|
|
js::Value *start_;
|
2011-04-24 07:56:56 -07:00
|
|
|
unsigned length_;
|
2012-04-30 17:10:30 -07:00
|
|
|
SkipRoot skip;
|
2011-04-24 07:56:56 -07:00
|
|
|
|
|
|
|
public:
|
2012-02-15 17:16:53 -08:00
|
|
|
AutoValueArray(JSContext *cx, js::Value *start, unsigned length
|
2011-04-24 07:56:56 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
2012-04-30 17:10:30 -07:00
|
|
|
: AutoGCRooter(cx, VALARRAY), start_(start), length_(length), skip(cx, start, length)
|
2011-04-24 07:56:56 -07:00
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
2012-02-15 17:16:53 -08:00
|
|
|
Value *start() { return start_; }
|
2011-04-24 07:56:56 -07:00
|
|
|
unsigned length() const { return length_; }
|
|
|
|
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-06-17 10:14:30 -07:00
|
|
|
/*
|
|
|
|
* Allocation policy that uses JSRuntime::malloc_ and friends, so that
|
|
|
|
* memory pressure is properly accounted for. This is suitable for
|
|
|
|
* long-lived objects owned by the JSRuntime.
|
|
|
|
*
|
|
|
|
* Since it doesn't hold a JSContext (those may not live long enough), it
|
|
|
|
* can't report out-of-memory conditions itself; the caller must check for
|
|
|
|
* OOM and take the appropriate action.
|
|
|
|
*
|
|
|
|
* FIXME bug 647103 - replace these *AllocPolicy names.
|
|
|
|
*/
|
|
|
|
class RuntimeAllocPolicy
|
|
|
|
{
|
|
|
|
JSRuntime *const runtime;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RuntimeAllocPolicy(JSRuntime *rt) : runtime(rt) {}
|
|
|
|
RuntimeAllocPolicy(JSContext *cx) : runtime(cx->runtime) {}
|
|
|
|
void *malloc_(size_t bytes) { return runtime->malloc_(bytes); }
|
|
|
|
void *realloc_(void *p, size_t bytes) { return runtime->realloc_(p, bytes); }
|
|
|
|
void free_(void *p) { runtime->free_(p); }
|
|
|
|
void reportAllocOverflow() const {}
|
|
|
|
};
|
|
|
|
|
2012-04-03 21:03:30 -07:00
|
|
|
/*
|
|
|
|
* FIXME bug 647103 - replace these *AllocPolicy names.
|
|
|
|
*/
|
|
|
|
class ContextAllocPolicy
|
|
|
|
{
|
|
|
|
JSContext *const cx;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ContextAllocPolicy(JSContext *cx) : cx(cx) {}
|
|
|
|
JSContext *context() const { return cx; }
|
|
|
|
void *malloc_(size_t bytes) { return cx->malloc_(bytes); }
|
|
|
|
void *realloc_(void *p, size_t oldBytes, size_t bytes) { return cx->realloc_(p, oldBytes, bytes); }
|
|
|
|
void free_(void *p) { cx->free_(p); }
|
|
|
|
void reportAllocOverflow() const { js_ReportAllocationOverflow(cx); }
|
|
|
|
};
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2010-03-04 20:44:09 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* jscntxt_h___ */
|