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:
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
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 "jsdhash.h"
|
|
|
|
#include "jsgc.h"
|
2010-06-07 02:17:15 -07:00
|
|
|
#include "jsgcchunk.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"
|
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
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
struct JSSharpObjectMap {
|
|
|
|
jsrefcount depth;
|
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 sharpgen;
|
2011-10-04 07:06:54 -07:00
|
|
|
JSHashTable *table;
|
|
|
|
};
|
|
|
|
|
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 {
|
2010-10-29 15:37:13 -07:00
|
|
|
class JaegerCompartment;
|
2010-08-11 11:23:29 -07:00
|
|
|
}
|
|
|
|
|
2011-06-14 19:21:47 -07:00
|
|
|
class WeakMapBase;
|
2011-11-22 14:41:43 -08:00
|
|
|
class InterpreterFrames;
|
2011-06-14 19:21:47 -07:00
|
|
|
|
2011-12-16 13:11:08 -08:00
|
|
|
class ScriptOpcodeCounts;
|
|
|
|
struct ScriptOpcodeCountsPair;
|
|
|
|
|
2012-01-27 15:32:53 -08:00
|
|
|
typedef HashMap<JSAtom *,
|
|
|
|
detail::RegExpCacheValue,
|
|
|
|
DefaultHasher<JSAtom *>,
|
|
|
|
RuntimeAllocPolicy> RegExpCache;
|
|
|
|
|
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;
|
|
|
|
JSObject *object;
|
|
|
|
};
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
typedef Vector<ScriptOpcodeCountsPair, 0, SystemAllocPolicy> ScriptOpcodeCountsVector;
|
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
|
|
|
|
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
|
|
|
|
2009-03-24 05:07:35 -07:00
|
|
|
/*
|
2011-07-18 14:54:48 -07:00
|
|
|
* Cycle collector uses this to communicate that the native stack of the
|
|
|
|
* GC thread should be scanned only if the thread have more than the given
|
|
|
|
* threshold of requests.
|
2009-03-24 05:07:35 -07:00
|
|
|
*/
|
2011-07-18 14:54:48 -07:00
|
|
|
unsigned requestThreshold;
|
2009-03-24 05:07:35 -07:00
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
ConservativeGCData()
|
2012-01-31 14:28:22 -08:00
|
|
|
: nativeStackTop(NULL), requestThreshold(0)
|
2011-07-18 14:54:48 -07:00
|
|
|
{}
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
} /* namespace js */
|
2012-01-24 17:32:30 -08:00
|
|
|
|
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. */
|
|
|
|
static const size_t TEMP_LIFO_ALLOC_PRIMARY_CHUNK_SIZE = 1 << 12;
|
|
|
|
js::LifoAlloc tempLifoAlloc;
|
|
|
|
|
|
|
|
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-01-27 15:32:53 -08:00
|
|
|
js::RegExpCache *reCache_;
|
2011-07-18 14:54:48 -07:00
|
|
|
|
|
|
|
JSC::ExecutableAllocator *createExecutableAllocator(JSContext *cx);
|
|
|
|
WTF::BumpPointerAllocator *createBumpPointerAllocator(JSContext *cx);
|
2012-01-27 15:32:53 -08:00
|
|
|
js::RegExpCache *createRegExpCache(JSContext *cx);
|
2011-07-18 14:54:48 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
JSC::ExecutableAllocator *getExecutableAllocator(JSContext *cx) {
|
|
|
|
return execAlloc_ ? execAlloc_ : createExecutableAllocator(cx);
|
|
|
|
}
|
|
|
|
WTF::BumpPointerAllocator *getBumpPointerAllocator(JSContext *cx) {
|
|
|
|
return bumpAlloc_ ? bumpAlloc_ : createBumpPointerAllocator(cx);
|
|
|
|
}
|
2012-01-27 15:32:53 -08:00
|
|
|
js::RegExpCache *maybeRegExpCache() {
|
|
|
|
return reCache_;
|
2011-07-18 14:54:48 -07:00
|
|
|
}
|
2012-01-27 15:32:53 -08:00
|
|
|
js::RegExpCache *getRegExpCache(JSContext *cx) {
|
|
|
|
return reCache_ ? reCache_ : createRegExpCache(cx);
|
2011-07-18 14:54:48 -07:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2010-07-19 13:36:49 -07:00
|
|
|
/* Compartment create/destroy callback. */
|
|
|
|
JSCompartmentCallback compartmentCallback;
|
|
|
|
|
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;
|
2007-03-22 10:30:00 -07:00
|
|
|
jsrefcount gcKeepAtoms;
|
2012-01-05 00:54:37 -08:00
|
|
|
size_t gcBytes;
|
|
|
|
size_t gcTriggerBytes;
|
2009-08-25 14:42:42 -07:00
|
|
|
size_t gcLastBytes;
|
|
|
|
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;
|
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 gcNumber;
|
2011-10-25 16:07:42 -07:00
|
|
|
js::GCMarker *gcIncrementalTracer;
|
2011-08-05 10:25:23 -07:00
|
|
|
void *gcVerifyData;
|
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;
|
|
|
|
int64_t gcJitReleaseTime;
|
2011-01-09 22:57:21 -08:00
|
|
|
JSGCMode gcMode;
|
2012-01-11 00:23:05 -08:00
|
|
|
volatile uintptr_t gcBarrierFailed;
|
|
|
|
volatile uintptr_t gcIsNeeded;
|
2011-06-14 19:21:47 -07:00
|
|
|
js::WeakMapBase *gcWeakMapList;
|
2011-08-23 17:35:09 -07:00
|
|
|
js::gcstats::Statistics gcStats;
|
|
|
|
|
|
|
|
/* 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-12-07 05:22:47 -08:00
|
|
|
/* Pre-allocated space for the GC mark stack. */
|
|
|
|
uintptr_t gcMarkStackArray[js::MARK_STACK_LENGTH];
|
2011-04-15 16:56:08 -07:00
|
|
|
|
2011-01-07 23:44:57 -08:00
|
|
|
/*
|
|
|
|
* Compartment that triggered GC. If more than one Compatment need GC,
|
2011-02-17 16:17:45 -08:00
|
|
|
* gcTriggerCompartment is reset to NULL and a global GC is performed.
|
2011-01-07 23:44:57 -08:00
|
|
|
*/
|
|
|
|
JSCompartment *gcTriggerCompartment;
|
|
|
|
|
|
|
|
/* Compartment that is currently involved in per-compartment GC */
|
|
|
|
JSCompartment *gcCurrentCompartment;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-07 17:31:24 -07:00
|
|
|
/*
|
|
|
|
* If this is non-NULL, all marked objects must belong to this compartment.
|
|
|
|
* This is used to look for compartment bugs.
|
|
|
|
*/
|
|
|
|
JSCompartment *gcCheckCompartment;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2010-10-07 13:43:52 -07:00
|
|
|
* We can pack these flags as only the GC thread writes to them. Atomic
|
|
|
|
* updates to packed bytes are not guaranteed, so stores issued by one
|
|
|
|
* thread may be lost due to unsynchronized read-modify-write cycles on
|
|
|
|
* other threads.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-08-30 11:46:18 -07:00
|
|
|
bool gcPoke;
|
|
|
|
bool gcMarkAndSweep;
|
|
|
|
bool gcRunning;
|
2009-07-27 14:29:02 -07:00
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* At this point, if gcZeal_ >= 2 then gcNextScheduled is reset to the
|
|
|
|
* value of gcZealFrequency. Otherwise, no additional GCs take place.
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
* Additionally, 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.
|
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;
|
|
|
|
bool gcDebugCompartmentGC;
|
|
|
|
|
|
|
|
int gcZeal() { return gcZeal_; }
|
|
|
|
|
|
|
|
bool needZealousGC() {
|
|
|
|
if (gcNextScheduled > 0 && --gcNextScheduled == 0) {
|
2011-08-05 10:25:23 -07:00
|
|
|
if (gcZeal() >= js::gc::ZealAllocThreshold && gcZeal() < js::gc::ZealVerifierThreshold)
|
2011-06-01 17:48:52 -07:00
|
|
|
gcNextScheduled = gcZealFrequency;
|
|
|
|
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
|
|
|
|
|
|
|
JSGCCallback gcCallback;
|
2011-11-09 13:32:17 -08:00
|
|
|
JSGCFinishedCallback gcFinishedCallback;
|
2009-10-18 08:40:19 -07:00
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
private:
|
2009-10-18 08:40:19 -07:00
|
|
|
/*
|
|
|
|
* Malloc counter to measure memory pressure for GC scheduling. It runs
|
|
|
|
* from gcMaxMallocBytes down to zero.
|
|
|
|
*/
|
2010-09-07 14:08:20 -07:00
|
|
|
volatile ptrdiff_t gcMallocBytes;
|
2010-08-19 12:28:12 -07:00
|
|
|
|
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
|
|
|
|
2011-12-16 13:11:08 -08:00
|
|
|
/* Strong references on scripts held for PCCount profiling API. */
|
|
|
|
js::ScriptOpcodeCountsVector *scriptPCCounters;
|
|
|
|
|
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
|
|
|
|
2011-08-14 21:12:48 -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
|
|
|
|
2007-06-14 23:44:18 -07:00
|
|
|
/* Per runtime debug hooks -- see jsprvtd.h and jsdbgapi.h. */
|
|
|
|
JSDebugHooks globalDebugHooks;
|
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
|
|
|
|
2011-12-16 13:11:08 -08:00
|
|
|
/* If true, new scripts must be created with PC counter information. */
|
|
|
|
bool profilingScripts;
|
|
|
|
|
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
|
|
|
|
2008-10-11 10:35:39 -07:00
|
|
|
/* Client opaque pointers */
|
2007-03-22 10:30:00 -07:00
|
|
|
void *data;
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/* These combine to interlock the GC and new requests. */
|
|
|
|
PRLock *gcLock;
|
|
|
|
|
2010-09-07 14:08:20 -07:00
|
|
|
js::GCHelperThread gcHelperThread;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* JS_THREADSAFE */
|
2011-08-03 17:43:39 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t debuggerMutations;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
2008-09-05 16:24:53 -07:00
|
|
|
* Security callbacks set on the runtime are used by each context unless
|
|
|
|
* an override is set on the context.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-09-05 16:24:53 -07:00
|
|
|
JSSecurityCallbacks *securityCallbacks;
|
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
|
|
|
*/
|
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 propertyRemovals;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* Number localization, used by jsnum.c */
|
|
|
|
const char *thousandsSeparator;
|
|
|
|
const char *decimalSeparator;
|
|
|
|
const char *numGrouping;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Weak references to lazily-created, well-known XML singletons.
|
|
|
|
*
|
|
|
|
* NB: Singleton objects must be carefully disconnected from the rest of
|
|
|
|
* the object graph usually associated with a JSContext's global object,
|
|
|
|
* including the set of standard class objects. See jsxml.c for details.
|
|
|
|
*/
|
|
|
|
JSObject *anynameObject;
|
|
|
|
JSObject *functionNamespaceObject;
|
|
|
|
|
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
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
/*
|
|
|
|
* The GSN cache is per thread since even multi-cx-per-thread embeddings
|
|
|
|
* do not interleave js_GetSrcNote calls.
|
|
|
|
*/
|
|
|
|
js::GSNCache gsnCache;
|
|
|
|
|
|
|
|
/* Property cache for faster call/get/set invocation. */
|
|
|
|
js::PropertyCache propertyCache;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2010-06-24 14:45:32 -07:00
|
|
|
JSWrapObjectCallback wrapObjectCallback;
|
2010-10-10 15:36:38 -07:00
|
|
|
JSPreWrapCallback preWrapObjectCallback;
|
2011-12-15 17:45:21 -08:00
|
|
|
js::PreserveWrapperCallback preserveWrapperCallback;
|
2010-06-24 14:45:32 -07:00
|
|
|
|
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
|
|
|
|
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; }
|
|
|
|
|
2011-06-20 14:44:26 -07:00
|
|
|
void setGCLastBytes(size_t lastBytes, JSGCInvocationKind gckind);
|
2012-01-05 00:54:37 -08:00
|
|
|
void reduceGCTriggerBytes(size_t amount);
|
2009-08-25 14:42:42 -07:00
|
|
|
|
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
|
|
|
|
2010-07-28 11:20:19 -07:00
|
|
|
bool isGCMallocLimitReached() const { return gcMallocBytes <= 0; }
|
|
|
|
|
2009-10-18 08:40:19 -07:00
|
|
|
void resetGCMallocBytes() { gcMallocBytes = ptrdiff_t(gcMaxMallocBytes); }
|
|
|
|
|
|
|
|
void setGCMaxMallocBytes(size_t value) {
|
|
|
|
/*
|
|
|
|
* For compatibility treat any value that exceeds PTRDIFF_T_MAX to
|
|
|
|
* mean that value.
|
|
|
|
*/
|
|
|
|
gcMaxMallocBytes = (ptrdiff_t(value) >= 0) ? value : size_t(-1) >> 1;
|
|
|
|
resetGCMallocBytes();
|
|
|
|
}
|
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);
|
2010-09-07 14:08:20 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The function must be called outside the GC lock.
|
|
|
|
*/
|
|
|
|
JS_FRIEND_API(void) onTooMuchMalloc();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
|
|
JS_FRIEND_API(void) triggerOperationCallback();
|
|
|
|
|
|
|
|
void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *normal, size_t *temporary,
|
|
|
|
size_t *regexpCode, size_t *stackCommitted);
|
|
|
|
|
|
|
|
void purge(JSContext *cx);
|
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-20 12:54:34 -08:00
|
|
|
extern const JSDebugHooks js_NullDebugHooks; /* defined in jsdbgapi.cpp */
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
namespace js {
|
|
|
|
|
2011-12-31 06:32:04 -08:00
|
|
|
template <typename T> class Root;
|
|
|
|
class CheckRoot;
|
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
struct AutoResolving;
|
2010-08-11 13:30:07 -07:00
|
|
|
|
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
|
|
|
OptionsHasXML(uint32_t options)
|
2010-09-13 09:38:22 -07:00
|
|
|
{
|
|
|
|
return !!(options & JSOPTION_XML);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
static const uint32_t mask = JSOPTION_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 {
|
2011-01-27 02:54:58 -08:00
|
|
|
static const uintN MASK = 0x0FFF; /* see JSVersion in jspubtd.h */
|
|
|
|
static const uintN HAS_XML = 0x1000; /* flag induced by XML option */
|
|
|
|
static const uintN FULL_MASK = 0x3FFF;
|
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
|
|
|
}
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
static inline bool
|
|
|
|
VersionHasXML(JSVersion version)
|
|
|
|
{
|
|
|
|
return !!(version & VersionFlags::HAS_XML);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return VersionHasXML(version) || VersionNumber(version) >= JSVERSION_1_6;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
static inline uintN
|
|
|
|
VersionFlagsToOptions(JSVersion version)
|
|
|
|
{
|
2011-06-21 09:53:19 -07:00
|
|
|
uintN copts = VersionHasXML(version) ? JSOPTION_XML : 0;
|
2011-01-27 02:54:58 -08:00
|
|
|
JS_ASSERT((copts & JSCOMPILEOPTION_MASK) == copts);
|
|
|
|
return copts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline JSVersion
|
|
|
|
OptionFlagsToVersion(uintN options, JSVersion version)
|
|
|
|
{
|
2012-01-15 00:13:08 -08:00
|
|
|
return VersionSetXML(version, OptionsHasXML(options));
|
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
|
|
|
|
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. */
|
|
|
|
JSBool throwing; /* is there a pending exception? */
|
|
|
|
js::Value exception; /* most-recently-thrown exception */
|
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
/* Per-context run options. */
|
|
|
|
uintN 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
|
|
|
|
|
|
|
/*
|
|
|
|
* True if generating an error, to prevent runaway recursion.
|
2010-07-15 17:58:36 -07:00
|
|
|
* NB: generatingError packs with throwing below.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
JSPackedBool generatingError;
|
|
|
|
|
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
|
|
|
|
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. */
|
|
|
|
js::ParseMapPool *parseMapPool_;
|
|
|
|
|
|
|
|
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:
|
2011-06-24 14:22:30 -07:00
|
|
|
js::ParseMapPool &parseMapPool() {
|
|
|
|
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
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
void setRunOptions(uintN ropts) {
|
|
|
|
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. */
|
2011-10-04 07:06:54 -07:00
|
|
|
inline void setCompileOptions(uintN newcopts);
|
2010-11-15 13:35:20 -08:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
uintN getRunOptions() const { return runOptions; }
|
2011-10-04 07:06:54 -07:00
|
|
|
inline uintN getCompileOptions() const;
|
|
|
|
inline uintN allOptions() const;
|
2011-01-27 02:54:58 -08:00
|
|
|
|
|
|
|
bool hasRunOption(uintN ropt) const {
|
|
|
|
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-11-08 13:28:49 -08:00
|
|
|
bool hasJITHardeningOption() const { return !hasRunOption(JSOPTION_SOFTEN); }
|
2011-01-27 02:54:58 -08:00
|
|
|
|
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
|
|
|
|
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
|
|
|
JSCList threadLinks; /* JSThread contextList linkage */
|
|
|
|
#endif
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
/* Stack of thread-stack-allocated GC roots. */
|
|
|
|
js::AutoGCRooter *autoGCRooters;
|
2007-06-14 23:44:18 -07:00
|
|
|
|
2011-12-31 06:32:04 -08:00
|
|
|
#ifdef JSGC_ROOT_ANALYSIS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stack allocated GC roots for stack GC heap pointers, which may be
|
|
|
|
* overwritten if moved during a GC.
|
|
|
|
*/
|
|
|
|
js::Root<js::gc::Cell*> *thingGCRooters[js::THING_ROOT_COUNT];
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Stack allocated list of stack locations which hold non-relocatable
|
|
|
|
* GC heap pointers (where the target is rooted somewhere else) or integer
|
|
|
|
* values which may be confused for GC heap pointers. These are used to
|
|
|
|
* suppress false positives which occur when a rooting analysis treats the
|
|
|
|
* location as holding a relocatable pointer, but have no other effect on
|
|
|
|
* GC behavior.
|
|
|
|
*/
|
|
|
|
js::CheckRoot *checkGCRooters;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* JSGC_ROOT_ANALYSIS */
|
|
|
|
|
2007-06-14 23:44:18 -07:00
|
|
|
/* Debug hooks associated with the current context. */
|
2009-11-13 09:04:23 -08:00
|
|
|
const JSDebugHooks *debugHooks;
|
2008-09-05 16:24:53 -07:00
|
|
|
|
|
|
|
/* Security callbacks that override any defined on the runtime. */
|
|
|
|
JSSecurityCallbacks *securityCallbacks;
|
2008-09-12 15:11:48 -07:00
|
|
|
|
2008-09-25 09:13:31 -07:00
|
|
|
/* Stored here to avoid passing it around as a parameter. */
|
|
|
|
uintN 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
|
|
|
|
|
|
|
inline js::mjit::JaegerCompartment *jaegerCompartment();
|
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). */
|
|
|
|
JSObject *enumerators;
|
|
|
|
|
2010-03-03 17:52:26 -08:00
|
|
|
private:
|
|
|
|
/*
|
|
|
|
* To go from a live generator frame (on the stack) to its generator object
|
|
|
|
* (see comment js_FloatingFrameIfGenerator), we maintain a stack of active
|
|
|
|
* generators, pushing and popping when entering and leaving generator
|
|
|
|
* frames, respectively.
|
|
|
|
*/
|
|
|
|
js::Vector<JSGenerator *, 2, js::SystemAllocPolicy> genStack;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/* Return the generator object for the given generator frame. */
|
2011-04-13 09:27:37 -07:00
|
|
|
JSGenerator *generatorFor(js::StackFrame *fp) const;
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
/* Early OOM-check. */
|
2010-03-03 18:10:13 -08:00
|
|
|
inline bool ensureGeneratorStackSpace();
|
2010-03-03 17:52:26 -08:00
|
|
|
|
|
|
|
bool enterGenerator(JSGenerator *gen) {
|
|
|
|
return genStack.append(gen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void leaveGenerator(JSGenerator *gen) {
|
|
|
|
JS_ASSERT(genStack.back() == gen);
|
|
|
|
genStack.popBack();
|
|
|
|
}
|
|
|
|
|
2010-04-27 06:46:24 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
/*
|
2011-03-31 01:14:12 -07:00
|
|
|
* When non-null JSContext::free_ delegates the job to the background
|
2010-09-07 14:08:20 -07:00
|
|
|
* thread.
|
2010-04-27 06:46:24 -07:00
|
|
|
*/
|
2010-09-07 14:08:20 -07:00
|
|
|
js::GCHelperThread *gcBackgroundFree;
|
2009-07-27 21:10:12 -07:00
|
|
|
#endif
|
|
|
|
|
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) {
|
2009-07-27 21:10:12 -07:00
|
|
|
JS_ASSERT(bytes != 0);
|
2011-03-31 01:14:12 -07:00
|
|
|
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) {
|
2010-04-27 06:46:24 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2010-09-07 14:08:20 -07:00
|
|
|
if (gcBackgroundFree) {
|
|
|
|
gcBackgroundFree->freeLater(p);
|
2009-07-27 21:10:12 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-04-27 06:46:24 -07:00
|
|
|
#endif
|
2011-03-31 01:14:12 -07:00
|
|
|
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-10-04 07:06:54 -07:00
|
|
|
/* For DEBUG. */
|
|
|
|
inline void assertValidStackDepth(uintN depth);
|
2010-07-28 11:20:19 -07:00
|
|
|
|
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-24 14:22:30 -07:00
|
|
|
/*
|
|
|
|
* Count of currently active compilations.
|
|
|
|
* When there are compilations active for the context, the GC must not
|
|
|
|
* purge the ParseMapPool.
|
|
|
|
*/
|
|
|
|
uintN activeCompilations;
|
|
|
|
|
2011-06-14 18:39:53 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Controls whether a quadratic-complexity assertion is performed during
|
|
|
|
* stack iteration, defaults to true.
|
|
|
|
*/
|
|
|
|
bool stackIterAssertionEnabled;
|
|
|
|
#endif
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
AutoResolving(JSContext *cx, JSObject *obj, jsid id, Kind kind = LOOKUP
|
|
|
|
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;
|
|
|
|
JSObject *const object;
|
|
|
|
jsid const id;
|
|
|
|
Kind const kind;
|
|
|
|
AutoResolving *const link;
|
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-01-11 09:52:21 -08:00
|
|
|
#ifdef JS_HAS_XML_SUPPORT
|
|
|
|
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
|
|
|
|
# define JS_LOCK_GC(rt)
|
|
|
|
# define JS_UNLOCK_GC(rt)
|
|
|
|
#endif
|
|
|
|
|
2010-04-08 05:54:18 -07:00
|
|
|
class AutoUnlockGC {
|
2011-01-05 14:50:30 -08:00
|
|
|
private:
|
2010-04-08 05:54:18 -07:00
|
|
|
JSRuntime *rt;
|
2011-01-05 14:50:30 -08:00
|
|
|
JS_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoUnlockGC(JSRuntime *rt
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: rt(rt)
|
|
|
|
{
|
|
|
|
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:
|
2009-09-27 23:17:47 -07:00
|
|
|
JSAutoResolveFlags(JSContext *cx, uintN flags
|
|
|
|
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;
|
|
|
|
uintN 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
|
|
|
/*
|
|
|
|
* Enumerate all contexts in a runtime that are in the same thread as a given
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
class ThreadContextRange {
|
|
|
|
JSCList *begin;
|
|
|
|
JSCList *end;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ThreadContextRange(JSContext *cx) {
|
|
|
|
end = &cx->runtime->contextList;
|
|
|
|
begin = end->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const { return begin == end; }
|
|
|
|
void popFront() { JS_ASSERT(!empty()); begin = begin->next; }
|
|
|
|
|
|
|
|
JSContext *front() const {
|
|
|
|
return JSContext::fromLinkField(begin);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
} /* namespace js */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create and destroy functions for JSContext, which is manually allocated
|
|
|
|
* and exclusively owned.
|
|
|
|
*/
|
|
|
|
extern JSContext *
|
|
|
|
js_NewContext(JSRuntime *rt, size_t stackChunkSize);
|
|
|
|
|
2011-07-18 14:54:48 -07:00
|
|
|
typedef enum JSDestroyContextMode {
|
|
|
|
JSDCM_NO_GC,
|
|
|
|
JSDCM_MAYBE_GC,
|
|
|
|
JSDCM_FORCE_GC,
|
|
|
|
JSDCM_NEW_FAILED
|
|
|
|
} JSDestroyContextMode;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern void
|
|
|
|
js_DestroyContext(JSContext *cx, JSDestroyContextMode mode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If unlocked, acquire and release rt->gcLock around *iterp update; otherwise
|
|
|
|
* the caller must be holding rt->gcLock.
|
|
|
|
*/
|
2009-01-05 16:22:42 -08:00
|
|
|
extern JSContext *
|
2007-03-22 10:30:00 -07:00
|
|
|
js_ContextIterator(JSRuntime *rt, JSBool unlocked, JSContext **iterp);
|
|
|
|
|
|
|
|
#ifdef va_start
|
|
|
|
extern JSBool
|
|
|
|
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
|
|
|
void *userRef, const uintN errorNumber,
|
|
|
|
JSBool charArgs, va_list ap);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
|
|
|
void *userRef, const uintN errorNumber,
|
|
|
|
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
|
|
|
|
|
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
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ReportIsNullOrUndefined(JSContext *cx, intN spindex, const js::Value &v,
|
2007-11-12 21:23:22 -08:00
|
|
|
JSString *fallback);
|
|
|
|
|
2008-08-08 09:02:50 -07:00
|
|
|
extern void
|
2010-07-14 23:19:36 -07:00
|
|
|
js_ReportMissingArg(JSContext *cx, const js::Value &v, uintN 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
|
|
|
|
js_ReportValueErrorFlags(JSContext *cx, uintN flags, const uintN errorNumber,
|
2010-07-14 23:19:36 -07:00
|
|
|
intN spindex, const js::Value &v, JSString *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
|
|
|
* If the operation callback flag was set, call the operation callback.
|
2008-01-03 01:28:40 -08:00
|
|
|
* This macro can run the full GC. Return true if it is OK to continue and
|
|
|
|
* false otherwise.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2010-07-22 13:59:59 -07:00
|
|
|
#define JS_CHECK_OPERATION_LIMIT(cx) \
|
2010-07-23 09:32:50 -07:00
|
|
|
(JS_ASSERT_REQUEST_DEPTH(cx), \
|
2011-07-18 14:54:48 -07:00
|
|
|
(!cx->runtime->interrupt || js_InvokeOperationCallback(cx)))
|
2010-10-22 10:48:06 -07:00
|
|
|
|
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);
|
|
|
|
|
2011-06-05 22:39:45 -07:00
|
|
|
/*
|
|
|
|
* Get the topmost scripted frame in a context. Note: if the topmost frame is
|
|
|
|
* in the middle of an inline call, that call will be expanded. To avoid this,
|
|
|
|
* use cx->stack.currentScript or cx->stack.currentScriptedScopeChain.
|
|
|
|
*/
|
2011-04-13 09:27:37 -07:00
|
|
|
extern js::StackFrame *
|
|
|
|
js_GetScriptedCaller(JSContext *cx, js::StackFrame *fp);
|
2009-02-18 10:47:16 -08:00
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
MakeRangeGCSafe(const Shape **beg, const Shape **end)
|
|
|
|
{
|
|
|
|
PodZero(beg, end - beg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static JS_ALWAYS_INLINE void
|
|
|
|
MakeRangeGCSafe(const Shape **vec, size_t len)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2011-02-07 12:06:32 -08:00
|
|
|
class AutoShapeVector : public AutoVectorRooter<const Shape *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoShapeVector(JSContext *cx
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<const Shape *>(cx, SHAPEVECTOR)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2011-10-25 16:07:42 -07:00
|
|
|
const js::Value *start_;
|
2011-04-24 07:56:56 -07:00
|
|
|
unsigned length_;
|
|
|
|
|
|
|
|
public:
|
2011-10-25 16:07:42 -07:00
|
|
|
AutoValueArray(JSContext *cx, const js::Value *start, unsigned length
|
2011-04-24 07:56:56 -07:00
|
|
|
JS_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoGCRooter(cx, VALARRAY), start_(start), length_(length)
|
|
|
|
{
|
|
|
|
JS_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:07:42 -07:00
|
|
|
const Value *start() const { 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 {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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___ */
|