2009-06-10 18:29:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2013-04-16 13:47:10 -07:00
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
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. */
|
|
|
|
|
2013-06-19 17:59:46 -07:00
|
|
|
#ifndef jscntxt_h
|
|
|
|
#define jscntxt_h
|
2011-12-28 06:09:07 -08:00
|
|
|
|
2013-06-23 04:21:01 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-12-28 06:09:07 -08:00
|
|
|
|
2011-10-04 15:33:00 -07:00
|
|
|
#include "js/Vector.h"
|
2013-07-07 23:18:48 -07:00
|
|
|
#include "vm/Runtime.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 */
|
|
|
|
#endif
|
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
struct DtoaState;
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_ReportOutOfMemory(js::ThreadSafeContext *cx);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_ReportAllocationOverflow(js::ThreadSafeContext *cx);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_ReportOverRecursed(js::ThreadSafeContext *cx);
|
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
namespace js {
|
2012-08-27 16:02:47 -07:00
|
|
|
|
2013-12-16 10:53:02 -08:00
|
|
|
namespace jit {
|
|
|
|
class IonContext;
|
|
|
|
class CompileCompartment;
|
|
|
|
}
|
2013-08-08 19:38:42 -07:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
struct CallsiteCloneKey {
|
|
|
|
/* The original function that we are cloning. */
|
|
|
|
JSFunction *original;
|
2012-10-01 16:59:11 -07:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
/* The script of the call. */
|
|
|
|
JSScript *script;
|
2012-11-21 10:31:57 -08:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
/* The offset of the call. */
|
|
|
|
uint32_t offset;
|
2012-12-30 10:21:52 -08:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
CallsiteCloneKey(JSFunction *f, JSScript *s, uint32_t o) : original(f), script(s), offset(o) {}
|
2013-02-07 11:34:43 -08:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
typedef CallsiteCloneKey Lookup;
|
2012-02-24 16:49:12 -08:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
static inline uint32_t hash(CallsiteCloneKey key) {
|
2013-12-03 08:17:50 -08:00
|
|
|
return uint32_t(size_t(key.script->offsetToPC(key.offset)) ^ size_t(key.original));
|
2012-02-24 16:49:12 -08:00
|
|
|
}
|
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
static inline bool match(const CallsiteCloneKey &a, const CallsiteCloneKey &b) {
|
|
|
|
return a.script == b.script && a.offset == b.offset && a.original == b.original;
|
2012-05-21 16:44:19 -07:00
|
|
|
}
|
2013-07-07 23:18:48 -07:00
|
|
|
};
|
2012-05-21 16:44:19 -07:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
typedef HashMap<CallsiteCloneKey,
|
|
|
|
ReadBarriered<JSFunction>,
|
|
|
|
CallsiteCloneKey,
|
|
|
|
SystemAllocPolicy> CallsiteCloneTable;
|
2012-02-13 21:36:11 -08:00
|
|
|
|
2013-11-05 18:00:44 -08:00
|
|
|
JSFunction *
|
2013-11-19 07:37:52 -08:00
|
|
|
ExistingCloneFunctionAtCallsite(const CallsiteCloneTable &table, JSFunction *fun,
|
2013-11-05 18:00:44 -08:00
|
|
|
JSScript *script, jsbytecode *pc);
|
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
JSFunction *CloneFunctionAtCallsite(JSContext *cx, HandleFunction fun,
|
|
|
|
HandleScript script, jsbytecode *pc);
|
2012-10-16 11:57:09 -07:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
typedef HashSet<JSObject *> ObjectSet;
|
|
|
|
typedef HashSet<Shape *> ShapeSet;
|
2012-11-22 07:02:18 -08:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
/* Detects cycles when traversing an object graph. */
|
|
|
|
class AutoCycleDetector
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
RootedObject obj;
|
|
|
|
bool cyclic;
|
|
|
|
uint32_t hashsetGenerationAtInit;
|
|
|
|
ObjectSet::AddPtr hashsetAddPointer;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-11-22 07:02:18 -08:00
|
|
|
|
2012-10-16 11:57:09 -07:00
|
|
|
public:
|
2013-07-07 23:18:48 -07:00
|
|
|
AutoCycleDetector(JSContext *cx, HandleObject objArg
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: cx(cx), obj(cx, objArg), cyclic(true)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-11-22 07:02:18 -08:00
|
|
|
}
|
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
~AutoCycleDetector();
|
2012-11-22 07:02:18 -08:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
bool init();
|
2013-03-16 20:36:37 -07:00
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
bool foundCycle() { return cyclic; }
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2013-07-07 23:18:48 -07:00
|
|
|
/* Updates references in the cycle detection set if the GC moves them. */
|
|
|
|
extern void
|
|
|
|
TraceCycleDetectionSet(JSTracer *trc, ObjectSet &set);
|
2010-01-11 09:52:21 -08:00
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
struct AutoResolving;
|
2013-07-25 21:23:14 -07:00
|
|
|
class DtoaCache;
|
2014-01-31 14:57:57 -08:00
|
|
|
class ForkJoinContext;
|
2013-07-10 08:29:52 -07:00
|
|
|
class RegExpCompartment;
|
2013-07-25 21:23:14 -07:00
|
|
|
class RegExpStatics;
|
2013-06-20 16:40:53 -07:00
|
|
|
|
2013-08-29 08:56:05 -07:00
|
|
|
namespace frontend { struct CompileError; }
|
|
|
|
|
2013-06-20 16:40:53 -07:00
|
|
|
/*
|
2013-07-10 08:29:52 -07:00
|
|
|
* Execution Context Overview:
|
|
|
|
*
|
|
|
|
* Several different structures may be used to provide a context for operations
|
|
|
|
* on the VM. Each context is thread local, but varies in what data it can
|
|
|
|
* access and what other threads may be running.
|
|
|
|
*
|
|
|
|
* - ThreadSafeContext is used by threads operating in one compartment which
|
|
|
|
* may run in parallel with other threads operating on the same or other
|
|
|
|
* compartments.
|
2013-06-20 16:40:53 -07:00
|
|
|
*
|
2013-07-19 07:06:02 -07:00
|
|
|
* - ExclusiveContext is used by threads operating in one compartment/zone,
|
|
|
|
* where other threads may operate in other compartments, but *not* the same
|
|
|
|
* compartment or zone which the ExclusiveContext is in. A thread with an
|
|
|
|
* ExclusiveContext may enter the atoms compartment and atomize strings, in
|
|
|
|
* which case a lock is used.
|
2013-06-20 16:40:53 -07:00
|
|
|
*
|
2013-07-10 08:29:52 -07:00
|
|
|
* - JSContext is used only by the runtime's main thread. The context may
|
2013-07-19 07:06:02 -07:00
|
|
|
* operate in any compartment or zone which is not used by an ExclusiveContext
|
|
|
|
* or ThreadSafeContext, and will only run in parallel with threads using such
|
2013-07-10 08:29:52 -07:00
|
|
|
* contexts.
|
|
|
|
*
|
|
|
|
* An ExclusiveContext coerces to a ThreadSafeContext, and a JSContext coerces
|
|
|
|
* to an ExclusiveContext or ThreadSafeContext.
|
|
|
|
*
|
|
|
|
* Contexts which are a ThreadSafeContext but not an ExclusiveContext are used
|
2014-01-31 14:57:57 -08:00
|
|
|
* to represent a ForkJoinContext, the per-thread parallel context used in PJS.
|
2013-06-20 16:40:53 -07:00
|
|
|
*/
|
2013-07-10 08:29:52 -07:00
|
|
|
|
|
|
|
struct ThreadSafeContext : ContextFriendFields,
|
2013-06-20 16:40:53 -07:00
|
|
|
public MallocProvider<ThreadSafeContext>
|
|
|
|
{
|
2013-10-08 15:14:03 -07:00
|
|
|
friend struct StackBaseShape;
|
|
|
|
friend UnownedBaseShape *BaseShape::lookupUnowned(ThreadSafeContext *cx,
|
|
|
|
const StackBaseShape &base);
|
2013-10-08 15:14:04 -07:00
|
|
|
friend Shape *JSObject::lookupChildProperty(ThreadSafeContext *cx,
|
|
|
|
JS::HandleObject obj, js::HandleShape parent,
|
|
|
|
js::StackShape &child);
|
2013-10-08 15:14:03 -07:00
|
|
|
|
2013-06-20 16:40:53 -07:00
|
|
|
public:
|
|
|
|
enum ContextKind {
|
|
|
|
Context_JS,
|
2013-07-10 08:29:52 -07:00
|
|
|
Context_Exclusive,
|
2013-06-20 16:40:53 -07:00
|
|
|
Context_ForkJoin
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
ContextKind contextKind_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PerThreadData *perThreadData;
|
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
ThreadSafeContext(JSRuntime *rt, PerThreadData *pt, ContextKind kind);
|
2013-06-20 16:40:53 -07:00
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
bool isJSContext() const {
|
|
|
|
return contextKind_ == Context_JS;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *maybeJSContext() const {
|
|
|
|
if (isJSContext())
|
|
|
|
return (JSContext *) this;
|
2013-10-07 09:43:08 -07:00
|
|
|
return nullptr;
|
2013-07-10 08:29:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *asJSContext() const {
|
|
|
|
// Note: there is no way to perform an unchecked coercion from a
|
|
|
|
// ThreadSafeContext to a JSContext. This ensures that trying to use
|
2013-10-07 09:43:08 -07:00
|
|
|
// the context as a JSContext off the main thread will nullptr crash
|
2013-07-10 08:29:52 -07:00
|
|
|
// rather than race.
|
|
|
|
JS_ASSERT(isJSContext());
|
|
|
|
return maybeJSContext();
|
|
|
|
}
|
|
|
|
|
2013-07-15 07:12:40 -07:00
|
|
|
// In some cases we could potentially want to do operations that require a
|
|
|
|
// JSContext while running off the main thread. While this should never
|
|
|
|
// actually happen, the wide enough API for working off the main thread
|
|
|
|
// makes such operations impossible to rule out. Rather than blindly using
|
|
|
|
// asJSContext() and crashing afterwards, this method may be used to watch
|
|
|
|
// for such cases and produce either a soft failure in release builds or
|
|
|
|
// an assertion failure in debug builds.
|
|
|
|
bool shouldBeJSContext() const {
|
|
|
|
JS_ASSERT(isJSContext());
|
|
|
|
return isJSContext();
|
|
|
|
}
|
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
bool isExclusiveContext() const {
|
|
|
|
return contextKind_ == Context_JS || contextKind_ == Context_Exclusive;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExclusiveContext *maybeExclusiveContext() const {
|
|
|
|
if (isExclusiveContext())
|
|
|
|
return (ExclusiveContext *) this;
|
2013-10-07 09:43:08 -07:00
|
|
|
return nullptr;
|
2013-07-10 08:29:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ExclusiveContext *asExclusiveContext() const {
|
|
|
|
JS_ASSERT(isExclusiveContext());
|
|
|
|
return maybeExclusiveContext();
|
|
|
|
}
|
2013-06-20 16:40:53 -07:00
|
|
|
|
2014-01-31 14:57:57 -08:00
|
|
|
bool isForkJoinContext() const;
|
|
|
|
ForkJoinContext *asForkJoinContext();
|
2013-06-20 16:40:53 -07:00
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
// The generational GC nursery may only be used on the main thread.
|
2013-06-20 16:40:53 -07:00
|
|
|
#ifdef JSGC_GENERATIONAL
|
2013-06-20 17:39:24 -07:00
|
|
|
inline bool hasNursery() const {
|
|
|
|
return isJSContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline js::Nursery &nursery() {
|
|
|
|
JS_ASSERT(hasNursery());
|
|
|
|
return runtime_->gcNursery;
|
|
|
|
}
|
2013-06-20 16:40:53 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocator used when allocating GCThings on this context. If we are a
|
2013-07-10 08:29:52 -07:00
|
|
|
* JSContext, this is the Zone allocator of the JSContext's zone.
|
|
|
|
* Otherwise, this is a per-thread allocator.
|
2013-06-20 16:40:53 -07:00
|
|
|
*
|
|
|
|
* This does not live in PerThreadData because the notion of an allocator
|
2013-07-10 08:29:52 -07:00
|
|
|
* is only per-thread when off the main thread. The runtime (and the main
|
|
|
|
* thread) can have more than one zone, each with its own allocator, and
|
|
|
|
* it's up to the context to specify what compartment and zone we are
|
|
|
|
* operating in.
|
2013-06-20 16:40:53 -07:00
|
|
|
*/
|
|
|
|
protected:
|
|
|
|
Allocator *allocator_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static size_t offsetOfAllocator() { return offsetof(ThreadSafeContext, allocator_); }
|
|
|
|
|
|
|
|
inline Allocator *const allocator();
|
2013-06-20 16:40:53 -07:00
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
// Allocations can only trigger GC when running on the main thread.
|
|
|
|
inline AllowGC allowGC() const { return isJSContext() ? CanGC : NoGC; }
|
2013-06-20 16:40:53 -07:00
|
|
|
|
|
|
|
template <typename T>
|
2013-07-04 00:57:00 -07:00
|
|
|
bool isInsideCurrentZone(T thing) const {
|
2013-10-08 15:14:03 -07:00
|
|
|
return thing->zoneFromAnyThread() == zone_;
|
2013-07-04 00:57:00 -07:00
|
|
|
}
|
2013-06-20 16:40:53 -07:00
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
template <typename T>
|
|
|
|
inline bool isInsideCurrentCompartment(T thing) const {
|
|
|
|
return thing->compartment() == compartment_;
|
|
|
|
}
|
|
|
|
|
2013-10-08 15:14:03 -07:00
|
|
|
template <typename T>
|
|
|
|
inline bool isThreadLocal(T thing) const;
|
|
|
|
|
2013-06-20 16:40:53 -07:00
|
|
|
void *onOutOfMemory(void *p, size_t nbytes) {
|
2013-07-10 08:29:52 -07:00
|
|
|
return runtime_->onOutOfMemory(p, nbytes, maybeJSContext());
|
2013-06-20 16:40:53 -07:00
|
|
|
}
|
2013-07-10 08:29:52 -07:00
|
|
|
|
2014-04-08 10:35:17 -07:00
|
|
|
/* Clear the pending exception (if any) due to OOM. */
|
|
|
|
void recoverFromOutOfMemory();
|
|
|
|
|
2013-06-20 16:40:53 -07:00
|
|
|
inline void updateMallocCounter(size_t nbytes) {
|
2013-07-10 08:29:52 -07:00
|
|
|
// Note: this is racy.
|
2013-06-20 16:40:53 -07:00
|
|
|
runtime_->updateMallocCounter(zone_, nbytes);
|
|
|
|
}
|
2013-07-10 08:29:52 -07:00
|
|
|
|
2013-06-20 16:40:53 -07:00
|
|
|
void reportAllocationOverflow() {
|
2013-07-10 08:29:52 -07:00
|
|
|
js_ReportAllocationOverflow(this);
|
|
|
|
}
|
|
|
|
|
2013-08-22 06:13:18 -07:00
|
|
|
// Accessors for immutable runtime data.
|
2014-02-19 08:02:13 -08:00
|
|
|
JSAtomState &names() { return *runtime_->commonNames; }
|
|
|
|
StaticStrings &staticStrings() { return *runtime_->staticStrings; }
|
|
|
|
AtomSet &permanentAtoms() { return *runtime_->permanentAtoms; }
|
2013-10-15 10:13:34 -07:00
|
|
|
const JS::AsmJSCacheOps &asmJSCacheOps() { return runtime_->asmJSCacheOps; }
|
2013-07-10 08:29:52 -07:00
|
|
|
PropertyName *emptyString() { return runtime_->emptyString; }
|
2013-08-22 06:13:18 -07:00
|
|
|
FreeOp *defaultFreeOp() { return runtime_->defaultFreeOp(); }
|
2013-08-27 10:48:55 -07:00
|
|
|
bool useHelperThreads() { return runtime_->useHelperThreads(); }
|
2013-08-12 16:41:24 -07:00
|
|
|
void *runtimeAddressForJit() { return runtime_; }
|
|
|
|
void *stackLimitAddress(StackKind kind) { return &runtime_->mainThread.nativeStackLimit[kind]; }
|
2014-01-29 04:34:14 -08:00
|
|
|
void *stackLimitAddressForJitCode(StackKind kind);
|
2013-08-08 20:51:29 -07:00
|
|
|
size_t gcSystemPageSize() { return runtime_->gcSystemPageSize; }
|
|
|
|
bool signalHandlersInstalled() const { return runtime_->signalHandlersInstalled(); }
|
|
|
|
bool jitSupportsFloatingPoint() const { return runtime_->jitSupportsFloatingPoint; }
|
2013-07-10 08:29:52 -07:00
|
|
|
|
|
|
|
// Thread local data that may be accessed freely.
|
|
|
|
DtoaState *dtoaState() {
|
|
|
|
return perThreadData->dtoaState;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-19 07:06:02 -07:00
|
|
|
struct WorkerThread;
|
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
class ExclusiveContext : public ThreadSafeContext
|
|
|
|
{
|
|
|
|
friend class gc::ArenaLists;
|
2013-07-19 07:06:02 -07:00
|
|
|
friend class AutoCompartment;
|
|
|
|
friend class AutoLockForExclusiveAccess;
|
2013-07-10 08:29:52 -07:00
|
|
|
friend struct StackBaseShape;
|
2013-08-01 11:47:39 -07:00
|
|
|
friend void JSScript::initCompartment(ExclusiveContext *cx);
|
2013-08-27 03:50:16 -07:00
|
|
|
friend class jit::IonContext;
|
2013-07-10 08:29:52 -07:00
|
|
|
|
2013-07-19 07:06:02 -07:00
|
|
|
// The worker on which this context is running, if this is not a JSContext.
|
2013-09-11 16:42:09 -07:00
|
|
|
WorkerThread *workerThread_;
|
2013-07-10 08:29:52 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ExclusiveContext(JSRuntime *rt, PerThreadData *pt, ContextKind kind)
|
2013-07-19 07:06:02 -07:00
|
|
|
: ThreadSafeContext(rt, pt, kind),
|
2013-10-07 09:43:08 -07:00
|
|
|
workerThread_(nullptr),
|
2013-07-19 07:06:02 -07:00
|
|
|
enterCompartmentDepth_(0)
|
2013-07-10 08:29:52 -07:00
|
|
|
{}
|
|
|
|
|
2013-07-19 07:06:02 -07:00
|
|
|
/*
|
|
|
|
* "Entering" a compartment changes cx->compartment (which changes
|
2014-03-19 01:28:57 -07:00
|
|
|
* cx->global). Note that this does not push any InterpreterFrame which means
|
2013-07-19 07:06:02 -07:00
|
|
|
* that it is possible for cx->fp()->compartment() != cx->compartment.
|
|
|
|
* This is not a problem since, in general, most places in the VM cannot
|
|
|
|
* know that they were called from script (e.g., they may have been called
|
|
|
|
* through the JSAPI via JS_CallFunction) and thus cannot expect fp.
|
|
|
|
*
|
|
|
|
* Compartments should be entered/left in a LIFO fasion. The depth of this
|
|
|
|
* enter/leave stack is maintained by enterCompartmentDepth_ and queried by
|
|
|
|
* hasEnteredCompartment.
|
|
|
|
*
|
|
|
|
* To enter a compartment, code should prefer using AutoCompartment over
|
|
|
|
* manually calling cx->enterCompartment/leaveCompartment.
|
|
|
|
*/
|
|
|
|
protected:
|
|
|
|
unsigned enterCompartmentDepth_;
|
|
|
|
inline void setCompartment(JSCompartment *comp);
|
|
|
|
public:
|
|
|
|
bool hasEnteredCompartment() const {
|
|
|
|
return enterCompartmentDepth_ > 0;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
unsigned getEnterCompartmentDepth() const {
|
|
|
|
return enterCompartmentDepth_;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline void enterCompartment(JSCompartment *c);
|
|
|
|
inline void leaveCompartment(JSCompartment *oldCompartment);
|
|
|
|
|
|
|
|
void setWorkerThread(WorkerThread *workerThread);
|
2013-09-11 16:42:09 -07:00
|
|
|
WorkerThread *workerThread() const { return workerThread_; }
|
2013-07-19 07:06:02 -07:00
|
|
|
|
2013-08-13 08:13:46 -07:00
|
|
|
// Threads with an ExclusiveContext may freely access any data in their
|
|
|
|
// compartment and zone.
|
|
|
|
JSCompartment *compartment() const {
|
|
|
|
JS_ASSERT_IF(runtime_->isAtomsCompartment(compartment_),
|
|
|
|
runtime_->currentThreadHasExclusiveAccess());
|
|
|
|
return compartment_;
|
|
|
|
}
|
|
|
|
JS::Zone *zone() const {
|
|
|
|
JS_ASSERT_IF(!compartment(), !zone_);
|
|
|
|
JS_ASSERT_IF(compartment(), js::GetCompartmentZone(compartment()) == zone_);
|
|
|
|
return zone_;
|
|
|
|
}
|
2013-07-10 08:29:52 -07:00
|
|
|
|
2013-08-13 08:13:46 -07:00
|
|
|
// Zone local methods that can be used freely from an ExclusiveContext.
|
2013-10-07 09:43:08 -07:00
|
|
|
types::TypeObject *getNewType(const Class *clasp, TaggedProto proto, JSFunction *fun = nullptr);
|
2014-02-07 16:50:28 -08:00
|
|
|
types::TypeObject *getSingletonType(const Class *clasp, TaggedProto proto);
|
2013-08-22 06:13:18 -07:00
|
|
|
inline js::LifoAlloc &typeLifoAlloc();
|
2013-07-10 08:29:52 -07:00
|
|
|
|
|
|
|
// Current global. This is only safe to use within the scope of the
|
|
|
|
// AutoCompartment from which it's called.
|
|
|
|
inline js::Handle<js::GlobalObject*> global() const;
|
|
|
|
|
2013-08-13 08:13:46 -07:00
|
|
|
// Methods to access runtime data that must be protected by locks.
|
2013-07-10 08:29:52 -07:00
|
|
|
frontend::ParseMapPool &parseMapPool() {
|
2013-08-13 08:13:46 -07:00
|
|
|
return runtime_->parseMapPool();
|
2013-07-10 08:29:52 -07:00
|
|
|
}
|
|
|
|
AtomSet &atoms() {
|
2013-08-13 08:13:46 -07:00
|
|
|
return runtime_->atoms();
|
2013-07-10 08:29:52 -07:00
|
|
|
}
|
2013-07-19 07:06:02 -07:00
|
|
|
JSCompartment *atomsCompartment() {
|
2013-08-13 08:13:46 -07:00
|
|
|
return runtime_->atomsCompartment();
|
2013-07-19 07:06:02 -07:00
|
|
|
}
|
2013-07-10 08:29:52 -07:00
|
|
|
ScriptDataTable &scriptDataTable() {
|
2013-08-13 08:13:46 -07:00
|
|
|
return runtime_->scriptDataTable();
|
2013-06-20 16:40:53 -07:00
|
|
|
}
|
2013-08-08 20:51:29 -07:00
|
|
|
|
2013-08-29 08:56:05 -07:00
|
|
|
// Methods specific to any WorkerThread for the context.
|
|
|
|
frontend::CompileError &addPendingCompileError();
|
2013-11-26 18:18:04 -08:00
|
|
|
void addPendingOverRecursed();
|
2013-06-20 16:40:53 -07:00
|
|
|
};
|
|
|
|
|
2010-08-29 11:57:08 -07:00
|
|
|
} /* namespace js */
|
2010-08-11 13:30:07 -07:00
|
|
|
|
2013-07-10 08:29:52 -07:00
|
|
|
struct JSContext : public js::ExclusiveContext,
|
2013-06-20 16:40:53 -07:00
|
|
|
public mozilla::LinkedListElement<JSContext>
|
2010-02-06 10:14:05 -08:00
|
|
|
{
|
2010-03-03 17:52:26 -08:00
|
|
|
explicit JSContext(JSRuntime *rt);
|
2011-03-13 07:45:02 -07:00
|
|
|
~JSContext();
|
2010-02-06 10:14:05 -08:00
|
|
|
|
2013-06-10 14:22:18 -07:00
|
|
|
JSRuntime *runtime() const { return runtime_; }
|
2013-06-19 02:33:13 -07:00
|
|
|
js::PerThreadData &mainThread() const { return runtime()->mainThread; }
|
2013-01-24 21:12:44 -08:00
|
|
|
|
2013-07-19 07:06:02 -07:00
|
|
|
friend class js::ExclusiveContext;
|
2014-02-26 06:55:34 -08:00
|
|
|
friend class JS::AutoSaveExceptionState;
|
2013-07-19 07:06:02 -07:00
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
private:
|
2011-01-07 02:03:14 -08:00
|
|
|
/* Exception state -- the exception member is a GC root by definition. */
|
2012-12-03 12:53:28 -08:00
|
|
|
bool throwing; /* is there a pending exception? */
|
2013-12-17 13:01:05 -08:00
|
|
|
js::Value unwrappedException_; /* most-recently-thrown exception */
|
2011-01-07 02:03:14 -08:00
|
|
|
|
2013-02-06 21:35:16 -08:00
|
|
|
/* Per-context options. */
|
2013-10-14 04:25:47 -07:00
|
|
|
JS::ContextOptions options_;
|
2011-01-25 04:11:47 -08:00
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
2013-06-06 20:48:45 -07:00
|
|
|
int32_t reportGranularity; /* see vm/Probes.h */
|
2011-03-29 10:25:20 -07:00
|
|
|
|
2011-03-07 14:00:00 -08:00
|
|
|
js::AutoResolving *resolvingList;
|
2011-02-17 10:39:05 -08: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-08-17 18:05:06 -07:00
|
|
|
/* See JS_SaveFrameChain/JS_RestoreFrameChain. */
|
|
|
|
private:
|
|
|
|
struct SavedFrameChain {
|
|
|
|
SavedFrameChain(JSCompartment *comp, unsigned count)
|
|
|
|
: compartment(comp), enterCompartmentCount(count) {}
|
|
|
|
JSCompartment *compartment;
|
|
|
|
unsigned enterCompartmentCount;
|
|
|
|
};
|
|
|
|
typedef js::Vector<SavedFrameChain, 1, js::SystemAllocPolicy> SaveStack;
|
|
|
|
SaveStack savedFrameChains_;
|
|
|
|
public:
|
|
|
|
bool saveFrameChain();
|
|
|
|
void restoreFrameChain();
|
2011-04-01 17:26:34 -07:00
|
|
|
|
2012-08-17 11:21:57 -07:00
|
|
|
/*
|
|
|
|
* When no compartments have been explicitly entered, the context's
|
|
|
|
* compartment will be set to the compartment of the "default compartment
|
|
|
|
* object".
|
|
|
|
*/
|
|
|
|
private:
|
|
|
|
JSObject *defaultCompartmentObject_;
|
|
|
|
public:
|
|
|
|
inline void setDefaultCompartmentObject(JSObject *obj);
|
|
|
|
inline void setDefaultCompartmentObjectIfUnset(JSObject *obj);
|
2013-09-04 14:06:55 -07:00
|
|
|
JSObject *maybeDefaultCompartmentObject() const {
|
2013-10-14 04:25:47 -07:00
|
|
|
JS_ASSERT(!options().noDefaultCompartmentObject());
|
2013-09-04 14:06:55 -07:00
|
|
|
return defaultCompartmentObject_;
|
|
|
|
}
|
2011-04-01 17:26:34 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* State for object and array toSource conversion. */
|
2012-08-17 16:48:02 -07:00
|
|
|
js::ObjectSet cycleDetectorSet;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-03 01:28:40 -08:00
|
|
|
/* Per-context optional error reporter. */
|
2007-03-22 10:30:00 -07:00
|
|
|
JSErrorReporter errorReporter;
|
|
|
|
|
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
|
|
|
|
2011-01-27 02:54:58 -08:00
|
|
|
public:
|
|
|
|
|
2010-09-13 09:38:22 -07:00
|
|
|
/*
|
|
|
|
* Return:
|
2011-02-17 16:17:45 -08:00
|
|
|
* - The newest scripted frame's version, if there is such a frame.
|
2013-06-29 08:11:17 -07:00
|
|
|
* - The version from the compartment.
|
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
|
|
|
*/
|
2013-06-05 19:07:43 -07:00
|
|
|
JSVersion findVersion() const;
|
2010-09-13 09:38:22 -07:00
|
|
|
|
2013-10-14 04:25:47 -07:00
|
|
|
const JS::ContextOptions &options() const {
|
|
|
|
return options_;
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2013-10-14 04:25:47 -07:00
|
|
|
JS::ContextOptions &options() {
|
|
|
|
return options_;
|
2010-11-15 13:35:20 -08:00
|
|
|
}
|
|
|
|
|
2013-06-10 14:22:18 -07:00
|
|
|
js::LifoAlloc &tempLifoAlloc() { return runtime()->tempLifoAlloc; }
|
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
|
|
|
#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
|
|
|
|
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
|
|
|
|
2013-05-02 04:32:28 -07:00
|
|
|
bool jitIsBroken;
|
2011-04-13 09:27:37 -07:00
|
|
|
|
2010-09-15 22:27:17 -07:00
|
|
|
void updateJITEnabled();
|
2009-07-16 18:36:19 -07:00
|
|
|
|
2013-06-19 02:33:13 -07:00
|
|
|
/* Whether this context has JS frames on the stack. */
|
|
|
|
bool currentlyRunning() const;
|
|
|
|
|
|
|
|
bool currentlyRunningInInterpreter() const {
|
|
|
|
return mainThread().activation()->isInterpreter();
|
|
|
|
}
|
|
|
|
bool currentlyRunningInJit() const {
|
|
|
|
return mainThread().activation()->isJit();
|
|
|
|
}
|
2014-03-19 01:28:57 -07:00
|
|
|
js::InterpreterFrame *interpreterFrame() const {
|
2013-06-19 02:33:13 -07:00
|
|
|
return mainThread().activation()->asInterpreter()->current();
|
|
|
|
}
|
2014-03-05 15:15:32 -08:00
|
|
|
js::InterpreterRegs &interpreterRegs() const {
|
2013-06-19 02:33:13 -07:00
|
|
|
return mainThread().activation()->asInterpreter()->regs();
|
|
|
|
}
|
|
|
|
|
2013-06-20 23:28:06 -07:00
|
|
|
/*
|
|
|
|
* Get the topmost script and optional pc on the stack. By default, this
|
|
|
|
* function only returns a JSScript in the current compartment, returning
|
2013-10-07 09:43:08 -07:00
|
|
|
* nullptr if the current script is in a different compartment. This
|
|
|
|
* behavior can be overridden by passing ALLOW_CROSS_COMPARTMENT.
|
2013-06-20 23:28:06 -07:00
|
|
|
*/
|
|
|
|
enum MaybeAllowCrossCompartment {
|
|
|
|
DONT_ALLOW_CROSS_COMPARTMENT = false,
|
|
|
|
ALLOW_CROSS_COMPARTMENT = true
|
|
|
|
};
|
2013-10-07 09:43:08 -07:00
|
|
|
inline JSScript *currentScript(jsbytecode **pc = nullptr,
|
2013-06-20 23:28:06 -07:00
|
|
|
MaybeAllowCrossCompartment = DONT_ALLOW_CROSS_COMPARTMENT) const;
|
|
|
|
|
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-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-01-07 02:03:14 -08:00
|
|
|
bool isExceptionPending() {
|
|
|
|
return throwing;
|
|
|
|
}
|
|
|
|
|
2014-01-17 08:05:06 -08:00
|
|
|
MOZ_WARN_UNUSED_RESULT
|
2013-12-17 13:01:05 -08:00
|
|
|
bool getPendingException(JS::MutableHandleValue rval);
|
2011-01-07 02:03:14 -08:00
|
|
|
|
2014-04-08 13:43:39 -07:00
|
|
|
bool isThrowingOutOfMemory();
|
|
|
|
|
2011-01-07 02:03:14 -08:00
|
|
|
void setPendingException(js::Value v);
|
|
|
|
|
|
|
|
void clearPendingException() {
|
2012-08-17 18:05:06 -07:00
|
|
|
throwing = false;
|
2013-12-17 13:01:05 -08:00
|
|
|
unwrappedException_.setUndefined();
|
2011-01-07 02:03:14 -08:00
|
|
|
}
|
|
|
|
|
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-07-07 15:40:33 -07:00
|
|
|
/*
|
|
|
|
* See JS_SetTrustedPrincipals in jsapi.h.
|
|
|
|
* Note: !cx->compartment is treated as trusted.
|
|
|
|
*/
|
|
|
|
bool runningWithTrustedPrincipals() const;
|
|
|
|
|
2013-06-23 04:21:01 -07:00
|
|
|
JS_FRIEND_API(size_t) sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
|
2011-12-01 19:08:20 -08:00
|
|
|
|
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
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2011-03-07 14:00:00 -08:00
|
|
|
: context(cx), object(obj), id(id), kind(kind), link(cx->resolvingList)
|
|
|
|
{
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2011-03-07 14:00:00 -08:00
|
|
|
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;
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2011-03-07 14:00:00 -08: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
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2010-01-11 09:52:21 -08:00
|
|
|
: mContext(cx), mSaved(cx->resolveFlags)
|
|
|
|
{
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_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;
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_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 {
|
2012-11-04 01:00:06 -07:00
|
|
|
JSContext *iter;
|
2011-08-23 12:42:17 -07:00
|
|
|
|
|
|
|
public:
|
2012-02-29 04:18:16 -08:00
|
|
|
explicit ContextIter(JSRuntime *rt) {
|
2012-11-04 01:00:06 -07:00
|
|
|
iter = rt->contextList.getFirst();
|
2011-08-23 12:42:17 -07:00
|
|
|
}
|
|
|
|
|
2012-02-29 04:18:16 -08:00
|
|
|
bool done() const {
|
2012-11-04 01:00:06 -07:00
|
|
|
return !iter;
|
2012-02-29 04:18:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void next() {
|
|
|
|
JS_ASSERT(!done());
|
2012-11-04 01:00:06 -07:00
|
|
|
iter = iter->getNext();
|
2012-02-29 04:18:16 -08:00
|
|
|
}
|
2011-08-23 12:42:17 -07:00
|
|
|
|
2012-02-29 04:18:16 -08:00
|
|
|
JSContext *get() const {
|
|
|
|
JS_ASSERT(!done());
|
2012-11-04 01:00:06 -07:00
|
|
|
return iter;
|
2011-08-23 12:42:17 -07:00
|
|
|
}
|
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);
|
|
|
|
|
2012-12-10 18:11:17 -08:00
|
|
|
enum ErrorArgumentsType {
|
|
|
|
ArgumentsAreUnicode,
|
|
|
|
ArgumentsAreASCII
|
|
|
|
};
|
|
|
|
|
2013-09-10 07:35:53 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loads and returns a self-hosted function by name. For performance, define
|
|
|
|
* the property name in vm/CommonPropertyNames.h.
|
|
|
|
*
|
|
|
|
* Defined in SelfHosting.cpp.
|
|
|
|
*/
|
|
|
|
JSFunction *
|
|
|
|
SelfHostedFunction(JSContext *cx, HandlePropertyName propName);
|
|
|
|
|
2012-03-28 03:13:30 -07:00
|
|
|
} /* namespace js */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef va_start
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
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
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
2012-02-28 15:11:11 -08:00
|
|
|
js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback,
|
|
|
|
void *userRef, const unsigned errorNumber,
|
2012-12-10 18:11:17 -08:00
|
|
|
js::ErrorArgumentsType argumentsType, va_list ap);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-06 15:23:14 -08:00
|
|
|
extern bool
|
|
|
|
js_ReportErrorNumberUCArray(JSContext *cx, unsigned flags, JSErrorCallback callback,
|
|
|
|
void *userRef, const unsigned errorNumber,
|
|
|
|
const jschar **args);
|
2013-07-10 08:29:52 -07:00
|
|
|
#endif
|
2012-11-06 15:23:14 -08:00
|
|
|
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
2013-08-29 08:56:05 -07:00
|
|
|
js_ExpandErrorArguments(js::ExclusiveContext *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,
|
2012-12-10 18:11:17 -08:00
|
|
|
js::ErrorArgumentsType argumentsType, va_list ap);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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
|
|
|
|
2012-08-30 03:04:57 -07:00
|
|
|
/*
|
2013-10-07 09:43:08 -07:00
|
|
|
* Prints a full report and returns true if the given report is non-nullptr
|
|
|
|
* and the report doesn't have the JSREPORT_WARNING flag set or reportWarnings
|
|
|
|
* is true.
|
|
|
|
* Returns false otherwise, printing just the message if the report is nullptr.
|
2012-08-30 03:04:57 -07:00
|
|
|
*/
|
|
|
|
extern bool
|
|
|
|
PrintError(JSContext *cx, FILE *file, const char *message, JSErrorReport *report,
|
|
|
|
bool reportWarnings);
|
2012-03-06 11:38:44 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2013-12-16 04:03:18 -08:00
|
|
|
* Send a JSErrorReport to the errorReporter callback.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2013-12-16 04:03:18 -08:00
|
|
|
void
|
|
|
|
CallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);
|
|
|
|
|
|
|
|
} /* namespace js */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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).
|
|
|
|
*/
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
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.
|
|
|
|
*/
|
2013-08-08 15:53:04 -07:00
|
|
|
extern bool
|
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, \
|
2013-10-07 09:43:08 -07:00
|
|
|
spindex, v, fallback, nullptr, nullptr))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define js_ReportValueError2(cx,errorNumber,spindex,v,fallback,arg1) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
2013-10-07 09:43:08 -07:00
|
|
|
spindex, v, fallback, arg1, nullptr))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define js_ReportValueError3(cx,errorNumber,spindex,v,fallback,arg1,arg2) \
|
|
|
|
((void)js_ReportValueErrorFlags(cx, JSREPORT_ERROR, errorNumber, \
|
|
|
|
spindex, v, fallback, arg1, arg2))
|
|
|
|
|
2013-01-18 16:35:37 -08:00
|
|
|
extern const JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-29 08:56:05 -07:00
|
|
|
char *
|
|
|
|
js_strdup(js::ExclusiveContext *cx, const char *s);
|
|
|
|
|
2010-07-23 09:32:50 -07:00
|
|
|
#ifdef JS_THREADSAFE
|
2013-06-10 14:22:18 -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
|
|
|
|
|
2014-03-10 14:28:43 -07:00
|
|
|
namespace js {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
2014-03-10 14:28:43 -07:00
|
|
|
* Invoke the interrupt callback and return false if the current execution
|
2009-02-10 14:07:01 -08:00
|
|
|
* is to be terminated.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-03-10 14:28:43 -07:00
|
|
|
bool
|
|
|
|
InvokeInterruptCallback(JSContext *cx);
|
2009-01-14 09:23:51 -08:00
|
|
|
|
2014-03-10 14:28:43 -07:00
|
|
|
bool
|
|
|
|
HandleExecutionInterrupt(JSContext *cx);
|
2010-06-07 23:55:13 -07:00
|
|
|
|
2012-04-11 17:03:07 -07:00
|
|
|
/*
|
2014-03-10 14:28:43 -07:00
|
|
|
* Process any pending interrupt requests. Long-running inner loops in C++ must
|
|
|
|
* call this periodically to make sure they are interruptible --- that is, to
|
|
|
|
* make sure they do not prevent the slow script dialog from appearing.
|
|
|
|
*
|
|
|
|
* This can run a full GC or call the interrupt callback, which could do
|
|
|
|
* anything. In the browser, it displays the slow script dialog.
|
|
|
|
*
|
|
|
|
* If this returns true, the caller can continue; if false, the caller must
|
|
|
|
* break out of its loop. This happens if, for example, the user clicks "Stop
|
|
|
|
* script" on the slow script dialog; treat it as an uncatchable error.
|
2012-04-11 17:03:07 -07:00
|
|
|
*/
|
2014-03-10 14:28:43 -07:00
|
|
|
inline bool
|
|
|
|
CheckForInterrupt(JSContext *cx)
|
2012-04-11 17:03:07 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT_REQUEST_DEPTH(cx);
|
2014-03-10 14:28:43 -07:00
|
|
|
return !cx->runtime()->interrupt || InvokeInterruptCallback(cx);
|
2012-04-11 17:03:07 -07:00
|
|
|
}
|
|
|
|
|
2011-10-04 07:06:54 -07:00
|
|
|
/************************************************************************/
|
|
|
|
|
2013-04-30 15:40:48 -07:00
|
|
|
class AutoStringVector : public AutoVectorRooter<JSString *>
|
2012-08-12 18:50:49 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoStringVector(JSContext *cx
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-04-30 15:40:48 -07:00
|
|
|
: AutoVectorRooter<JSString *>(cx, STRINGVECTOR)
|
2012-08-12 18:50:49 -07:00
|
|
|
{
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-08-12 18:50:49 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-08-12 18:50:49 -07:00
|
|
|
};
|
|
|
|
|
2013-11-01 08:10:47 -07:00
|
|
|
class AutoPropertyNameVector : public AutoVectorRooter<PropertyName *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoPropertyNameVector(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: AutoVectorRooter<PropertyName *>(cx, STRINGVECTOR)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-04-30 15:40:09 -07:00
|
|
|
class AutoShapeVector : public AutoVectorRooter<Shape *>
|
2011-02-07 12:06:32 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoShapeVector(JSContext *cx
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-04-30 15:40:09 -07:00
|
|
|
: AutoVectorRooter<Shape *>(cx, SHAPEVECTOR)
|
2011-02-07 12:06:32 -08:00
|
|
|
{
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2010-07-14 23:19:36 -07:00
|
|
|
}
|
|
|
|
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2010-03-01 14:46:15 -08:00
|
|
|
};
|
|
|
|
|
2013-04-30 15:41:12 -07:00
|
|
|
class AutoObjectObjectHashMap : public AutoHashMapRooter<JSObject *, JSObject *>
|
2012-12-13 13:50:56 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoObjectObjectHashMap(JSContext *cx
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-04-30 15:41:12 -07:00
|
|
|
: AutoHashMapRooter<JSObject *, JSObject *>(cx, OBJOBJHASHMAP)
|
2012-12-13 13:50:56 -08:00
|
|
|
{
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2012-12-13 13:50:56 -08:00
|
|
|
}
|
2013-02-07 00:22:28 -08:00
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-04-30 15:41:12 -07:00
|
|
|
class AutoObjectUnsigned32HashMap : public AutoHashMapRooter<JSObject *, uint32_t>
|
2013-02-07 00:22:28 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoObjectUnsigned32HashMap(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-04-30 15:41:12 -07:00
|
|
|
: AutoHashMapRooter<JSObject *, uint32_t>(cx, OBJU32HASHMAP)
|
2013-02-07 00:22:28 -08:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-04-30 15:41:12 -07:00
|
|
|
class AutoObjectHashSet : public AutoHashSetRooter<JSObject *>
|
2013-02-07 00:22:28 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoObjectHashSet(JSContext *cx
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-04-30 15:41:12 -07:00
|
|
|
: AutoHashSetRooter<JSObject *>(cx, OBJHASHSET)
|
2013-02-07 00:22:28 -08:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
2012-12-13 13:50:56 -08:00
|
|
|
|
2012-12-27 09:20:22 -08:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2012-12-13 13:50:56 -08:00
|
|
|
};
|
|
|
|
|
2014-02-11 02:59:15 -08:00
|
|
|
/* AutoArrayRooter roots an external array of Values. */
|
|
|
|
class AutoArrayRooter : private AutoGCRooter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoArrayRooter(JSContext *cx, size_t len, Value *vec
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2014-03-24 15:32:36 -07:00
|
|
|
: AutoGCRooter(cx, len), array(vec)
|
2014-02-11 02:59:15 -08:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
JS_ASSERT(tag_ >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeLength(size_t newLength) {
|
|
|
|
tag_ = ptrdiff_t(newLength);
|
|
|
|
JS_ASSERT(tag_ >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeArray(Value *newArray, size_t newLength) {
|
|
|
|
changeLength(newLength);
|
|
|
|
array = newArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *start() {
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t length() {
|
|
|
|
JS_ASSERT(tag_ >= 0);
|
|
|
|
return size_t(tag_);
|
|
|
|
}
|
|
|
|
|
|
|
|
MutableHandleValue handleAt(size_t i) {
|
|
|
|
JS_ASSERT(i < size_t(tag_));
|
|
|
|
return MutableHandleValue::fromMarkedLocation(&array[i]);
|
|
|
|
}
|
|
|
|
HandleValue handleAt(size_t i) const {
|
|
|
|
JS_ASSERT(i < size_t(tag_));
|
|
|
|
return HandleValue::fromMarkedLocation(&array[i]);
|
|
|
|
}
|
|
|
|
MutableHandleValue operator[](size_t i) {
|
|
|
|
JS_ASSERT(i < size_t(tag_));
|
|
|
|
return MutableHandleValue::fromMarkedLocation(&array[i]);
|
|
|
|
}
|
|
|
|
HandleValue operator[](size_t i) const {
|
|
|
|
JS_ASSERT(i < size_t(tag_));
|
|
|
|
return HandleValue::fromMarkedLocation(&array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend void AutoGCRooter::trace(JSTracer *trc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Value *array;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2013-03-06 10:10:35 -08:00
|
|
|
class AutoAssertNoException
|
2013-01-24 19:18:34 -08:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
JSContext *cx;
|
|
|
|
bool hadException;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2013-03-06 10:10:35 -08:00
|
|
|
AutoAssertNoException(JSContext *cx)
|
2013-01-24 19:18:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
: cx(cx),
|
|
|
|
hadException(cx->isExceptionPending())
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-06 10:10:35 -08:00
|
|
|
~AutoAssertNoException()
|
2013-01-24 19:18:34 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT_IF(!hadException, !cx->isExceptionPending());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-17 10:14:30 -07:00
|
|
|
/*
|
|
|
|
* FIXME bug 647103 - replace these *AllocPolicy names.
|
|
|
|
*/
|
|
|
|
class ContextAllocPolicy
|
|
|
|
{
|
2013-08-29 08:56:05 -07:00
|
|
|
ThreadSafeContext *const cx_;
|
2011-06-17 10:14:30 -07:00
|
|
|
|
|
|
|
public:
|
2013-08-29 08:56:05 -07:00
|
|
|
ContextAllocPolicy(ThreadSafeContext *cx) : cx_(cx) {}
|
|
|
|
ThreadSafeContext *context() const { return cx_; }
|
2013-02-17 22:56:32 -08:00
|
|
|
void *malloc_(size_t bytes) { return cx_->malloc_(bytes); }
|
|
|
|
void *calloc_(size_t bytes) { return cx_->calloc_(bytes); }
|
|
|
|
void *realloc_(void *p, size_t oldBytes, size_t bytes) { return cx_->realloc_(p, oldBytes, bytes); }
|
2012-08-31 15:01:33 -07:00
|
|
|
void free_(void *p) { js_free(p); }
|
2013-02-17 22:56:32 -08:00
|
|
|
void reportAllocOverflow() const { js_ReportAllocationOverflow(cx_); }
|
2011-06-17 10:14:30 -07:00
|
|
|
};
|
|
|
|
|
2013-06-19 17:33:14 -07:00
|
|
|
/* Exposed intrinsics so that Ion may inline them. */
|
2013-08-02 00:41:57 -07:00
|
|
|
bool intrinsic_ToObject(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_IsCallable(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_ThrowError(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_NewDenseArray(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
|
|
|
|
bool intrinsic_UnsafePutElements(JSContext *cx, unsigned argc, Value *vp);
|
2014-04-10 05:07:03 -07:00
|
|
|
bool intrinsic_DefineValueProperty(JSContext *cx, unsigned argc, Value *vp);
|
2013-08-02 00:41:57 -07:00
|
|
|
bool intrinsic_UnsafeSetReservedSlot(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_UnsafeGetReservedSlot(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_HaveSameClass(JSContext *cx, unsigned argc, Value *vp);
|
2013-11-29 08:54:31 -08:00
|
|
|
bool intrinsic_IsPackedArray(JSContext *cx, unsigned argc, Value *vp);
|
2013-08-02 00:41:57 -07:00
|
|
|
|
|
|
|
bool intrinsic_ShouldForceSequential(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_NewParallelArray(JSContext *cx, unsigned argc, Value *vp);
|
2014-02-07 14:40:29 -08:00
|
|
|
bool intrinsic_ForkJoinGetSlice(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_InParallelSection(JSContext *cx, unsigned argc, Value *vp);
|
2013-02-07 11:34:43 -08:00
|
|
|
|
2014-03-21 06:18:09 -07:00
|
|
|
bool intrinsic_ObjectIsTypedObject(JSContext *cx, unsigned argc, Value *vp);
|
2014-02-26 08:57:51 -08:00
|
|
|
bool intrinsic_ObjectIsTransparentTypedObject(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_ObjectIsOpaqueTypedObject(JSContext *cx, unsigned argc, Value *vp);
|
2014-02-28 06:54:44 -08:00
|
|
|
bool intrinsic_ObjectIsTypeDescr(JSContext *cx, unsigned argc, Value *vp);
|
2014-03-21 06:18:09 -07:00
|
|
|
bool intrinsic_TypeDescrIsSimpleType(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_TypeDescrIsArrayType(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_TypeDescrIsUnsizedArrayType(JSContext *cx, unsigned argc, Value *vp);
|
|
|
|
bool intrinsic_TypeDescrIsSizedArrayType(JSContext *cx, unsigned argc, Value *vp);
|
2014-02-26 08:57:51 -08:00
|
|
|
|
2013-11-17 14:33:09 -08:00
|
|
|
class AutoLockForExclusiveAccess
|
|
|
|
{
|
2013-12-19 11:56:27 -08:00
|
|
|
#ifdef JS_THREADSAFE
|
2013-11-17 14:33:09 -08:00
|
|
|
JSRuntime *runtime;
|
|
|
|
|
|
|
|
void init(JSRuntime *rt) {
|
|
|
|
runtime = rt;
|
|
|
|
if (runtime->numExclusiveThreads) {
|
2014-02-05 10:40:35 -08:00
|
|
|
runtime->assertCanLock(ExclusiveAccessLock);
|
2013-11-17 14:33:09 -08:00
|
|
|
PR_Lock(runtime->exclusiveAccessLock);
|
2013-12-16 10:53:02 -08:00
|
|
|
#ifdef DEBUG
|
2013-11-17 14:33:09 -08:00
|
|
|
runtime->exclusiveAccessOwner = PR_GetCurrentThread();
|
2013-12-16 10:53:02 -08:00
|
|
|
#endif
|
2013-11-17 14:33:09 -08:00
|
|
|
} else {
|
|
|
|
JS_ASSERT(!runtime->mainThreadHasExclusiveAccess);
|
|
|
|
runtime->mainThreadHasExclusiveAccess = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoLockForExclusiveAccess(ExclusiveContext *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
init(cx->runtime_);
|
|
|
|
}
|
|
|
|
AutoLockForExclusiveAccess(JSRuntime *rt MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
init(rt);
|
|
|
|
}
|
|
|
|
~AutoLockForExclusiveAccess() {
|
|
|
|
if (runtime->numExclusiveThreads) {
|
|
|
|
JS_ASSERT(runtime->exclusiveAccessOwner == PR_GetCurrentThread());
|
|
|
|
runtime->exclusiveAccessOwner = nullptr;
|
|
|
|
PR_Unlock(runtime->exclusiveAccessLock);
|
|
|
|
} else {
|
|
|
|
JS_ASSERT(runtime->mainThreadHasExclusiveAccess);
|
|
|
|
runtime->mainThreadHasExclusiveAccess = false;
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 11:56:27 -08:00
|
|
|
#else // JS_THREADSAFE
|
2013-11-17 14:33:09 -08:00
|
|
|
public:
|
|
|
|
AutoLockForExclusiveAccess(ExclusiveContext *cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
AutoLockForExclusiveAccess(JSRuntime *rt MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
}
|
|
|
|
~AutoLockForExclusiveAccess() {
|
|
|
|
// An empty destructor is needed to avoid warnings from clang about
|
|
|
|
// unused local variables of this type.
|
|
|
|
}
|
2013-12-19 11:56:27 -08:00
|
|
|
#endif // JS_THREADSAFE
|
2013-11-17 14:33:09 -08:00
|
|
|
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2014-03-09 08:14:49 -07:00
|
|
|
void
|
|
|
|
CrashAtUnhandlableOOM(const char *reason);
|
|
|
|
|
2010-07-14 23:19:36 -07:00
|
|
|
} /* namespace js */
|
|
|
|
|
2010-03-04 20:44:09 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2013-06-19 17:59:46 -07:00
|
|
|
#endif /* jscntxt_h */
|